@acid-cat/cli 0.19.0 → 0.20.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,291 +0,0 @@
1
- import { isObject, memberOf } from "../json.js";
2
- import { Checks, abortable, expect, expectEqual, orStop, until } from "./check.js";
3
- import { META, checkEvents, checkTools, subscriptionOf } from "./mcp.js";
4
- import { checkProperties, clientInvoke } from "./properties.js";
5
- import { spawn } from "node:child_process";
6
- import { randomUUID } from "node:crypto";
7
- import { Client } from "@modelcontextprotocol/client";
8
- import { StdioClientTransport } from "@modelcontextprotocol/client/stdio";
9
- // src/conform/mcp-stdio.ts
10
- const RULE = "spec/surfaces/mcp.md#stdio";
11
- const ERAS = [{
12
- revision: "2026-07-28",
13
- connects: "an MCP client connects with revision 2026-07-28",
14
- options: { versionNegotiation: { mode: { pin: "2026-07-28" } } }
15
- }, {
16
- revision: "2025-11-25",
17
- connects: "an MCP client connects with the initialize handshake of revision 2025-11-25",
18
- options: {}
19
- }];
20
- function environment() {
21
- return Object.fromEntries(Object.entries(process.env).flatMap(([name, value]) => value === void 0 ? [] : [[name, value]]));
22
- }
23
- async function connect(command, options, changes, signal) {
24
- const [program, ...args] = command;
25
- if (program === void 0) throw new Error("the command that starts the MCP server is empty");
26
- const client = new Client({
27
- name: "acid-cat-conform",
28
- version: "0.1.0"
29
- }, {
30
- ...options,
31
- listChanged: { tools: {
32
- autoRefresh: false,
33
- debounceMs: 0,
34
- onChanged: () => void (changes.count += 1)
35
- } }
36
- });
37
- const transport = new StdioClientTransport({
38
- command: program,
39
- args,
40
- env: environment(),
41
- stderr: "ignore"
42
- });
43
- await client.connect(transport, { signal });
44
- return client;
45
- }
46
- async function checkMcpStdio(command, options) {
47
- const all = [];
48
- for (const era of ERAS) {
49
- const checks = new Checks(`mcp-stdio ${era.revision}`, options.deadline, options.signal);
50
- all.push(checks);
51
- const changes = { count: 0 };
52
- let client;
53
- await checks.run(era.connects, RULE, async (signal) => {
54
- client = await connect(command, era.options, changes, signal);
55
- expectEqual(client.getNegotiatedProtocolVersion(), era.revision, "the revision of the session");
56
- });
57
- if (client === void 0) continue;
58
- const mcp = client;
59
- try {
60
- await checkTools(checks, mcp);
61
- await checkChanges(checks, mcp, changes);
62
- all.push(await checkProperties(`mcp-stdio ${era.revision} properties`, clientInvoke(mcp), options.deadline, options.signal));
63
- } finally {
64
- await mcp.close();
65
- }
66
- }
67
- all.push(await checkLines(command, options));
68
- all.push(await checkStdioEvents(command, options));
69
- return all;
70
- }
71
- async function checkStdioEvents(command, options) {
72
- const checks = new Checks("mcp-stdio events", options.deadline, options.signal);
73
- const controller = new AbortController();
74
- const server = startRaw(command, orStop(controller.signal, options.signal));
75
- try {
76
- await checkEvents(checks, stdioChannel(server), {
77
- transport: "stdio",
78
- poll: options.poll,
79
- webhook: false
80
- });
81
- } finally {
82
- controller.abort();
83
- }
84
- return checks;
85
- }
86
- function stdioChannel(server) {
87
- let next = 0;
88
- const send = (id, method, params) => server.write(JSON.stringify({
89
- jsonrpc: "2.0",
90
- id,
91
- method,
92
- params: {
93
- ...params,
94
- _meta: META
95
- }
96
- }));
97
- return {
98
- async request(method, params, signal) {
99
- const id = `conform-request-${next += 1}`;
100
- send(id, method, params);
101
- return until(`the response to ${method}`, async () => server.messages.find((message) => memberOf(message, "id") === id), isObject, signal);
102
- },
103
- async stream(id, params, signal) {
104
- send(id, "events/stream", params);
105
- const belongs = (message) => isObject(message) && (message.id === id || subscriptionOf(message) === id);
106
- let position = 0;
107
- let ended = false;
108
- return {
109
- async next() {
110
- if (ended) return void 0;
111
- const found = await until("the next message of the subscription", async () => server.messages.slice(position).findIndex(belongs), (index) => index >= 0, signal);
112
- const message = server.messages[position + found];
113
- position += found + 1;
114
- if (!belongs(message)) throw new Error("the message of the subscription is not a JSON-RPC message");
115
- if (message.id === id) ended = true;
116
- return message;
117
- },
118
- async cancel() {
119
- if (ended) return;
120
- ended = true;
121
- server.write(JSON.stringify({
122
- jsonrpc: "2.0",
123
- method: "notifications/cancelled",
124
- params: { requestId: id }
125
- }));
126
- }
127
- };
128
- }
129
- };
130
- }
131
- async function checkChanges(checks, mcp, changes) {
132
- const set = (on, signal) => mcp.callTool({
133
- name: "fixture.switch.set",
134
- arguments: { on }
135
- }, { signal });
136
- const listsToggle = async (signal) => (await mcp.listTools(void 0, { signal })).tools.some((tool) => tool.name === "fixture.toggle");
137
- await checks.run("notifications/tools/list_changed comes when a capability becomes unavailable or available", RULE, async (signal) => {
138
- try {
139
- const before = changes.count;
140
- await set(false, signal);
141
- await until("notifications/tools/list_changed comes", async () => changes.count, (count) => count > before, signal);
142
- expect(!await listsToggle(signal), "fixture.toggle must not be listed while it is unavailable");
143
- const off = changes.count;
144
- await set(true, signal);
145
- await until("notifications/tools/list_changed comes again", async () => changes.count, (count) => count > off, signal);
146
- expect(await listsToggle(signal), "fixture.toggle must be listed when it is available again");
147
- } finally {
148
- await set(true, AbortSignal.timeout(checks.deadline));
149
- }
150
- });
151
- }
152
- function startRaw(command, signal) {
153
- const [program, ...args] = command;
154
- if (program === void 0) throw new Error("the command that starts the MCP server is empty");
155
- const child = spawn(program, args, {
156
- stdio: [
157
- "pipe",
158
- "pipe",
159
- "ignore"
160
- ],
161
- signal,
162
- killSignal: "SIGKILL"
163
- });
164
- const lines = [];
165
- const messages = [];
166
- let rest = "";
167
- child.stdout.on("data", (chunk) => {
168
- const parts = (rest + chunk.toString()).split("\n");
169
- rest = parts.pop() ?? "";
170
- for (const line of parts) {
171
- lines.push(line);
172
- try {
173
- messages.push(JSON.parse(line));
174
- } catch {
175
- messages.push(void 0);
176
- }
177
- }
178
- });
179
- child.stdin.on("error", () => void 0);
180
- const exited = new Promise((resolve, reject) => {
181
- child.on("error", (error) => reject(signal.aborted ? /* @__PURE__ */ new Error("waiting until the MCP server exits") : error));
182
- child.on("close", (code, exitSignal) => resolve({
183
- code,
184
- signal: exitSignal
185
- }));
186
- });
187
- exited.catch(() => void 0);
188
- let next = 0;
189
- const write = (line) => child.stdin.write(`${line}\n`);
190
- const request = async (method, params = {}) => {
191
- const id = `conform-${next += 1}`;
192
- write(JSON.stringify({
193
- jsonrpc: "2.0",
194
- id,
195
- method,
196
- params
197
- }));
198
- return until(`the response to ${method}`, async () => messages.find((message) => memberOf(message, "id") === id), isObject, signal);
199
- };
200
- return {
201
- child,
202
- lines,
203
- messages,
204
- write,
205
- request,
206
- exited
207
- };
208
- }
209
- async function handshake(server, revision = "2025-11-25") {
210
- const response = await server.request("initialize", {
211
- protocolVersion: revision,
212
- capabilities: {},
213
- clientInfo: {
214
- name: "acid-cat-conform",
215
- version: "0.1.0"
216
- }
217
- });
218
- server.write(JSON.stringify({
219
- jsonrpc: "2.0",
220
- method: "notifications/initialized"
221
- }));
222
- return response;
223
- }
224
- async function checkLines(command, options) {
225
- const checks = new Checks("mcp-stdio", options.deadline, options.signal);
226
- const withServer = (body) => async (signal) => {
227
- const controller = new AbortController();
228
- const server = startRaw(command, AbortSignal.any([controller.signal, signal]));
229
- try {
230
- await body(server, signal);
231
- } finally {
232
- controller.abort();
233
- }
234
- };
235
- await checks.run("initialize with a revision that the server does not serve gives a revision that it serves", RULE, withServer(async (server) => {
236
- const response = await handshake(server, "1999-01-01");
237
- const version = memberOf(memberOf(response, "result"), "protocolVersion");
238
- expect(typeof version === "string" && version !== "1999-01-01", `expected another revision, got ${JSON.stringify(response)}`);
239
- }));
240
- await checks.run("a line that is not JSON gets the error -32700, and the session stays open", RULE, withServer(async (server, signal) => {
241
- await handshake(server);
242
- server.write("{");
243
- const parseError = await until("the error -32700", async () => server.messages.find((message) => memberOf(memberOf(message, "error"), "code") === -32700), isObject, signal);
244
- expectEqual(parseError["id"], null, "the id of the error");
245
- const echo = await server.request("tools/call", {
246
- name: "fixture.echo",
247
- arguments: { text: "after" }
248
- });
249
- expectEqual(memberOf(memberOf(echo, "result"), "structuredContent"), { text: "after" }, "structuredContent after the error");
250
- }));
251
- await checks.run("standard output has only JSON-RPC messages, also after a defect", RULE, withServer(async (server) => {
252
- await handshake(server);
253
- await server.request("tools/list");
254
- await server.request("tools/call", {
255
- name: "fixture.crash",
256
- arguments: {}
257
- });
258
- await server.request("tools/call", {
259
- name: "fixture.echo",
260
- arguments: { text: "last" }
261
- });
262
- const other = server.messages.findIndex((message) => memberOf(message, "jsonrpc") !== "2.0");
263
- expect(other === -1, `standard output must have only JSON-RPC messages, got the line ${JSON.stringify(server.lines[other])}`);
264
- }));
265
- await checks.run("the server exits when standard input ends, also during a call", RULE, withServer(async (server, signal) => {
266
- await handshake(server);
267
- const key = randomUUID();
268
- server.write(JSON.stringify({
269
- jsonrpc: "2.0",
270
- id: "conform-hold",
271
- method: "tools/call",
272
- params: {
273
- name: "fixture.hold",
274
- arguments: { key }
275
- }
276
- }));
277
- const held = async () => {
278
- const response = await server.request("tools/call", {
279
- name: "fixture.held",
280
- arguments: {}
281
- });
282
- return memberOf(memberOf(memberOf(response, "result"), "structuredContent"), "keys");
283
- };
284
- await until("fixture.held gives the key of the call", held, (keys) => Array.isArray(keys) && keys.includes(key), signal);
285
- server.child.stdin.end();
286
- const exit = await abortable(server.exited, signal);
287
- expect(exit.signal === null, `the process must exit, not end by the signal ${exit.signal}`);
288
- }));
289
- return checks;
290
- }
291
- export { checkMcpStdio };
@@ -1,47 +0,0 @@
1
- import { Client } from "@modelcontextprotocol/client";
2
- import type { JsonObject } from "../json.js";
3
- import { Checks } from "./check.js";
4
- import type { PollSettings } from "./poll.js";
5
- import type { WebhookSettings } from "./webhook.js";
6
- export declare function mcpClient(url: string, signal?: AbortSignal, handshake?: boolean): Promise<Client>;
7
- export interface McpCheckOptions {
8
- readonly maximumBytes: number;
9
- readonly deadline: number;
10
- readonly signal?: AbortSignal | undefined;
11
- readonly handshake: boolean;
12
- readonly poll: PollSettings;
13
- readonly webhook: WebhookSettings | undefined;
14
- }
15
- export declare function checkMcp(url: string, options: McpCheckOptions): Promise<Checks>;
16
- export declare function mcpRequestHeaders(method: string, params: JsonObject): Record<string, string>;
17
- export declare function checkTools(checks: Checks, mcp: Client): Promise<void>;
18
- export declare const EVENTS_REVISION = "2026-07-28";
19
- export declare const META: {
20
- "io.modelcontextprotocol/protocolVersion": string;
21
- "io.modelcontextprotocol/clientCapabilities": {};
22
- };
23
- export type Message = JsonObject;
24
- export interface EventStream {
25
- next(): Promise<Message | undefined>;
26
- cancel(): Promise<void>;
27
- }
28
- export interface Channel {
29
- request(method: string, params: JsonObject, signal: AbortSignal): Promise<Message>;
30
- stream(id: string, params: JsonObject, signal: AbortSignal): Promise<EventStream>;
31
- }
32
- export declare function httpChannel(url: string, headers?: Readonly<Record<string, string>>): Channel;
33
- export declare const subscriptionOf: (message: Message) => unknown;
34
- export interface EventsOptions {
35
- readonly transport: "http" | "stdio";
36
- readonly poll: PollSettings;
37
- readonly webhook: boolean;
38
- }
39
- export declare function eventRequests(channel: Channel): {
40
- resultOf: (method: string, params: JsonObject, signal: AbortSignal) => Promise<JsonObject>;
41
- errorOf: (message: Message | undefined) => JsonObject;
42
- tool: (name: string, args: JsonObject, signal: AbortSignal) => Promise<unknown>;
43
- watching: (signal: AbortSignal) => Promise<readonly string[]>;
44
- signalKey: (key: string, value: string, signal: AbortSignal) => Promise<unknown>;
45
- };
46
- export declare const count: (keys: readonly string[], key: string) => number;
47
- export declare function checkEvents(checks: Checks, channel: Channel, options: EventsOptions): Promise<void>;