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

mongodb-js / mongodb-mcp-server / 17657973871

11 Sep 2025 09:37PM UTC coverage: 81.59% (+0.4%) from 81.188%
17657973871

Pull #524

github

web-flow
Merge 7617674d0 into d6b84c7bd
Pull Request #524: chore: update smithery dockerfile to be closer to the official one

962 of 1279 branches covered (75.22%)

Branch coverage included in aggregate %.

4866 of 5864 relevant lines covered (82.98%)

46.3 hits per line

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

68.47
/src/resources/common/exportedData.ts
1
import type {
2
    CompleteResourceTemplateCallback,
3
    ListResourcesCallback,
4
    ReadResourceTemplateCallback,
5
} from "@modelcontextprotocol/sdk/server/mcp.js";
6
import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
2✔
7
import type { Server } from "../../server.js";
8
import { LogId } from "../../common/logger.js";
2✔
9
import type { Session } from "../../common/session.js";
10

11
export class ExportedData {
2✔
12
    private readonly name = "exported-data";
2✔
13
    private readonly description = "Data files exported in the current session.";
2✔
14
    private readonly uri = "exported-data://{exportName}";
2✔
15
    private server?: Server;
16

17
    constructor(private readonly session: Session) {}
2✔
18

19
    public register(server: Server): void {
61✔
20
        this.server = server;
61✔
21
        this.server.mcpServer.registerResource(
61✔
22
            this.name,
61✔
23
            new ResourceTemplate(this.uri, {
61✔
24
                /**
25
                 * A few clients have the capability of listing templated
26
                 * resources as well and this callback provides support for that
27
                 * */
28
                list: this.listResourcesCallback,
61✔
29
                /**
30
                 * This is to provide auto completion when user starts typing in
31
                 * value for template variable, in our case, exportName */
32
                complete: {
61✔
33
                    exportName: this.autoCompleteExportName,
61✔
34
                },
61✔
35
            }),
61✔
36
            { description: this.description },
61✔
37
            this.readResourceCallback
61✔
38
        );
61✔
39
        this.session.exportsManager.on("export-available", (uri: string): void => {
61✔
40
            server.sendResourceListChanged();
21✔
41
            server.sendResourceUpdated(uri);
21✔
42
        });
61✔
43
        this.session.exportsManager.on("export-expired", (): void => {
61✔
44
            server.sendResourceListChanged();
×
45
        });
61✔
46
    }
61✔
47

48
    private listResourcesCallback: ListResourcesCallback = () => {
61✔
49
        try {
×
50
            return {
×
51
                resources: this.session.exportsManager.availableExports.map(
×
52
                    ({ exportName, exportTitle, exportURI }) => ({
×
53
                        name: exportName,
×
54
                        description: exportTitle,
×
55
                        uri: exportURI,
×
56
                        mimeType: "application/json",
×
57
                    })
×
58
                ),
×
59
            };
×
60
        } catch (error) {
×
61
            this.session.logger.error({
×
62
                id: LogId.exportedDataListError,
×
63
                context: "Error when listing exported data resources",
×
64
                message: error instanceof Error ? error.message : String(error),
×
65
            });
×
66
            return {
×
67
                resources: [],
×
68
            };
×
69
        }
×
70
    };
×
71

72
    private autoCompleteExportName: CompleteResourceTemplateCallback = (value) => {
61✔
73
        try {
1✔
74
            return this.session.exportsManager.availableExports
1✔
75
                .filter(({ exportName, exportTitle }) => {
1✔
76
                    const lcExportName = exportName.toLowerCase();
2✔
77
                    const lcExportTitle = exportTitle.toLowerCase();
2✔
78
                    const lcValue = value.toLowerCase();
2✔
79
                    return lcExportName.startsWith(lcValue) || lcExportTitle.includes(lcValue);
2✔
80
                })
1✔
81
                .map(({ exportName }) => exportName);
1✔
82
        } catch (error) {
1!
83
            this.session.logger.error({
×
84
                id: LogId.exportedDataAutoCompleteError,
×
85
                context: "Error when autocompleting exported data",
×
86
                message: error instanceof Error ? error.message : String(error),
×
87
            });
×
88
            return [];
×
89
        }
×
90
    };
1✔
91

92
    private readResourceCallback: ReadResourceTemplateCallback = async (url, { exportName }) => {
61✔
93
        try {
3✔
94
            if (typeof exportName !== "string") {
3!
95
                throw new Error("Cannot retrieve exported data, exportName not provided.");
×
96
            }
×
97

98
            const content = await this.session.exportsManager.readExport(exportName);
3✔
99

100
            return {
1✔
101
                contents: [
1✔
102
                    {
1✔
103
                        uri: url.href,
1✔
104
                        text: content,
1✔
105
                        mimeType: "application/json",
1✔
106
                    },
1✔
107
                ],
1✔
108
            };
1✔
109
        } catch (error) {
3✔
110
            return {
2✔
111
                contents: [
2✔
112
                    {
2✔
113
                        uri: url.href,
2✔
114
                        text: `Error reading ${url.href}: ${error instanceof Error ? error.message : String(error)}`,
2!
115
                    },
2✔
116
                ],
2✔
117
                isError: true,
2✔
118
            };
2✔
119
        }
2✔
120
    };
3✔
121
}
2✔
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