@acid-cat/cli 0.24.0 → 0.25.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 +13 -3
- package/conformance/fixture.acidcat.json +20 -1
- package/conformance/mcp-skills/fixture-guide/SKILL.md +13 -0
- package/conformance/mcp-skills/fixture-guide/assets/sample.bin +0 -0
- package/conformance/mcp-skills/fixture-guide/references/notes.txt +2 -0
- package/conformance/mcp-skills/fixture-other/SKILL.md +8 -0
- package/dist/{conform-LH9KgQ9-.js → conform-CnopVX0Y.js} +358 -112
- package/dist/index.d.ts +14 -1
- package/dist/index.js +2 -2
- package/dist/main.js +2 -2
- package/package.json +5 -3
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { canonicalText } from "@acid-cat/catalog";
|
|
2
|
-
import { CALL_FAILURE_KINDS, MCP_EVENTS_EXTENSION, MCP_HEADER_MISMATCH, MCP_HEARTBEAT_MAX_MS, MCP_HEARTBEAT_MIN_MS, MCP_PROTOCOL_VERSION_KEY, MCP_SERVER_CARD_CACHE_CONTROL, MCP_SERVER_CARD_MEDIA_TYPE, MCP_SERVER_CARD_PATH, MCP_SUBSCRIPTION_ID, MCP_WEBHOOK_DEFAULTS, REFERENCE, bundle, bundle as bundle$1, cliAliases, encodeMcpHeaderValue, eventSchemasOf, isCidr, isOccurrence, mcpHeaderErrors, mcpParamHeaders, resolveType, schemasOf, targetCatalog, targetCatalog as targetCatalog$1, visitObjects, webhookSignature, webhookSubscriptionId } from "@acid-cat/spec-ts";
|
|
2
|
+
import { CALL_FAILURE_KINDS, MCP_EVENTS_EXTENSION, MCP_HEADER_MISMATCH, MCP_HEARTBEAT_MAX_MS, MCP_HEARTBEAT_MIN_MS, MCP_PROTOCOL_VERSION_KEY, MCP_SERVER_CARD_CACHE_CONTROL, MCP_SERVER_CARD_MEDIA_TYPE, MCP_SERVER_CARD_PATH, MCP_SKILLS_EXTENSION, MCP_SKILL_FILE, MCP_SUBSCRIPTION_ID, MCP_WEBHOOK_DEFAULTS, REFERENCE, bundle, bundle as bundle$1, byCodePoint, cliAliases, encodeMcpHeaderValue, eventSchemasOf, isCidr, isOccurrence, mcpHeaderErrors, mcpNameParam, mcpOptionsErrors, mcpParamHeaders, mcpResourceNotFound, mcpSkillMediaType, mcpSkillUri, mcpTargetSkills, resolveType, schemasOf, targetCatalog, targetCatalog as targetCatalog$1, visitObjects, webhookSignature, webhookSubscriptionId } from "@acid-cat/spec-ts";
|
|
3
3
|
import { Result, Schema, SchemaIssue, SchemaRepresentation } from "effect";
|
|
4
4
|
import { availableParallelism, tmpdir } from "node:os";
|
|
5
5
|
import { setTimeout as setTimeout$1 } from "node:timers/promises";
|
|
@@ -8,7 +8,7 @@ import { existsSync } from "node:fs";
|
|
|
8
8
|
import { mkdtemp, rm } from "node:fs/promises";
|
|
9
9
|
import { join } from "node:path";
|
|
10
10
|
import { isDeepStrictEqual } from "node:util";
|
|
11
|
-
import { randomBytes, randomUUID } from "node:crypto";
|
|
11
|
+
import { createHash, randomBytes, randomUUID } from "node:crypto";
|
|
12
12
|
import { Client, SdkError, StreamableHTTPClientTransport } from "@modelcontextprotocol/client";
|
|
13
13
|
import { createServer } from "node:https";
|
|
14
14
|
import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
|
|
@@ -88,7 +88,10 @@ var catalog_schema_default = {
|
|
|
88
88
|
"description": { "type": "string" },
|
|
89
89
|
"options": {
|
|
90
90
|
"type": "object",
|
|
91
|
-
"properties": {
|
|
91
|
+
"properties": {
|
|
92
|
+
"cli": { "$ref": "#/$defs/cliOptions" },
|
|
93
|
+
"mcp": { "$ref": "#/$defs/mcpOptions" }
|
|
94
|
+
}
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
},
|
|
@@ -122,6 +125,21 @@ var catalog_schema_default = {
|
|
|
122
125
|
}
|
|
123
126
|
}
|
|
124
127
|
},
|
|
128
|
+
"mcpOptions": {
|
|
129
|
+
"description": "The settings of the MCP surface. See spec/surfaces/mcp.md#skills-of-a-target.",
|
|
130
|
+
"type": "object",
|
|
131
|
+
"properties": { "skills": {
|
|
132
|
+
"description": "The names of the skills that the MCP surface of the target serves.",
|
|
133
|
+
"type": "array",
|
|
134
|
+
"uniqueItems": true,
|
|
135
|
+
"items": {
|
|
136
|
+
"type": "string",
|
|
137
|
+
"minLength": 1,
|
|
138
|
+
"maxLength": 64,
|
|
139
|
+
"pattern": "^[a-z0-9]+(-[a-z0-9]+)*$"
|
|
140
|
+
}
|
|
141
|
+
} }
|
|
142
|
+
},
|
|
125
143
|
"schema": {
|
|
126
144
|
"description": "A JSON Schema 2020-12 schema in object form. A catalog does not use the boolean schemas true and false. Its $refs point into the catalog's $defs.",
|
|
127
145
|
"type": "object"
|
|
@@ -232,7 +250,8 @@ const KNOWN_MEMBERS = {
|
|
|
232
250
|
"input",
|
|
233
251
|
"payload"
|
|
234
252
|
],
|
|
235
|
-
cliOptions: ["aliases", "default"]
|
|
253
|
+
cliOptions: ["aliases", "default"],
|
|
254
|
+
mcpOptions: ["skills"]
|
|
236
255
|
};
|
|
237
256
|
const optional = (object, key, isMember) => !Object.hasOwn(object, key) || isMember(object[key]);
|
|
238
257
|
const isString = (value) => typeof value === "string";
|
|
@@ -292,7 +311,7 @@ function ruleErrors(catalog) {
|
|
|
292
311
|
if (member === "input" && references.length === 0) errors.push(...mcpHeaderErrors(bundle(schema, types)).map((error) => `${id} input: ${error}`));
|
|
293
312
|
}
|
|
294
313
|
}
|
|
295
|
-
for (const target of Object.
|
|
314
|
+
for (const [name, target] of Object.entries(catalog.targets)) errors.push(...cliAliases(catalog, name).errors, ...mcpOptionsErrors(name, target));
|
|
296
315
|
return errors;
|
|
297
316
|
}
|
|
298
317
|
function catalogSchemas(catalog) {
|
|
@@ -310,7 +329,11 @@ function unknownMembers(catalog) {
|
|
|
310
329
|
const unknown = (where, value, known) => Object.keys(value).filter((key) => !known.includes(key) && !key.startsWith("x-")).map((key) => `${where}: unknown member ${key}; give extensions an x- prefix`);
|
|
311
330
|
return [
|
|
312
331
|
...unknown("the catalog", catalog, KNOWN_MEMBERS.catalog),
|
|
313
|
-
...Object.entries(catalog.targets).flatMap(([name, target]) => [
|
|
332
|
+
...Object.entries(catalog.targets).flatMap(([name, target]) => [
|
|
333
|
+
...unknown(`target ${name}`, target, KNOWN_MEMBERS.target),
|
|
334
|
+
...isObject(target.options) && isObject(target.options.cli) ? unknown(`target ${name} options.cli`, target.options.cli, KNOWN_MEMBERS.cliOptions) : [],
|
|
335
|
+
...isObject(target.options) && isObject(target.options.mcp) ? unknown(`target ${name} options.mcp`, target.options.mcp, KNOWN_MEMBERS.mcpOptions) : []
|
|
336
|
+
]),
|
|
314
337
|
...Object.entries(catalog.capabilities).flatMap(([id, capability]) => unknown(id, capability, KNOWN_MEMBERS.capability)),
|
|
315
338
|
...Object.entries(catalog.events ?? {}).flatMap(([id, event]) => unknown(id, event, KNOWN_MEMBERS.event))
|
|
316
339
|
];
|
|
@@ -419,7 +442,14 @@ const fixture = {
|
|
|
419
442
|
"default": "quick"
|
|
420
443
|
} }
|
|
421
444
|
},
|
|
422
|
-
"mcp": {
|
|
445
|
+
"mcp": {
|
|
446
|
+
"surfaces": ["mcp"],
|
|
447
|
+
"options": { "mcp": { "skills": ["fixture-guide"] } }
|
|
448
|
+
},
|
|
449
|
+
"mcp-other": {
|
|
450
|
+
"surfaces": ["mcp"],
|
|
451
|
+
"options": { "mcp": { "skills": ["fixture-other"] } }
|
|
452
|
+
}
|
|
423
453
|
},
|
|
424
454
|
$defs: { "Note": {
|
|
425
455
|
"properties": {
|
|
@@ -973,7 +1003,7 @@ function expectEqual(actual, expected, what) {
|
|
|
973
1003
|
const sorted = (values) => [...values].sort();
|
|
974
1004
|
const FORBIDDEN_ORIGIN = "https://not-allowed.acid-cat.invalid";
|
|
975
1005
|
// src/conform/cli.ts
|
|
976
|
-
const RULE$
|
|
1006
|
+
const RULE$9 = "spec/surfaces/cli.md";
|
|
977
1007
|
const USAGES = {
|
|
978
1008
|
"fixture.crash": "fixture crash",
|
|
979
1009
|
"fixture.document": "fixture document --text <string>",
|
|
@@ -1025,15 +1055,15 @@ const EVENT_ALIAS_USAGES = {
|
|
|
1025
1055
|
"fixture.echoes": ["echoes '<json>' [--cursor <string>] [--max-age-ms <integer>]"],
|
|
1026
1056
|
"fixture.ticks": ["ticks [--gap <integer>] [--key <string>] [--cursor <string>] [--max-age-ms <integer>]", "ticks-to <count> [--gap <integer>] [--key <string>] [--cursor <string>] [--max-age-ms <integer>]"]
|
|
1027
1057
|
};
|
|
1028
|
-
const ALIASES = `${RULE$
|
|
1029
|
-
const DOCUMENTS = `${RULE$
|
|
1030
|
-
const STANDARD_INPUT = `${RULE$
|
|
1058
|
+
const ALIASES = `${RULE$9}#aliases`;
|
|
1059
|
+
const DOCUMENTS = `${RULE$9}#documents`;
|
|
1060
|
+
const STANDARD_INPUT = `${RULE$9}#standard-input`;
|
|
1031
1061
|
const DOCUMENT = "a \"quote\", a \\ backslash,\na second line: été, 日本";
|
|
1032
|
-
const POSITIONAL_ARGUMENTS = `${RULE$
|
|
1033
|
-
const isEntry$
|
|
1062
|
+
const POSITIONAL_ARGUMENTS = `${RULE$9}#positional-arguments`;
|
|
1063
|
+
const isEntry$2 = (value) => isObject(value) && typeof value.id === "string";
|
|
1034
1064
|
function entriesOf$1(stdout) {
|
|
1035
1065
|
const list = parseJson(stdout);
|
|
1036
|
-
if (!isArrayOf(list, isEntry$
|
|
1066
|
+
if (!isArrayOf(list, isEntry$2)) throw new Error(`list must give a list of objects with an id, got ${JSON.stringify(list)}`);
|
|
1037
1067
|
return list;
|
|
1038
1068
|
}
|
|
1039
1069
|
/**
|
|
@@ -1091,12 +1121,12 @@ async function checkCli(command, options) {
|
|
|
1091
1121
|
listing.catch(() => void 0);
|
|
1092
1122
|
const listed = (signal) => abortable(listing, signal);
|
|
1093
1123
|
await checks.concurrently((check) => {
|
|
1094
|
-
check("a value goes to standard output with exit code 0", `${RULE$
|
|
1124
|
+
check("a value goes to standard output with exit code 0", `${RULE$9}#outcomes`, async (signal) => {
|
|
1095
1125
|
const result = await run(signal, "fixture", "echo", "--text", "hello");
|
|
1096
1126
|
expectEqual(result.code, 0, "exit code");
|
|
1097
1127
|
expectEqual(parseJson(result.stdout), { text: "hello" }, "standard output");
|
|
1098
1128
|
});
|
|
1099
|
-
check("a value of a capability with no output schema writes nothing, with exit code 0", `${RULE$
|
|
1129
|
+
check("a value of a capability with no output schema writes nothing, with exit code 0", `${RULE$9}#outcomes`, async (signal) => {
|
|
1100
1130
|
for (const result of await Promise.all([
|
|
1101
1131
|
[
|
|
1102
1132
|
"fixture",
|
|
@@ -1144,12 +1174,12 @@ async function checkCli(command, options) {
|
|
|
1144
1174
|
check("list gives the media type of a capability whose output schema is a document, and only of it", DOCUMENTS, async (signal) => {
|
|
1145
1175
|
for (const { id, mediaType } of await listed(signal)) expectEqual(mediaType, id === "fixture.document" ? "text/plain" : void 0, `the media type of ${id}`);
|
|
1146
1176
|
});
|
|
1147
|
-
check("a failure goes to standard output with exit code 1", `${RULE$
|
|
1177
|
+
check("a failure goes to standard output with exit code 1", `${RULE$9}#outcomes`, async (signal) => {
|
|
1148
1178
|
const result = await run(signal, "fixture", "refuse");
|
|
1149
1179
|
expectEqual(result.code, 1, "exit code");
|
|
1150
1180
|
expectEqual(memberOf(parseJson(result.stdout), "_tag"), "Refused", "_tag");
|
|
1151
1181
|
});
|
|
1152
|
-
check("a defect goes to standard error with exit code 5", `${RULE$
|
|
1182
|
+
check("a defect goes to standard error with exit code 5", `${RULE$9}#outcomes`, async (signal) => {
|
|
1153
1183
|
const result = await run(signal, "fixture", "crash");
|
|
1154
1184
|
expectEqual(result.code, 5, "exit code");
|
|
1155
1185
|
expect(/"kind":"internal"/.test(result.stderr), "standard error must contain the call failure");
|
|
@@ -1276,11 +1306,11 @@ async function checkCli(command, options) {
|
|
|
1276
1306
|
],
|
|
1277
1307
|
3
|
|
1278
1308
|
]
|
|
1279
|
-
]) check(name, `${RULE$
|
|
1309
|
+
]) check(name, `${RULE$9}#outcomes`, async (signal) => {
|
|
1280
1310
|
await expectUsageError(run(signal, ...args), code);
|
|
1281
1311
|
});
|
|
1282
1312
|
});
|
|
1283
|
-
await checks.run("an interrupt cancels the call with exit code 130", `${RULE$
|
|
1313
|
+
await checks.run("an interrupt cancels the call with exit code 130", `${RULE$9}#commands`, async (signal) => {
|
|
1284
1314
|
const directory = await mkdtemp(join(tmpdir(), "acid-cat-conform-"));
|
|
1285
1315
|
const marker = join(directory, "held");
|
|
1286
1316
|
try {
|
|
@@ -1309,7 +1339,7 @@ async function checkCli(command, options) {
|
|
|
1309
1339
|
}
|
|
1310
1340
|
});
|
|
1311
1341
|
await checks.concurrently((check) => {
|
|
1312
|
-
check("each flag gives the value of its property, and a repeated flag gives one item for each occurrence", `${RULE$
|
|
1342
|
+
check("each flag gives the value of its property, and a repeated flag gives one item for each occurrence", `${RULE$9}#commands`, async (signal) => {
|
|
1313
1343
|
const scalars = [
|
|
1314
1344
|
"--mode",
|
|
1315
1345
|
"slow",
|
|
@@ -1346,7 +1376,7 @@ async function checkCli(command, options) {
|
|
|
1346
1376
|
const output = parseJson(result.stdout);
|
|
1347
1377
|
expect(isDeepStrictEqual(output, expected), `standard output: expected ${JSON.stringify(expected)}, got ${JSON.stringify(output)}`);
|
|
1348
1378
|
});
|
|
1349
|
-
check("a repeated flag that occurs once with JSON text of an array gives that array", `${RULE$
|
|
1379
|
+
check("a repeated flag that occurs once with JSON text of an array gives that array", `${RULE$9}#commands`, async (signal) => {
|
|
1350
1380
|
const result = await run(signal, "fixture", "flags", "--steps", "[2,1]", "--mode", "fast", "--verbose", "--tags=[\"a\",\"b\"]");
|
|
1351
1381
|
expectEqual(result.code, 0, "exit code");
|
|
1352
1382
|
const expected = {
|
|
@@ -1358,22 +1388,22 @@ async function checkCli(command, options) {
|
|
|
1358
1388
|
const output = parseJson(result.stdout);
|
|
1359
1389
|
expect(isDeepStrictEqual(output, expected), `standard output: expected ${JSON.stringify(expected)}, got ${JSON.stringify(output)}`);
|
|
1360
1390
|
});
|
|
1361
|
-
check("a flag takes the next argument as its value, also when it starts with -", `${RULE$
|
|
1391
|
+
check("a flag takes the next argument as its value, also when it starts with -", `${RULE$9}#commands`, async (signal) => {
|
|
1362
1392
|
const result = await run(signal, "fixture", "echo", "--text", "-x");
|
|
1363
1393
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
1364
1394
|
expectEqual(parseJson(result.stdout), { text: "-x" }, "standard output");
|
|
1365
1395
|
});
|
|
1366
|
-
check("a first argument -- is ignored", `${RULE$
|
|
1396
|
+
check("a first argument -- is ignored", `${RULE$9}#commands`, async (signal) => {
|
|
1367
1397
|
const result = await run(signal, "--", "fixture", "echo", "--text", "hello");
|
|
1368
1398
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
1369
1399
|
expectEqual(parseJson(result.stdout), { text: "hello" }, "standard output");
|
|
1370
1400
|
});
|
|
1371
|
-
check("call gives the value of a capability", `${RULE$
|
|
1401
|
+
check("call gives the value of a capability", `${RULE$9}#commands`, async (signal) => {
|
|
1372
1402
|
const result = await run(signal, "call", "fixture.echo", "{\"text\":\"hello\"}");
|
|
1373
1403
|
expectEqual(result.code, 0, "exit code");
|
|
1374
1404
|
expectEqual(parseJson(result.stdout), { text: "hello" }, "standard output");
|
|
1375
1405
|
});
|
|
1376
|
-
check("list gives the capabilities of the target, then its events", `${RULE$
|
|
1406
|
+
check("list gives the capabilities of the target, then its events", `${RULE$9}#commands`, async (signal) => {
|
|
1377
1407
|
const entries = await listed(signal);
|
|
1378
1408
|
const ids = (kind) => entries.filter((entry) => entry.kind === kind).map((entry) => entry.id);
|
|
1379
1409
|
expectEqual(sorted(ids("capability")), idsOf("cli"), "the ids of the items with kind: capability");
|
|
@@ -1382,7 +1412,7 @@ async function checkCli(command, options) {
|
|
|
1382
1412
|
const firstEvent = entries.findIndex((entry) => entry.kind === "event");
|
|
1383
1413
|
expect(firstEvent === -1 || entries.slice(firstEvent).every((entry) => entry.kind === "event"), "the events must come after the capabilities");
|
|
1384
1414
|
});
|
|
1385
|
-
check("list gives the usage of each capability and each event, with its flags", `${RULE$
|
|
1415
|
+
check("list gives the usage of each capability and each event, with its flags", `${RULE$9}#commands`, async (signal) => {
|
|
1386
1416
|
const entries = await listed(signal);
|
|
1387
1417
|
for (const { id, kind, usage } of entries) {
|
|
1388
1418
|
expect(typeof usage === "string", `${id} must have a usage`);
|
|
@@ -1566,7 +1596,7 @@ function checkHelp(check, command, listed) {
|
|
|
1566
1596
|
...entries.filter((each) => each.kind === "capability" && each.id.startsWith(`${prefix}.`)).map((each) => ` ${String(each.usage)}`),
|
|
1567
1597
|
""
|
|
1568
1598
|
].join("\n");
|
|
1569
|
-
check("--help after the path of a command writes the help of the capability", `${RULE$
|
|
1599
|
+
check("--help after the path of a command writes the help of the capability", `${RULE$9}#commands`, async (signal) => {
|
|
1570
1600
|
const entries = await listed(signal);
|
|
1571
1601
|
const helps = [
|
|
1572
1602
|
"fixture.raw",
|
|
@@ -1642,13 +1672,13 @@ function checkHelp(check, command, listed) {
|
|
|
1642
1672
|
expectHelp(await run(signal, ...name.split(" "), ...values, "--help"), usage, description);
|
|
1643
1673
|
}));
|
|
1644
1674
|
});
|
|
1645
|
-
check("--help after watch and the id of an event writes the help of the event", `${RULE$
|
|
1675
|
+
check("--help after watch and the id of an event writes the help of the event", `${RULE$9}#events`, async (signal) => {
|
|
1646
1676
|
const { usage, description } = entry(await listed(signal), "fixture.ticks");
|
|
1647
1677
|
expectHelp(await run(signal, "watch", "fixture.ticks", "--help"), usage, description);
|
|
1648
1678
|
expectHelp(await run(signal, "watch", "fixture.ticks", "--cursor", "--help"), usage, description);
|
|
1649
1679
|
expectHelp(await run(signal, "watch", "fixture.ticks", "--", "--help"), usage, description);
|
|
1650
1680
|
});
|
|
1651
|
-
check("--help after a shared prefix writes its command list to standard output", `${RULE$
|
|
1681
|
+
check("--help after a shared prefix writes its command list to standard output", `${RULE$9}#commands`, async (signal) => {
|
|
1652
1682
|
const entries = await listed(signal);
|
|
1653
1683
|
const result = await run(signal, "fixture", "switch", "--help");
|
|
1654
1684
|
expectEqual(result.code, 0, `exit code, with standard error ${JSON.stringify(result.stderr)}`);
|
|
@@ -1662,8 +1692,8 @@ function checkHelp(check, command, listed) {
|
|
|
1662
1692
|
expectEqual(result.stdout, "", "standard output");
|
|
1663
1693
|
expectEqual(result.stderr, commandList(entries, "fixture.switch"), "standard error");
|
|
1664
1694
|
};
|
|
1665
|
-
check("a shared prefix alone writes its command list to standard error with exit code 2", `${RULE$
|
|
1666
|
-
check("a shared prefix and a flag that is not --help write its command list to standard error with exit code 2", `${RULE$
|
|
1695
|
+
check("a shared prefix alone writes its command list to standard error with exit code 2", `${RULE$9}#commands`, (signal) => expectUnknown(signal, "fixture", "switch"));
|
|
1696
|
+
check("a shared prefix and a flag that is not --help write its command list to standard error with exit code 2", `${RULE$9}#commands`, (signal) => expectUnknown(signal, "fixture", "switch", "--on"));
|
|
1667
1697
|
}
|
|
1668
1698
|
function checkAliases(check, command, listed) {
|
|
1669
1699
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
@@ -1908,7 +1938,7 @@ function checkAliases(check, command, listed) {
|
|
|
1908
1938
|
}
|
|
1909
1939
|
});
|
|
1910
1940
|
}
|
|
1911
|
-
const EVENTS$1 = `${RULE$
|
|
1941
|
+
const EVENTS$1 = `${RULE$9}#events`;
|
|
1912
1942
|
function checkWatch(check, command) {
|
|
1913
1943
|
const run = (signal, ...args) => start(command, args, signal).run;
|
|
1914
1944
|
check("watch writes each occurrence as one line of JSON, and exits with 0 when the subscription is complete", EVENTS$1, async (signal) => {
|
|
@@ -2112,11 +2142,11 @@ function parse(raw) {
|
|
|
2112
2142
|
};
|
|
2113
2143
|
}
|
|
2114
2144
|
// src/conform/http.ts
|
|
2115
|
-
const RULE$
|
|
2116
|
-
const isEntry = (value) => isObject(value) && typeof value.id === "string";
|
|
2145
|
+
const RULE$8 = "spec/surfaces/http.md";
|
|
2146
|
+
const isEntry$1 = (value) => isObject(value) && typeof value.id === "string";
|
|
2117
2147
|
async function entriesOf(response) {
|
|
2118
2148
|
const list = await readJson(response);
|
|
2119
|
-
if (!isArrayOf(list, isEntry)) throw new Error(`GET /capabilities must give a list of objects with an id, got ${JSON.stringify(list)}`);
|
|
2149
|
+
if (!isArrayOf(list, isEntry$1)) throw new Error(`GET /capabilities must give a list of objects with an id, got ${JSON.stringify(list)}`);
|
|
2120
2150
|
return list;
|
|
2121
2151
|
}
|
|
2122
2152
|
async function checkHttp(base, options) {
|
|
@@ -2131,12 +2161,12 @@ async function checkHttp(base, options) {
|
|
|
2131
2161
|
signal
|
|
2132
2162
|
});
|
|
2133
2163
|
const kindOf = async (response) => memberOf(await readJson(response), "kind");
|
|
2134
|
-
await checks.run("GET /capabilities lists the capabilities of the target with their availability", `${RULE$
|
|
2164
|
+
await checks.run("GET /capabilities lists the capabilities of the target with their availability", `${RULE$8}#requests`, async (signal) => {
|
|
2135
2165
|
const list = await entriesOf(await fetch(`${base}/capabilities`, { signal }));
|
|
2136
2166
|
expectEqual(sorted(list.map((entry) => entry.id)), idsOf("api"), "ids");
|
|
2137
2167
|
expect(list.every((entry) => typeof entry.available === "boolean"), "each entry must have available");
|
|
2138
2168
|
});
|
|
2139
|
-
await checks.run("a value has the status 200", `${RULE$
|
|
2169
|
+
await checks.run("a value has the status 200", `${RULE$8}#requests`, async (signal) => {
|
|
2140
2170
|
const response = await post(signal, "fixture.echo", { text: "hello" });
|
|
2141
2171
|
expectEqual(response.status, 200, "status");
|
|
2142
2172
|
expectEqual(await readJson(response), {
|
|
@@ -2144,7 +2174,7 @@ async function checkHttp(base, options) {
|
|
|
2144
2174
|
value: { text: "hello" }
|
|
2145
2175
|
}, "body");
|
|
2146
2176
|
});
|
|
2147
|
-
await checks.run("a failure has the status 200 and ok: false", `${RULE$
|
|
2177
|
+
await checks.run("a failure has the status 200 and ok: false", `${RULE$8}#requests`, async (signal) => {
|
|
2148
2178
|
const response = await post(signal, "fixture.refuse", {});
|
|
2149
2179
|
const body = await readJson(response);
|
|
2150
2180
|
expectEqual(response.status, 200, "status");
|
|
@@ -2172,12 +2202,12 @@ async function checkHttp(base, options) {
|
|
|
2172
2202
|
500,
|
|
2173
2203
|
"internal"
|
|
2174
2204
|
]
|
|
2175
|
-
]) await checks.run(name, `${RULE$
|
|
2205
|
+
]) await checks.run(name, `${RULE$8}#requests`, async (signal) => {
|
|
2176
2206
|
const response = await post(signal, id, input);
|
|
2177
2207
|
expectEqual(response.status, status, "status");
|
|
2178
2208
|
expectEqual(await kindOf(response), kind, "kind");
|
|
2179
2209
|
});
|
|
2180
|
-
await checks.run("an unavailable capability has the status 503", `${RULE$
|
|
2210
|
+
await checks.run("an unavailable capability has the status 503", `${RULE$8}#requests`, async (signal) => {
|
|
2181
2211
|
await post(signal, "fixture.switch.set", { on: false });
|
|
2182
2212
|
try {
|
|
2183
2213
|
const toggle = (await entriesOf(await fetch(`${base}/capabilities`, { signal }))).find((entry) => entry.id === "fixture.toggle");
|
|
@@ -2190,22 +2220,22 @@ async function checkHttp(base, options) {
|
|
|
2190
2220
|
}
|
|
2191
2221
|
});
|
|
2192
2222
|
const status = async (response, expected) => expectEqual(response.status, expected, "status");
|
|
2193
|
-
await checks.run("a method that is not accepted is rejected with 405", `${RULE$
|
|
2223
|
+
await checks.run("a method that is not accepted is rejected with 405", `${RULE$8}#requests`, async (signal) => {
|
|
2194
2224
|
await status(await fetch(`${base}/capabilities`, {
|
|
2195
2225
|
method: "PUT",
|
|
2196
2226
|
signal
|
|
2197
2227
|
}), 405);
|
|
2198
2228
|
});
|
|
2199
|
-
await checks.run("an origin that is not allowed is rejected with 403", `${RULE$
|
|
2229
|
+
await checks.run("an origin that is not allowed is rejected with 403", `${RULE$8}#requests`, async (signal) => {
|
|
2200
2230
|
await status(await post(signal, "fixture.echo", { text: "x" }, { Origin: FORBIDDEN_ORIGIN }), 403);
|
|
2201
2231
|
});
|
|
2202
|
-
await checks.run("a media type other than JSON is rejected with 415", `${RULE$
|
|
2232
|
+
await checks.run("a media type other than JSON is rejected with 415", `${RULE$8}#requests`, async (signal) => {
|
|
2203
2233
|
await status(await post(signal, "fixture.echo", { text: "x" }, { "Content-Type": "text/plain" }), 415);
|
|
2204
2234
|
});
|
|
2205
|
-
await checks.run("a body over the limit is rejected with 413", `${RULE$
|
|
2235
|
+
await checks.run("a body over the limit is rejected with 413", `${RULE$8}#requests`, async (signal) => {
|
|
2206
2236
|
await status(await post(signal, "fixture.echo", " ".repeat(options.maximumBytes + 1)), 413);
|
|
2207
2237
|
});
|
|
2208
|
-
await checks.run("a body that is not UTF-8 is rejected with 400", `${RULE$
|
|
2238
|
+
await checks.run("a body that is not UTF-8 is rejected with 400", `${RULE$8}#requests`, async (signal) => {
|
|
2209
2239
|
await status(await post(signal, "fixture.echo", new Uint8Array([
|
|
2210
2240
|
123,
|
|
2211
2241
|
255,
|
|
@@ -2215,7 +2245,7 @@ async function checkHttp(base, options) {
|
|
|
2215
2245
|
await checkEvents$1(checks, base);
|
|
2216
2246
|
return checks;
|
|
2217
2247
|
}
|
|
2218
|
-
const EVENTS = `${RULE$
|
|
2248
|
+
const EVENTS = `${RULE$8}#events`;
|
|
2219
2249
|
async function checkEvents$1(checks, base) {
|
|
2220
2250
|
const subscribe = (signal, id, input, headers = {}) => fetch(`${base}/events/${id}`, {
|
|
2221
2251
|
method: "POST",
|
|
@@ -2280,9 +2310,9 @@ async function checkEvents$1(checks, base) {
|
|
|
2280
2310
|
expect(typeof delivered === "number", `fixture.signal must give the number of subscriptions, got ${JSON.stringify(delivered)}`);
|
|
2281
2311
|
return delivered;
|
|
2282
2312
|
};
|
|
2283
|
-
await checks.run("GET /events lists the events of the target", `${RULE$
|
|
2313
|
+
await checks.run("GET /events lists the events of the target", `${RULE$8}#requests`, async (signal) => {
|
|
2284
2314
|
const list = await readJson(await fetch(`${base}/events`, { signal }));
|
|
2285
|
-
if (!isArrayOf(list, isEntry)) throw new Error(`GET /events must give a list of objects with an id, got ${JSON.stringify(list)}`);
|
|
2315
|
+
if (!isArrayOf(list, isEntry$1)) throw new Error(`GET /events must give a list of objects with an id, got ${JSON.stringify(list)}`);
|
|
2286
2316
|
expectEqual(sorted(list.map((entry) => entry.id)), eventIdsOf("api"), "ids");
|
|
2287
2317
|
});
|
|
2288
2318
|
for (const [name, id, input, status, kind] of [
|
|
@@ -2404,7 +2434,7 @@ async function checkEvents$1(checks, base) {
|
|
|
2404
2434
|
});
|
|
2405
2435
|
}
|
|
2406
2436
|
// src/conform/poll.ts
|
|
2407
|
-
const RULE$
|
|
2437
|
+
const RULE$7 = "spec/surfaces/mcp.md#poll";
|
|
2408
2438
|
const MAXIMUM_TICKS = 100;
|
|
2409
2439
|
const MAXIMUM_EVENTS = 100;
|
|
2410
2440
|
function pollRequests(channel) {
|
|
@@ -2479,7 +2509,7 @@ function pollRequests(channel) {
|
|
|
2479
2509
|
}
|
|
2480
2510
|
async function checkPoll(checks, channel, settings) {
|
|
2481
2511
|
const { errorOf, watching, polledOf, poll, pollUntil, pollError, dataOf, watched, ticks, hasKey, expectStart, startWatch, signalAll } = pollRequests(channel);
|
|
2482
|
-
await checks.run("events/poll with no cursor and no lease starts a lease with no occurrences, whose subscription starts now; a cursor of the lease gives the occurrences after it, in order; and no cursor gives the newest position", RULE$
|
|
2512
|
+
await checks.run("events/poll with no cursor and no lease starts a lease with no occurrences, whose subscription starts now; a cursor of the lease gives the occurrences after it, in order; and no cursor gives the newest position", RULE$7, async (signal) => {
|
|
2483
2513
|
const key = randomUUID();
|
|
2484
2514
|
const start = await startWatch(key, signal);
|
|
2485
2515
|
await signalAll(key, ["a", "b"], signal);
|
|
@@ -2494,7 +2524,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2494
2524
|
const next = await poll("fixture.watch", { key }, { cursor: both.cursor }, signal);
|
|
2495
2525
|
expectEqual(dataOf(next), watched(key, "c"), "the data of the occurrences after the cursor of the last result");
|
|
2496
2526
|
});
|
|
2497
|
-
await checks.run("maxEvents limits the occurrences of a result, and hasMore tells that the buffer has more", RULE$
|
|
2527
|
+
await checks.run("maxEvents limits the occurrences of a result, and hasMore tells that the buffer has more", RULE$7, async (signal) => {
|
|
2498
2528
|
const key = randomUUID();
|
|
2499
2529
|
const start = await startWatch(key, signal);
|
|
2500
2530
|
await signalAll(key, [
|
|
@@ -2514,7 +2544,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2514
2544
|
expectEqual(dataOf(second), watched(key, "3"), "the data of the second result");
|
|
2515
2545
|
expectEqual(second.hasMore, false, "hasMore of the second result");
|
|
2516
2546
|
});
|
|
2517
|
-
await checks.run("a maxEvents that is not an integer of 1 or more is the error -32602", RULE$
|
|
2547
|
+
await checks.run("a maxEvents that is not an integer of 1 or more is the error -32602", RULE$7, async (signal) => {
|
|
2518
2548
|
for (const maxEvents of [
|
|
2519
2549
|
0,
|
|
2520
2550
|
-1,
|
|
@@ -2522,7 +2552,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2522
2552
|
"2"
|
|
2523
2553
|
]) expectEqual((await pollError("fixture.watch", { key: randomUUID() }, { maxEvents }, signal)).code, -32602, `the JSON-RPC error code for maxEvents ${JSON.stringify(maxEvents)}`);
|
|
2524
2554
|
});
|
|
2525
|
-
await checks.run("a cursor that is not of the lease, while the lease exists, gives no occurrences, the newest position and truncated: true", RULE$
|
|
2555
|
+
await checks.run("a cursor that is not of the lease, while the lease exists, gives no occurrences, the newest position and truncated: true", RULE$7, async (signal) => {
|
|
2526
2556
|
const key = randomUUID();
|
|
2527
2557
|
const start = await startWatch(key, signal);
|
|
2528
2558
|
const other = await poll("fixture.watch", { key: randomUUID() }, {}, signal);
|
|
@@ -2534,7 +2564,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2534
2564
|
const after = await pollUntil("the lease has the next occurrence", "fixture.watch", { key }, { cursor: foreign.cursor }, (each) => each.events.length > 0, signal);
|
|
2535
2565
|
expectEqual(dataOf(after), watched(key, "after"), "the data of the occurrences after the newest position");
|
|
2536
2566
|
});
|
|
2537
|
-
await checks.run("a cursor that is not of a lease, with no lease, starts a lease that starts now, with truncated: true", RULE$
|
|
2567
|
+
await checks.run("a cursor that is not of a lease, with no lease, starts a lease that starts now, with truncated: true", RULE$7, async (signal) => {
|
|
2538
2568
|
const other = await poll("fixture.watch", { key: randomUUID() }, {}, signal);
|
|
2539
2569
|
const key = randomUUID();
|
|
2540
2570
|
const started = await poll("fixture.watch", { key }, { cursor: other.cursor }, signal);
|
|
@@ -2544,7 +2574,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2544
2574
|
const polled = await pollUntil("the lease has the occurrence", "fixture.watch", { key }, { cursor: started.cursor }, (each) => each.events.length > 0, signal);
|
|
2545
2575
|
expectEqual(dataOf(polled), watched(key, "now"), "the data of the occurrences");
|
|
2546
2576
|
});
|
|
2547
|
-
await checks.run("a cursor of push delivery has no cursor of the provider: the new lease starts now, with truncated: true", RULE$
|
|
2577
|
+
await checks.run("a cursor of push delivery has no cursor of the provider: the new lease starts now, with truncated: true", RULE$7, async (signal) => {
|
|
2548
2578
|
const input = {
|
|
2549
2579
|
count: 3,
|
|
2550
2580
|
key: randomUUID()
|
|
@@ -2554,7 +2584,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2554
2584
|
const polled = await pollUntil("the lease has the last tick", "fixture.ticks", input, { cursor: started.cursor }, (each) => each.events.some((event) => memberOf(event.data, "n") === 3), signal);
|
|
2555
2585
|
expectEqual(dataOf(polled), ticks(1, 3), "the data of the occurrences, from n = 1");
|
|
2556
2586
|
});
|
|
2557
|
-
await checks.run("a cursor of another lease with a cursor of the provider starts a lease that resumes after it", RULE$
|
|
2587
|
+
await checks.run("a cursor of another lease with a cursor of the provider starts a lease that resumes after it", RULE$7, async (signal) => {
|
|
2558
2588
|
const first = {
|
|
2559
2589
|
count: 3,
|
|
2560
2590
|
key: randomUUID()
|
|
@@ -2576,7 +2606,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2576
2606
|
expectEqual(dataOf(polled), ticks(2, 4), "the data of the occurrences after the cursor of the provider");
|
|
2577
2607
|
expectEqual(polled.truncated, false, "truncated");
|
|
2578
2608
|
});
|
|
2579
|
-
await checks.run("an occurrence after a gap gives a result with truncated: true, and its item has no truncated", RULE$
|
|
2609
|
+
await checks.run("an occurrence after a gap gives a result with truncated: true, and its item has no truncated", RULE$7, async (signal) => {
|
|
2580
2610
|
const input = {
|
|
2581
2611
|
count: 3,
|
|
2582
2612
|
gap: 2,
|
|
@@ -2594,7 +2624,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2594
2624
|
});
|
|
2595
2625
|
if (settings.bufferLimit !== void 0) {
|
|
2596
2626
|
const limit = settings.bufferLimit;
|
|
2597
|
-
await checks.run("a cursor older than the buffer gives the occurrences in the buffer, and truncated: true", RULE$
|
|
2627
|
+
await checks.run("a cursor older than the buffer gives the occurrences in the buffer, and truncated: true", RULE$7, async (signal) => {
|
|
2598
2628
|
expect(Number.isSafeInteger(limit) && limit >= 1 && limit + 3 <= MAXIMUM_TICKS, `conform tests the buffer only when it keeps 1 to 97 occurrences, got ${limit}`);
|
|
2599
2629
|
const total = limit + 3;
|
|
2600
2630
|
const input = {
|
|
@@ -2611,7 +2641,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2611
2641
|
expectEqual([polled.truncated, polled.hasMore], [true, false], "truncated and hasMore");
|
|
2612
2642
|
});
|
|
2613
2643
|
}
|
|
2614
|
-
await checks.run("a failure before the first occurrence is a JSON-RPC error, and starts no lease", RULE$
|
|
2644
|
+
await checks.run("a failure before the first occurrence is a JSON-RPC error, and starts no lease", RULE$7, async (signal) => {
|
|
2615
2645
|
for (const [name, input, code] of [
|
|
2616
2646
|
[
|
|
2617
2647
|
"fixture.secret",
|
|
@@ -2634,7 +2664,7 @@ async function checkPoll(checks, channel, settings) {
|
|
|
2634
2664
|
if (code === -32023) expectEqual(memberOf(error.data, "kind"), "event", `data.kind of the ${attempt} poll of ${name}`);
|
|
2635
2665
|
}
|
|
2636
2666
|
});
|
|
2637
|
-
await checks.run("after a defect, the next poll is the error -32603 and ends the lease, and a later poll starts a new lease", RULE$
|
|
2667
|
+
await checks.run("after a defect, the next poll is the error -32603 and ends the lease, and a later poll starts a new lease", RULE$7, async (signal) => {
|
|
2638
2668
|
const start = async () => {
|
|
2639
2669
|
const message = await channel.request("events/poll", {
|
|
2640
2670
|
name: "fixture.broken",
|
|
@@ -2676,7 +2706,7 @@ async function checkPollLease(checks, channel, leaseMs) {
|
|
|
2676
2706
|
}, hasKey(key), signal);
|
|
2677
2707
|
return lease;
|
|
2678
2708
|
};
|
|
2679
|
-
await checks.run("a lease that gets no poll for the lease time ends, and cancels its subscription", RULE$
|
|
2709
|
+
await checks.run("a lease that gets no poll for the lease time ends, and cancels its subscription", RULE$7, async (signal) => {
|
|
2680
2710
|
expect(Number.isSafeInteger(leaseMs) && leaseMs >= 1 && leaseMs < checks.deadline, `conform tests the end of a lease only when the lease time is shorter than the deadline of ${checks.deadline} ms, got ${leaseMs}`);
|
|
2681
2711
|
const key = randomUUID();
|
|
2682
2712
|
const started = await poll("fixture.watch", { key }, {}, signal);
|
|
@@ -2971,7 +3001,7 @@ var $defs = {
|
|
|
2971
3001
|
}
|
|
2972
3002
|
};
|
|
2973
3003
|
// src/conform/server-card.ts
|
|
2974
|
-
const RULE$
|
|
3004
|
+
const RULE$6 = "spec/surfaces/mcp.md#server-card";
|
|
2975
3005
|
const decodeCard = (() => {
|
|
2976
3006
|
const definitions = $defs;
|
|
2977
3007
|
const schema = SchemaRepresentation.fromJsonSchemaDocument({
|
|
@@ -3017,7 +3047,7 @@ async function checkServerCard(checks, url, channel) {
|
|
|
3017
3047
|
}).catch(() => void 0);
|
|
3018
3048
|
if (first !== void 0 && first.status !== 200) return void 0;
|
|
3019
3049
|
let card;
|
|
3020
|
-
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$
|
|
3050
|
+
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$6, async (signal) => {
|
|
3021
3051
|
const response = first ?? await fetch(cardUrl, { signal });
|
|
3022
3052
|
expectEqual(response.status, 200, "status");
|
|
3023
3053
|
expectEqual(response.headers.get("Content-Type"), MCP_SERVER_CARD_MEDIA_TYPE, "Content-Type");
|
|
@@ -3032,7 +3062,7 @@ async function checkServerCard(checks, url, channel) {
|
|
|
3032
3062
|
});
|
|
3033
3063
|
if (card === void 0) return void 0;
|
|
3034
3064
|
const served = card;
|
|
3035
|
-
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$
|
|
3065
|
+
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$6, async (signal) => {
|
|
3036
3066
|
const remotes = served.remotes;
|
|
3037
3067
|
expect(Array.isArray(remotes) && remotes.length === 1, `the card must have one remote, got ${JSON.stringify(remotes)}`);
|
|
3038
3068
|
const remote = remotes[0];
|
|
@@ -3067,7 +3097,7 @@ async function checkServerCard(checks, url, channel) {
|
|
|
3067
3097
|
expectEqual(memberOf(result, "protocolVersion"), version, `the revision that initialize gives for ${version} of supportedProtocolVersions`);
|
|
3068
3098
|
}
|
|
3069
3099
|
});
|
|
3070
|
-
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$
|
|
3100
|
+
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$6, async (signal) => {
|
|
3071
3101
|
const response = await fetch(cardUrl, { signal });
|
|
3072
3102
|
await response.body?.cancel();
|
|
3073
3103
|
expectHeaders(response, CORS_HEADERS);
|
|
@@ -3091,7 +3121,7 @@ async function checkServerCard(checks, url, channel) {
|
|
|
3091
3121
|
expectHeaders(preflight, CORS_HEADERS);
|
|
3092
3122
|
expectEqual(preflight.headers.get("ETag"), null, "the ETag of OPTIONS");
|
|
3093
3123
|
});
|
|
3094
|
-
await checks.run("the signing keys of the card are public Ed25519 keys with a kid, and its egress ranges are CIDR text", RULE$
|
|
3124
|
+
await checks.run("the signing keys of the card are public Ed25519 keys with a kid, and its egress ranges are CIDR text", RULE$6, () => {
|
|
3095
3125
|
const keys = signingKeysOf(served);
|
|
3096
3126
|
for (const key of keys) {
|
|
3097
3127
|
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)}`);
|
|
@@ -3107,7 +3137,7 @@ async function checkServerCard(checks, url, channel) {
|
|
|
3107
3137
|
return served;
|
|
3108
3138
|
}
|
|
3109
3139
|
// src/conform/webhook.ts
|
|
3110
|
-
const RULE$
|
|
3140
|
+
const RULE$5 = "spec/surfaces/mcp.md#webhook";
|
|
3111
3141
|
const REFRESH_BEFORE_PRECISION_MS = 1;
|
|
3112
3142
|
const isVerification = (request) => memberOf(request.body, "type") === "verification";
|
|
3113
3143
|
async function startReceiver(settings) {
|
|
@@ -3211,7 +3241,7 @@ async function checkWebhook(checks, url, settings, signingKeys) {
|
|
|
3211
3241
|
try {
|
|
3212
3242
|
receiver = await startReceiver(settings);
|
|
3213
3243
|
} catch (error) {
|
|
3214
|
-
await checks.run("conform starts an HTTPS receiver with the certificate and the key", RULE$
|
|
3244
|
+
await checks.run("conform starts an HTTPS receiver with the certificate and the key", RULE$5, () => {
|
|
3215
3245
|
throw error instanceof Error ? error : new Error(String(error));
|
|
3216
3246
|
});
|
|
3217
3247
|
return;
|
|
@@ -3280,19 +3310,19 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3280
3310
|
const minTtlMs = settings.minTtlMs ?? MCP_WEBHOOK_DEFAULTS.minTtlMs;
|
|
3281
3311
|
const maxTtlMs = settings.maxTtlMs ?? MCP_WEBHOOK_DEFAULTS.maxTtlMs;
|
|
3282
3312
|
if (maxTtlMs <= checks.deadline) {
|
|
3283
|
-
await checks.run("the maximum lifetime of a subscription is longer than the deadline", RULE$
|
|
3313
|
+
await checks.run("the maximum lifetime of a subscription is longer than the deadline", RULE$5, () => {
|
|
3284
3314
|
throw new Error(`conform tests webhook delivery only when the maximum lifetime is longer than the deadline of ${checks.deadline} ms, got ${maxTtlMs}`);
|
|
3285
3315
|
});
|
|
3286
3316
|
return;
|
|
3287
3317
|
}
|
|
3288
|
-
await checks.run("events/subscribe and events/unsubscribe with no principal are Forbidden", RULE$
|
|
3318
|
+
await checks.run("events/subscribe and events/unsubscribe with no principal are Forbidden", RULE$5, async (signal) => {
|
|
3289
3319
|
const hook = receiver.url();
|
|
3290
3320
|
const input = { key: randomUUID() };
|
|
3291
3321
|
expectEqual(errorOf(await anonymous.request("events/subscribe", subscribeParams("fixture.watch", input, hook.url, newSecret()), signal)).code, -32024, "the JSON-RPC error code of events/subscribe");
|
|
3292
3322
|
expectEqual(errorOf(await anonymous.request("events/unsubscribe", unsubscribeParams("fixture.watch", input, hook.url), signal)).code, -32024, "the JSON-RPC error code of events/unsubscribe");
|
|
3293
3323
|
expectEqual(hook.received().length, 0, "the requests that the receiver got");
|
|
3294
3324
|
});
|
|
3295
|
-
await checks.run("a URL that is not https, or a secret that is not valid, is the error -32602", RULE$
|
|
3325
|
+
await checks.run("a URL that is not https, or a secret that is not valid, is the error -32602", RULE$5, async (signal) => {
|
|
3296
3326
|
const hook = receiver.url();
|
|
3297
3327
|
const http = hook.url.replace(/^https:/, "http:");
|
|
3298
3328
|
for (const [what, params] of [
|
|
@@ -3302,7 +3332,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3302
3332
|
]) expectEqual(errorOf(await channel.request("events/subscribe", params, signal)).code, -32602, `the JSON-RPC error code for ${what}`);
|
|
3303
3333
|
expectEqual(hook.received().length, 0, "the requests that the receiver got");
|
|
3304
3334
|
});
|
|
3305
|
-
await checks.run("the server verifies a new URL with a challenge, then answers with the subscription", RULE$
|
|
3335
|
+
await checks.run("the server verifies a new URL with a challenge, then answers with the subscription", RULE$5, async (signal) => {
|
|
3306
3336
|
const hook = receiver.url();
|
|
3307
3337
|
const input = {
|
|
3308
3338
|
count: 0,
|
|
@@ -3319,7 +3349,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3319
3349
|
await cleanup("fixture.ticks", input, hook.url);
|
|
3320
3350
|
}
|
|
3321
3351
|
});
|
|
3322
|
-
await checks.run("an endpoint that does not answer the challenge is CallbackEndpointError, and the subscription does not start", RULE$
|
|
3352
|
+
await checks.run("an endpoint that does not answer the challenge is CallbackEndpointError, and the subscription does not start", RULE$5, async (signal) => {
|
|
3323
3353
|
const hook = receiver.url((request) => isVerification(request) ? {
|
|
3324
3354
|
status: 200,
|
|
3325
3355
|
body: JSON.stringify({ challenge: "wrong" })
|
|
@@ -3331,7 +3361,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3331
3361
|
await until("the key is not in fixture.watching", () => watching(signal), (keys) => !keys.includes(input.key), signal);
|
|
3332
3362
|
expectEqual(hook.received().length, 1, "the requests that the receiver got: only the verification");
|
|
3333
3363
|
});
|
|
3334
|
-
await checks.run("each occurrence is one signed POST, in order, whose cursor is the watermark", RULE$
|
|
3364
|
+
await checks.run("each occurrence is one signed POST, in order, whose cursor is the watermark", RULE$5, async (signal) => {
|
|
3335
3365
|
const hook = receiver.url();
|
|
3336
3366
|
const input = {
|
|
3337
3367
|
count: 3,
|
|
@@ -3361,7 +3391,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3361
3391
|
await cleanup("fixture.ticks", input, hook.url);
|
|
3362
3392
|
}
|
|
3363
3393
|
});
|
|
3364
|
-
await checks.run("a subscription gets the things that happen; a renewal grants a new lifetime and signs with both secrets; events/unsubscribe ends it", RULE$
|
|
3394
|
+
await checks.run("a subscription gets the things that happen; a renewal grants a new lifetime and signs with both secrets; events/unsubscribe ends it", RULE$5, async (signal) => {
|
|
3365
3395
|
const hook = receiver.url();
|
|
3366
3396
|
const input = { key: randomUUID() };
|
|
3367
3397
|
const [first, second] = [newSecret(), newSecret()];
|
|
@@ -3395,7 +3425,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3395
3425
|
await cleanup("fixture.watch", input, hook.url);
|
|
3396
3426
|
}
|
|
3397
3427
|
});
|
|
3398
|
-
await checks.run("a delivery that gets a status that is not 2xx is sent again, with the same webhook-id", RULE$
|
|
3428
|
+
await checks.run("a delivery that gets a status that is not 2xx is sent again, with the same webhook-id", RULE$5, async (signal) => {
|
|
3399
3429
|
const hook = receiver.url((request, index) => !isVerification(request) && index === 0 ? { status: 500 } : void 0);
|
|
3400
3430
|
const input = { key: randomUUID() };
|
|
3401
3431
|
const secret = newSecret();
|
|
@@ -3412,7 +3442,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3412
3442
|
await cleanup("fixture.watch", input, hook.url);
|
|
3413
3443
|
}
|
|
3414
3444
|
});
|
|
3415
|
-
await checks.run("a 410 abandons the delivery at once, and the next occurrence follows", RULE$
|
|
3445
|
+
await checks.run("a 410 abandons the delivery at once, and the next occurrence follows", RULE$5, async (signal) => {
|
|
3416
3446
|
const hook = receiver.url((request, index) => !isVerification(request) && index === 0 ? { status: 410 } : void 0);
|
|
3417
3447
|
const input = { key: randomUUID() };
|
|
3418
3448
|
try {
|
|
@@ -3435,7 +3465,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3435
3465
|
await cleanup("fixture.watch", input, hook.url);
|
|
3436
3466
|
}
|
|
3437
3467
|
});
|
|
3438
|
-
await checks.run("a defect after an occurrence sends the control message terminated", RULE$
|
|
3468
|
+
await checks.run("a defect after an occurrence sends the control message terminated", RULE$5, async (signal) => {
|
|
3439
3469
|
const hook = receiver.url();
|
|
3440
3470
|
const secret = newSecret();
|
|
3441
3471
|
try {
|
|
@@ -3453,7 +3483,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3453
3483
|
await cleanup("fixture.broken", {}, hook.url);
|
|
3454
3484
|
}
|
|
3455
3485
|
});
|
|
3456
|
-
await checks.run("before an occurrence after a gap, the server sends the control message gap with the watermark", RULE$
|
|
3486
|
+
await checks.run("before an occurrence after a gap, the server sends the control message gap with the watermark", RULE$5, async (signal) => {
|
|
3457
3487
|
const hook = receiver.url();
|
|
3458
3488
|
const input = {
|
|
3459
3489
|
count: 3,
|
|
@@ -3478,7 +3508,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3478
3508
|
await cleanup("fixture.ticks", input, hook.url);
|
|
3479
3509
|
}
|
|
3480
3510
|
});
|
|
3481
|
-
await checks.run("the server grants ttlMs between the minimum and the maximum lifetime, and the maximum with no ttlMs", RULE$
|
|
3511
|
+
await checks.run("the server grants ttlMs between the minimum and the maximum lifetime, and the maximum with no ttlMs", RULE$5, async (signal) => {
|
|
3482
3512
|
const hook = receiver.url();
|
|
3483
3513
|
const cases = [
|
|
3484
3514
|
[
|
|
@@ -3514,7 +3544,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3514
3544
|
}
|
|
3515
3545
|
}
|
|
3516
3546
|
});
|
|
3517
|
-
if (settings.minTtlMs !== void 0) await checks.run("a subscription with no renewal ends at the end of its lifetime, and gets no more deliveries", RULE$
|
|
3547
|
+
if (settings.minTtlMs !== void 0) await checks.run("a subscription with no renewal ends at the end of its lifetime, and gets no more deliveries", RULE$5, async (signal) => {
|
|
3518
3548
|
const hook = receiver.url();
|
|
3519
3549
|
const input = { key: randomUUID() };
|
|
3520
3550
|
try {
|
|
@@ -3541,7 +3571,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3541
3571
|
const max = settings.maxSubscriptions;
|
|
3542
3572
|
const other = settings.otherPrincipal;
|
|
3543
3573
|
const name = `a new subscription over the limit of a principal is ResourceExhausted, and a renewal still works${other === void 0 ? "" : ", and another principal can still subscribe"}`;
|
|
3544
|
-
await checks.run(name, RULE$
|
|
3574
|
+
await checks.run(name, RULE$5, async (signal) => {
|
|
3545
3575
|
const client = other === void 0 ? main : {
|
|
3546
3576
|
channel: httpChannel(url, { Authorization: `Bearer ${other}` }),
|
|
3547
3577
|
principal: other
|
|
@@ -3578,7 +3608,7 @@ async function checkWithReceiver(checks, url, settings, receiver, signingKeys) {
|
|
|
3578
3608
|
}
|
|
3579
3609
|
}
|
|
3580
3610
|
// src/conform/mcp.ts
|
|
3581
|
-
const RULE$
|
|
3611
|
+
const RULE$4 = "spec/surfaces/mcp.md";
|
|
3582
3612
|
/** Runtimes measure the idle time of a stream with timers of 1 ms resolution, so a heartbeat can come 1 ms early. */
|
|
3583
3613
|
const TIMER_RESOLUTION_MS = 1;
|
|
3584
3614
|
async function mcpClient(url, signal, handshake = false) {
|
|
@@ -3596,7 +3626,7 @@ const textOf = (result) => {
|
|
|
3596
3626
|
async function checkMcp(url, options) {
|
|
3597
3627
|
const checks = new Checks("mcp", options.deadline, options.signal);
|
|
3598
3628
|
let client;
|
|
3599
|
-
await checks.run("an MCP client connects with revision 2026-07-28", `${RULE$
|
|
3629
|
+
await checks.run("an MCP client connects with revision 2026-07-28", `${RULE$4}#http`, async (signal) => {
|
|
3600
3630
|
client = await mcpClient(url, signal);
|
|
3601
3631
|
});
|
|
3602
3632
|
if (client === void 0) return checks;
|
|
@@ -3617,30 +3647,30 @@ async function checkMcp(url, options) {
|
|
|
3617
3647
|
expectEqual(response.headers.get("Cache-Control"), "no-store", "Cache-Control");
|
|
3618
3648
|
if (code !== void 0) expectEqual(memberOf(memberOf(await readJson(response), "error"), "code"), code, "JSON-RPC error code");
|
|
3619
3649
|
};
|
|
3620
|
-
await checks.run("a method other than POST is rejected with 405", `${RULE$
|
|
3650
|
+
await checks.run("a method other than POST is rejected with 405", `${RULE$4}#http`, async (signal) => {
|
|
3621
3651
|
const response = await fetch(url, { signal });
|
|
3622
3652
|
await rejection(response, 405);
|
|
3623
3653
|
expectEqual(response.headers.get("Allow"), "POST", "Allow");
|
|
3624
3654
|
});
|
|
3625
|
-
await checks.run("an origin that is not allowed is rejected with 403", `${RULE$
|
|
3655
|
+
await checks.run("an origin that is not allowed is rejected with 403", `${RULE$4}#http`, async (signal) => {
|
|
3626
3656
|
await rejection(await post(signal, {
|
|
3627
3657
|
headers: { Origin: FORBIDDEN_ORIGIN },
|
|
3628
3658
|
body: "{}"
|
|
3629
3659
|
}), 403);
|
|
3630
3660
|
});
|
|
3631
|
-
await checks.run("a media type other than JSON is rejected with 415", `${RULE$
|
|
3661
|
+
await checks.run("a media type other than JSON is rejected with 415", `${RULE$4}#http`, async (signal) => {
|
|
3632
3662
|
await rejection(await post(signal, {
|
|
3633
3663
|
headers: { "Content-Type": "text/plain" },
|
|
3634
3664
|
body: "{}"
|
|
3635
3665
|
}), 415);
|
|
3636
3666
|
});
|
|
3637
|
-
await checks.run("a body over the limit is rejected with 413 and -32600", `${RULE$
|
|
3667
|
+
await checks.run("a body over the limit is rejected with 413 and -32600", `${RULE$4}#http`, async (signal) => {
|
|
3638
3668
|
await rejection(await post(signal, { body: " ".repeat(options.maximumBytes + 1) }), 413, -32600);
|
|
3639
3669
|
});
|
|
3640
|
-
await checks.run("a body that is not JSON is rejected with 400 and -32700", `${RULE$
|
|
3670
|
+
await checks.run("a body that is not JSON is rejected with 400 and -32700", `${RULE$4}#http`, async (signal) => {
|
|
3641
3671
|
await rejection(await post(signal, { body: "{" }), 400, -32700);
|
|
3642
3672
|
});
|
|
3643
|
-
await checks.run("a body that is not UTF-8 is rejected with 400", `${RULE$
|
|
3673
|
+
await checks.run("a body that is not UTF-8 is rejected with 400", `${RULE$4}#http`, async (signal) => {
|
|
3644
3674
|
await rejection(await post(signal, { body: new Uint8Array([
|
|
3645
3675
|
123,
|
|
3646
3676
|
255,
|
|
@@ -3666,9 +3696,10 @@ function inputSchemaOf(method, name) {
|
|
|
3666
3696
|
return input === void 0 ? void 0 : bundle$1(input, mcpCatalog.$defs ?? {});
|
|
3667
3697
|
}
|
|
3668
3698
|
function mcpRequestHeaders(method, params) {
|
|
3699
|
+
const name = mcpNameParam(method) === "uri" ? params.uri : params.name;
|
|
3669
3700
|
return {
|
|
3670
3701
|
"Mcp-Method": method,
|
|
3671
|
-
...typeof
|
|
3702
|
+
...typeof name === "string" ? { "Mcp-Name": encodeMcpHeaderValue(name) } : {},
|
|
3672
3703
|
...mcpParamHeaders(inputSchemaOf(method, params.name), params.arguments)
|
|
3673
3704
|
};
|
|
3674
3705
|
}
|
|
@@ -3726,11 +3757,11 @@ async function checkHeaders(checks, url) {
|
|
|
3726
3757
|
key: "k"
|
|
3727
3758
|
}
|
|
3728
3759
|
};
|
|
3729
|
-
await checks.run("a request whose Mcp-Method header is not its method gets 400 and HeaderMismatch", `${RULE$
|
|
3760
|
+
await checks.run("a request whose Mcp-Method header is not its method gets 400 and HeaderMismatch", `${RULE$4}#http`, async (signal) => {
|
|
3730
3761
|
await rejected(await send(signal, "tools/call", echo, named("tools/list", "fixture.echo")), "tools/call with Mcp-Method: tools/list");
|
|
3731
3762
|
await rejected(await send(signal, "events/stream", ticks, named("events/poll", "fixture.ticks", { "Mcp-Param-Key": "k" })), "events/stream with Mcp-Method: events/poll");
|
|
3732
3763
|
});
|
|
3733
|
-
await checks.run("tools/call and events/stream with no Mcp-Name header, or another name, get 400 and HeaderMismatch", `${RULE$
|
|
3764
|
+
await checks.run("tools/call and events/stream with no Mcp-Name header, or another name, get 400 and HeaderMismatch", `${RULE$4}#http`, async (signal) => {
|
|
3734
3765
|
await rejected(await send(signal, "tools/call", echo, { "Mcp-Method": "tools/call" }), "tools/call with no Mcp-Name");
|
|
3735
3766
|
await rejected(await send(signal, "tools/call", echo, named("tools/call", "fixture.refuse")), "tools/call with another Mcp-Name");
|
|
3736
3767
|
await rejected(await send(signal, "events/stream", ticks, {
|
|
@@ -3739,7 +3770,7 @@ async function checkHeaders(checks, url) {
|
|
|
3739
3770
|
}), "events/stream with no Mcp-Name");
|
|
3740
3771
|
await rejected(await send(signal, "events/stream", ticks, named("events/stream", "fixture.watch", { "Mcp-Param-Key": "k" })), "events/stream with another Mcp-Name");
|
|
3741
3772
|
});
|
|
3742
|
-
await checks.run("an Mcp-Name header in the base64 form is decoded before the comparison", `${RULE$
|
|
3773
|
+
await checks.run("an Mcp-Name header in the base64 form is decoded before the comparison", `${RULE$4}#http`, async (signal) => {
|
|
3743
3774
|
const base64 = (text) => `=?base64?${Buffer.from(text).toString("base64")}?=`;
|
|
3744
3775
|
await accepted(await send(signal, "tools/call", echo, named("tools/call", base64("fixture.echo"))), "tools/call with Mcp-Name in the base64 form");
|
|
3745
3776
|
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");
|
|
@@ -3767,7 +3798,7 @@ async function checkHeaders(checks, url) {
|
|
|
3767
3798
|
value: "k",
|
|
3768
3799
|
other: "j",
|
|
3769
3800
|
base64: "=?base64?aw==?="
|
|
3770
|
-
}]) 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$
|
|
3801
|
+
}]) 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$4}#http`, async (signal) => {
|
|
3771
3802
|
const params = {
|
|
3772
3803
|
name,
|
|
3773
3804
|
arguments: args
|
|
@@ -3781,7 +3812,7 @@ async function checkHeaders(checks, url) {
|
|
|
3781
3812
|
arguments: absent
|
|
3782
3813
|
}, named(method, name)), `${method} with no argument and no ${header}`);
|
|
3783
3814
|
});
|
|
3784
|
-
await checks.run("a header value in the base64 form keeps a leading U+FEFF", `${RULE$
|
|
3815
|
+
await checks.run("a header value in the base64 form keeps a leading U+FEFF", `${RULE$4}#headers`, async (signal) => {
|
|
3785
3816
|
const header = { "Mcp-Param-Key": "=?base64?77u/aw==?=" };
|
|
3786
3817
|
await accepted(await send(signal, "events/stream", {
|
|
3787
3818
|
name: "fixture.ticks",
|
|
@@ -3793,7 +3824,7 @@ async function checkHeaders(checks, url) {
|
|
|
3793
3824
|
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");
|
|
3794
3825
|
});
|
|
3795
3826
|
}
|
|
3796
|
-
const ANCHOR = `${RULE$
|
|
3827
|
+
const ANCHOR = `${RULE$4}#earlier-revisions-through-http`;
|
|
3797
3828
|
async function checkHandshake(checks, url, deadline) {
|
|
3798
3829
|
const handshakeChecks = new Checks("mcp 2025-11-25", deadline, checks.signal);
|
|
3799
3830
|
let client;
|
|
@@ -3836,6 +3867,7 @@ async function checkHandshake(checks, url, deadline) {
|
|
|
3836
3867
|
expectEqual(memberOf(result, "protocolVersion"), "2025-11-25", "protocolVersion");
|
|
3837
3868
|
const extensions = memberOf(memberOf(result, "capabilities"), "extensions");
|
|
3838
3869
|
expect(memberOf(extensions, MCP_EVENTS_EXTENSION) === void 0, `the capabilities of initialize must not have the events extension, got ${JSON.stringify(extensions)}`);
|
|
3870
|
+
expect(memberOf(extensions, MCP_SKILLS_EXTENSION) === void 0 && memberOf(memberOf(result, "capabilities"), "resources") === void 0, `the capabilities of initialize must have no skills, got ${JSON.stringify(memberOf(result, "capabilities"))}`);
|
|
3839
3871
|
});
|
|
3840
3872
|
await handshakeChecks.run("a notification of a revision with a handshake gets 202", ANCHOR, async (signal) => {
|
|
3841
3873
|
expectEqual((await rpc(signal, { method: "notifications/initialized" }, "2025-11-25")).status, 202, "status");
|
|
@@ -3847,14 +3879,14 @@ async function checkTools(checks, mcp) {
|
|
|
3847
3879
|
name,
|
|
3848
3880
|
arguments: args
|
|
3849
3881
|
}, { signal });
|
|
3850
|
-
await checks.run("the instructions are the description of the catalog", `${RULE$
|
|
3882
|
+
await checks.run("the instructions are the description of the catalog", `${RULE$4}#server`, () => {
|
|
3851
3883
|
expectEqual(mcp.getInstructions(), fixture.description, "instructions");
|
|
3852
3884
|
});
|
|
3853
|
-
await checks.run("tools/list gives each available capability of the target", `${RULE$
|
|
3885
|
+
await checks.run("tools/list gives each available capability of the target", `${RULE$4}#tools`, async (signal) => {
|
|
3854
3886
|
const { tools } = await mcp.listTools(void 0, { signal });
|
|
3855
3887
|
expectEqual(sorted(tools.map((tool) => tool.name)), idsOf("mcp"), "tools");
|
|
3856
3888
|
});
|
|
3857
|
-
await checks.run("tools have their hints and output schemas", `${RULE$
|
|
3889
|
+
await checks.run("tools have their hints and output schemas", `${RULE$4}#tools`, async (signal) => {
|
|
3858
3890
|
const { tools } = await mcp.listTools(void 0, { signal });
|
|
3859
3891
|
const echo = tools.find((tool) => tool.name === "fixture.echo");
|
|
3860
3892
|
const refuse = tools.find((tool) => tool.name === "fixture.refuse");
|
|
@@ -3872,19 +3904,19 @@ async function checkTools(checks, mcp) {
|
|
|
3872
3904
|
expect(refuse?.outputSchema === void 0, "fixture.refuse has no object output, so it must have no outputSchema");
|
|
3873
3905
|
expect(echo?.inputSchema.type === "object", "an inputSchema must be an object");
|
|
3874
3906
|
});
|
|
3875
|
-
await checks.run("a value is a tool result with structured content", `${RULE$
|
|
3907
|
+
await checks.run("a value is a tool result with structured content", `${RULE$4}#tools`, async (signal) => {
|
|
3876
3908
|
const result = await call(signal, "fixture.echo", { text: "hello" });
|
|
3877
3909
|
expect(result.isError !== true, "a value must not be an error result");
|
|
3878
3910
|
expectEqual(result.structuredContent, { text: "hello" }, "structuredContent");
|
|
3879
3911
|
expectEqual(textOf(result), { text: "hello" }, "text content");
|
|
3880
3912
|
});
|
|
3881
|
-
await checks.run("a failure is an error result with ok: false", `${RULE$
|
|
3913
|
+
await checks.run("a failure is an error result with ok: false", `${RULE$4}#tools`, async (signal) => {
|
|
3882
3914
|
const result = await call(signal, "fixture.refuse", {});
|
|
3883
3915
|
expect(result.isError === true, "a failure must be an error result");
|
|
3884
3916
|
const body = textOf(result);
|
|
3885
3917
|
expect(memberOf(body, "ok") === false && memberOf(memberOf(body, "error"), "_tag") === "Refused", `expected { ok: false, error: { _tag: "Refused" } }, got ${JSON.stringify(body)}`);
|
|
3886
3918
|
});
|
|
3887
|
-
await checks.run("a defect is an internal call failure with no internal details", `${RULE$
|
|
3919
|
+
await checks.run("a defect is an internal call failure with no internal details", `${RULE$4}#tools`, async (signal) => {
|
|
3888
3920
|
const result = await call(signal, "fixture.crash", {});
|
|
3889
3921
|
const body = textOf(result);
|
|
3890
3922
|
expect(isObject(body), `expected an object, got ${JSON.stringify(body)}`);
|
|
@@ -3892,15 +3924,15 @@ async function checkTools(checks, mcp) {
|
|
|
3892
3924
|
const message = typeof body.message === "string" ? body.message : "";
|
|
3893
3925
|
expect(!/\n\s+at /.test(message), "the message must not contain a stack trace");
|
|
3894
3926
|
});
|
|
3895
|
-
await checks.run("an input that does not agree with its schema is invalid-input", `${RULE$
|
|
3927
|
+
await checks.run("an input that does not agree with its schema is invalid-input", `${RULE$4}#tools`, async (signal) => {
|
|
3896
3928
|
const result = await call(signal, "fixture.echo", { text: 1 });
|
|
3897
3929
|
expectEqual(memberOf(textOf(result), "kind"), "invalid-input", "kind");
|
|
3898
3930
|
});
|
|
3899
|
-
await checks.run("a capability outside the target is an unknown tool", `${RULE$
|
|
3931
|
+
await checks.run("a capability outside the target is an unknown tool", `${RULE$4}#tools`, async (signal) => {
|
|
3900
3932
|
const error = await call(signal, "fixture.hidden", {}).then(() => void 0, (caught) => caught);
|
|
3901
3933
|
expect(memberOf(error, "code") === -32602, `expected the JSON-RPC error -32602, got ${JSON.stringify(error)}`);
|
|
3902
3934
|
});
|
|
3903
|
-
await checks.run("an unavailable capability is not listed", `${RULE$
|
|
3935
|
+
await checks.run("an unavailable capability is not listed", `${RULE$4}#tools`, async (signal) => {
|
|
3904
3936
|
await call(signal, "fixture.switch.set", { on: false });
|
|
3905
3937
|
try {
|
|
3906
3938
|
const { tools } = await mcp.listTools(void 0, { signal });
|
|
@@ -4028,7 +4060,7 @@ function eventRequests(channel) {
|
|
|
4028
4060
|
}
|
|
4029
4061
|
const count = (keys, key) => keys.filter((each) => each === key).length;
|
|
4030
4062
|
async function checkEvents(checks, channel, options) {
|
|
4031
|
-
const RULE_EVENTS = `${RULE$
|
|
4063
|
+
const RULE_EVENTS = `${RULE$4}#events`;
|
|
4032
4064
|
const { resultOf, errorOf, watching, signalKey } = eventRequests(channel);
|
|
4033
4065
|
const notification = async (stream, id, method) => {
|
|
4034
4066
|
const message = await stream.next();
|
|
@@ -4191,7 +4223,7 @@ async function checkEvents(checks, channel, options) {
|
|
|
4191
4223
|
[2500, 2500]
|
|
4192
4224
|
]) {
|
|
4193
4225
|
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" : ""}`;
|
|
4194
|
-
await checks.run(name, `${RULE$
|
|
4226
|
+
await checks.run(name, `${RULE$4}#push`, async (signal) => {
|
|
4195
4227
|
const id = streamId();
|
|
4196
4228
|
const requested = performance.now();
|
|
4197
4229
|
const stream = await channel.stream(id, {
|
|
@@ -4280,7 +4312,7 @@ async function checkEvents(checks, channel, options) {
|
|
|
4280
4312
|
});
|
|
4281
4313
|
if (delivery.includes("poll")) await checkPoll(checks, channel, options.poll);
|
|
4282
4314
|
else {
|
|
4283
|
-
await checks.should("the server serves poll delivery", `${RULE$
|
|
4315
|
+
await checks.should("the server serves poll delivery", `${RULE$4}#events`, () => {
|
|
4284
4316
|
throw new Error("events/list gives no poll delivery. A server that keeps no state between requests serves push only.");
|
|
4285
4317
|
});
|
|
4286
4318
|
await checks.run("events/poll is Unsupported, with the delivery mode poll", RULE_EVENTS, async (signal) => {
|
|
@@ -4295,7 +4327,7 @@ async function checkEvents(checks, channel, options) {
|
|
|
4295
4327
|
}, "data");
|
|
4296
4328
|
});
|
|
4297
4329
|
}
|
|
4298
|
-
if (!delivery.includes("webhook")) await checks.run("events/subscribe and events/unsubscribe are Unsupported, with the delivery mode webhook", `${RULE$
|
|
4330
|
+
if (!delivery.includes("webhook")) await checks.run("events/subscribe and events/unsubscribe are Unsupported, with the delivery mode webhook", `${RULE$4}#webhook`, async (signal) => {
|
|
4299
4331
|
const url = "https://webhook.acid-cat.invalid/hook";
|
|
4300
4332
|
const subscribe = {
|
|
4301
4333
|
name: "fixture.ticks",
|
|
@@ -4320,6 +4352,198 @@ async function checkEvents(checks, channel, options) {
|
|
|
4320
4352
|
}
|
|
4321
4353
|
});
|
|
4322
4354
|
}
|
|
4355
|
+
// src/conform/mcp-skills.ts
|
|
4356
|
+
const RULE$3 = "spec/surfaces/mcp.md#methods";
|
|
4357
|
+
const METHOD_NOT_FOUND = -32601;
|
|
4358
|
+
const INVALID_PARAMS = -32602;
|
|
4359
|
+
/**
|
|
4360
|
+
* Check the skills that an MCP server through HTTP serves for a target of a catalog (spec/surfaces/mcp.md#skills):
|
|
4361
|
+
* `server/discover`, `skills/list`, `skills/get`, `resources/list` and `resources/read`. The digest and the size of each
|
|
4362
|
+
* file must agree with the bytes that `resources/read` gives. A skill that another target of the catalog names gets the
|
|
4363
|
+
* same answer as a skill that does not exist.
|
|
4364
|
+
*/
|
|
4365
|
+
async function checkMcpSkills(url, catalog, target, options = {}) {
|
|
4366
|
+
const checks = new Checks("mcp skills", options.deadline ?? 3e4, options.signal);
|
|
4367
|
+
await checkSkills(checks, httpChannel(url), catalog, target);
|
|
4368
|
+
if (mcpTargetSkills(catalog.targets[target]).length > 0) await checkNameHeader(checks, url, catalog, target);
|
|
4369
|
+
return checks.results;
|
|
4370
|
+
}
|
|
4371
|
+
const isResource = (value) => isObject(value) && typeof value.uri === "string" && typeof value.digest === "string" && typeof value.size === "number";
|
|
4372
|
+
const isEntry = (value) => isObject(value) && typeof value.uri === "string" && isObject(value.frontmatter) && isArrayOf(value.resources, isResource);
|
|
4373
|
+
const sha256 = (bytes) => `sha256:${createHash("sha256").update(bytes).digest("hex")}`;
|
|
4374
|
+
function unknownSkillOf(catalog) {
|
|
4375
|
+
const named = new Set(Object.values(catalog.targets).flatMap((each) => mcpTargetSkills(each)));
|
|
4376
|
+
let unknown = "no-such-skill";
|
|
4377
|
+
while (named.has(unknown)) unknown = `${unknown}-x`;
|
|
4378
|
+
return unknown;
|
|
4379
|
+
}
|
|
4380
|
+
async function checkSkills(checks, channel, catalog, target) {
|
|
4381
|
+
const names = mcpTargetSkills(catalog.targets[target]);
|
|
4382
|
+
const others = Object.entries(catalog.targets).filter(([name]) => name !== target).flatMap(([, other]) => mcpTargetSkills(other)).filter((name) => !names.includes(name));
|
|
4383
|
+
const answer = async (method, params, signal) => {
|
|
4384
|
+
const message = await channel.request(method, params, signal);
|
|
4385
|
+
const result = memberOf(message, "result");
|
|
4386
|
+
const error = memberOf(message, "error");
|
|
4387
|
+
expect(isObject(result) || isObject(error), `${method} must give a result or an error, got ${JSON.stringify(message)}`);
|
|
4388
|
+
return {
|
|
4389
|
+
result: isObject(result) ? result : void 0,
|
|
4390
|
+
error: isObject(error) ? error : void 0
|
|
4391
|
+
};
|
|
4392
|
+
};
|
|
4393
|
+
const resultOf = async (method, params, signal) => {
|
|
4394
|
+
const { result, error } = await answer(method, params, signal);
|
|
4395
|
+
if (result === void 0) throw new Error(`${method} ${JSON.stringify(params)} must give a result, got the error ${JSON.stringify(error)}`);
|
|
4396
|
+
expectEqual([
|
|
4397
|
+
result.resultType,
|
|
4398
|
+
result.ttlMs,
|
|
4399
|
+
result.cacheScope
|
|
4400
|
+
], [
|
|
4401
|
+
"complete",
|
|
4402
|
+
0,
|
|
4403
|
+
"private"
|
|
4404
|
+
], `the resultType, ttlMs and cacheScope of ${method}`);
|
|
4405
|
+
return result;
|
|
4406
|
+
};
|
|
4407
|
+
const errorOf = async (method, params, signal) => {
|
|
4408
|
+
const { error, result } = await answer(method, params, signal);
|
|
4409
|
+
if (error === void 0) throw new Error(`${method} ${JSON.stringify(params)} must give an error, got ${JSON.stringify(result)}`);
|
|
4410
|
+
return {
|
|
4411
|
+
code: error.code,
|
|
4412
|
+
message: error.message
|
|
4413
|
+
};
|
|
4414
|
+
};
|
|
4415
|
+
await checks.run(names.length > 0 ? `server/discover declares resources and the extension ${MCP_SKILLS_EXTENSION}` : `server/discover declares neither resources nor the extension ${MCP_SKILLS_EXTENSION}, and skills/list is not a method`, RULE$3, async (signal) => {
|
|
4416
|
+
const capabilities = memberOf(await resultOf("server/discover", {}, signal), "capabilities");
|
|
4417
|
+
const declared = [memberOf(capabilities, "resources"), memberOf(memberOf(capabilities, "extensions"), MCP_SKILLS_EXTENSION)];
|
|
4418
|
+
if (names.length > 0) expect(declared.every(isObject), `the capabilities must have resources and the extension ${MCP_SKILLS_EXTENSION}, got ${JSON.stringify(capabilities)}`);
|
|
4419
|
+
else {
|
|
4420
|
+
expectEqual(declared, [void 0, void 0], `the resources and the extension ${MCP_SKILLS_EXTENSION} of the capabilities`);
|
|
4421
|
+
expectEqual((await errorOf("skills/list", {}, signal)).code, METHOD_NOT_FOUND, "the JSON-RPC error code of skills/list");
|
|
4422
|
+
}
|
|
4423
|
+
});
|
|
4424
|
+
if (names.length === 0) return;
|
|
4425
|
+
let entries = [];
|
|
4426
|
+
const mimeTypes = /* @__PURE__ */ new Map();
|
|
4427
|
+
await checks.run("skills/list gives each skill of the target, in the order of the catalog, with its frontmatter", RULE$3, async (signal) => {
|
|
4428
|
+
const result = await resultOf("skills/list", {}, signal);
|
|
4429
|
+
expect(!("nextCursor" in result), "the result of skills/list must have no nextCursor");
|
|
4430
|
+
const skills = result.skills;
|
|
4431
|
+
if (!isArrayOf(skills, isEntry)) throw new Error(`skills/list must give a list of skill entries, got ${JSON.stringify(result)}`);
|
|
4432
|
+
expectEqual(skills.map((entry) => entry.uri), names.map((name) => mcpSkillUri(name)), "the URIs of the skills");
|
|
4433
|
+
for (const [index, entry] of skills.entries()) {
|
|
4434
|
+
expectEqual(entry.frontmatter.name, names[index], `the name in the frontmatter of ${entry.uri}`);
|
|
4435
|
+
expect(typeof entry.frontmatter.description === "string", `the frontmatter of ${entry.uri} must have a string description`);
|
|
4436
|
+
const directory = mcpSkillUri(String(names[index]), "");
|
|
4437
|
+
expect(entry.resources.every((resource) => resource.uri.startsWith(directory)), `each file of ${entry.uri} must have a URI that starts with ${directory}`);
|
|
4438
|
+
const paths = entry.resources.map((resource) => resource.uri.slice(directory.length));
|
|
4439
|
+
expectEqual(paths, [...paths].sort(byCodePoint), `the paths of the files of ${entry.uri}, in code point order`);
|
|
4440
|
+
expect(paths.includes(MCP_SKILL_FILE), `the files of ${entry.uri} must have ${MCP_SKILL_FILE}`);
|
|
4441
|
+
}
|
|
4442
|
+
entries = skills;
|
|
4443
|
+
});
|
|
4444
|
+
await checks.run("the size and the digest of each file agree with the bytes that resources/read gives", RULE$3, async (signal) => {
|
|
4445
|
+
expect(entries.length > 0, "skills/list gave no skills");
|
|
4446
|
+
for (const entry of entries) for (const resource of entry.resources) {
|
|
4447
|
+
const contents = (await resultOf("resources/read", { uri: resource.uri }, signal)).contents;
|
|
4448
|
+
const content = isArrayOf(contents, isObject) && contents.length === 1 ? contents[0] : void 0;
|
|
4449
|
+
expect(content !== void 0, `resources/read of ${resource.uri} must give one object in contents, got ${JSON.stringify(contents)}`);
|
|
4450
|
+
expectEqual(content.uri, resource.uri, `the uri of the content of ${resource.uri}`);
|
|
4451
|
+
const bytes = bytesOf(content, resource.uri);
|
|
4452
|
+
expectEqual(content.mimeType, mcpSkillMediaType(resource.uri, typeof content.text === "string"), `the mimeType of ${resource.uri}`);
|
|
4453
|
+
expectEqual(resource.size, bytes.byteLength, `the size of ${resource.uri}`);
|
|
4454
|
+
expectEqual(resource.digest, sha256(bytes), `the digest of ${resource.uri}`);
|
|
4455
|
+
mimeTypes.set(resource.uri, content.mimeType);
|
|
4456
|
+
}
|
|
4457
|
+
});
|
|
4458
|
+
await checks.run("skills/get gives the entry that skills/list gives", RULE$3, async (signal) => {
|
|
4459
|
+
expect(entries.length > 0, "skills/list gave no skills");
|
|
4460
|
+
for (const entry of entries) expectEqual((await resultOf("skills/get", { uri: entry.uri }, signal)).skill, entry, `the skill of skills/get ${entry.uri}`);
|
|
4461
|
+
});
|
|
4462
|
+
await checks.run("resources/list gives each file of each skill, with its name, its media type and its size", RULE$3, async (signal) => {
|
|
4463
|
+
expect(mimeTypes.size > 0, "resources/read gave no files");
|
|
4464
|
+
const result = await resultOf("resources/list", {}, signal);
|
|
4465
|
+
expect(!("nextCursor" in result), "the result of resources/list must have no nextCursor");
|
|
4466
|
+
const expected = entries.flatMap((entry) => {
|
|
4467
|
+
const name = String(entry.frontmatter.name);
|
|
4468
|
+
return entry.resources.map((resource) => {
|
|
4469
|
+
const path = resource.uri.slice(mcpSkillUri(name, "").length);
|
|
4470
|
+
const mimeType = mimeTypes.get(resource.uri);
|
|
4471
|
+
return path === MCP_SKILL_FILE ? {
|
|
4472
|
+
uri: resource.uri,
|
|
4473
|
+
name,
|
|
4474
|
+
description: entry.frontmatter.description,
|
|
4475
|
+
mimeType,
|
|
4476
|
+
size: resource.size
|
|
4477
|
+
} : {
|
|
4478
|
+
uri: resource.uri,
|
|
4479
|
+
name: path,
|
|
4480
|
+
mimeType,
|
|
4481
|
+
size: resource.size
|
|
4482
|
+
};
|
|
4483
|
+
});
|
|
4484
|
+
});
|
|
4485
|
+
const resources = result.resources;
|
|
4486
|
+
expect(isArrayOf(resources, isObject), `resources/list must give a list of resources, got ${JSON.stringify(result)}`);
|
|
4487
|
+
expectEqual(resources.map(sortedKeys), expected.map(sortedKeys), "the resources");
|
|
4488
|
+
});
|
|
4489
|
+
await checks.run(others.length > 0 ? "a skill of another target is not served, and gets the answer of a skill that does not exist" : "a skill that does not exist gets the error -32602", `spec/surfaces/mcp.md#skills-of-a-target`, async (signal) => {
|
|
4490
|
+
const unknown = mcpSkillUri(unknownSkillOf(catalog));
|
|
4491
|
+
const read = await errorOf("resources/read", { uri: unknown }, signal);
|
|
4492
|
+
expectEqual(read, {
|
|
4493
|
+
code: INVALID_PARAMS,
|
|
4494
|
+
message: mcpResourceNotFound(unknown)
|
|
4495
|
+
}, `the error of resources/read ${unknown}`);
|
|
4496
|
+
const get = await errorOf("skills/get", { uri: unknown }, signal);
|
|
4497
|
+
expectEqual(get.code, INVALID_PARAMS, `the error code of skills/get ${unknown}`);
|
|
4498
|
+
for (const other of others) {
|
|
4499
|
+
const uri = mcpSkillUri(other);
|
|
4500
|
+
expect(!entries.some((entry) => entry.uri === uri), `skills/list must not give ${uri}`);
|
|
4501
|
+
const withOther = (error) => ({
|
|
4502
|
+
code: error.code,
|
|
4503
|
+
message: typeof error.message === "string" ? error.message.replaceAll(unknown, uri) : error.message
|
|
4504
|
+
});
|
|
4505
|
+
expectEqual(await errorOf("resources/read", { uri }, signal), withOther(read), `the error of resources/read ${uri}`);
|
|
4506
|
+
expectEqual(await errorOf("skills/get", { uri }, signal), withOther(get), `the error of skills/get ${uri}`);
|
|
4507
|
+
}
|
|
4508
|
+
});
|
|
4509
|
+
}
|
|
4510
|
+
function bytesOf(content, uri) {
|
|
4511
|
+
if (typeof content.text === "string") return new TextEncoder().encode(content.text);
|
|
4512
|
+
const blob = content.blob;
|
|
4513
|
+
expect(typeof blob === "string", `the content of ${uri} must have text or blob`);
|
|
4514
|
+
const bytes = Buffer.from(blob, "base64");
|
|
4515
|
+
expectEqual(bytes.toString("base64"), blob, `the blob of ${uri}, in base64`);
|
|
4516
|
+
return new Uint8Array(bytes);
|
|
4517
|
+
}
|
|
4518
|
+
const sortedKeys = (value) => Object.fromEntries(Object.entries(value).sort(([a], [b]) => byCodePoint(a, b)));
|
|
4519
|
+
async function checkNameHeader(checks, url, catalog, target) {
|
|
4520
|
+
const [name] = mcpTargetSkills(catalog.targets[target]);
|
|
4521
|
+
if (name === void 0) return;
|
|
4522
|
+
await checks.run("resources/read with an Mcp-Name header that is not params.uri gets 400 and HeaderMismatch", "spec/surfaces/mcp.md#headers", async (signal) => {
|
|
4523
|
+
const response = await fetch(url, {
|
|
4524
|
+
method: "POST",
|
|
4525
|
+
headers: {
|
|
4526
|
+
"Content-Type": "application/json",
|
|
4527
|
+
Accept: "application/json, text/event-stream",
|
|
4528
|
+
"MCP-Protocol-Version": EVENTS_REVISION,
|
|
4529
|
+
"Mcp-Method": "resources/read",
|
|
4530
|
+
"Mcp-Name": mcpSkillUri(unknownSkillOf(catalog))
|
|
4531
|
+
},
|
|
4532
|
+
body: JSON.stringify({
|
|
4533
|
+
jsonrpc: "2.0",
|
|
4534
|
+
id: "conform-skill-header",
|
|
4535
|
+
method: "resources/read",
|
|
4536
|
+
params: {
|
|
4537
|
+
uri: mcpSkillUri(name),
|
|
4538
|
+
_meta: META
|
|
4539
|
+
}
|
|
4540
|
+
}),
|
|
4541
|
+
signal
|
|
4542
|
+
});
|
|
4543
|
+
expectEqual(response.status, 400, "the status");
|
|
4544
|
+
expectEqual(memberOf(memberOf(await readJson(response), "error"), "code"), MCP_HEADER_MISMATCH, "the JSON-RPC error code");
|
|
4545
|
+
});
|
|
4546
|
+
}
|
|
4323
4547
|
// src/conform/properties.ts
|
|
4324
4548
|
const RULE$2 = "spec/invocation.md#cancellation-and-concurrency";
|
|
4325
4549
|
function httpInvoke(base) {
|
|
@@ -4522,6 +4746,7 @@ async function checkMcpStdio(command, options) {
|
|
|
4522
4746
|
}
|
|
4523
4747
|
}
|
|
4524
4748
|
all.push(await checkLines(command, options));
|
|
4749
|
+
all.push(await checkStdioSkills(command, options));
|
|
4525
4750
|
all.push(await checkStdioEvents(command, options));
|
|
4526
4751
|
return all;
|
|
4527
4752
|
}
|
|
@@ -4540,6 +4765,22 @@ async function checkStdioEvents(command, options) {
|
|
|
4540
4765
|
}
|
|
4541
4766
|
return checks;
|
|
4542
4767
|
}
|
|
4768
|
+
async function checkStdioSkills(command, options) {
|
|
4769
|
+
const checks = new Checks("mcp-stdio skills", options.deadline, options.signal);
|
|
4770
|
+
const controller = new AbortController();
|
|
4771
|
+
const server = startRaw(command, orStop(controller.signal, options.signal));
|
|
4772
|
+
try {
|
|
4773
|
+
await checkSkills(checks, stdioChannel(server), fixture, "mcp");
|
|
4774
|
+
} finally {
|
|
4775
|
+
controller.abort();
|
|
4776
|
+
}
|
|
4777
|
+
await checks.run("the capabilities of initialize have no skills", `${RULE$1}`, async (signal) => {
|
|
4778
|
+
const handshakeServer = startRaw(command, signal);
|
|
4779
|
+
const capabilities = memberOf(memberOf(await handshake(handshakeServer), "result"), "capabilities");
|
|
4780
|
+
expect(memberOf(capabilities, "resources") === void 0 && memberOf(memberOf(capabilities, "extensions"), MCP_SKILLS_EXTENSION) === void 0, `the capabilities of initialize must have no skills, got ${JSON.stringify(capabilities)}`);
|
|
4781
|
+
});
|
|
4782
|
+
return checks;
|
|
4783
|
+
}
|
|
4543
4784
|
function stdioChannel(server) {
|
|
4544
4785
|
let next = 0;
|
|
4545
4786
|
const send = (id, method, params) => server.write(JSON.stringify({
|
|
@@ -4991,6 +5232,11 @@ async function conform(options) {
|
|
|
4991
5232
|
webhook: options.webhook
|
|
4992
5233
|
})).results);
|
|
4993
5234
|
signal?.throwIfAborted();
|
|
5235
|
+
results.push(...await checkMcpSkills(options.mcp, fixture, "mcp", {
|
|
5236
|
+
deadline,
|
|
5237
|
+
signal
|
|
5238
|
+
}));
|
|
5239
|
+
signal?.throwIfAborted();
|
|
4994
5240
|
const mcp = await mcpInvoke(options.mcp, orStop(AbortSignal.timeout(deadline), signal)).catch(() => void 0);
|
|
4995
5241
|
if (mcp !== void 0) {
|
|
4996
5242
|
results.push(...(await checkProperties("mcp", mcp.invoke, deadline, signal)).results);
|
|
@@ -5042,4 +5288,4 @@ async function conform(options) {
|
|
|
5042
5288
|
}
|
|
5043
5289
|
return results;
|
|
5044
5290
|
}
|
|
5045
|
-
export {
|
|
5291
|
+
export { bundle as a, isCatalog as c, parseJson as d, fixture as i, readSchemas as l, checkMcpSkills as n, catalogSchemas as o, DEADLINE as r, check as s, conform as t, targetCatalog as u };
|