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

mongodb-js / mongodb-mcp-server / 16292877152

15 Jul 2025 12:10PM UTC coverage: 77.385% (+2.1%) from 75.27%
16292877152

push

github

web-flow
chore(tests): switch to vitest (#363)

498 of 687 branches covered (72.49%)

Branch coverage included in aggregate %.

0 of 27 new or added lines in 2 files covered. (0.0%)

293 existing lines in 26 files now uncovered.

2828 of 3611 relevant lines covered (78.32%)

28.46 hits per line

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

86.11
/src/helpers/EJsonTransport.ts
1
import { JSONRPCMessage, JSONRPCMessageSchema } from "@modelcontextprotocol/sdk/types.js";
1!
2
import { EJSON } from "bson";
1✔
3
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
1✔
4

5
// This is almost a copy of ReadBuffer from @modelcontextprotocol/sdk
6
// but it uses EJSON.parse instead of JSON.parse to handle BSON types
7
export class EJsonReadBuffer {
1✔
8
    private _buffer?: Buffer;
9

10
    append(chunk: Buffer): void {
1✔
11
        this._buffer = this._buffer ? Buffer.concat([this._buffer, chunk]) : chunk;
1!
12
    }
1✔
13

14
    readMessage(): JSONRPCMessage | null {
1✔
15
        if (!this._buffer) {
2!
16
            return null;
×
UNCOV
17
        }
×
18

19
        const index = this._buffer.indexOf("\n");
2✔
20
        if (index === -1) {
2✔
21
            return null;
1✔
22
        }
1✔
23

24
        const line = this._buffer.toString("utf8", 0, index).replace(/\r$/, "");
1✔
25
        this._buffer = this._buffer.subarray(index + 1);
1✔
26

27
        // This is using EJSON.parse instead of JSON.parse to handle BSON types
28
        return JSONRPCMessageSchema.parse(EJSON.parse(line));
1✔
29
    }
2✔
30

31
    clear(): void {
1✔
32
        this._buffer = undefined;
3✔
33
    }
3✔
34
}
1✔
35

36
// This is a hacky workaround for https://github.com/mongodb-js/mongodb-mcp-server/issues/211
37
// The underlying issue is that StdioServerTransport uses JSON.parse to deserialize
38
// messages, but that doesn't handle bson types, such as ObjectId when serialized as EJSON.
39
//
40
// This function creates a StdioServerTransport and replaces the internal readBuffer with EJsonReadBuffer
41
// that uses EJson.parse instead.
42
export function createEJsonTransport(): StdioServerTransport {
1✔
43
    const server = new StdioServerTransport();
3✔
44
    server["_readBuffer"] = new EJsonReadBuffer();
3✔
45

46
    return server;
3✔
47
}
3✔
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

© 2025 Coveralls, Inc