• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

mongodb-js / mongodb-mcp-server / 14645678364

24 Apr 2025 03:35PM UTC coverage: 81.974% (+0.1%) from 81.846%
14645678364

Pull #116

github

nirinchev
fix: workaround windsurf sometimes skipping the arguments
Pull Request #116: fix: workaround models not providing arguments when everything is optional

124 of 200 branches covered (62.0%)

Branch coverage included in aggregate %.

11 of 11 new or added lines in 1 file covered. (100.0%)

2 existing lines in 1 file now uncovered.

690 of 793 relevant lines covered (87.01%)

47.69 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

91.43
/src/server.ts
1
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
2
import { Session } from "./session.js";
3
import { Transport } from "@modelcontextprotocol/sdk/shared/transport.js";
4
import { AtlasTools } from "./tools/atlas/tools.js";
31✔
5
import { MongoDbTools } from "./tools/mongodb/tools.js";
31✔
6
import logger, { initializeLogger } from "./logger.js";
31✔
7
import { mongoLogId } from "mongodb-log-writer";
31✔
8
import { ObjectId } from "mongodb";
31✔
9
import { Telemetry } from "./telemetry/telemetry.js";
31✔
10
import { UserConfig } from "./config.js";
11
import { CallToolRequestSchema, CallToolResult } from "@modelcontextprotocol/sdk/types.js";
31✔
12

13
export interface ServerOptions {
14
    session: Session;
15
    userConfig: UserConfig;
16
    mcpServer: McpServer;
17
}
18

19
export class Server {
31✔
20
    public readonly session: Session;
21
    private readonly mcpServer: McpServer;
22
    private readonly telemetry: Telemetry;
23
    private readonly userConfig: UserConfig;
24

25
    constructor({ session, mcpServer, userConfig }: ServerOptions) {
26
        this.session = session;
27✔
27
        this.telemetry = new Telemetry(session);
27✔
28
        this.mcpServer = mcpServer;
27✔
29
        this.userConfig = userConfig;
27✔
30
    }
31

32
    async connect(transport: Transport) {
33
        this.mcpServer.server.registerCapabilities({ logging: {} });
27✔
34
        this.registerTools();
27✔
35
        this.registerResources();
27✔
36

37
        const existingHandler = this.mcpServer.server["_requestHandlers"].get(CallToolRequestSchema.shape.method.value);
27✔
38
        this.mcpServer.server.setRequestHandler(CallToolRequestSchema, (request, extra): Promise<CallToolResult> => {
27✔
39
            if (!request.params.arguments) {
345✔
40
                request.params.arguments = {};
2✔
41
            }
42

43
            return existingHandler(request, extra);
345✔
44
        });
45

46
        await initializeLogger(this.mcpServer, this.userConfig.logPath);
27✔
47

48
        await this.mcpServer.connect(transport);
27✔
49

50
        this.mcpServer.server.oninitialized = () => {
27✔
51
            this.session.setAgentRunner(this.mcpServer.server.getClientVersion());
27✔
52
            this.session.sessionId = new ObjectId().toString();
27✔
53

54
            logger.info(
27✔
55
                mongoLogId(1_000_004),
56
                "server",
57
                `Server started with transport ${transport.constructor.name} and agent runner ${this.session.agentRunner?.name}`
58
            );
59
        };
60
    }
61

62
    async close(): Promise<void> {
63
        await this.session.close();
27✔
64
        await this.mcpServer.close();
27✔
65
    }
66

67
    private registerTools() {
68
        for (const tool of [...AtlasTools, ...MongoDbTools]) {
27✔
69
            new tool(this.session, this.userConfig, this.telemetry).register(this.mcpServer);
810✔
70
        }
71
    }
72

73
    private registerResources() {
74
        if (this.userConfig.connectionString) {
27!
UNCOV
75
            this.mcpServer.resource(
×
76
                "connection-string",
77
                "config://connection-string",
78
                {
79
                    description: "Preconfigured connection string that will be used as a default in the `connect` tool",
80
                },
81
                (uri) => {
UNCOV
82
                    return {
×
83
                        contents: [
84
                            {
85
                                text: `Preconfigured connection string: ${this.userConfig.connectionString}`,
86
                                uri: uri.href,
87
                            },
88
                        ],
89
                    };
90
                }
91
            );
92
        }
93
    }
94
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc