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

mongodb-js / mongodb-mcp-server / 14624246692

23 Apr 2025 05:23PM UTC coverage: 75.368% (-3.1%) from 78.42%
14624246692

push

github

web-flow
feat: core telemetry functionality (#87)

Co-authored-by: Filipe Constantinov Menezes <filipe.menezes@mongodb.com>

102 of 187 branches covered (54.55%)

Branch coverage included in aggregate %.

52 of 91 new or added lines in 7 files covered. (57.14%)

26 existing lines in 6 files now uncovered.

614 of 763 relevant lines covered (80.47%)

33.99 hits per line

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

89.29
/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 { ObjectId } from "mongodb";
18✔
9
import { Telemetry } from "./telemetry/telemetry.js";
18✔
10
import { UserConfig } from "./config.js";
11

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

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

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

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

36
        await initializeLogger(this.mcpServer, this.userConfig.logPath);
19✔
37

38
        await this.mcpServer.connect(transport);
19✔
39

40
        this.mcpServer.server.oninitialized = () => {
19✔
41
            this.session.setAgentRunner(this.mcpServer.server.getClientVersion());
19✔
42
            this.session.sessionId = new ObjectId().toString();
19✔
43

44
            logger.info(
19✔
45
                mongoLogId(1_000_004),
46
                "server",
47
                `Server started with transport ${transport.constructor.name} and agent runner ${this.session.agentRunner?.name}`
48
            );
49
        };
50
    }
51

52
    async close(): Promise<void> {
53
        await this.session.close();
19✔
54
        await this.mcpServer.close();
19✔
55
    }
56

57
    private registerTools() {
58
        for (const tool of [...AtlasTools, ...MongoDbTools]) {
19✔
59
            new tool(this.session, this.userConfig, this.telemetry).register(this.mcpServer);
551✔
60
        }
61
    }
62

63
    private registerResources() {
64
        if (this.userConfig.connectionString) {
19!
UNCOV
65
            this.mcpServer.resource(
×
66
                "connection-string",
67
                "config://connection-string",
68
                {
69
                    description: "Preconfigured connection string that will be used as a default in the `connect` tool",
70
                },
71
                (uri) => {
UNCOV
72
                    return {
×
73
                        contents: [
74
                            {
75
                                text: `Preconfigured connection string: ${this.userConfig.connectionString}`,
76
                                uri: uri.href,
77
                            },
78
                        ],
79
                    };
80
                }
81
            );
82
        }
83
    }
84
}
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