1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
import { describe, it, expect } from "bun:test";
import { routeMcpRequest } from "../lib/mcp";
const ctx = { userId: "u1", scopes: ["repo"] };
const tools = {};
const stubResources = {
list: async () => ({
resources: [
{ uri: "gluecron://repo/ccantynz/Vapron", name: "ccantynz/Vapron" },
],
}),
read: async (uri: string) => ({
contents: [{ uri, mimeType: "text/markdown", text: "# hello" }],
}),
};
function rpc(method: string, params?: unknown) {
return { jsonrpc: "2.0" as const, id: 1, method, params };
}
describe("MCP resources capability", () => {
it("initialize advertises resources when a provider is wired", async () => {
const res: any = await routeMcpRequest(rpc("initialize"), {
ctx,
tools,
resources: stubResources,
});
expect(res.result.capabilities.resources).toBeDefined();
expect(res.result.capabilities.tools).toBeDefined();
});
it("initialize omits resources when NO provider is wired", async () => {
const res: any = await routeMcpRequest(rpc("initialize"), { ctx, tools });
expect(res.result.capabilities.resources).toBeUndefined();
});
it("resources/list routes to the provider", async () => {
const res: any = await routeMcpRequest(rpc("resources/list"), {
ctx,
tools,
resources: stubResources,
});
expect(res.result.resources).toHaveLength(1);
expect(res.result.resources[0].uri).toBe("gluecron://repo/ccantynz/Vapron");
});
it("resources/read passes the uri through and returns contents", async () => {
const res: any = await routeMcpRequest(
rpc("resources/read", { uri: "gluecron://repo/ccantynz/Vapron" }),
{ ctx, tools, resources: stubResources }
);
expect(res.result.contents[0].text).toBe("# hello");
});
it("resources/read without a uri is an invalid-params error", async () => {
const res: any = await routeMcpRequest(rpc("resources/read", {}), {
ctx,
tools,
resources: stubResources,
});
expect(res.error).toBeDefined();
expect(res.error.code).toBe(-32602);
});
it("resources/list with no provider returns an empty list (no crash)", async () => {
const res: any = await routeMcpRequest(rpc("resources/list"), { ctx, tools });
expect(res.result.resources).toEqual([]);
});
});
|