Skip to content

Commit 8445e3b

Browse files
committed
fix: workaround windsurf sometimes skipping the arguments
1 parent 4350cb3 commit 8445e3b

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

src/server.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { mongoLogId } from "mongodb-log-writer";
88
import { ObjectId } from "mongodb";
99
import { Telemetry } from "./telemetry/telemetry.js";
1010
import { UserConfig } from "./config.js";
11+
import { CallToolRequestSchema, CallToolResult } from "@modelcontextprotocol/sdk/types.js";
1112

1213
export interface ServerOptions {
1314
session: Session;
@@ -33,6 +34,15 @@ export class Server {
3334
this.registerTools();
3435
this.registerResources();
3536

37+
const existingHandler = this.mcpServer.server["_requestHandlers"].get(CallToolRequestSchema.shape.method.value);
38+
this.mcpServer.server.setRequestHandler(CallToolRequestSchema, (request, extra): Promise<CallToolResult> => {
39+
if (!request.params.arguments) {
40+
request.params.arguments = {};
41+
}
42+
43+
return existingHandler(request, extra);
44+
});
45+
3646
await initializeLogger(this.mcpServer, this.userConfig.logPath);
3747

3848
await this.mcpServer.connect(transport);

tests/integration/tools/mongodb/metadata/connect.test.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,23 @@ describeWithMongoDB("Connect tool", (integration) => {
1515
},
1616
]);
1717

18+
describe("without arguments", () => {
19+
it("prompts for connection string if not set", async () => {
20+
const response = await integration.mcpClient().callTool({ name: "connect" });
21+
const content = getResponseContent(response.content);
22+
expect(content).toContain("No connection details provided");
23+
});
24+
25+
it("connects to the database if connection string is set", async () => {
26+
config.connectionString = integration.connectionString();
27+
28+
const response = await integration.mcpClient().callTool({ name: "connect" });
29+
const content = getResponseContent(response.content);
30+
expect(content).toContain("Successfully connected");
31+
expect(content).toContain(integration.connectionString());
32+
});
33+
});
34+
1835
describe("with default config", () => {
1936
describe("without connection string", () => {
2037
it("prompts for connection string", async () => {

0 commit comments

Comments
 (0)