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

mongodb-js / mongodb-mcp-server / 16646753322

31 Jul 2025 10:39AM UTC coverage: 80.911%. First build
16646753322

Pull #413

github

web-flow
Merge 235ffcf80 into b24fe5e12
Pull Request #413: chore: Probe of concept for reactive resources based on the session MCP-80

609 of 792 branches covered (76.89%)

Branch coverage included in aggregate %.

133 of 159 new or added lines in 6 files covered. (83.65%)

3265 of 3996 relevant lines covered (81.71%)

52.5 hits per line

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

84.31
/src/resources/resource.ts
1
import { Server } from "../server.js";
2
import { Session } from "../common/session.js";
3
import { UserConfig } from "../common/config.js";
4
import { Telemetry } from "../telemetry/telemetry.js";
5
import type { SessionEvents } from "../common/session.js";
6
import { ReadResourceCallback, ResourceMetadata } from "@modelcontextprotocol/sdk/server/mcp.js";
7

8
type PayloadOf<K extends keyof SessionEvents> = SessionEvents[K][0];
9

10
type ResourceConfiguration = { name: string; uri: string; config: ResourceMetadata };
11

12
export function ReactiveResource<Value, RelevantEvents extends readonly (keyof SessionEvents)[]>(
2✔
13
    { name, uri, config: resourceConfig }: ResourceConfiguration,
124✔
14
    {
124✔
15
        initial,
124✔
16
        events,
124✔
17
    }: {
124✔
18
        initial: Value;
19
        events: RelevantEvents;
20
    }
21
) {
124✔
22
    type SomeEvent = RelevantEvents[number];
23

24
    abstract class NewReactiveResource {
124✔
25
        protected readonly session: Session;
26
        protected readonly config: UserConfig;
27
        protected current: Value;
28

29
        constructor(
124✔
30
            protected readonly server: Server,
138✔
31
            protected readonly telemetry: Telemetry,
138✔
32
            current?: Value
138✔
33
        ) {
138✔
34
            this.current = current ?? initial;
138✔
35
            this.session = server.session;
138✔
36
            this.config = server.userConfig;
138✔
37

38
            for (const event of events) {
138✔
39
                this.session.on(event, (...args: SessionEvents[typeof event]) => {
296✔
40
                    this.reduceApply(event, (args as unknown[])[0] as PayloadOf<typeof event>);
969✔
41
                    this.triggerUpdate();
969✔
42
                });
296✔
43
            }
296✔
44
        }
138✔
45

46
        public register(): void {
124✔
47
            this.server.mcpServer.registerResource(name, uri, resourceConfig, this.resourceCallback);
128✔
48
        }
128✔
49

50
        private resourceCallback: ReadResourceCallback = (uri) => ({
124✔
NEW
51
            contents: [
×
NEW
52
                {
×
NEW
53
                    text: this.toOutput(),
×
NEW
54
                    mimeType: "application/json",
×
NEW
55
                    uri: uri.href,
×
NEW
56
                },
×
NEW
57
            ],
×
NEW
58
        });
×
59

60
        private triggerUpdate() {
124✔
61
            void this.server.mcpServer.server.sendResourceUpdated({ uri });
969✔
62
        }
969✔
63

64
        reduceApply(eventName: SomeEvent, ...event: PayloadOf<SomeEvent>[]): void {
124✔
65
            this.current = this.reduce(eventName, ...event);
977✔
66
        }
977✔
67

68
        protected abstract reduce(eventName: SomeEvent, ...event: PayloadOf<SomeEvent>[]): Value;
69
        abstract toOutput(): string;
70
    }
124✔
71

72
    return NewReactiveResource;
124✔
73
}
124✔
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