create-ailk 0.44.0 → 0.46.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +6 -3
- package/component-catalog.json +24 -1
- package/component-catalog.md +6 -5
- package/dist/add-module.d.ts +7 -0
- package/dist/add-module.js +17 -2
- package/dist/apply-design.js +1 -12
- package/dist/lib/env-catalog.js +2 -2
- package/dist/lib/import-mdx.js +10 -2
- package/dist/lib/license-key-files.d.ts +2 -0
- package/dist/lib/license-key-files.js +11 -0
- package/dist/paid-sections.d.ts +19 -0
- package/dist/paid-sections.js +41 -0
- package/dist/programmatic.js +56 -6
- package/dist/seed-workspace.d.ts +1 -1
- package/dist/seed-workspace.js +10 -3
- package/dist/surfaces.js +1 -1
- package/dist/update.d.ts +21 -2
- package/dist/update.js +188 -10
- package/package.json +3 -3
- package/templates/apps/api/.env.example +23 -0
- package/templates/apps/api/CLAUDE.md +17 -7
- package/templates/apps/api/src/lib/__mocks__/prisma.ts +11 -0
- package/templates/apps/mcp/.env.example +14 -3
- package/templates/apps/mcp/CLAUDE.md +47 -24
- package/templates/apps/mcp/src/index.ts +1 -1
- package/templates/apps/web/.env.example +1 -1
- package/templates/apps/web/CLAUDE.md +47 -16
- package/templates/apps/web/app/.well-known/mcp.json/build-manifest.ts +44 -41
- package/templates/apps/web/app/.well-known/mcp.json/route.ts +24 -33
- package/templates/apps/web/app/[locale]/layout.tsx +10 -7
- package/templates/apps/web/app/api/site-status/__tests__/route.test.ts +120 -0
- package/templates/apps/web/app/api/site-status/route.ts +62 -0
- package/templates/apps/web/app/llms.txt/route.ts +3 -3
- package/templates/apps/web/app/openapi.json/__tests__/route.test.ts +21 -4
- package/templates/apps/web/app/openapi.json/route.ts +10 -9
- package/templates/apps/web/app/sitemap.xml/route.ts +3 -3
- package/templates/apps/web/auth.ts +25 -1
- package/templates/apps/web/lib/__tests__/fixtures/mcp-stub-server.ts +245 -0
- package/templates/apps/web/lib/__tests__/mcp-served-tools.test.ts +395 -0
- package/templates/apps/web/lib/__tests__/offerings-pricing.test.ts +112 -0
- package/templates/apps/web/lib/__tests__/pricing-page.test.ts +280 -0
- package/templates/apps/web/lib/__tests__/site-brand.test.ts +5 -6
- package/templates/apps/web/lib/__tests__/site-visibility.test.ts +64 -0
- package/templates/apps/web/lib/__tests__/structured-data.test.tsx +108 -11
- package/templates/apps/web/lib/license-key-store.ts +1 -1
- package/templates/apps/web/lib/mcp-oauth.ts +64 -0
- package/templates/apps/web/lib/mcp-served-tools.ts +231 -0
- package/templates/apps/web/lib/offerings-pricing.ts +30 -6
- package/templates/apps/web/lib/pricing-page.ts +142 -35
- package/templates/apps/web/lib/site-brand.tsx +1 -7
- package/templates/apps/web/lib/site-visibility.ts +45 -0
- package/templates/apps/web/messages/en.json +8 -0
- package/templates/apps/web/middleware.ts +16 -1
- package/templates/apps/web/src/lib/routes.ts +3 -3
- package/versions.json +51 -51
- package/templates/apps/web/app/.well-known/ai-plugin.json/route.ts +0 -93
- package/templates/apps/web/lib/release-scope.ts +0 -47
|
@@ -0,0 +1,245 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A `node:http` stub of the MCP server's anonymous `/mcp` route (#11951 §5),
|
|
3
|
+
* answering the way the SDK's Streamable HTTP transport answered the spec's
|
|
4
|
+
* probe in each mode:
|
|
5
|
+
*
|
|
6
|
+
* - `stateless` — JSON bodies, no session; a bare `tools/list` is accepted.
|
|
7
|
+
* - `stateful` — `text/event-stream` bodies, an `Mcp-Session-Id` on
|
|
8
|
+
* `initialize`, 400 for any other POST without it; `DELETE` with it answers
|
|
9
|
+
* 200, or 400 when it carries a `content-type` (Fastify's empty-JSON-body
|
|
10
|
+
* refusal).
|
|
11
|
+
*
|
|
12
|
+
* Like the server's abuse guard it refuses a `user-agent` other than
|
|
13
|
+
* `MCP_DISCOVERY_USER_AGENT` with `403 {"error":"blocked user agent"}`; like
|
|
14
|
+
* the transport it answers 406 to an `accept` missing either type and 415 to
|
|
15
|
+
* a POST that is not `application/json`. `tools/list` can be served in pages,
|
|
16
|
+
* and `override` can answer any request with a fixed status, a raw body, or
|
|
17
|
+
* no answer at all. `experimental` is put in the `initialize` result's
|
|
18
|
+
* `capabilities`, as the server reports its installed tools (#11978 D4).
|
|
19
|
+
* Every request is recorded. The stub follows the server, never the other
|
|
20
|
+
* way round.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
createServer,
|
|
25
|
+
type IncomingHttpHeaders,
|
|
26
|
+
type IncomingMessage,
|
|
27
|
+
type ServerResponse,
|
|
28
|
+
} from "node:http";
|
|
29
|
+
import type { AddressInfo } from "node:net";
|
|
30
|
+
|
|
31
|
+
import { MCP_DISCOVERY_USER_AGENT } from "../../mcp-served-tools";
|
|
32
|
+
|
|
33
|
+
export interface StubTool {
|
|
34
|
+
name: string;
|
|
35
|
+
description?: string;
|
|
36
|
+
inputSchema: Record<string, unknown>;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
export interface RecordedRequest {
|
|
40
|
+
method: string;
|
|
41
|
+
/** The JSON-RPC `method` and `id`, when the body carried them. */
|
|
42
|
+
rpcMethod?: string;
|
|
43
|
+
rpcId?: unknown;
|
|
44
|
+
params?: Record<string, unknown>;
|
|
45
|
+
headers: IncomingHttpHeaders;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/** What `override` may answer in place of the stub's own reply. */
|
|
49
|
+
export type StubOverride =
|
|
50
|
+
| { status: number; contentType?: string; body?: string }
|
|
51
|
+
| "hang";
|
|
52
|
+
|
|
53
|
+
export interface McpStubOptions {
|
|
54
|
+
mode: "stateless" | "stateful";
|
|
55
|
+
tools: readonly StubTool[];
|
|
56
|
+
/** Serve `tools/list` this many entries a page, `nextCursor` on all but the last. */
|
|
57
|
+
pageSize?: number;
|
|
58
|
+
override?: (request: RecordedRequest) => StubOverride | undefined;
|
|
59
|
+
/** #11978 D4 — the `initialize` result's `capabilities.experimental`. */
|
|
60
|
+
experimental?: Record<string, unknown>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export interface McpStub {
|
|
64
|
+
/** The stub's `/mcp` URL. */
|
|
65
|
+
url: string;
|
|
66
|
+
requests: RecordedRequest[];
|
|
67
|
+
close(): Promise<void>;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const SESSION_ID = "stub-session-1";
|
|
71
|
+
const PROTOCOL_VERSION = "2025-03-26";
|
|
72
|
+
|
|
73
|
+
function readBody(req: IncomingMessage): Promise<string> {
|
|
74
|
+
return new Promise((resolve, reject) => {
|
|
75
|
+
let data = "";
|
|
76
|
+
req.setEncoding("utf8");
|
|
77
|
+
req.on("data", (chunk: string) => {
|
|
78
|
+
data += chunk;
|
|
79
|
+
});
|
|
80
|
+
req.on("end", () => resolve(data));
|
|
81
|
+
req.on("error", reject);
|
|
82
|
+
});
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
function parseRpc(
|
|
86
|
+
raw: string,
|
|
87
|
+
): { id?: unknown; method?: string; params?: Record<string, unknown> } | null {
|
|
88
|
+
try {
|
|
89
|
+
const value: unknown = JSON.parse(raw);
|
|
90
|
+
return typeof value === "object" && value !== null && !Array.isArray(value)
|
|
91
|
+
? (value as { id?: unknown; method?: string; params?: Record<string, unknown> })
|
|
92
|
+
: null;
|
|
93
|
+
} catch {
|
|
94
|
+
return null;
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
export async function startMcpStub(options: McpStubOptions): Promise<McpStub> {
|
|
99
|
+
const requests: RecordedRequest[] = [];
|
|
100
|
+
|
|
101
|
+
function send(
|
|
102
|
+
res: ServerResponse,
|
|
103
|
+
status: number,
|
|
104
|
+
message: unknown,
|
|
105
|
+
extraHeaders: Record<string, string> = {},
|
|
106
|
+
): void {
|
|
107
|
+
if (options.mode === "stateful") {
|
|
108
|
+
res.writeHead(status, { "content-type": "text/event-stream", ...extraHeaders });
|
|
109
|
+
res.end(`event: message\ndata: ${JSON.stringify(message)}\n\n`);
|
|
110
|
+
return;
|
|
111
|
+
}
|
|
112
|
+
res.writeHead(status, { "content-type": "application/json", ...extraHeaders });
|
|
113
|
+
res.end(JSON.stringify(message));
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
function plain(res: ServerResponse, status: number, body = ""): void {
|
|
117
|
+
res.writeHead(status, body ? { "content-type": "application/json" } : {});
|
|
118
|
+
res.end(body);
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
async function handle(req: IncomingMessage, res: ServerResponse): Promise<void> {
|
|
122
|
+
const raw = await readBody(req);
|
|
123
|
+
const rpc = req.method === "POST" ? parseRpc(raw) : null;
|
|
124
|
+
const recorded: RecordedRequest = {
|
|
125
|
+
method: req.method ?? "",
|
|
126
|
+
...(typeof rpc?.method === "string" ? { rpcMethod: rpc.method } : {}),
|
|
127
|
+
...(rpc && "id" in rpc ? { rpcId: rpc.id } : {}),
|
|
128
|
+
...(rpc?.params ? { params: rpc.params } : {}),
|
|
129
|
+
headers: req.headers,
|
|
130
|
+
};
|
|
131
|
+
requests.push(recorded);
|
|
132
|
+
|
|
133
|
+
const forced = options.override?.(recorded);
|
|
134
|
+
if (forced === "hang") return;
|
|
135
|
+
if (forced) {
|
|
136
|
+
res.writeHead(forced.status, forced.contentType ? { "content-type": forced.contentType } : {});
|
|
137
|
+
res.end(forced.body ?? "");
|
|
138
|
+
return;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
if (req.headers["user-agent"] !== MCP_DISCOVERY_USER_AGENT) {
|
|
142
|
+
plain(res, 403, JSON.stringify({ error: "blocked user agent" }));
|
|
143
|
+
return;
|
|
144
|
+
}
|
|
145
|
+
const accept = req.headers["accept"] ?? "";
|
|
146
|
+
if (!accept.includes("application/json") || !accept.includes("text/event-stream")) {
|
|
147
|
+
plain(res, 406);
|
|
148
|
+
return;
|
|
149
|
+
}
|
|
150
|
+
const session = req.headers["mcp-session-id"];
|
|
151
|
+
|
|
152
|
+
if (req.method === "DELETE") {
|
|
153
|
+
if (options.mode !== "stateful" || session !== SESSION_ID) plain(res, 400);
|
|
154
|
+
else if (req.headers["content-type"] !== undefined) plain(res, 400);
|
|
155
|
+
else plain(res, 200);
|
|
156
|
+
return;
|
|
157
|
+
}
|
|
158
|
+
if (req.method !== "POST") {
|
|
159
|
+
plain(res, 405);
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (req.headers["content-type"] !== "application/json") {
|
|
163
|
+
plain(res, 415);
|
|
164
|
+
return;
|
|
165
|
+
}
|
|
166
|
+
if (rpc === null || typeof rpc.method !== "string") {
|
|
167
|
+
plain(res, 400);
|
|
168
|
+
return;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
if (rpc.method === "initialize") {
|
|
172
|
+
send(
|
|
173
|
+
res,
|
|
174
|
+
200,
|
|
175
|
+
{
|
|
176
|
+
jsonrpc: "2.0",
|
|
177
|
+
id: rpc.id,
|
|
178
|
+
result: {
|
|
179
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
180
|
+
capabilities: {
|
|
181
|
+
tools: { listChanged: true },
|
|
182
|
+
...(options.experimental ? { experimental: options.experimental } : {}),
|
|
183
|
+
},
|
|
184
|
+
serverInfo: { name: "mcp-stub", version: "0.0.0" },
|
|
185
|
+
},
|
|
186
|
+
},
|
|
187
|
+
options.mode === "stateful" ? { "mcp-session-id": SESSION_ID } : {},
|
|
188
|
+
);
|
|
189
|
+
return;
|
|
190
|
+
}
|
|
191
|
+
if (options.mode === "stateful" && session !== SESSION_ID) {
|
|
192
|
+
plain(res, 400);
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
if (rpc.method === "notifications/initialized") {
|
|
196
|
+
plain(res, 202);
|
|
197
|
+
return;
|
|
198
|
+
}
|
|
199
|
+
if (rpc.method === "tools/list") {
|
|
200
|
+
const size = options.pageSize ?? options.tools.length;
|
|
201
|
+
const cursor = rpc.params?.["cursor"];
|
|
202
|
+
const start = typeof cursor === "string" ? Number(cursor) : 0;
|
|
203
|
+
const page = options.tools.slice(start, start + size);
|
|
204
|
+
const next = start + size < options.tools.length ? String(start + size) : undefined;
|
|
205
|
+
send(res, 200, {
|
|
206
|
+
jsonrpc: "2.0",
|
|
207
|
+
id: rpc.id,
|
|
208
|
+
result: { tools: page, ...(next ? { nextCursor: next } : {}) },
|
|
209
|
+
});
|
|
210
|
+
return;
|
|
211
|
+
}
|
|
212
|
+
send(res, 200, {
|
|
213
|
+
jsonrpc: "2.0",
|
|
214
|
+
id: rpc.id,
|
|
215
|
+
error: { code: -32601, message: "Method not found" },
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const server = createServer((req, res) => {
|
|
220
|
+
handle(req, res).catch(() => {
|
|
221
|
+
if (!res.headersSent) plain(res, 500);
|
|
222
|
+
});
|
|
223
|
+
});
|
|
224
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
225
|
+
const { port } = server.address() as AddressInfo;
|
|
226
|
+
|
|
227
|
+
return {
|
|
228
|
+
url: `http://127.0.0.1:${port}/mcp`,
|
|
229
|
+
requests,
|
|
230
|
+
close: () =>
|
|
231
|
+
new Promise<void>((resolve) => {
|
|
232
|
+
server.closeAllConnections();
|
|
233
|
+
server.close(() => resolve());
|
|
234
|
+
}),
|
|
235
|
+
};
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/** A URL on a port bound and then closed: every connection is refused. */
|
|
239
|
+
export async function refusedUrl(): Promise<string> {
|
|
240
|
+
const server = createServer();
|
|
241
|
+
await new Promise<void>((resolve) => server.listen(0, "127.0.0.1", resolve));
|
|
242
|
+
const { port } = server.address() as AddressInfo;
|
|
243
|
+
await new Promise<void>((resolve) => server.close(() => resolve()));
|
|
244
|
+
return `http://127.0.0.1:${port}/mcp`;
|
|
245
|
+
}
|
|
@@ -0,0 +1,395 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @jest-environment node
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* `readServedMcpTools` against a `node:http` stub of the MCP server's
|
|
7
|
+
* anonymous `/mcp` route (#11951 spec AC-1, AC-2, §5.2): the four-step
|
|
8
|
+
* exchange in both transport modes, `nextCursor` paging, every failed-read
|
|
9
|
+
* shape resolving `null`, the 60-second shared answer and the user agent.
|
|
10
|
+
* `readMcpServer` (#11978 D3, AC-5 (b)): a refusal told from an outage, and
|
|
11
|
+
* the installed tools the server reports.
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import {
|
|
15
|
+
MCP_DISCOVERY_USER_AGENT,
|
|
16
|
+
MCP_TOOLS_TIMEOUT_MS,
|
|
17
|
+
MCP_TOOLS_TTL_MS,
|
|
18
|
+
__resetServedMcpToolsForTests,
|
|
19
|
+
readMcpServer,
|
|
20
|
+
readServedMcpTools,
|
|
21
|
+
} from "../mcp-served-tools";
|
|
22
|
+
|
|
23
|
+
import {
|
|
24
|
+
refusedUrl,
|
|
25
|
+
startMcpStub,
|
|
26
|
+
type McpStub,
|
|
27
|
+
type McpStubOptions,
|
|
28
|
+
type StubTool,
|
|
29
|
+
} from "./fixtures/mcp-stub-server";
|
|
30
|
+
|
|
31
|
+
const SERVED: readonly StubTool[] = [
|
|
32
|
+
{
|
|
33
|
+
name: "capture_lead",
|
|
34
|
+
description: "Capture a lead.",
|
|
35
|
+
inputSchema: { type: "object", properties: { email: { type: "string" } } },
|
|
36
|
+
},
|
|
37
|
+
{
|
|
38
|
+
name: "zz_not_in_catalog",
|
|
39
|
+
description: "A tool newer than the web's catalog.",
|
|
40
|
+
inputSchema: { type: "object", properties: {} },
|
|
41
|
+
},
|
|
42
|
+
{
|
|
43
|
+
name: "list_pages",
|
|
44
|
+
description: "List pages.",
|
|
45
|
+
inputSchema: { type: "object", properties: {} },
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
const stubs: McpStub[] = [];
|
|
50
|
+
async function stub(options: Partial<McpStubOptions> = {}): Promise<McpStub> {
|
|
51
|
+
const started = await startMcpStub({ mode: "stateless", tools: SERVED, ...options });
|
|
52
|
+
stubs.push(started);
|
|
53
|
+
return started;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
__resetServedMcpToolsForTests();
|
|
58
|
+
});
|
|
59
|
+
|
|
60
|
+
afterEach(async () => {
|
|
61
|
+
jest.restoreAllMocks();
|
|
62
|
+
await Promise.all(stubs.splice(0).map((s) => s.close()));
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
describe("readServedMcpTools — the exchange (AC-1)", () => {
|
|
66
|
+
it.each(["stateless", "stateful"] as const)(
|
|
67
|
+
"%s: returns the served entries in the server's order",
|
|
68
|
+
async (mode) => {
|
|
69
|
+
const server = await stub({ mode });
|
|
70
|
+
expect(await readServedMcpTools(server.url)).toEqual(SERVED);
|
|
71
|
+
},
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
it("stateful: initialize, initialized, tools/list with the session, then DELETE", async () => {
|
|
75
|
+
const server = await stub({ mode: "stateful" });
|
|
76
|
+
await readServedMcpTools(server.url);
|
|
77
|
+
|
|
78
|
+
expect(server.requests.map((r) => [r.method, r.rpcMethod])).toEqual([
|
|
79
|
+
["POST", "initialize"],
|
|
80
|
+
["POST", "notifications/initialized"],
|
|
81
|
+
["POST", "tools/list"],
|
|
82
|
+
["DELETE", undefined],
|
|
83
|
+
]);
|
|
84
|
+
for (const r of server.requests.slice(1)) {
|
|
85
|
+
expect(r.headers["mcp-session-id"]).toBe("stub-session-1");
|
|
86
|
+
expect(r.headers["mcp-protocol-version"]).toBe("2025-03-26");
|
|
87
|
+
}
|
|
88
|
+
expect(server.requests[3]?.headers["content-type"]).toBeUndefined();
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it("stateless: no session header and no DELETE", async () => {
|
|
92
|
+
const server = await stub({ mode: "stateless" });
|
|
93
|
+
await readServedMcpTools(server.url);
|
|
94
|
+
|
|
95
|
+
expect(server.requests.map((r) => r.rpcMethod)).toEqual([
|
|
96
|
+
"initialize",
|
|
97
|
+
"notifications/initialized",
|
|
98
|
+
"tools/list",
|
|
99
|
+
]);
|
|
100
|
+
for (const r of server.requests) {
|
|
101
|
+
expect(r.headers["mcp-session-id"]).toBeUndefined();
|
|
102
|
+
}
|
|
103
|
+
});
|
|
104
|
+
|
|
105
|
+
it.each(["stateless", "stateful"] as const)(
|
|
106
|
+
"%s: follows nextCursor across pages",
|
|
107
|
+
async (mode) => {
|
|
108
|
+
const server = await stub({ mode, pageSize: 2 });
|
|
109
|
+
expect((await readServedMcpTools(server.url))?.map((t) => t.name)).toEqual([
|
|
110
|
+
"capture_lead",
|
|
111
|
+
"zz_not_in_catalog",
|
|
112
|
+
"list_pages",
|
|
113
|
+
]);
|
|
114
|
+
const lists = server.requests.filter((r) => r.rpcMethod === "tools/list");
|
|
115
|
+
expect(lists).toHaveLength(2);
|
|
116
|
+
expect(lists[0]?.params).toEqual({});
|
|
117
|
+
expect(lists[1]?.params).toEqual({ cursor: "2" });
|
|
118
|
+
},
|
|
119
|
+
);
|
|
120
|
+
|
|
121
|
+
it("keeps an entry's description optional", async () => {
|
|
122
|
+
const server = await stub({
|
|
123
|
+
tools: [{ name: "bare", inputSchema: { type: "object" } }],
|
|
124
|
+
});
|
|
125
|
+
expect(await readServedMcpTools(server.url)).toEqual([
|
|
126
|
+
{ name: "bare", inputSchema: { type: "object" } },
|
|
127
|
+
]);
|
|
128
|
+
});
|
|
129
|
+
});
|
|
130
|
+
|
|
131
|
+
describe("readServedMcpTools — a failed read is null, never a rejection (AC-2)", () => {
|
|
132
|
+
async function overriding(
|
|
133
|
+
override: NonNullable<McpStubOptions["override"]>,
|
|
134
|
+
mode: McpStubOptions["mode"] = "stateless",
|
|
135
|
+
): Promise<string> {
|
|
136
|
+
return (await stub({ mode, override })).url;
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
const rpcBody = (id: unknown, result: unknown) =>
|
|
140
|
+
JSON.stringify({ jsonrpc: "2.0", id, result });
|
|
141
|
+
|
|
142
|
+
it("(i) the connection is refused", async () => {
|
|
143
|
+
await expect(readServedMcpTools(await refusedUrl())).resolves.toBeNull();
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
it("(ii) initialize answers 500", async () => {
|
|
147
|
+
const url = await overriding((r) =>
|
|
148
|
+
r.rpcMethod === "initialize" ? { status: 500 } : undefined,
|
|
149
|
+
);
|
|
150
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
151
|
+
});
|
|
152
|
+
|
|
153
|
+
it("(iii) tools/list answers a body that is not JSON", async () => {
|
|
154
|
+
const url = await overriding((r) =>
|
|
155
|
+
r.rpcMethod === "tools/list"
|
|
156
|
+
? { status: 200, contentType: "application/json", body: "<html>oops" }
|
|
157
|
+
: undefined,
|
|
158
|
+
);
|
|
159
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
160
|
+
});
|
|
161
|
+
|
|
162
|
+
it(
|
|
163
|
+
"(iv) the server never answers — bounded by the deadline",
|
|
164
|
+
async () => {
|
|
165
|
+
const url = await overriding(() => "hang");
|
|
166
|
+
const started = Date.now();
|
|
167
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
168
|
+
expect(Date.now() - started).toBeLessThan(MCP_TOOLS_TIMEOUT_MS + 1000);
|
|
169
|
+
},
|
|
170
|
+
MCP_TOOLS_TIMEOUT_MS + 2000,
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
it("stateful: a failed tools/list still ends the session", async () => {
|
|
174
|
+
const server = await stub({
|
|
175
|
+
mode: "stateful",
|
|
176
|
+
override: (r) => (r.rpcMethod === "tools/list" ? { status: 503 } : undefined),
|
|
177
|
+
});
|
|
178
|
+
await expect(readServedMcpTools(server.url)).resolves.toBeNull();
|
|
179
|
+
expect(server.requests.at(-1)?.method).toBe("DELETE");
|
|
180
|
+
expect(server.requests.at(-1)?.headers["mcp-session-id"]).toBe("stub-session-1");
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
it("tools/list answers non-2xx", async () => {
|
|
184
|
+
const url = await overriding((r) =>
|
|
185
|
+
r.rpcMethod === "tools/list" ? { status: 503 } : undefined,
|
|
186
|
+
);
|
|
187
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
188
|
+
});
|
|
189
|
+
|
|
190
|
+
it("tools/list answers a JSON-RPC error", async () => {
|
|
191
|
+
const url = await overriding((r) =>
|
|
192
|
+
r.rpcMethod === "tools/list"
|
|
193
|
+
? {
|
|
194
|
+
status: 200,
|
|
195
|
+
contentType: "application/json",
|
|
196
|
+
body: JSON.stringify({
|
|
197
|
+
jsonrpc: "2.0",
|
|
198
|
+
id: r.rpcId,
|
|
199
|
+
error: { code: -32603, message: "boom" },
|
|
200
|
+
}),
|
|
201
|
+
}
|
|
202
|
+
: undefined,
|
|
203
|
+
);
|
|
204
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
205
|
+
});
|
|
206
|
+
|
|
207
|
+
it("result.tools is not an array", async () => {
|
|
208
|
+
const url = await overriding((r) =>
|
|
209
|
+
r.rpcMethod === "tools/list"
|
|
210
|
+
? { status: 200, contentType: "application/json", body: rpcBody(r.rpcId, { tools: {} }) }
|
|
211
|
+
: undefined,
|
|
212
|
+
);
|
|
213
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
214
|
+
});
|
|
215
|
+
|
|
216
|
+
it("an entry has no string name", async () => {
|
|
217
|
+
const url = await overriding((r) =>
|
|
218
|
+
r.rpcMethod === "tools/list"
|
|
219
|
+
? {
|
|
220
|
+
status: 200,
|
|
221
|
+
contentType: "application/json",
|
|
222
|
+
body: rpcBody(r.rpcId, { tools: [{ name: 7, inputSchema: {} }] }),
|
|
223
|
+
}
|
|
224
|
+
: undefined,
|
|
225
|
+
);
|
|
226
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
227
|
+
});
|
|
228
|
+
|
|
229
|
+
it("an entry has no object inputSchema", async () => {
|
|
230
|
+
const url = await overriding((r) =>
|
|
231
|
+
r.rpcMethod === "tools/list"
|
|
232
|
+
? {
|
|
233
|
+
status: 200,
|
|
234
|
+
contentType: "application/json",
|
|
235
|
+
body: rpcBody(r.rpcId, { tools: [{ name: "x" }] }),
|
|
236
|
+
}
|
|
237
|
+
: undefined,
|
|
238
|
+
);
|
|
239
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("the answer's id does not match the request's", async () => {
|
|
243
|
+
const url = await overriding((r) =>
|
|
244
|
+
r.rpcMethod === "tools/list"
|
|
245
|
+
? {
|
|
246
|
+
status: 200,
|
|
247
|
+
contentType: "application/json",
|
|
248
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 999, result: { tools: [] } }),
|
|
249
|
+
}
|
|
250
|
+
: undefined,
|
|
251
|
+
);
|
|
252
|
+
await expect(readServedMcpTools(url)).resolves.toBeNull();
|
|
253
|
+
});
|
|
254
|
+
|
|
255
|
+
it("a tenth page still carries nextCursor", async () => {
|
|
256
|
+
const many: StubTool[] = Array.from({ length: 11 }, (_, i) => ({
|
|
257
|
+
name: `t${i}`,
|
|
258
|
+
inputSchema: { type: "object" },
|
|
259
|
+
}));
|
|
260
|
+
const server = await stub({ tools: many, pageSize: 1 });
|
|
261
|
+
await expect(readServedMcpTools(server.url)).resolves.toBeNull();
|
|
262
|
+
expect(server.requests.filter((r) => r.rpcMethod === "tools/list")).toHaveLength(10);
|
|
263
|
+
});
|
|
264
|
+
|
|
265
|
+
it("a default user agent is refused by the guard, so the constant is what passes", async () => {
|
|
266
|
+
const server = await stub();
|
|
267
|
+
const res = await fetch(server.url, {
|
|
268
|
+
method: "POST",
|
|
269
|
+
headers: {
|
|
270
|
+
accept: "application/json, text/event-stream",
|
|
271
|
+
"content-type": "application/json",
|
|
272
|
+
},
|
|
273
|
+
body: JSON.stringify({ jsonrpc: "2.0", id: 1, method: "tools/list", params: {} }),
|
|
274
|
+
});
|
|
275
|
+
expect(res.status).toBe(403);
|
|
276
|
+
expect(await readServedMcpTools(server.url)).toEqual(SERVED);
|
|
277
|
+
});
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
describe("readServedMcpTools — sharing and the user agent (§5.2)", () => {
|
|
281
|
+
const handshakes = (s: McpStub) =>
|
|
282
|
+
s.requests.filter((r) => r.rpcMethod === "initialize").length;
|
|
283
|
+
|
|
284
|
+
it("two concurrent calls make one handshake", async () => {
|
|
285
|
+
const server = await stub();
|
|
286
|
+
const [a, b] = await Promise.all([
|
|
287
|
+
readServedMcpTools(server.url),
|
|
288
|
+
readServedMcpTools(server.url),
|
|
289
|
+
]);
|
|
290
|
+
expect(a).toEqual(SERVED);
|
|
291
|
+
expect(b).toEqual(SERVED);
|
|
292
|
+
expect(handshakes(server)).toBe(1);
|
|
293
|
+
});
|
|
294
|
+
|
|
295
|
+
it("a call inside the window makes none; one after it makes a new one", async () => {
|
|
296
|
+
const server = await stub();
|
|
297
|
+
const now = Date.now();
|
|
298
|
+
const clock = jest.spyOn(Date, "now").mockReturnValue(now);
|
|
299
|
+
await readServedMcpTools(server.url);
|
|
300
|
+
clock.mockReturnValue(now + MCP_TOOLS_TTL_MS - 1);
|
|
301
|
+
await readServedMcpTools(server.url);
|
|
302
|
+
expect(handshakes(server)).toBe(1);
|
|
303
|
+
clock.mockReturnValue(now + MCP_TOOLS_TTL_MS);
|
|
304
|
+
await readServedMcpTools(server.url);
|
|
305
|
+
expect(handshakes(server)).toBe(2);
|
|
306
|
+
});
|
|
307
|
+
|
|
308
|
+
it("a failure is shared too, inside the window", async () => {
|
|
309
|
+
const server = await stub({
|
|
310
|
+
override: (r) => (r.rpcMethod === "initialize" ? { status: 500 } : undefined),
|
|
311
|
+
});
|
|
312
|
+
expect(await readServedMcpTools(server.url)).toBeNull();
|
|
313
|
+
expect(await readServedMcpTools(server.url)).toBeNull();
|
|
314
|
+
expect(handshakes(server)).toBe(1);
|
|
315
|
+
});
|
|
316
|
+
|
|
317
|
+
it("a different URL makes its own", async () => {
|
|
318
|
+
const one = await stub();
|
|
319
|
+
const two = await stub({ tools: SERVED.slice(0, 1) });
|
|
320
|
+
expect(await readServedMcpTools(one.url)).toEqual(SERVED);
|
|
321
|
+
expect(await readServedMcpTools(two.url)).toEqual(SERVED.slice(0, 1));
|
|
322
|
+
expect(handshakes(one)).toBe(1);
|
|
323
|
+
expect(handshakes(two)).toBe(1);
|
|
324
|
+
});
|
|
325
|
+
|
|
326
|
+
it("every request carries MCP_DISCOVERY_USER_AGENT, which no built-in guard pattern matches", async () => {
|
|
327
|
+
const server = await stub({ mode: "stateful" });
|
|
328
|
+
await readServedMcpTools(server.url);
|
|
329
|
+
expect(server.requests.length).toBeGreaterThan(0);
|
|
330
|
+
for (const r of server.requests) {
|
|
331
|
+
expect(r.headers["user-agent"]).toBe(MCP_DISCOVERY_USER_AGENT);
|
|
332
|
+
}
|
|
333
|
+
for (const pattern of [/curl\//i, /node-fetch/i, /axios/i, /python-requests/i]) {
|
|
334
|
+
expect(MCP_DISCOVERY_USER_AGENT).not.toMatch(pattern);
|
|
335
|
+
}
|
|
336
|
+
});
|
|
337
|
+
});
|
|
338
|
+
|
|
339
|
+
// #11978 D3, AC-5 (b) — what the site's status report says of its MCP server.
|
|
340
|
+
describe("readMcpServer — the answer the status route reports (#11978 D3)", () => {
|
|
341
|
+
const INSTALLED = ["create_booking", "get_redirect"];
|
|
342
|
+
|
|
343
|
+
it.each(["stateless", "stateful"] as const)(
|
|
344
|
+
"%s: an initialize carrying ailk/installed → answering with the installed names",
|
|
345
|
+
async (mode) => {
|
|
346
|
+
const server = await stub({ mode, experimental: { "ailk/installed": { tools: INSTALLED } } });
|
|
347
|
+
expect(await readMcpServer(server.url)).toEqual({
|
|
348
|
+
state: "answering",
|
|
349
|
+
tools: SERVED,
|
|
350
|
+
installed: INSTALLED,
|
|
351
|
+
});
|
|
352
|
+
__resetServedMcpToolsForTests();
|
|
353
|
+
expect(await readServedMcpTools(server.url)).toEqual(SERVED);
|
|
354
|
+
},
|
|
355
|
+
);
|
|
356
|
+
|
|
357
|
+
it("an initialize without it → installed null", async () => {
|
|
358
|
+
const server = await stub();
|
|
359
|
+
expect(await readMcpServer(server.url)).toEqual({
|
|
360
|
+
state: "answering",
|
|
361
|
+
tools: SERVED,
|
|
362
|
+
installed: null,
|
|
363
|
+
});
|
|
364
|
+
});
|
|
365
|
+
|
|
366
|
+
it.each([
|
|
367
|
+
[{ "ailk/installed": { tools: "create_booking" } }],
|
|
368
|
+
[{ "ailk/installed": { tools: [1] } }],
|
|
369
|
+
[{ "ailk/installed": [] }],
|
|
370
|
+
])("a malformed capability %j → installed null", async (experimental) => {
|
|
371
|
+
const server = await stub({ experimental });
|
|
372
|
+
expect(await readMcpServer(server.url)).toMatchObject({ installed: null });
|
|
373
|
+
});
|
|
374
|
+
|
|
375
|
+
it("initialize answering 404 → refused, and readServedMcpTools null", async () => {
|
|
376
|
+
const server = await stub({ override: (r) => (r.rpcMethod === "initialize" ? { status: 404 } : undefined) });
|
|
377
|
+
expect(await readMcpServer(server.url)).toEqual({ state: "refused" });
|
|
378
|
+
expect(await readServedMcpTools(server.url)).toBeNull();
|
|
379
|
+
});
|
|
380
|
+
|
|
381
|
+
it("initialize answering 500 → unreachable", async () => {
|
|
382
|
+
const server = await stub({ override: (r) => (r.rpcMethod === "initialize" ? { status: 500 } : undefined) });
|
|
383
|
+
expect(await readMcpServer(server.url)).toEqual({ state: "unreachable" });
|
|
384
|
+
expect(await readServedMcpTools(server.url)).toBeNull();
|
|
385
|
+
});
|
|
386
|
+
|
|
387
|
+
it("a tools/list 404 after an answered initialize → unreachable, not refused", async () => {
|
|
388
|
+
const server = await stub({ override: (r) => (r.rpcMethod === "tools/list" ? { status: 404 } : undefined) });
|
|
389
|
+
expect(await readMcpServer(server.url)).toEqual({ state: "unreachable" });
|
|
390
|
+
});
|
|
391
|
+
|
|
392
|
+
it("a refused connection → unreachable", async () => {
|
|
393
|
+
expect(await readMcpServer(await refusedUrl())).toEqual({ state: "unreachable" });
|
|
394
|
+
});
|
|
395
|
+
});
|