@acid-cat/cli 0.19.0 → 0.21.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.
Files changed (42) hide show
  1. package/README.md +32 -2
  2. package/conformance/fixture.acidcat.json +96 -0
  3. package/dist/conform-LH9KgQ9-.js +5045 -0
  4. package/dist/index.d.ts +164 -4
  5. package/dist/index.js +96 -4
  6. package/dist/main.d.ts +1 -2
  7. package/dist/main.js +1090 -7
  8. package/package.json +4 -3
  9. package/dist/catalog.d.ts +0 -12
  10. package/dist/catalog.js +0 -149
  11. package/dist/conform/check.d.ts +0 -47
  12. package/dist/conform/check.js +0 -178
  13. package/dist/conform/cli.d.ts +0 -5
  14. package/dist/conform/cli.js +0 -721
  15. package/dist/conform/http.d.ts +0 -6
  16. package/dist/conform/http.js +0 -297
  17. package/dist/conform/index.d.ts +0 -69
  18. package/dist/conform/index.js +0 -80
  19. package/dist/conform/mcp-stdio.d.ts +0 -7
  20. package/dist/conform/mcp-stdio.js +0 -291
  21. package/dist/conform/mcp.d.ts +0 -47
  22. package/dist/conform/mcp.js +0 -754
  23. package/dist/conform/poll.d.ts +0 -13
  24. package/dist/conform/poll.js +0 -295
  25. package/dist/conform/properties.d.ts +0 -12
  26. package/dist/conform/properties.js +0 -151
  27. package/dist/conform/serve.d.ts +0 -12
  28. package/dist/conform/serve.js +0 -96
  29. package/dist/conform/server-card.d.ts +0 -5
  30. package/dist/conform/server-card.js +0 -142
  31. package/dist/conform/sse.d.ts +0 -9
  32. package/dist/conform/sse.js +0 -53
  33. package/dist/conform/webhook.d.ts +0 -30
  34. package/dist/conform/webhook.js +0 -481
  35. package/dist/conform/webmcp.d.ts +0 -53
  36. package/dist/conform/webmcp.js +0 -232
  37. package/dist/json/catalog.schema.json.js +0 -170
  38. package/dist/json/fixture.acidcat.json.js +0 -396
  39. package/dist/json/package.json.js +0 -3
  40. package/dist/json/server-card.schema.json.js +0 -281
  41. package/dist/json.d.ts +0 -11
  42. package/dist/json.js +0 -13
@@ -1,142 +0,0 @@
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,9 +0,0 @@
1
- export interface SseMessage {
2
- readonly event?: string;
3
- readonly id?: string;
4
- readonly data: string;
5
- }
6
- export declare function sseReader(response: Response): {
7
- next(): Promise<SseMessage | undefined>;
8
- cancel: () => Promise<void | undefined>;
9
- };
@@ -1,53 +0,0 @@
1
- // src/conform/sse.ts
2
- function sseReader(response) {
3
- if (response.body === null) throw new Error("the response has no body");
4
- const reader = response.body.getReader();
5
- const decoder = new TextDecoder();
6
- let text = "";
7
- const read = async () => {
8
- for (;;) {
9
- const end = /\r?\n\r?\n/.exec(text);
10
- if (end !== null) {
11
- const raw = text.slice(0, end.index);
12
- text = text.slice(end.index + end[0].length);
13
- return parse(raw);
14
- }
15
- const chunk = await reader.read();
16
- if (chunk.done) return text.trim() === "" ? void 0 : parse(text);
17
- text += decoder.decode(chunk.value, { stream: true });
18
- }
19
- };
20
- return {
21
- async next() {
22
- for (;;) {
23
- const frame = await read();
24
- if (frame === void 0) return void 0;
25
- if (frame.type === "message") return frame.message;
26
- }
27
- },
28
- cancel: () => reader.cancel().catch(() => void 0)
29
- };
30
- }
31
- function parse(raw) {
32
- const fields = { data: [] };
33
- const lines = raw.split(/\r?\n/);
34
- if (lines.every((line) => line.startsWith(":"))) return { type: "comment" };
35
- for (const line of lines) {
36
- if (line.startsWith(":")) continue;
37
- const colon = line.indexOf(":");
38
- const name = colon === -1 ? line : line.slice(0, colon);
39
- const value = colon === -1 ? "" : line.slice(colon + 1).replace(/^ /, "");
40
- if (name === "event") fields.event = value;
41
- else if (name === "id") fields.id = value;
42
- else if (name === "data") fields.data.push(value);
43
- }
44
- return {
45
- type: "message",
46
- message: {
47
- ...fields.event === void 0 ? {} : { event: fields.event },
48
- ...fields.id === void 0 ? {} : { id: fields.id },
49
- data: fields.data.join("\n")
50
- }
51
- };
52
- }
53
- export { sseReader };
@@ -1,30 +0,0 @@
1
- import type { JsonObject } from "../json.js";
2
- import { Checks } from "./check.js";
3
- export interface WebhookSettings {
4
- /** The principal that the deployment gives to a request with the header `Authorization: Bearer <principal>`. */
5
- readonly principal: string;
6
- /** The certificate of the receiver, in PEM. It must be valid for the IP address 127.0.0.1. */
7
- readonly cert: string;
8
- /** The private key of the certificate, in PEM. */
9
- readonly key: string;
10
- /**
11
- * A second principal, given to a request with the header `Authorization: Bearer <otherPrincipal>`. With it, the check
12
- * of the limit fills the subscriptions of this principal, which no other check uses, and checks that the first
13
- * principal can still subscribe.
14
- */
15
- readonly otherPrincipal?: string | undefined;
16
- /**
17
- * The maximum lifetime of a subscription in the deployment, in milliseconds. The default is the default of the
18
- * specification, 3 600 000. It must be longer than the deadline: a subscription must last for a whole check.
19
- */
20
- readonly maxTtlMs?: number | undefined;
21
- /**
22
- * The minimum lifetime of a subscription in the deployment, in milliseconds. The default is the default of the
23
- * specification, 60 000. With it, conform also tests that a subscription with no renewal ends: it must be shorter
24
- * than the deadline.
25
- */
26
- readonly minTtlMs?: number | undefined;
27
- /** The maximum number of subscriptions of one principal in the deployment. With it, conform tests the limit. */
28
- readonly maxSubscriptions?: number | undefined;
29
- }
30
- export declare function checkWebhook(checks: Checks, url: string, settings: WebhookSettings, signingKeys: readonly JsonObject[]): Promise<void>;