Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api-extractor/reports/mongodb-mcp-server.public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,7 @@ export class ConnectionStateConnected implements ConnectionState {
// (undocumented)
connectionStringInfo?: ConnectionStringInfo | undefined;
// (undocumented)
isSearchSupported(logger: LoggerBase): Promise<boolean>;
isSearchSupported(logger?: LoggerBase): Promise<boolean>;
// (undocumented)
serviceProvider: NodeDriverServiceProvider;
// (undocumented)
Expand Down
2 changes: 1 addition & 1 deletion api-extractor/reports/web.public.api.md
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,7 @@ export class ConnectionStateConnected implements ConnectionState {
// (undocumented)
connectionStringInfo?: ConnectionStringInfo | undefined;
// (undocumented)
isSearchSupported(logger: LoggerBase): Promise<boolean>;
isSearchSupported(logger?: LoggerBase): Promise<boolean>;
// (undocumented)
serviceProvider: NodeDriverServiceProvider;
// (undocumented)
Expand Down
6 changes: 3 additions & 3 deletions src/common/connectionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { generateConnectionInfoFromCliArgs, type ConnectionInfo } from "@mongosh
import type { DeviceId } from "../helpers/deviceId.js";
import { type UserConfig } from "./config/userConfig.js";
import { MongoDBError, ErrorCodes } from "./errors.js";
import { type LoggerBase, LogId } from "./logging/index.js";
import { LogId, NullLogger, type LoggerBase } from "./logging/index.js";
import { packageInfo } from "./packageInfo.js";
import { type AppNameComponents, setAppNameParamIfMissing } from "../helpers/connectionOptions.js";
import {
Expand Down Expand Up @@ -59,9 +59,9 @@ export class ConnectionStateConnected implements ConnectionState {

private _isSearchSupported?: boolean;

public async isSearchSupported(logger: LoggerBase): Promise<boolean> {
public async isSearchSupported(logger?: LoggerBase): Promise<boolean> {
if (this._isSearchSupported === undefined) {
this._isSearchSupported = await this.probeSearchCapability(logger);
this._isSearchSupported = await this.probeSearchCapability(logger ?? new NullLogger());
}

return this._isSearchSupported;
Expand Down
13 changes: 12 additions & 1 deletion tests/unit/common/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { MongoServerError } from "mongodb";
import { NodeDriverServiceProvider } from "@mongosh/service-provider-node-driver";
import { Session } from "../../../src/common/session.js";
import { CompositeLogger } from "../../../src/common/logging/index.js";
import { MCPConnectionManager } from "../../../src/common/connectionManager.js";
import { type ConnectionStateConnected, MCPConnectionManager } from "../../../src/common/connectionManager.js";
import { ExportsManager } from "../../../src/common/exportsManager.js";
import { DeviceId } from "../../../src/helpers/deviceId.js";
import { Keychain } from "../../../src/common/keychain.js";
Expand Down Expand Up @@ -193,6 +193,17 @@ describe("Session", () => {
expect(await session.isSearchSupported()).toEqual(true);
expect(getSearchIndexesMock).toHaveBeenCalledTimes(1);
});

it("should allow direct search support checks without a logger", async () => {
getSearchIndexesMock.mockResolvedValue([]);

await session.connectToMongoDB({
connectionString: "mongodb://localhost:27017",
});

const connectionState = session.connectionManager.currentConnectionState as ConnectionStateConnected;
expect(await connectionState.isSearchSupported()).toEqual(true);
});
});

describe("assertSearchSupported", () => {
Expand Down
Loading