@acid-cat/cli 0.16.0 → 0.18.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 +23 -20
- package/conformance/fixture.acidcat.json +8 -6
- package/conformance/server-card.LICENSE +201 -0
- package/conformance/server-card.schema.json +295 -0
- package/dist/catalog.d.ts +2 -2
- package/dist/catalog.js +5 -4
- package/dist/conform/check.d.ts +4 -4
- package/dist/conform/check.js +10 -10
- package/dist/conform/cli.js +5 -5
- package/dist/conform/http.js +5 -5
- package/dist/conform/index.d.ts +4 -4
- package/dist/conform/index.js +1 -1
- package/dist/conform/mcp-stdio.js +1 -1
- package/dist/conform/mcp.d.ts +1 -0
- package/dist/conform/mcp.js +196 -16
- package/dist/conform/poll.js +1 -1
- package/dist/conform/properties.d.ts +1 -1
- package/dist/conform/properties.js +2 -2
- package/dist/conform/server-card.d.ts +5 -0
- package/dist/conform/server-card.js +142 -0
- package/dist/conform/webhook.d.ts +2 -1
- package/dist/conform/webhook.js +25 -6
- package/dist/conform/webmcp.js +5 -5
- package/dist/index.d.ts +1 -1
- package/dist/index.js +2 -2
- package/dist/json/catalog.schema.json.js +5 -5
- package/dist/json/fixture.acidcat.json.js +12 -6
- package/dist/json/package.json.js +1 -1
- package/dist/json/server-card.schema.json.js +281 -0
- package/dist/main.js +10 -10
- package/package.json +7 -5
package/dist/conform/mcp.js
CHANGED
|
@@ -2,12 +2,13 @@ import { isArrayOf, isObject, isStringArray, memberOf, parseJson, readJson } fro
|
|
|
2
2
|
import { Checks, FORBIDDEN_ORIGIN, eventIdsOf, expect, expectEqual, expectOccurrence, fixture, idsOf, sorted, until } from "./check.js";
|
|
3
3
|
import { checkPoll } from "./poll.js";
|
|
4
4
|
import { sseReader } from "./sse.js";
|
|
5
|
+
import { checkServerCard, signingKeysOf } from "./server-card.js";
|
|
5
6
|
import { checkWebhook } from "./webhook.js";
|
|
6
|
-
import { MCP_EVENTS_EXTENSION, MCP_SUBSCRIPTION_ID } from "@acid-cat/spec-ts";
|
|
7
|
+
import { MCP_EVENTS_EXTENSION, MCP_HEADER_MISMATCH, MCP_HEARTBEAT_MAX_MS, MCP_HEARTBEAT_MIN_MS, MCP_PROTOCOL_VERSION_KEY, MCP_SUBSCRIPTION_ID, bundle, encodeMcpHeaderValue, mcpParamHeaders, targetCatalog } from "@acid-cat/spec-ts";
|
|
7
8
|
import { randomUUID } from "node:crypto";
|
|
8
9
|
import { Client, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
|
9
10
|
// src/conform/mcp.ts
|
|
10
|
-
const RULE = "spec/
|
|
11
|
+
const RULE = "spec/surfaces/mcp.md";
|
|
11
12
|
async function mcpClient(url, signal, handshake = false) {
|
|
12
13
|
const client = new Client({
|
|
13
14
|
name: "acid-cat-conform",
|
|
@@ -74,15 +75,153 @@ async function checkMcp(url, options) {
|
|
|
74
75
|
125
|
|
75
76
|
]) }), 400);
|
|
76
77
|
});
|
|
78
|
+
await checkHeaders(checks, url);
|
|
79
|
+
const card = await checkServerCard(checks, url, httpChannel(url));
|
|
77
80
|
await checkEvents(checks, httpChannel(url), {
|
|
78
81
|
transport: "http",
|
|
79
82
|
poll: options.poll,
|
|
80
83
|
webhook: options.webhook !== void 0
|
|
81
84
|
});
|
|
82
|
-
if (options.webhook !== void 0) await checkWebhook(checks, url, options.webhook);
|
|
85
|
+
if (options.webhook !== void 0) await checkWebhook(checks, url, options.webhook, card === void 0 ? [] : signingKeysOf(card));
|
|
83
86
|
if (options.handshake) await checkHandshake(checks, url, options.deadline);
|
|
84
87
|
return checks;
|
|
85
88
|
}
|
|
89
|
+
const mcpCatalog = targetCatalog(fixture, "mcp");
|
|
90
|
+
function inputSchemaOf(method, name) {
|
|
91
|
+
if (typeof name !== "string") return void 0;
|
|
92
|
+
const entries = method === "tools/call" ? mcpCatalog.capabilities : method.startsWith("events/") ? mcpCatalog.events ?? {} : {};
|
|
93
|
+
const input = Object.hasOwn(entries, name) ? entries[name]?.input : void 0;
|
|
94
|
+
return input === void 0 ? void 0 : bundle(input, mcpCatalog.$defs ?? {});
|
|
95
|
+
}
|
|
96
|
+
function mcpRequestHeaders(method, params) {
|
|
97
|
+
return {
|
|
98
|
+
"Mcp-Method": method,
|
|
99
|
+
...typeof params.name === "string" ? { "Mcp-Name": encodeMcpHeaderValue(params.name) } : {},
|
|
100
|
+
...mcpParamHeaders(inputSchemaOf(method, params.name), params.arguments)
|
|
101
|
+
};
|
|
102
|
+
}
|
|
103
|
+
async function checkHeaders(checks, url) {
|
|
104
|
+
const send = (signal, method, params, headers) => fetch(url, {
|
|
105
|
+
method: "POST",
|
|
106
|
+
headers: {
|
|
107
|
+
"Content-Type": "application/json",
|
|
108
|
+
Accept: "application/json, text/event-stream",
|
|
109
|
+
"MCP-Protocol-Version": EVENTS_REVISION,
|
|
110
|
+
...headers
|
|
111
|
+
},
|
|
112
|
+
body: JSON.stringify({
|
|
113
|
+
jsonrpc: "2.0",
|
|
114
|
+
id: `conform-${randomUUID()}`,
|
|
115
|
+
method,
|
|
116
|
+
params: {
|
|
117
|
+
...params,
|
|
118
|
+
_meta: META
|
|
119
|
+
}
|
|
120
|
+
}),
|
|
121
|
+
signal
|
|
122
|
+
});
|
|
123
|
+
const rejected = async (response, what) => {
|
|
124
|
+
expectEqual(response.status, 400, `the status of ${what}`);
|
|
125
|
+
expectEqual(memberOf(memberOf(await readJson(response), "error"), "code"), MCP_HEADER_MISMATCH, `the JSON-RPC error code of ${what}`);
|
|
126
|
+
};
|
|
127
|
+
const accepted = async (response, what) => {
|
|
128
|
+
expectEqual(response.status, 200, `the status of ${what}`);
|
|
129
|
+
if (response.headers.get("Content-Type")?.startsWith("text/event-stream") === true) {
|
|
130
|
+
const reader = sseReader(response);
|
|
131
|
+
try {
|
|
132
|
+
const first = await reader.next();
|
|
133
|
+
expectEqual(memberOf(parseJson(first?.data ?? "null"), "method"), "notifications/events/active", `the first message of ${what}`);
|
|
134
|
+
} finally {
|
|
135
|
+
await reader.cancel();
|
|
136
|
+
}
|
|
137
|
+
return;
|
|
138
|
+
}
|
|
139
|
+
const code = memberOf(memberOf(await readJson(response), "error"), "code");
|
|
140
|
+
expect(code !== MCP_HEADER_MISMATCH, `${what} must not be a header mismatch`);
|
|
141
|
+
};
|
|
142
|
+
const named = (method, name, headers = {}) => ({
|
|
143
|
+
"Mcp-Method": method,
|
|
144
|
+
"Mcp-Name": name,
|
|
145
|
+
...headers
|
|
146
|
+
});
|
|
147
|
+
const echo = {
|
|
148
|
+
name: "fixture.echo",
|
|
149
|
+
arguments: { text: "x" }
|
|
150
|
+
};
|
|
151
|
+
const ticks = {
|
|
152
|
+
name: "fixture.ticks",
|
|
153
|
+
arguments: {
|
|
154
|
+
count: 1,
|
|
155
|
+
key: "k"
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
await checks.run("a request whose Mcp-Method header is not its method gets 400 and HeaderMismatch", `${RULE}#http`, async (signal) => {
|
|
159
|
+
await rejected(await send(signal, "tools/call", echo, named("tools/list", "fixture.echo")), "tools/call with Mcp-Method: tools/list");
|
|
160
|
+
await rejected(await send(signal, "events/stream", ticks, named("events/poll", "fixture.ticks", { "Mcp-Param-Key": "k" })), "events/stream with Mcp-Method: events/poll");
|
|
161
|
+
});
|
|
162
|
+
await checks.run("tools/call and events/stream with no Mcp-Name header, or another name, get 400 and HeaderMismatch", `${RULE}#http`, async (signal) => {
|
|
163
|
+
await rejected(await send(signal, "tools/call", echo, { "Mcp-Method": "tools/call" }), "tools/call with no Mcp-Name");
|
|
164
|
+
await rejected(await send(signal, "tools/call", echo, named("tools/call", "fixture.refuse")), "tools/call with another Mcp-Name");
|
|
165
|
+
await rejected(await send(signal, "events/stream", ticks, {
|
|
166
|
+
"Mcp-Method": "events/stream",
|
|
167
|
+
"Mcp-Param-Key": "k"
|
|
168
|
+
}), "events/stream with no Mcp-Name");
|
|
169
|
+
await rejected(await send(signal, "events/stream", ticks, named("events/stream", "fixture.watch", { "Mcp-Param-Key": "k" })), "events/stream with another Mcp-Name");
|
|
170
|
+
});
|
|
171
|
+
await checks.run("an Mcp-Name header in the base64 form is decoded before the comparison", `${RULE}#http`, async (signal) => {
|
|
172
|
+
const base64 = (text) => `=?base64?${Buffer.from(text).toString("base64")}?=`;
|
|
173
|
+
await accepted(await send(signal, "tools/call", echo, named("tools/call", base64("fixture.echo"))), "tools/call with Mcp-Name in the base64 form");
|
|
174
|
+
await accepted(await send(signal, "events/stream", ticks, named("events/stream", base64("fixture.ticks"), { "Mcp-Param-Key": "k" })), "events/stream with Mcp-Name in the base64 form");
|
|
175
|
+
});
|
|
176
|
+
for (const { kind, method, name, args, absent, header, value, other, base64 } of [{
|
|
177
|
+
kind: "a tool",
|
|
178
|
+
method: "tools/call",
|
|
179
|
+
name: "fixture.switch.set",
|
|
180
|
+
args: { on: true },
|
|
181
|
+
absent: {},
|
|
182
|
+
header: "Mcp-Param-On",
|
|
183
|
+
value: "true",
|
|
184
|
+
other: "false",
|
|
185
|
+
base64: "=?base64?dHJ1ZQ==?="
|
|
186
|
+
}, {
|
|
187
|
+
kind: "an event",
|
|
188
|
+
method: "events/stream",
|
|
189
|
+
name: "fixture.ticks",
|
|
190
|
+
args: {
|
|
191
|
+
count: 1,
|
|
192
|
+
key: "k"
|
|
193
|
+
},
|
|
194
|
+
absent: { count: 1 },
|
|
195
|
+
header: "Mcp-Param-Key",
|
|
196
|
+
value: "k",
|
|
197
|
+
other: "j",
|
|
198
|
+
base64: "=?base64?aw==?="
|
|
199
|
+
}]) await checks.run(`the Mcp-Param header of an annotated argument of ${kind} must agree with the argument, and is not expected for an absent argument`, `${RULE}#http`, async (signal) => {
|
|
200
|
+
const params = {
|
|
201
|
+
name,
|
|
202
|
+
arguments: args
|
|
203
|
+
};
|
|
204
|
+
await rejected(await send(signal, method, params, named(method, name)), `${method} with no ${header}`);
|
|
205
|
+
await rejected(await send(signal, method, params, named(method, name, { [header]: other })), `${method} with another ${header}`);
|
|
206
|
+
await accepted(await send(signal, method, params, named(method, name, { [header]: value })), `${method} with ${header}: ${value}`);
|
|
207
|
+
await accepted(await send(signal, method, params, named(method, name, { [header]: base64 })), `${method} with ${header} in the base64 form`);
|
|
208
|
+
await accepted(await send(signal, method, {
|
|
209
|
+
name,
|
|
210
|
+
arguments: absent
|
|
211
|
+
}, named(method, name)), `${method} with no argument and no ${header}`);
|
|
212
|
+
});
|
|
213
|
+
await checks.run("a header value in the base64 form keeps a leading U+FEFF", `${RULE}#headers`, async (signal) => {
|
|
214
|
+
const header = { "Mcp-Param-Key": "=?base64?77u/aw==?=" };
|
|
215
|
+
await accepted(await send(signal, "events/stream", {
|
|
216
|
+
name: "fixture.ticks",
|
|
217
|
+
arguments: {
|
|
218
|
+
count: 1,
|
|
219
|
+
key: "k"
|
|
220
|
+
}
|
|
221
|
+
}, named("events/stream", "fixture.ticks", header)), "events/stream with key U+FEFF k");
|
|
222
|
+
await rejected(await send(signal, "events/stream", ticks, named("events/stream", "fixture.ticks", header)), "events/stream with key k and the base64 of U+FEFF k");
|
|
223
|
+
});
|
|
224
|
+
}
|
|
86
225
|
const ANCHOR = `${RULE}#earlier-revisions-through-http`;
|
|
87
226
|
async function checkHandshake(checks, url, deadline) {
|
|
88
227
|
const handshakeChecks = new Checks("mcp 2025-11-25", deadline);
|
|
@@ -140,7 +279,7 @@ async function checkTools(checks, mcp) {
|
|
|
140
279
|
await checks.run("the instructions are the description of the catalog", `${RULE}#server`, () => {
|
|
141
280
|
expectEqual(mcp.getInstructions(), fixture.description, "instructions");
|
|
142
281
|
});
|
|
143
|
-
await checks.run("tools/list gives each available capability of the
|
|
282
|
+
await checks.run("tools/list gives each available capability of the target", `${RULE}#tools`, async (signal) => {
|
|
144
283
|
const { tools } = await mcp.listTools(void 0, { signal });
|
|
145
284
|
expectEqual(sorted(tools.map((tool) => tool.name)), idsOf("mcp"), "tools");
|
|
146
285
|
});
|
|
@@ -186,7 +325,7 @@ async function checkTools(checks, mcp) {
|
|
|
186
325
|
const result = await call(signal, "fixture.echo", { text: 1 });
|
|
187
326
|
expectEqual(memberOf(textOf(result), "kind"), "invalid-input", "kind");
|
|
188
327
|
});
|
|
189
|
-
await checks.run("a capability outside the
|
|
328
|
+
await checks.run("a capability outside the target is an unknown tool", `${RULE}#tools`, async (signal) => {
|
|
190
329
|
const error = await call(signal, "fixture.hidden", {}).then(() => void 0, (caught) => caught);
|
|
191
330
|
expect(memberOf(error, "code") === -32602, `expected the JSON-RPC error -32602, got ${JSON.stringify(error)}`);
|
|
192
331
|
});
|
|
@@ -202,7 +341,7 @@ async function checkTools(checks, mcp) {
|
|
|
202
341
|
}
|
|
203
342
|
const EVENTS_REVISION = "2026-07-28";
|
|
204
343
|
const META = {
|
|
205
|
-
|
|
344
|
+
[MCP_PROTOCOL_VERSION_KEY]: EVENTS_REVISION,
|
|
206
345
|
"io.modelcontextprotocol/clientCapabilities": {}
|
|
207
346
|
};
|
|
208
347
|
function httpChannel(url, headers = {}) {
|
|
@@ -212,9 +351,8 @@ function httpChannel(url, headers = {}) {
|
|
|
212
351
|
...headers,
|
|
213
352
|
"Content-Type": "application/json",
|
|
214
353
|
Accept: "application/json, text/event-stream",
|
|
215
|
-
"Mcp-Method": method,
|
|
216
354
|
"MCP-Protocol-Version": EVENTS_REVISION,
|
|
217
|
-
...
|
|
355
|
+
...mcpRequestHeaders(method, params)
|
|
218
356
|
},
|
|
219
357
|
body: JSON.stringify({
|
|
220
358
|
jsonrpc: "2.0",
|
|
@@ -268,6 +406,10 @@ function httpChannel(url, headers = {}) {
|
|
|
268
406
|
}
|
|
269
407
|
};
|
|
270
408
|
}
|
|
409
|
+
function expectHeartbeatGrant(granted, expected) {
|
|
410
|
+
if (expected !== void 0) expectEqual(granted, expected, "the heartbeatMs of notifications/events/active");
|
|
411
|
+
else expect(typeof granted === "number" && Number.isSafeInteger(granted) && granted >= 1, `notifications/events/active must grant a heartbeatMs that is a positive integer, got ${JSON.stringify(granted)}`);
|
|
412
|
+
}
|
|
271
413
|
const subscriptionOf = (message) => memberOf(memberOf(memberOf(message, "params") ?? memberOf(message, "result"), "_meta"), MCP_SUBSCRIPTION_ID);
|
|
272
414
|
const paramsOf = (message) => {
|
|
273
415
|
const params = memberOf(message, "params");
|
|
@@ -324,9 +466,10 @@ async function checkEvents(checks, channel, options) {
|
|
|
324
466
|
return message;
|
|
325
467
|
};
|
|
326
468
|
const occurrence = async (stream, id, name) => expectOccurrence(paramsOf(await notification(stream, id, "notifications/events/event")), name);
|
|
327
|
-
const active = async (stream, id) => {
|
|
328
|
-
const
|
|
329
|
-
expectEqual(
|
|
469
|
+
const active = async (stream, id, heartbeatMs) => {
|
|
470
|
+
const { heartbeatMs: granted, ...rest } = paramsOf(await notification(stream, id, "notifications/events/active"));
|
|
471
|
+
expectEqual(rest, { truncated: false }, "the params of notifications/events/active, without heartbeatMs");
|
|
472
|
+
expectHeartbeatGrant(granted, heartbeatMs);
|
|
330
473
|
};
|
|
331
474
|
const complete = async (stream, id) => {
|
|
332
475
|
const message = await stream.next();
|
|
@@ -342,7 +485,7 @@ async function checkEvents(checks, channel, options) {
|
|
|
342
485
|
expect(isObject(memberOf(extensions, MCP_EVENTS_EXTENSION)), `the capabilities must have the extension ${MCP_EVENTS_EXTENSION}, got ${JSON.stringify(result)}`);
|
|
343
486
|
});
|
|
344
487
|
let delivery = [];
|
|
345
|
-
await checks.run("events/list gives each event of the
|
|
488
|
+
await checks.run("events/list gives each event of the target, with the delivery modes of the server and its schemas", RULE_EVENTS, async (signal) => {
|
|
346
489
|
const result = await resultOf("events/list", {}, signal);
|
|
347
490
|
const entries = result.events;
|
|
348
491
|
if (!isArrayOf(entries, isObject)) throw new Error(`events/list must give a list of events, got ${JSON.stringify(result)}`);
|
|
@@ -366,7 +509,7 @@ async function checkEvents(checks, channel, options) {
|
|
|
366
509
|
});
|
|
367
510
|
for (const [name, params, code, kind] of [
|
|
368
511
|
[
|
|
369
|
-
"events/stream of an event outside the
|
|
512
|
+
"events/stream of an event outside the target is NotFound, with the kind event",
|
|
370
513
|
{
|
|
371
514
|
name: "fixture.secret",
|
|
372
515
|
arguments: {}
|
|
@@ -401,6 +544,16 @@ async function checkEvents(checks, channel, options) {
|
|
|
401
544
|
},
|
|
402
545
|
-32602,
|
|
403
546
|
void 0
|
|
547
|
+
],
|
|
548
|
+
[
|
|
549
|
+
"events/stream with a heartbeatMs that is not a positive integer is the error -32602",
|
|
550
|
+
{
|
|
551
|
+
name: "fixture.ticks",
|
|
552
|
+
arguments: { count: 1 },
|
|
553
|
+
heartbeatMs: 0
|
|
554
|
+
},
|
|
555
|
+
-32602,
|
|
556
|
+
void 0
|
|
404
557
|
]
|
|
405
558
|
]) await checks.run(name, RULE_EVENTS, async (signal) => {
|
|
406
559
|
const stream = await channel.stream(streamId(), params, signal);
|
|
@@ -446,10 +599,12 @@ async function checkEvents(checks, channel, options) {
|
|
|
446
599
|
try {
|
|
447
600
|
await active(stream, id);
|
|
448
601
|
expectEqual((await occurrence(stream, id, "fixture.ticks")).data, { n: 1 }, "data");
|
|
449
|
-
|
|
602
|
+
const { heartbeatMs, ...gap } = paramsOf(await notification(stream, id, "notifications/events/active"));
|
|
603
|
+
expectEqual(gap, {
|
|
450
604
|
truncated: true,
|
|
451
605
|
cursor: "2"
|
|
452
|
-
}, "the params of notifications/events/active before the gap");
|
|
606
|
+
}, "the params of notifications/events/active before the gap, without heartbeatMs");
|
|
607
|
+
expectHeartbeatGrant(heartbeatMs);
|
|
453
608
|
const after = paramsOf(await notification(stream, id, "notifications/events/event"));
|
|
454
609
|
expect(!("truncated" in after), `the params of notifications/events/event must have no truncated, got ${JSON.stringify(after)}`);
|
|
455
610
|
expectEqual(expectOccurrence(after, "fixture.ticks").data, { n: 2 }, "data");
|
|
@@ -459,6 +614,31 @@ async function checkEvents(checks, channel, options) {
|
|
|
459
614
|
await stream.cancel();
|
|
460
615
|
}
|
|
461
616
|
});
|
|
617
|
+
for (const [suggested, granted] of [
|
|
618
|
+
[5, MCP_HEARTBEAT_MIN_MS],
|
|
619
|
+
[999999, MCP_HEARTBEAT_MAX_MS],
|
|
620
|
+
[2500, 2500]
|
|
621
|
+
]) {
|
|
622
|
+
const name = `events/stream with heartbeatMs: ${suggested} grants heartbeatMs: ${granted} on notifications/events/active${granted === MCP_HEARTBEAT_MIN_MS ? ", then sends heartbeats at that interval" : ""}`;
|
|
623
|
+
await checks.run(name, `${RULE}#push`, async (signal) => {
|
|
624
|
+
const id = streamId();
|
|
625
|
+
const stream = await channel.stream(id, {
|
|
626
|
+
name: "fixture.watch",
|
|
627
|
+
arguments: { key: randomUUID() },
|
|
628
|
+
heartbeatMs: suggested
|
|
629
|
+
}, signal);
|
|
630
|
+
try {
|
|
631
|
+
await active(stream, id, granted);
|
|
632
|
+
if (granted !== MCP_HEARTBEAT_MIN_MS) return;
|
|
633
|
+
const started = Date.now();
|
|
634
|
+
expectEqual(paramsOf(await notification(stream, id, "notifications/events/heartbeat")), { cursor: null }, "the params of notifications/events/heartbeat");
|
|
635
|
+
const waited = Date.now() - started;
|
|
636
|
+
expect(waited >= granted / 2 && waited < granted * 3, `the heartbeat must come about ${granted} ms after notifications/events/active, came after ${waited} ms`);
|
|
637
|
+
} finally {
|
|
638
|
+
await stream.cancel();
|
|
639
|
+
}
|
|
640
|
+
});
|
|
641
|
+
}
|
|
462
642
|
await checks.run("events/stream with a cursor starts after it", RULE_EVENTS, async (signal) => {
|
|
463
643
|
const id = streamId();
|
|
464
644
|
const stream = await channel.stream(id, {
|
|
@@ -569,4 +749,4 @@ async function checkEvents(checks, channel, options) {
|
|
|
569
749
|
}
|
|
570
750
|
});
|
|
571
751
|
}
|
|
572
|
-
export { EVENTS_REVISION, META, checkEvents, checkMcp, checkTools, count, eventRequests, httpChannel, mcpClient, subscriptionOf };
|
|
752
|
+
export { EVENTS_REVISION, META, checkEvents, checkMcp, checkTools, count, eventRequests, httpChannel, mcpClient, mcpRequestHeaders, subscriptionOf };
|
package/dist/conform/poll.js
CHANGED
|
@@ -3,7 +3,7 @@ import { expect, expectEqual, expectOccurrence, until } from "./check.js";
|
|
|
3
3
|
import { eventRequests } from "./mcp.js";
|
|
4
4
|
import { randomUUID } from "node:crypto";
|
|
5
5
|
// src/conform/poll.ts
|
|
6
|
-
const RULE = "spec/
|
|
6
|
+
const RULE = "spec/surfaces/mcp.md#poll";
|
|
7
7
|
const MAXIMUM_TICKS = 100;
|
|
8
8
|
const MAXIMUM_EVENTS = 100;
|
|
9
9
|
function pollRequests(channel) {
|
|
@@ -9,4 +9,4 @@ export declare function mcpInvoke(url: string, signal: AbortSignal): Promise<{
|
|
|
9
9
|
close(): Promise<void>;
|
|
10
10
|
}>;
|
|
11
11
|
export declare function clientInvoke(client: Client): Invoke;
|
|
12
|
-
export declare function checkProperties(
|
|
12
|
+
export declare function checkProperties(surface: string, invoke: Invoke, deadline: number): Promise<Checks>;
|
|
@@ -124,8 +124,8 @@ const cancellations = fc.array(fc.boolean(), {
|
|
|
124
124
|
minLength: 2,
|
|
125
125
|
maxLength: 5
|
|
126
126
|
}).filter((flags) => flags.includes(true) && flags.includes(false));
|
|
127
|
-
async function checkProperties(
|
|
128
|
-
const checks = new Checks(`${
|
|
127
|
+
async function checkProperties(surface, invoke, deadline) {
|
|
128
|
+
const checks = new Checks(`${surface} properties`, deadline);
|
|
129
129
|
await checks.run("concurrent calls each get exactly their own outcome", RULE, async (signal) => {
|
|
130
130
|
await fc.assert(fc.asyncProperty(fc.array(operation, {
|
|
131
131
|
minLength: 1,
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { JsonObject } from "../json.js";
|
|
2
|
+
import type { Checks } from "./check.js";
|
|
3
|
+
import type { Channel } from "./mcp.js";
|
|
4
|
+
export declare function signingKeysOf(card: JsonObject): readonly JsonObject[];
|
|
5
|
+
export declare function checkServerCard(checks: Checks, url: string, channel: Channel): Promise<JsonObject | undefined>;
|
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
import { $defs } from "../json/server-card.schema.json.js";
|
|
2
|
+
import { isObject, isStringArray, memberOf, parseJson } from "../json.js";
|
|
3
|
+
import { expect, expectEqual } from "./check.js";
|
|
4
|
+
import { MCP_EVENTS_EXTENSION, MCP_SERVER_CARD_CACHE_CONTROL, MCP_SERVER_CARD_MEDIA_TYPE, MCP_SERVER_CARD_PATH, isCidr } from "@acid-cat/spec-ts";
|
|
5
|
+
import { Result, Schema, SchemaIssue, SchemaRepresentation } from "effect";
|
|
6
|
+
// src/conform/server-card.ts
|
|
7
|
+
const RULE = "spec/surfaces/mcp.md#server-card";
|
|
8
|
+
const decodeCard = (() => {
|
|
9
|
+
const definitions = $defs;
|
|
10
|
+
const schema = SchemaRepresentation.fromJsonSchemaDocument({
|
|
11
|
+
dialect: "draft-2020-12",
|
|
12
|
+
schema: { $ref: "#/$defs/ServerCard" },
|
|
13
|
+
definitions
|
|
14
|
+
}, { patterns: "apply" });
|
|
15
|
+
return Schema.decodeUnknownResult(Schema.toType(schema));
|
|
16
|
+
})();
|
|
17
|
+
const formatIssues = SchemaIssue.makeFormatterStandardSchemaV1();
|
|
18
|
+
const PRIVATE_JWK_MEMBERS = [
|
|
19
|
+
"d",
|
|
20
|
+
"p",
|
|
21
|
+
"q",
|
|
22
|
+
"dp",
|
|
23
|
+
"dq",
|
|
24
|
+
"qi",
|
|
25
|
+
"oth",
|
|
26
|
+
"k"
|
|
27
|
+
];
|
|
28
|
+
const CORS_HEADERS = {
|
|
29
|
+
"Access-Control-Allow-Origin": "*",
|
|
30
|
+
"Access-Control-Allow-Methods": "GET",
|
|
31
|
+
"Access-Control-Allow-Headers": "Content-Type, If-None-Match",
|
|
32
|
+
"Access-Control-Expose-Headers": "ETag",
|
|
33
|
+
"Cache-Control": MCP_SERVER_CARD_CACHE_CONTROL
|
|
34
|
+
};
|
|
35
|
+
function expectHeaders(response, headers) {
|
|
36
|
+
for (const [name, value] of Object.entries(headers)) expectEqual(response.headers.get(name), value, name);
|
|
37
|
+
}
|
|
38
|
+
function signingKeysOf(card) {
|
|
39
|
+
const remotes = card.remotes;
|
|
40
|
+
const remote = Array.isArray(remotes) ? remotes[0] : void 0;
|
|
41
|
+
const webhooks = memberOf(memberOf(memberOf(remote, "extensionsInfo"), MCP_EVENTS_EXTENSION), "webhooks");
|
|
42
|
+
const keys = memberOf(memberOf(webhooks, "signingKeys"), "keys");
|
|
43
|
+
return Array.isArray(keys) ? keys.filter(isObject) : [];
|
|
44
|
+
}
|
|
45
|
+
async function checkServerCard(checks, url, channel) {
|
|
46
|
+
const cardUrl = `${url}${MCP_SERVER_CARD_PATH}`;
|
|
47
|
+
const first = await fetch(cardUrl, {
|
|
48
|
+
headers: { Accept: MCP_SERVER_CARD_MEDIA_TYPE },
|
|
49
|
+
signal: AbortSignal.timeout(checks.deadline)
|
|
50
|
+
}).catch(() => void 0);
|
|
51
|
+
if (first !== void 0 && first.status !== 200) return void 0;
|
|
52
|
+
let card;
|
|
53
|
+
await checks.run("GET of the URL of the server and /server-card gives a card that the JSON Schema of the Server Card extension accepts", RULE, async (signal) => {
|
|
54
|
+
const response = first ?? await fetch(cardUrl, { signal });
|
|
55
|
+
expectEqual(response.status, 200, "status");
|
|
56
|
+
expectEqual(response.headers.get("Content-Type"), MCP_SERVER_CARD_MEDIA_TYPE, "Content-Type");
|
|
57
|
+
const body = parseJson(await response.text());
|
|
58
|
+
const decoded = decodeCard(body);
|
|
59
|
+
if (Result.isFailure(decoded)) {
|
|
60
|
+
const problems = formatIssues(decoded.failure.issue).issues.map((issue) => `${(issue.path ?? []).map((key) => `[${JSON.stringify(key)}]`).join("")}: ${issue.message}`);
|
|
61
|
+
throw new Error(`the JSON Schema of the Server Card extension refuses the card: ${problems.join("; ")}`);
|
|
62
|
+
}
|
|
63
|
+
expect(isObject(body), "the card must be an object");
|
|
64
|
+
card = body;
|
|
65
|
+
});
|
|
66
|
+
if (card === void 0) return void 0;
|
|
67
|
+
const served = card;
|
|
68
|
+
await checks.run("the card has one remote with the URL of the server, the version of server/discover, and the revisions that the server serves", RULE, async (signal) => {
|
|
69
|
+
const remotes = served.remotes;
|
|
70
|
+
expect(Array.isArray(remotes) && remotes.length === 1, `the card must have one remote, got ${JSON.stringify(remotes)}`);
|
|
71
|
+
const remote = remotes[0];
|
|
72
|
+
expectEqual(memberOf(remote, "type"), "streamable-http", "the type of the remote");
|
|
73
|
+
expectEqual(memberOf(remote, "url"), url, "the URL of the remote");
|
|
74
|
+
const discovered = memberOf(await channel.request("server/discover", {}, signal), "result");
|
|
75
|
+
expectEqual(served.version, memberOf(memberOf(memberOf(discovered, "_meta"), "io.modelcontextprotocol/serverInfo"), "version"), "the version of the card and of server/discover");
|
|
76
|
+
const versions = memberOf(remote, "supportedProtocolVersions");
|
|
77
|
+
const discoveredVersions = memberOf(discovered, "supportedVersions");
|
|
78
|
+
expect(isStringArray(versions) && isStringArray(discoveredVersions), `supportedProtocolVersions and supportedVersions must be lists of text, got ${JSON.stringify([versions, discoveredVersions])}`);
|
|
79
|
+
for (const version of discoveredVersions) expect(versions.includes(version), `supportedProtocolVersions must have ${version} of server/discover, got ${JSON.stringify(versions)}`);
|
|
80
|
+
for (const version of versions.filter((each) => !discoveredVersions.includes(each))) {
|
|
81
|
+
const response = await fetch(url, {
|
|
82
|
+
method: "POST",
|
|
83
|
+
headers: { "Content-Type": "application/json" },
|
|
84
|
+
body: JSON.stringify({
|
|
85
|
+
jsonrpc: "2.0",
|
|
86
|
+
id: 1,
|
|
87
|
+
method: "initialize",
|
|
88
|
+
params: {
|
|
89
|
+
protocolVersion: version,
|
|
90
|
+
capabilities: {},
|
|
91
|
+
clientInfo: {
|
|
92
|
+
name: "acid-cat-conform",
|
|
93
|
+
version: "0.1.0"
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}),
|
|
97
|
+
signal
|
|
98
|
+
});
|
|
99
|
+
const result = memberOf(parseJson(await response.text()), "result");
|
|
100
|
+
expectEqual(memberOf(result, "protocolVersion"), version, `the revision that initialize gives for ${version} of supportedProtocolVersions`);
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
await checks.run("the card has the CORS and cache headers and an ETag, If-None-Match with the ETag gets 304 with the same headers and ETag, and OPTIONS gets 204 with no ETag", RULE, async (signal) => {
|
|
104
|
+
const response = await fetch(cardUrl, { signal });
|
|
105
|
+
await response.body?.cancel();
|
|
106
|
+
expectHeaders(response, CORS_HEADERS);
|
|
107
|
+
const etag = response.headers.get("ETag");
|
|
108
|
+
expect(etag !== null && etag !== "", "the card must have an ETag");
|
|
109
|
+
const unchanged = await fetch(cardUrl, {
|
|
110
|
+
headers: { "If-None-Match": etag },
|
|
111
|
+
signal
|
|
112
|
+
});
|
|
113
|
+
expectEqual(unchanged.status, 304, "the status of a GET with If-None-Match");
|
|
114
|
+
expectEqual(await unchanged.text(), "", "the body of a 304");
|
|
115
|
+
expectHeaders(unchanged, {
|
|
116
|
+
...CORS_HEADERS,
|
|
117
|
+
ETag: etag
|
|
118
|
+
});
|
|
119
|
+
const preflight = await fetch(cardUrl, {
|
|
120
|
+
method: "OPTIONS",
|
|
121
|
+
signal
|
|
122
|
+
});
|
|
123
|
+
expectEqual(preflight.status, 204, "the status of OPTIONS");
|
|
124
|
+
expectHeaders(preflight, CORS_HEADERS);
|
|
125
|
+
expectEqual(preflight.headers.get("ETag"), null, "the ETag of OPTIONS");
|
|
126
|
+
});
|
|
127
|
+
await checks.run("the signing keys of the card are public Ed25519 keys with a kid, and its egress ranges are CIDR text", RULE, () => {
|
|
128
|
+
const keys = signingKeysOf(served);
|
|
129
|
+
for (const key of keys) {
|
|
130
|
+
expect(key.kty === "OKP" && key.crv === "Ed25519" && typeof key.kid === "string" && typeof key.x === "string", `a signing key must have kty OKP, crv Ed25519, a kid and x, got ${JSON.stringify(key)}`);
|
|
131
|
+
const secrets = PRIVATE_JWK_MEMBERS.filter((member) => member in key);
|
|
132
|
+
expect(secrets.length === 0, `a signing key of the card must have no private member, got ${secrets.join(", ")}`);
|
|
133
|
+
}
|
|
134
|
+
const remotes = served.remotes;
|
|
135
|
+
const remote = Array.isArray(remotes) ? remotes[0] : void 0;
|
|
136
|
+
const ranges = memberOf(memberOf(memberOf(memberOf(remote, "extensionsInfo"), MCP_EVENTS_EXTENSION), "webhooks"), "egressIpRanges");
|
|
137
|
+
if (ranges === void 0) return;
|
|
138
|
+
expect(isStringArray(ranges) && ranges.every(isCidr), `egressIpRanges must be a list of CIDR text, got ${JSON.stringify(ranges)}`);
|
|
139
|
+
});
|
|
140
|
+
return served;
|
|
141
|
+
}
|
|
142
|
+
export { checkServerCard, signingKeysOf };
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { JsonObject } from "../json.js";
|
|
1
2
|
import { Checks } from "./check.js";
|
|
2
3
|
export interface WebhookSettings {
|
|
3
4
|
/** The principal that the deployment gives to a request with the header `Authorization: Bearer <principal>`. */
|
|
@@ -26,4 +27,4 @@ export interface WebhookSettings {
|
|
|
26
27
|
/** The maximum number of subscriptions of one principal in the deployment. With it, conform tests the limit. */
|
|
27
28
|
readonly maxSubscriptions?: number | undefined;
|
|
28
29
|
}
|
|
29
|
-
export declare function checkWebhook(checks: Checks, url: string, settings: WebhookSettings): Promise<void>;
|
|
30
|
+
export declare function checkWebhook(checks: Checks, url: string, settings: WebhookSettings, signingKeys: readonly JsonObject[]): Promise<void>;
|
package/dist/conform/webhook.js
CHANGED
|
@@ -5,7 +5,7 @@ import { MCP_WEBHOOK_DEFAULTS, isOccurrence, webhookSignature, webhookSubscripti
|
|
|
5
5
|
import { randomBytes, randomUUID } from "node:crypto";
|
|
6
6
|
import { createServer } from "node:https";
|
|
7
7
|
// src/conform/webhook.ts
|
|
8
|
-
const RULE = "spec/
|
|
8
|
+
const RULE = "spec/surfaces/mcp.md#webhook";
|
|
9
9
|
const REFRESH_BEFORE_PRECISION_MS = 1;
|
|
10
10
|
const isVerification = (request) => memberOf(request.body, "type") === "verification";
|
|
11
11
|
async function startReceiver(settings) {
|
|
@@ -67,7 +67,7 @@ function header(request, name) {
|
|
|
67
67
|
expect(typeof value === "string", `the request must have the header ${name}, got ${JSON.stringify(request.headers)}`);
|
|
68
68
|
return value;
|
|
69
69
|
}
|
|
70
|
-
async function
|
|
70
|
+
async function expectSignedWith(signingKeys, request, subscription, secrets, type) {
|
|
71
71
|
expect(header(request, "content-type").startsWith("application/json"), `Content-Type must be application/json, got ${header(request, "content-type")}`);
|
|
72
72
|
const id = header(request, "webhook-id");
|
|
73
73
|
const pattern = type === void 0 ? /^msg_[A-Za-z0-9]+$/ : new RegExp(`^msg_${type}_[A-Za-z0-9]+$`);
|
|
@@ -77,17 +77,35 @@ async function expectSigned(request, subscription, secrets, type) {
|
|
|
77
77
|
expect(/^\d+$/.test(timestampText) && Math.abs(timestamp - Date.now() / 1e3) <= 300, `webhook-timestamp must be the time in seconds, got ${JSON.stringify(timestampText)}`);
|
|
78
78
|
expectEqual(header(request, "x-mcp-subscription-id"), subscription, "X-MCP-Subscription-Id");
|
|
79
79
|
const signatures = header(request, "webhook-signature").split(" ");
|
|
80
|
+
expectEqual(signatures.length, secrets.length + signingKeys.length, `the number of signatures, one v1 for each secret and one v1a for each signing key of the Server Card, in ${JSON.stringify(signatures)}`);
|
|
81
|
+
const symmetric = signatures.slice(0, secrets.length);
|
|
80
82
|
for (const secret of secrets) {
|
|
81
83
|
const expected = await webhookSignature([secret], id, timestamp, request.text);
|
|
82
|
-
expect(
|
|
84
|
+
expect(symmetric.includes(expected), `webhook-signature must start with the v1 signature ${expected} of each secret, got ${JSON.stringify(signatures)}`);
|
|
83
85
|
}
|
|
86
|
+
await expectServerSignatures(signingKeys, signatures.slice(secrets.length), `${id}.${timestamp}.${request.text}`);
|
|
84
87
|
return id;
|
|
85
88
|
}
|
|
89
|
+
async function expectServerSignatures(signingKeys, asymmetric, signed) {
|
|
90
|
+
expect(asymmetric.every((each) => each.startsWith("v1a,")), `the signatures after the v1 signatures must be v1a signatures, got ${JSON.stringify(asymmetric)}`);
|
|
91
|
+
for (const [index, key] of signingKeys.entries()) {
|
|
92
|
+
const x = key.x;
|
|
93
|
+
expect(typeof x === "string", `the signing key ${JSON.stringify(key.kid)} must have x`);
|
|
94
|
+
const publicKey = await crypto.subtle.importKey("jwk", {
|
|
95
|
+
kty: "OKP",
|
|
96
|
+
crv: "Ed25519",
|
|
97
|
+
x
|
|
98
|
+
}, "Ed25519", false, ["verify"]);
|
|
99
|
+
const signature = Buffer.from((asymmetric[index] ?? "").slice(4), "base64");
|
|
100
|
+
const verified = await crypto.subtle.verify("Ed25519", publicKey, signature, new TextEncoder().encode(signed));
|
|
101
|
+
expect(verified, `the v1a signature ${index + 1} must verify with the signing key ${JSON.stringify(key.kid)} of the Server Card`);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
86
104
|
function expectDelivered(request, name) {
|
|
87
105
|
expect(isObject(request.body) && !("truncated" in request.body), `the body must be an occurrence without truncated, got ${request.text}`);
|
|
88
106
|
return expectOccurrence(request.body, name);
|
|
89
107
|
}
|
|
90
|
-
async function checkWebhook(checks, url, settings) {
|
|
108
|
+
async function checkWebhook(checks, url, settings, signingKeys) {
|
|
91
109
|
let receiver;
|
|
92
110
|
try {
|
|
93
111
|
receiver = await startReceiver(settings);
|
|
@@ -98,12 +116,13 @@ async function checkWebhook(checks, url, settings) {
|
|
|
98
116
|
return;
|
|
99
117
|
}
|
|
100
118
|
try {
|
|
101
|
-
await checkWithReceiver(checks, url, settings, receiver);
|
|
119
|
+
await checkWithReceiver(checks, url, settings, receiver, signingKeys);
|
|
102
120
|
} finally {
|
|
103
121
|
await receiver.close();
|
|
104
122
|
}
|
|
105
123
|
}
|
|
106
|
-
async function checkWithReceiver(checks, url, settings, receiver) {
|
|
124
|
+
async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
125
|
+
const expectSigned = (request, subscription, secrets, type) => expectSignedWith(signingKeys, request, subscription, secrets, type);
|
|
107
126
|
const principal = settings.principal;
|
|
108
127
|
const channel = httpChannel(url, { Authorization: `Bearer ${principal}` });
|
|
109
128
|
const anonymous = httpChannel(url);
|
package/dist/conform/webmcp.js
CHANGED
|
@@ -2,7 +2,7 @@ import { isArrayOf, isObject, isStringArray, memberOf, parseJson } from "../json
|
|
|
2
2
|
import { Checks, abortable, expect, expectEqual, fixture, idsOf, sorted, until } from "./check.js";
|
|
3
3
|
import { REFERENCE, visitObjects } from "@acid-cat/spec-ts";
|
|
4
4
|
// src/conform/webmcp.ts
|
|
5
|
-
const RULE = "spec/
|
|
5
|
+
const RULE = "spec/surfaces/webmcp.md";
|
|
6
6
|
const TARGET = "app";
|
|
7
7
|
/** The function uses no imports and no outer variables, because the browser driver sends its source text to the page. */
|
|
8
8
|
function createTestHost() {
|
|
@@ -156,17 +156,17 @@ async function heldKeys(driver, signal) {
|
|
|
156
156
|
}
|
|
157
157
|
async function checkWebMcp(driver, options) {
|
|
158
158
|
const checks = new Checks("webmcp", options.deadline);
|
|
159
|
-
const
|
|
159
|
+
const capabilities = fixture.capabilities;
|
|
160
160
|
const expected = idsOf(TARGET);
|
|
161
|
-
await checks.run("each available capability of the
|
|
161
|
+
await checks.run("each available capability of the target is a tool", `${RULE}#tools`, async (signal) => {
|
|
162
162
|
await until(`the tools are ${expected.join(", ")}`, () => names(driver, signal), (tools) => JSON.stringify(tools) === JSON.stringify(expected), signal);
|
|
163
163
|
});
|
|
164
164
|
await checks.run("a tool has the description and the bundled input schema of its capability", `${RULE}#tools`, async (signal) => {
|
|
165
165
|
for (const tool of await driver.tools(signal)) {
|
|
166
|
-
expectEqual(tool.description,
|
|
166
|
+
expectEqual(tool.description, capabilities[tool.name]?.description, `description of ${tool.name}`);
|
|
167
167
|
const schema = tool.inputSchema;
|
|
168
168
|
expect(isObject(schema), `the input schema of ${tool.name} must be an object`);
|
|
169
|
-
expectSameInputShape(tool.name, schema,
|
|
169
|
+
expectSameInputShape(tool.name, schema, capabilities[tool.name]?.input ?? {});
|
|
170
170
|
expect(isBundled(schema), `the input schema of ${tool.name} must be bundled`);
|
|
171
171
|
}
|
|
172
172
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export { bundle, check,
|
|
1
|
+
export { bundle, check, targetCatalog } from "./catalog.js";
|
|
2
2
|
export type { Catalog, Report } from "./catalog.js";
|
|
3
3
|
export { conform, fixture, serve } from "./conform/index.js";
|
|
4
4
|
export type { Check, ConformOptions, PollSettings, Routes, Served, WebHandler, WebhookSettings } from "./conform/index.js";
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { bundle, check,
|
|
1
|
+
import { bundle, check, targetCatalog } from "./catalog.js";
|
|
2
2
|
import { fixture } from "./conform/check.js";
|
|
3
3
|
import { serve } from "./conform/serve.js";
|
|
4
4
|
import { conform } from "./conform/index.js";
|
|
5
|
-
export { bundle, check, conform, fixture, serve,
|
|
5
|
+
export { bundle, check, conform, fixture, serve, targetCatalog };
|