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

mongodb-js / mongodb-mcp-server / 14621147270

23 Apr 2025 02:47PM UTC coverage: 75.13% (-3.3%) from 78.42%
14621147270

Pull #87

github

blva
chore: reformat
Pull Request #87: feat: core telemetry functionality

100 of 188 branches covered (53.19%)

Branch coverage included in aggregate %.

51 of 90 new or added lines in 8 files covered. (56.67%)

16 existing lines in 4 files now uncovered.

622 of 773 relevant lines covered (80.47%)

37.2 hits per line

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

88.46
/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";
18✔
5
import { MongoDbTools } from "./tools/mongodb/tools.js";
18✔
6
import logger, { initializeLogger } from "./logger.js";
18✔
7
import { mongoLogId } from "mongodb-log-writer";
18✔
8
import config from "./config.js";
18✔
9
import { ObjectId } from "mongodb";
18✔
10

11
export class Server {
18✔
12
    public readonly session: Session;
13
    private readonly mcpServer: McpServer;
14

15
    constructor({ mcpServer, session }: { mcpServer: McpServer; session: Session }) {
16
        this.mcpServer = mcpServer;
18✔
17
        this.session = session;
18✔
18
    }
19

20
    async connect(transport: Transport) {
21
        this.mcpServer.server.registerCapabilities({ logging: {} });
18✔
22
        this.registerTools();
18✔
23
        this.registerResources();
18✔
24

25
        await initializeLogger(this.mcpServer);
18✔
26

27
        await this.mcpServer.connect(transport);
18✔
28

29
        this.mcpServer.server.oninitialized = () => {
18✔
30
            this.session.setAgentRunner(this.mcpServer.server.getClientVersion());
18✔
31
            this.session.sessionId = new ObjectId().toString();
18✔
32

33
            logger.info(
18✔
34
                mongoLogId(1_000_004),
35
                "server",
36
                `Server started with transport ${transport.constructor.name} and agent runner ${this.session.agentRunner?.name}`
37
            );
38
        };
39
    }
40

41
    async close(): Promise<void> {
42
        await this.session.close();
18✔
43
        await this.mcpServer.close();
18✔
44
    }
45

46
    private registerTools() {
47
        for (const tool of [...AtlasTools, ...MongoDbTools]) {
18✔
48
            new tool(this.session).register(this.mcpServer);
522✔
49
        }
50
    }
51

52
    private registerResources() {
53
        if (config.connectionString) {
18!
UNCOV
54
            this.mcpServer.resource(
×
55
                "connection-string",
56
                "config://connection-string",
57
                {
58
                    description: "Preconfigured connection string that will be used as a default in the `connect` tool",
59
                },
60
                (uri) => {
UNCOV
61
                    return {
×
62
                        contents: [
63
                            {
64
                                text: `Preconfigured connection string: ${config.connectionString}`,
65
                                uri: uri.href,
66
                            },
67
                        ],
68
                    };
69
                }
70
            );
71
        }
72
    }
73
}
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