Skip to content

Commit c14a5d4

Browse files
committed
Tests for mergeCapabilities
1 parent 7ac5a5f commit c14a5d4

File tree

1 file changed

+93
-5
lines changed

1 file changed

+93
-5
lines changed

src/shared/protocol.test.ts

Lines changed: 93 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { Protocol } from "./protocol.js";
2-
import { Transport } from "./transport.js";
1+
import { ZodType, z } from "zod";
32
import {
4-
McpError,
3+
ClientCapabilities,
54
ErrorCode,
5+
McpError,
6+
Notification,
67
Request,
78
Result,
8-
Notification,
9+
ServerCapabilities,
910
} from "../types.js";
10-
import { ZodType, z } from "zod";
11+
import { Protocol, mergeCapabilities } from "./protocol.js";
12+
import { Transport } from "./transport.js";
1113

1214
// Mock Transport class
1315
class MockTransport implements Transport {
@@ -61,3 +63,89 @@ describe("protocol tests", () => {
6163
expect(oncloseMock).toHaveBeenCalled();
6264
});
6365
});
66+
67+
describe("mergeCapabilities", () => {
68+
it("should merge client capabilities", () => {
69+
const base: ClientCapabilities = {
70+
sampling: {},
71+
roots: {
72+
listChanged: true,
73+
},
74+
};
75+
76+
const additional: ClientCapabilities = {
77+
experimental: {
78+
feature: true,
79+
},
80+
roots: {
81+
newProp: true,
82+
},
83+
};
84+
85+
const merged = mergeCapabilities(base, additional);
86+
expect(merged).toEqual({
87+
sampling: {},
88+
roots: {
89+
listChanged: true,
90+
newProp: true,
91+
},
92+
experimental: {
93+
feature: true,
94+
},
95+
});
96+
});
97+
98+
it("should merge server capabilities", () => {
99+
const base: ServerCapabilities = {
100+
logging: {},
101+
prompts: {
102+
listChanged: true,
103+
},
104+
};
105+
106+
const additional: ServerCapabilities = {
107+
resources: {
108+
subscribe: true,
109+
},
110+
prompts: {
111+
newProp: true,
112+
},
113+
};
114+
115+
const merged = mergeCapabilities(base, additional);
116+
expect(merged).toEqual({
117+
logging: {},
118+
prompts: {
119+
listChanged: true,
120+
newProp: true,
121+
},
122+
resources: {
123+
subscribe: true,
124+
},
125+
});
126+
});
127+
128+
it("should override existing values with additional values", () => {
129+
const base: ServerCapabilities = {
130+
prompts: {
131+
listChanged: false,
132+
},
133+
};
134+
135+
const additional: ServerCapabilities = {
136+
prompts: {
137+
listChanged: true,
138+
},
139+
};
140+
141+
const merged = mergeCapabilities(base, additional);
142+
expect(merged.prompts!.listChanged).toBe(true);
143+
});
144+
145+
it("should handle empty objects", () => {
146+
const base = {};
147+
const additional = {};
148+
const merged = mergeCapabilities(base, additional);
149+
expect(merged).toEqual({});
150+
});
151+
});

0 commit comments

Comments
 (0)