eutaxy 0.17.2 → 0.19.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 (74) hide show
  1. package/README.md +15 -12
  2. package/dist/aws.d.mts +2 -2
  3. package/dist/aws.mjs +3 -2
  4. package/dist/aws.mjs.map +1 -1
  5. package/dist/bin.mjs +1 -1
  6. package/dist/check-zkHLdWyf.mjs +1281 -0
  7. package/dist/check-zkHLdWyf.mjs.map +1 -0
  8. package/dist/cli-CNAKqV9R.mjs +297 -0
  9. package/dist/cli-CNAKqV9R.mjs.map +1 -0
  10. package/dist/cli.d.mts.map +1 -1
  11. package/dist/cli.mjs +1 -1
  12. package/dist/cloudflare.d.mts +56 -5
  13. package/dist/cloudflare.d.mts.map +1 -1
  14. package/dist/cloudflare.mjs +6417 -3
  15. package/dist/cloudflare.mjs.map +1 -0
  16. package/dist/{delivery-invariants-DO3j1mmD.mjs → delivery-invariants-BJDck0K8.mjs} +2 -2
  17. package/dist/{delivery-invariants-DO3j1mmD.mjs.map → delivery-invariants-BJDck0K8.mjs.map} +1 -1
  18. package/dist/{delivery-invariants-D7DI7i8x.d.mts → delivery-invariants-C3GXJIbg.d.mts} +2 -2
  19. package/dist/{delivery-invariants-D7DI7i8x.d.mts.map → delivery-invariants-C3GXJIbg.d.mts.map} +1 -1
  20. package/dist/draft-DEUDffHa.mjs +467 -0
  21. package/dist/draft-DEUDffHa.mjs.map +1 -0
  22. package/dist/{src-fxWc6oGc.mjs → generate-TBJM3-2P.mjs} +3 -574
  23. package/dist/generate-TBJM3-2P.mjs.map +1 -0
  24. package/dist/index.d.mts +45 -37
  25. package/dist/index.d.mts.map +1 -1
  26. package/dist/index.mjs +7 -4
  27. package/dist/index.mjs.map +1 -1
  28. package/dist/install-DkzpGA5D.mjs +611 -0
  29. package/dist/install-DkzpGA5D.mjs.map +1 -0
  30. package/dist/{explore-CkKiOuz6.d.mts → ir-KpC2epGn.d.mts} +88 -53
  31. package/dist/ir-KpC2epGn.d.mts.map +1 -0
  32. package/dist/keys-xtanNmuR.mjs +111 -0
  33. package/dist/keys-xtanNmuR.mjs.map +1 -0
  34. package/dist/mcp-B64Ko6y7.mjs +539 -0
  35. package/dist/mcp-B64Ko6y7.mjs.map +1 -0
  36. package/dist/{platform-D4hlJjm3.d.mts → platform-Cs9V9t2k.d.mts} +92 -11
  37. package/dist/platform-Cs9V9t2k.d.mts.map +1 -0
  38. package/dist/pool-CXN4CwGY.mjs +61 -0
  39. package/dist/pool-CXN4CwGY.mjs.map +1 -0
  40. package/dist/{provers-DS44OeEm.mjs → provers-D8VaY_OM.mjs} +18 -2
  41. package/dist/provers-D8VaY_OM.mjs.map +1 -0
  42. package/dist/reader-B9FSoEYW.mjs +1 -0
  43. package/dist/reader-Cz6_bLf6.mjs +3774 -0
  44. package/dist/reader-Cz6_bLf6.mjs.map +1 -0
  45. package/dist/report-_Vzavqg0.mjs +310 -0
  46. package/dist/report-_Vzavqg0.mjs.map +1 -0
  47. package/dist/src-B2DpVbMN.mjs +2 -0
  48. package/dist/src-BFGTvuA_.mjs +1235 -0
  49. package/dist/src-BFGTvuA_.mjs.map +1 -0
  50. package/dist/src-BtLZPRyG.mjs +120 -0
  51. package/dist/src-BtLZPRyG.mjs.map +1 -0
  52. package/dist/src-CB8DcvsK.mjs +1 -0
  53. package/dist/src-COuquJvI.mjs +269 -0
  54. package/dist/src-COuquJvI.mjs.map +1 -0
  55. package/dist/src-Chn-m_r1.mjs +1082 -0
  56. package/dist/src-Chn-m_r1.mjs.map +1 -0
  57. package/dist/src-DwYD3QQJ.mjs +346 -0
  58. package/dist/src-DwYD3QQJ.mjs.map +1 -0
  59. package/dist/{src-D_hHC_-3.mjs → src-Dx4QvrQb.mjs} +945 -548
  60. package/dist/src-Dx4QvrQb.mjs.map +1 -0
  61. package/dist/toolchain-DWfymxAJ.mjs +80 -0
  62. package/dist/toolchain-DWfymxAJ.mjs.map +1 -0
  63. package/dist/verdict-evEM5Gxx.mjs +12 -0
  64. package/dist/verdict-evEM5Gxx.mjs.map +1 -0
  65. package/package.json +4 -1
  66. package/dist/cli-B0Gs2mhT.mjs +0 -9445
  67. package/dist/cli-B0Gs2mhT.mjs.map +0 -1
  68. package/dist/explore-CkKiOuz6.d.mts.map +0 -1
  69. package/dist/platform-D4hlJjm3.d.mts.map +0 -1
  70. package/dist/provers-DS44OeEm.mjs.map +0 -1
  71. package/dist/src-D_hHC_-3.mjs.map +0 -1
  72. package/dist/src-fxWc6oGc.mjs.map +0 -1
  73. package/dist/workerd-DhrzU6AZ.mjs +0 -6300
  74. package/dist/workerd-DhrzU6AZ.mjs.map +0 -1
@@ -0,0 +1,539 @@
1
+ import { a as proverNames, c as typescriptMissing, l as typescriptNeeded, n as exitCodes, o as runCheck, r as loadProver } from "./check-zkHLdWyf.mjs";
2
+ import { t as runDraft } from "./draft-DEUDffHa.mjs";
3
+ import { dirname } from "node:path";
4
+ import { createInterface } from "node:readline";
5
+ // packages/cli/src/version.ts
6
+ /** The published package's version, as the MCP server reports it; the release tooling keeps it in step. */
7
+ const eutaxyVersion = "0.19.0";
8
+ // packages/cli/src/mcp.ts
9
+ /**
10
+ * `eutaxy mcp`: a Model Context Protocol server over stdio, so a coding
11
+ * agent runs the loop "check, read the report, fix or prove, check again"
12
+ * through one tool. One JSON-RPC message per line on stdin and stdout,
13
+ * logs on stderr, exit when stdin closes; written with the standard
14
+ * library alone. It speaks both eras of the protocol: the stateless
15
+ * `2026-07-28` revision, every request carrying its version and client
16
+ * capabilities in `_meta` and `server/discover` answering what is
17
+ * supported; and the `2025-11-25` revision (and its predecessors) with the
18
+ * `initialize` handshake today's clients open with. The tools are pure
19
+ * functions of the repository's files that return the JSON report, as
20
+ * structured content beside its text; a verdict is a result whatever it
21
+ * says, and only a command that could not run is a tool error. Eutaxy
22
+ * never calls a model: every verdict depends only on files.
23
+ */
24
+ /** The protocol revisions served: the stateless one by `_meta`, the handshake ones by `initialize`. */
25
+ const modernVersions = ["2026-07-28"];
26
+ const legacyVersions = [
27
+ "2025-11-25",
28
+ "2025-06-18",
29
+ "2025-03-26",
30
+ "2024-11-05"
31
+ ];
32
+ const protocolVersionKey = "io.modelcontextprotocol/protocolVersion";
33
+ const clientCapabilitiesKey = "io.modelcontextprotocol/clientCapabilities";
34
+ const serverInfoKey = "io.modelcontextprotocol/serverInfo";
35
+ const serverInfo = {
36
+ name: "eutaxy",
37
+ version: eutaxyVersion
38
+ };
39
+ const instructions = [
40
+ "Eutaxy checks Cloudflare Workers by deterministic simulation and proves properties of their pure TypeScript core.",
41
+ "`check` runs a scenario file (*.sim.ts) and returns the verdict: BOUNDED (no violation within the bounds), VIOLATED (with the shrunk schedule, and a regression test written beside the scenario that replays it), or UNSUPPORTED.",
42
+ "`report` runs every spec file (*.props.ts) under a directory through the TESTED rung and, with engines named, the PROVEN rung.",
43
+ "`goals` lists the properties the Lean engine could not prove and writes each module's open goals beside its spec file as <spec>.goals.lean, a proof file with every proof open: copy it to <spec>.lean, add lemmas and tactics, then call `prove` on the spec file. A proof whose source or spec changed since the goals were written is stale, never PROVEN.",
44
+ "`prover_status` says which proof engines are installed; `eutaxy prover install lean` or `smt` installs one.",
45
+ "Verdicts depend only on files in the repository; nothing here calls a model."
46
+ ].join("\n");
47
+ const realRunners = {
48
+ check: runCheck,
49
+ report: async (o) => {
50
+ try {
51
+ return await (await import("./report-_Vzavqg0.mjs")).runReport(o);
52
+ } catch (err) {
53
+ if (!typescriptMissing(err)) throw err;
54
+ o.stderr(`eutaxy report needs ${typescriptNeeded}\n`);
55
+ return exitCodes.error;
56
+ }
57
+ },
58
+ status: async () => {
59
+ const engines = [];
60
+ for (const name of proverNames) {
61
+ const a = await loadProver(name).then((engine) => engine.available(), (err) => ({ unavailable: err instanceof Error ? err.message : String(err) }));
62
+ engines.push({
63
+ name,
64
+ ..."unavailable" in a ? {
65
+ installed: false,
66
+ reason: a.unavailable
67
+ } : {
68
+ installed: true,
69
+ version: a.version
70
+ }
71
+ });
72
+ }
73
+ return { engines };
74
+ }
75
+ };
76
+ var ToolError = class extends Error {};
77
+ /** A command's exit code and what it printed. */
78
+ async function capture(run) {
79
+ let stdout = "";
80
+ let stderr = "";
81
+ return {
82
+ code: await run((t) => {
83
+ stdout += t;
84
+ }, (t) => {
85
+ stderr += t;
86
+ }),
87
+ stdout,
88
+ stderr
89
+ };
90
+ }
91
+ /** The report a command printed as JSON, or a tool error with what it said instead. */
92
+ function reported(what, r) {
93
+ if (r.code === exitCodes.error) throw new ToolError(`${what} could not run (exit 3): ${r.stderr.trim() || r.stdout.trim()}`);
94
+ try {
95
+ return JSON.parse(r.stdout);
96
+ } catch {
97
+ throw new ToolError(`${what} printed no JSON report: ${(r.stdout + r.stderr).trim()}`);
98
+ }
99
+ }
100
+ const str = (args, key, required = false) => {
101
+ const v = args[key];
102
+ if (v === void 0) {
103
+ if (required) throw new ToolError(`${key} is required`);
104
+ return;
105
+ }
106
+ if (typeof v !== "string" || v.length === 0) throw new ToolError(`${key} must be a non-empty string`);
107
+ return v;
108
+ };
109
+ const bool = (args, key) => {
110
+ const v = args[key];
111
+ if (v === void 0) return void 0;
112
+ if (typeof v !== "boolean") throw new ToolError(`${key} must be a boolean`);
113
+ return v;
114
+ };
115
+ const positiveInt = (args, key) => {
116
+ const v = args[key];
117
+ if (v === void 0) return void 0;
118
+ if (typeof v !== "number" || !Number.isInteger(v) || v <= 0) throw new ToolError(`${key} must be a positive integer`);
119
+ return v;
120
+ };
121
+ const strings = (args, key) => {
122
+ const v = args[key];
123
+ if (v === void 0) return void 0;
124
+ if (!Array.isArray(v) || !v.every((x) => typeof x === "string" && x.length > 0)) throw new ToolError(`${key} must be an array of non-empty strings`);
125
+ return v;
126
+ };
127
+ const only = (args, allowed) => {
128
+ const extra = Object.keys(args).find((k) => !allowed.includes(k));
129
+ if (extra !== void 0) throw new ToolError(`unknown argument ${extra}; the arguments are ${allowed.join(", ")}`);
130
+ };
131
+ const engineNames = [...proverNames];
132
+ const proversSchema = {
133
+ type: "array",
134
+ items: {
135
+ type: "string",
136
+ enum: engineNames
137
+ },
138
+ description: `Proof engines for the PROVEN rung: ${engineNames.join(", ")}`
139
+ };
140
+ const asResult = (structured, isError = false) => ({
141
+ structured,
142
+ text: JSON.stringify(structured, null, 2),
143
+ ...isError ? { isError: true } : {}
144
+ });
145
+ const tools = [
146
+ {
147
+ name: "check",
148
+ title: "Check a scenario",
149
+ description: "Run a scenario file (*.sim.ts) in the simulator and return the JSON report: the verdict (BOUNDED, VIOLATED with the shrunk schedule, or UNSUPPORTED), the spec verdicts, and on a violation the path of the regression test written beside the scenario (regressionTest), and the errors nothing handled during a run whose verdict still stands (unhandledErrors). Exit code 1 is a violation or a refuted spec, not an error.",
150
+ inputSchema: {
151
+ type: "object",
152
+ properties: {
153
+ scenario: {
154
+ type: "string",
155
+ description: "Path of the scenario file, relative to the working directory"
156
+ },
157
+ wrangler: {
158
+ type: "string",
159
+ description: "Wrangler config path; default: the one the scenario names, else the one beside it"
160
+ },
161
+ seed: {
162
+ type: "string",
163
+ description: "Exploration seed; default: the scenario file name"
164
+ },
165
+ maxRuns: {
166
+ type: "integer",
167
+ minimum: 1,
168
+ description: "Cap on exploration runs"
169
+ },
170
+ budgetMs: {
171
+ type: "integer",
172
+ minimum: 1,
173
+ description: "Time budget in milliseconds, replacing the scenario's"
174
+ },
175
+ exhaustive: {
176
+ type: "boolean",
177
+ description: "Run every schedule within the bounds once"
178
+ },
179
+ provers: proversSchema,
180
+ regression: {
181
+ type: "boolean",
182
+ description: "Write the regression test on a violation; default true"
183
+ },
184
+ out: {
185
+ type: "string",
186
+ description: "Where to write the regression test"
187
+ }
188
+ },
189
+ required: ["scenario"],
190
+ additionalProperties: false
191
+ },
192
+ async run(args, ctx, runners) {
193
+ only(args, [
194
+ "scenario",
195
+ "wrangler",
196
+ "seed",
197
+ "maxRuns",
198
+ "budgetMs",
199
+ "exhaustive",
200
+ "provers",
201
+ "regression",
202
+ "out"
203
+ ]);
204
+ const scenario = str(args, "scenario", true);
205
+ const wrangler = str(args, "wrangler");
206
+ const seed = str(args, "seed");
207
+ const maxRuns = positiveInt(args, "maxRuns");
208
+ const budgetMs = positiveInt(args, "budgetMs");
209
+ const engines = strings(args, "provers");
210
+ const out = str(args, "out");
211
+ const r = await capture((stdout, stderr) => runners.check({
212
+ scenario,
213
+ cwd: ctx.cwd,
214
+ ...wrangler === void 0 ? {} : { wrangler },
215
+ ...seed === void 0 ? {} : { seed },
216
+ ...maxRuns === void 0 ? {} : { maxRuns },
217
+ ...budgetMs === void 0 ? {} : { budgetMs },
218
+ exhaustive: bool(args, "exhaustive") === true,
219
+ ...engines === void 0 ? {} : { provers: engines },
220
+ json: true,
221
+ ...out === void 0 ? {} : { out },
222
+ noRegression: bool(args, "regression") === false,
223
+ expectViolation: false,
224
+ keep: false,
225
+ stdout,
226
+ stderr
227
+ }));
228
+ return asResult({
229
+ exitCode: r.code,
230
+ report: reported("check", r)
231
+ });
232
+ }
233
+ },
234
+ {
235
+ name: "report",
236
+ title: "Report on the spec files",
237
+ description: "Run every spec file (*.props.ts) under a directory through the TESTED rung and, with engines named, the PROVEN rung; return the JSON report of spec verdicts. Exit code 1 is a refuted or conflicting spec, not an error.",
238
+ inputSchema: {
239
+ type: "object",
240
+ properties: {
241
+ dir: {
242
+ type: "string",
243
+ description: "Directory to search; default: the working directory"
244
+ },
245
+ provers: proversSchema,
246
+ seed: {
247
+ type: "string",
248
+ description: "Seed for the TESTED rung; default report"
249
+ }
250
+ },
251
+ additionalProperties: false
252
+ },
253
+ async run(args, ctx, runners) {
254
+ only(args, [
255
+ "dir",
256
+ "provers",
257
+ "seed"
258
+ ]);
259
+ const dir = str(args, "dir");
260
+ const engines = strings(args, "provers");
261
+ const seed = str(args, "seed");
262
+ const r = await capture((stdout, stderr) => runners.report({
263
+ cwd: ctx.cwd,
264
+ ...dir === void 0 ? {} : { dir },
265
+ ...engines === void 0 ? {} : { provers: engines },
266
+ ...seed === void 0 ? {} : { seed },
267
+ json: true,
268
+ stdout,
269
+ stderr
270
+ }));
271
+ return asResult({
272
+ exitCode: r.code,
273
+ report: reported("report", r)
274
+ });
275
+ }
276
+ },
277
+ {
278
+ name: "goals",
279
+ title: "List the open proof goals",
280
+ description: "Run the Lean engine on every spec file under a directory and list the properties it could not prove, each with the statement it tried; write each module's open goals beside its spec file as <spec>.goals.lean, a proof file with every proof open (copy it to <spec>.lean, add lemmas and tactics, then call prove). Needs the lean engine installed.",
281
+ inputSchema: {
282
+ type: "object",
283
+ properties: { dir: {
284
+ type: "string",
285
+ description: "Directory to search; default: the working directory"
286
+ } },
287
+ additionalProperties: false
288
+ },
289
+ async run(args, ctx, runners) {
290
+ only(args, ["dir"]);
291
+ const dir = str(args, "dir");
292
+ const r = await capture((stdout, stderr) => runners.report({
293
+ cwd: ctx.cwd,
294
+ ...dir === void 0 ? {} : { dir },
295
+ provers: ["lean"],
296
+ goals: true,
297
+ json: true,
298
+ stdout,
299
+ stderr
300
+ }));
301
+ return asResult({
302
+ exitCode: r.code,
303
+ report: reported("goals", r)
304
+ });
305
+ }
306
+ },
307
+ {
308
+ name: "prove",
309
+ title: "Check the proofs supplied for a spec file",
310
+ description: "Run the Lean engine on one module, the one whose spec file (*.props.ts) is given, with the proofs supplied beside it in <spec>.lean, and return its spec verdicts: PROVEN where a proof closes (Lean's kernel checked it against the statement Eutaxy emitted), UNKNOWN with the reason where it does not, or where the proof file is stale (written for another version of the module or the spec).",
311
+ inputSchema: {
312
+ type: "object",
313
+ properties: { spec: {
314
+ type: "string",
315
+ description: "Path of the spec file, relative to the working directory"
316
+ } },
317
+ required: ["spec"],
318
+ additionalProperties: false
319
+ },
320
+ async run(args, ctx, runners) {
321
+ only(args, ["spec"]);
322
+ const spec = str(args, "spec", true);
323
+ const r = await capture((stdout, stderr) => runners.report({
324
+ cwd: ctx.cwd,
325
+ dir: dirname(spec),
326
+ only: spec,
327
+ provers: ["lean"],
328
+ json: true,
329
+ stdout,
330
+ stderr
331
+ }));
332
+ return asResult({
333
+ exitCode: r.code,
334
+ report: reported("prove", r)
335
+ });
336
+ }
337
+ },
338
+ {
339
+ name: "draft",
340
+ title: "Draft a scenario",
341
+ description: "Draft a scenario (*.sim.ts) from a wrangler config (JSON or JSONC) and the Worker module it names: the bindings become setup steps (a service binding whose Worker's config is found under the directory becomes a callee), the Worker's handlers the drive, the hosts its code fetches the externals; the invariants and the drive's events are holes marked TODO for you to fill before calling check. Returns the source, the draft as data and its notes (bindings not modelled, guesses made); with out, also writes the file, never over an existing one. Nothing is imported or run.",
342
+ inputSchema: {
343
+ type: "object",
344
+ properties: {
345
+ config: {
346
+ type: "string",
347
+ description: "Wrangler config path, relative to the working directory; default: wrangler.jsonc or wrangler.json there"
348
+ },
349
+ worker: {
350
+ type: "string",
351
+ description: "The Worker module; default: the config's main"
352
+ },
353
+ out: {
354
+ type: "string",
355
+ description: "Where to write the scenario; paths in it are relative to its directory. Default: not written"
356
+ }
357
+ },
358
+ additionalProperties: false
359
+ },
360
+ async run(args, ctx) {
361
+ only(args, [
362
+ "config",
363
+ "worker",
364
+ "out"
365
+ ]);
366
+ const config = str(args, "config");
367
+ const worker = str(args, "worker");
368
+ const out = str(args, "out");
369
+ let stdout = "";
370
+ let stderr = "";
371
+ const code = runDraft({
372
+ cwd: ctx.cwd,
373
+ ...config === void 0 ? {} : { config },
374
+ ...worker === void 0 ? {} : { worker },
375
+ ...out === void 0 ? {} : { out },
376
+ json: true,
377
+ stdout: (t) => {
378
+ stdout += t;
379
+ },
380
+ stderr: (t) => {
381
+ stderr += t;
382
+ }
383
+ });
384
+ if (code !== 0) throw new ToolError(stderr.trim() || `draft exited ${code}`);
385
+ return asResult(JSON.parse(stdout));
386
+ }
387
+ },
388
+ {
389
+ name: "prover_status",
390
+ title: "Which proof engines are installed",
391
+ description: "For each proof engine (lean, smt): whether its pinned toolchain is installed and its version, or why not and how to install it (eutaxy prover install <name>).",
392
+ inputSchema: {
393
+ type: "object",
394
+ additionalProperties: false
395
+ },
396
+ async run(args, _ctx, runners) {
397
+ only(args, []);
398
+ return asResult(await runners.status());
399
+ }
400
+ }
401
+ ];
402
+ const errorResponse = (id, code, message, data) => ({
403
+ jsonrpc: "2.0",
404
+ id,
405
+ error: {
406
+ code,
407
+ message,
408
+ ...data === void 0 ? {} : { data }
409
+ }
410
+ });
411
+ /** A result in the requester's era: the stateless one carries `resultType` and the server's identity. */
412
+ const resultResponse = (req, result) => ({
413
+ jsonrpc: "2.0",
414
+ id: req.id,
415
+ result: req.modern ? {
416
+ resultType: "complete",
417
+ ...result,
418
+ _meta: { [serverInfoKey]: serverInfo }
419
+ } : result
420
+ });
421
+ const toolListing = () => tools.map((t) => ({
422
+ name: t.name,
423
+ title: t.title,
424
+ description: t.description,
425
+ inputSchema: t.inputSchema
426
+ }));
427
+ async function callTool(req, ctx) {
428
+ const name = req.params["name"];
429
+ const tool = tools.find((t) => t.name === name);
430
+ if (typeof name !== "string" || !tool) return errorResponse(req.id, -32602, `Unknown tool: ${String(name)}`);
431
+ const args = req.params["arguments"] ?? {};
432
+ if (typeof args !== "object" || args === null || Array.isArray(args)) return errorResponse(req.id, -32602, "arguments must be an object");
433
+ const runners = {
434
+ ...realRunners,
435
+ ...ctx.runners
436
+ };
437
+ let result;
438
+ try {
439
+ result = await tool.run(args, ctx, runners);
440
+ } catch (err) {
441
+ const message = err instanceof Error ? err.message : String(err);
442
+ result = {
443
+ structured: { error: message },
444
+ text: message,
445
+ isError: true
446
+ };
447
+ }
448
+ return resultResponse(req, {
449
+ content: [{
450
+ type: "text",
451
+ text: result.text
452
+ }],
453
+ structuredContent: result.structured,
454
+ isError: result.isError === true
455
+ });
456
+ }
457
+ /**
458
+ * One line in, at most one line out: the response to a request, nothing
459
+ * for a notification. A request of the stateless era whose version is not
460
+ * served gets the `UnsupportedProtocolVersion` error with what is.
461
+ */
462
+ async function handleLine(line, ctx) {
463
+ let message;
464
+ try {
465
+ message = JSON.parse(line);
466
+ } catch {
467
+ return JSON.stringify(errorResponse(null, -32700, "Parse error"));
468
+ }
469
+ if (Array.isArray(message)) return JSON.stringify(errorResponse(null, -32600, "Invalid Request: batches are not supported"));
470
+ if (typeof message !== "object" || message === null) return JSON.stringify(errorResponse(null, -32600, "Invalid Request"));
471
+ const m = message;
472
+ const id = m["id"];
473
+ const idOk = typeof id === "string" || typeof id === "number";
474
+ if (m["jsonrpc"] !== "2.0" || typeof m["method"] !== "string") return JSON.stringify(errorResponse(idOk ? id : null, -32600, "Invalid Request"));
475
+ if (id === void 0) return void 0;
476
+ if (!idOk) return JSON.stringify(errorResponse(null, -32600, "Invalid Request: id must be a string or a number"));
477
+ const params = typeof m["params"] === "object" && m["params"] !== null ? m["params"] : {};
478
+ const meta = typeof params["_meta"] === "object" && params["_meta"] !== null ? params["_meta"] : {};
479
+ const requested = meta[protocolVersionKey];
480
+ const req = {
481
+ id,
482
+ method: m["method"],
483
+ params,
484
+ modern: typeof requested === "string"
485
+ };
486
+ if (req.modern) {
487
+ if (!modernVersions.includes(requested)) return JSON.stringify(errorResponse(req.id, -32022, "Unsupported protocol version", {
488
+ supported: [...modernVersions],
489
+ requested
490
+ }));
491
+ if (typeof meta[clientCapabilitiesKey] !== "object" || meta[clientCapabilitiesKey] === null) return JSON.stringify(errorResponse(req.id, -32602, `Invalid params: _meta.${clientCapabilitiesKey} is required`));
492
+ }
493
+ let response;
494
+ try {
495
+ response = await dispatch(req, ctx);
496
+ } catch (err) {
497
+ response = errorResponse(req.id, -32603, `Internal error: ${err instanceof Error ? err.message : String(err)}`);
498
+ }
499
+ return JSON.stringify(response);
500
+ }
501
+ async function dispatch(req, ctx) {
502
+ switch (req.method) {
503
+ case "initialize": {
504
+ const asked = req.params["protocolVersion"];
505
+ const version = typeof asked === "string" && legacyVersions.includes(asked) ? asked : legacyVersions[0];
506
+ return resultResponse(req, {
507
+ protocolVersion: version,
508
+ capabilities: { tools: {} },
509
+ serverInfo,
510
+ instructions
511
+ });
512
+ }
513
+ case "ping": return resultResponse(req, {});
514
+ case "server/discover": return resultResponse(req, {
515
+ supportedVersions: [...modernVersions],
516
+ capabilities: { tools: {} },
517
+ instructions
518
+ });
519
+ case "tools/list": return resultResponse(req, { tools: toolListing() });
520
+ case "tools/call": return callTool(req, ctx);
521
+ default: return errorResponse(req.id, -32601, `Method not found: ${req.method}`);
522
+ }
523
+ }
524
+ /** Serve on the process's standard streams until stdin closes. Requests are answered one at a time, in order. */
525
+ async function serveStdio(ctx) {
526
+ const lines = createInterface({
527
+ input: process.stdin,
528
+ crlfDelay: Number.POSITIVE_INFINITY
529
+ });
530
+ for await (const line of lines) {
531
+ if (line.trim().length === 0) continue;
532
+ const out = await handleLine(line, ctx);
533
+ if (out !== void 0) process.stdout.write(`${out}\n`);
534
+ }
535
+ return exitCodes.BOUNDED;
536
+ }
537
+ export { serveStdio };
538
+
539
+ //# sourceMappingURL=mcp-B64Ko6y7.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-B64Ko6y7.mjs","names":[],"sources":["../../cli/src/version.ts","../../cli/src/mcp.ts"],"sourcesContent":["/** The published package's version, as the MCP server reports it; the release tooling keeps it in step. */\nexport const eutaxyVersion = \"0.19.0\"; // x-release-please-version\n","/**\n * `eutaxy mcp`: a Model Context Protocol server over stdio, so a coding\n * agent runs the loop \"check, read the report, fix or prove, check again\"\n * through one tool. One JSON-RPC message per line on stdin and stdout,\n * logs on stderr, exit when stdin closes; written with the standard\n * library alone. It speaks both eras of the protocol: the stateless\n * `2026-07-28` revision, every request carrying its version and client\n * capabilities in `_meta` and `server/discover` answering what is\n * supported; and the `2025-11-25` revision (and its predecessors) with the\n * `initialize` handshake today's clients open with. The tools are pure\n * functions of the repository's files that return the JSON report, as\n * structured content beside its text; a verdict is a result whatever it\n * says, and only a command that could not run is a tool error. Eutaxy\n * never calls a model: every verdict depends only on files.\n */\n\nimport { dirname } from \"node:path\";\nimport { createInterface } from \"node:readline\";\nimport { type CheckOptions, exitCodes, loadProver, proverNames, runCheck } from \"./check.ts\";\nimport { runDraft } from \"./draft.ts\";\nimport type { ReportOptions } from \"./report.ts\";\nimport { typescriptMissing, typescriptNeeded } from \"./specs.ts\";\nimport { eutaxyVersion } from \"./version.ts\";\n\n/** The protocol revisions served: the stateless one by `_meta`, the handshake ones by `initialize`. */\nexport const modernVersions: readonly string[] = [\"2026-07-28\"];\nexport const legacyVersions: readonly string[] = [\n \"2025-11-25\",\n \"2025-06-18\",\n \"2025-03-26\",\n \"2024-11-05\",\n];\n\nconst protocolVersionKey = \"io.modelcontextprotocol/protocolVersion\";\nconst clientCapabilitiesKey = \"io.modelcontextprotocol/clientCapabilities\";\nconst serverInfoKey = \"io.modelcontextprotocol/serverInfo\";\n\nexport const serverInfo = { name: \"eutaxy\", version: eutaxyVersion } as const;\n\nexport const instructions = [\n \"Eutaxy checks Cloudflare Workers by deterministic simulation and proves properties of their pure TypeScript core.\",\n \"`check` runs a scenario file (*.sim.ts) and returns the verdict: BOUNDED (no violation within the bounds), VIOLATED (with the shrunk schedule, and a regression test written beside the scenario that replays it), or UNSUPPORTED.\",\n \"`report` runs every spec file (*.props.ts) under a directory through the TESTED rung and, with engines named, the PROVEN rung.\",\n \"`goals` lists the properties the Lean engine could not prove and writes each module's open goals beside its spec file as <spec>.goals.lean, a proof file with every proof open: copy it to <spec>.lean, add lemmas and tactics, then call `prove` on the spec file. A proof whose source or spec changed since the goals were written is stale, never PROVEN.\",\n \"`prover_status` says which proof engines are installed; `eutaxy prover install lean` or `smt` installs one.\",\n \"Verdicts depend only on files in the repository; nothing here calls a model.\",\n].join(\"\\n\");\n\ntype Json = null | boolean | number | string | Json[] | { [key: string]: Json };\ntype Params = Record<string, unknown>;\n\ninterface Request {\n readonly id: string | number;\n readonly method: string;\n readonly params: Params;\n /** The `_meta` the request carries, when it is of the stateless era. */\n readonly modern: boolean;\n}\n\n/** What a tool answers: structured content, its text form, and whether the tool itself failed. */\nexport interface ToolResult {\n readonly structured: Json;\n readonly text: string;\n readonly isError?: boolean;\n}\n\n/** The commands the tools run, injectable for tests; the real ones otherwise. */\nexport interface Runners {\n readonly check: (o: CheckOptions) => Promise<number>;\n readonly report: (o: ReportOptions) => Promise<number>;\n readonly status: () => Promise<Json>;\n}\n\nexport interface McpContext {\n readonly cwd: string;\n /** Where logs go: stderr. */\n readonly log: (text: string) => void;\n readonly runners?: Partial<Runners>;\n}\n\nconst realRunners: Runners = {\n check: runCheck,\n // The report and the engines load the spec reader, and with it the TypeScript compiler: loaded\n // when a tool that needs them is called, so the server starts in a project without it.\n report: async (o) => {\n try {\n return await (await import(\"./report.ts\")).runReport(o);\n } catch (err) {\n if (!typescriptMissing(err)) throw err;\n o.stderr(`eutaxy report needs ${typescriptNeeded}\\n`);\n return exitCodes.error;\n }\n },\n status: async () => {\n const engines: Json[] = [];\n for (const name of proverNames) {\n // An engine that cannot be loaded (no TypeScript compiler here) is not installed, with why:\n // the others are still reported.\n const a = await loadProver(name).then(\n (engine) => engine.available(),\n (err: unknown) => ({ unavailable: err instanceof Error ? err.message : String(err) }),\n );\n engines.push({\n name,\n ...(\"unavailable\" in a\n ? { installed: false, reason: a.unavailable }\n : { installed: true, version: a.version }),\n });\n }\n return { engines };\n },\n};\n\nclass ToolError extends Error {}\n\n/** A command's exit code and what it printed. */\nasync function capture(\n run: (stdout: (t: string) => void, stderr: (t: string) => void) => Promise<number>,\n): Promise<{ code: number; stdout: string; stderr: string }> {\n let stdout = \"\";\n let stderr = \"\";\n const code = await run(\n (t) => {\n stdout += t;\n },\n (t) => {\n stderr += t;\n },\n );\n return { code, stdout, stderr };\n}\n\n/** The report a command printed as JSON, or a tool error with what it said instead. */\nfunction reported(what: string, r: { code: number; stdout: string; stderr: string }): Json {\n if (r.code === exitCodes.error)\n throw new ToolError(`${what} could not run (exit 3): ${r.stderr.trim() || r.stdout.trim()}`);\n try {\n return JSON.parse(r.stdout) as Json;\n } catch {\n throw new ToolError(`${what} printed no JSON report: ${(r.stdout + r.stderr).trim()}`);\n }\n}\n\nconst str = (args: Params, key: string, required = false): string | undefined => {\n const v = args[key];\n if (v === undefined) {\n if (required) throw new ToolError(`${key} is required`);\n return undefined;\n }\n if (typeof v !== \"string\" || v.length === 0)\n throw new ToolError(`${key} must be a non-empty string`);\n return v;\n};\nconst bool = (args: Params, key: string): boolean | undefined => {\n const v = args[key];\n if (v === undefined) return undefined;\n if (typeof v !== \"boolean\") throw new ToolError(`${key} must be a boolean`);\n return v;\n};\nconst positiveInt = (args: Params, key: string): number | undefined => {\n const v = args[key];\n if (v === undefined) return undefined;\n if (typeof v !== \"number\" || !Number.isInteger(v) || v <= 0)\n throw new ToolError(`${key} must be a positive integer`);\n return v;\n};\nconst strings = (args: Params, key: string): string[] | undefined => {\n const v = args[key];\n if (v === undefined) return undefined;\n if (!Array.isArray(v) || !v.every((x) => typeof x === \"string\" && x.length > 0))\n throw new ToolError(`${key} must be an array of non-empty strings`);\n return v as string[];\n};\nconst only = (args: Params, allowed: readonly string[]): void => {\n const extra = Object.keys(args).find((k) => !allowed.includes(k));\n if (extra !== undefined)\n throw new ToolError(`unknown argument ${extra}; the arguments are ${allowed.join(\", \")}`);\n};\n\ninterface Tool {\n readonly name: string;\n readonly title: string;\n readonly description: string;\n readonly inputSchema: Json;\n readonly run: (args: Params, ctx: McpContext, runners: Runners) => Promise<ToolResult>;\n}\n\nconst engineNames: string[] = [...proverNames];\nconst proversSchema: Json = {\n type: \"array\",\n items: { type: \"string\", enum: engineNames },\n description: `Proof engines for the PROVEN rung: ${engineNames.join(\", \")}`,\n};\n\nconst asResult = (structured: Json, isError = false): ToolResult => ({\n structured,\n text: JSON.stringify(structured, null, 2),\n ...(isError ? { isError: true } : {}),\n});\n\nexport const tools: readonly Tool[] = [\n {\n name: \"check\",\n title: \"Check a scenario\",\n description:\n \"Run a scenario file (*.sim.ts) in the simulator and return the JSON report: the verdict (BOUNDED, VIOLATED with the shrunk schedule, or UNSUPPORTED), the spec verdicts, and on a violation the path of the regression test written beside the scenario (regressionTest), and the errors nothing handled during a run whose verdict still stands (unhandledErrors). Exit code 1 is a violation or a refuted spec, not an error.\",\n inputSchema: {\n type: \"object\",\n properties: {\n scenario: {\n type: \"string\",\n description: \"Path of the scenario file, relative to the working directory\",\n },\n wrangler: {\n type: \"string\",\n description:\n \"Wrangler config path; default: the one the scenario names, else the one beside it\",\n },\n seed: { type: \"string\", description: \"Exploration seed; default: the scenario file name\" },\n maxRuns: { type: \"integer\", minimum: 1, description: \"Cap on exploration runs\" },\n budgetMs: {\n type: \"integer\",\n minimum: 1,\n description: \"Time budget in milliseconds, replacing the scenario's\",\n },\n exhaustive: { type: \"boolean\", description: \"Run every schedule within the bounds once\" },\n provers: proversSchema,\n regression: {\n type: \"boolean\",\n description: \"Write the regression test on a violation; default true\",\n },\n out: { type: \"string\", description: \"Where to write the regression test\" },\n },\n required: [\"scenario\"],\n additionalProperties: false,\n },\n async run(args, ctx, runners) {\n only(args, [\n \"scenario\",\n \"wrangler\",\n \"seed\",\n \"maxRuns\",\n \"budgetMs\",\n \"exhaustive\",\n \"provers\",\n \"regression\",\n \"out\",\n ]);\n const scenario = str(args, \"scenario\", true) as string;\n const wrangler = str(args, \"wrangler\");\n const seed = str(args, \"seed\");\n const maxRuns = positiveInt(args, \"maxRuns\");\n const budgetMs = positiveInt(args, \"budgetMs\");\n const engines = strings(args, \"provers\");\n const out = str(args, \"out\");\n const r = await capture((stdout, stderr) =>\n runners.check({\n scenario,\n cwd: ctx.cwd,\n ...(wrangler === undefined ? {} : { wrangler }),\n ...(seed === undefined ? {} : { seed }),\n ...(maxRuns === undefined ? {} : { maxRuns }),\n ...(budgetMs === undefined ? {} : { budgetMs }),\n exhaustive: bool(args, \"exhaustive\") === true,\n ...(engines === undefined ? {} : { provers: engines }),\n json: true,\n ...(out === undefined ? {} : { out }),\n noRegression: bool(args, \"regression\") === false,\n expectViolation: false,\n keep: false,\n stdout,\n stderr,\n }),\n );\n return asResult({ exitCode: r.code, report: reported(\"check\", r) });\n },\n },\n {\n name: \"report\",\n title: \"Report on the spec files\",\n description:\n \"Run every spec file (*.props.ts) under a directory through the TESTED rung and, with engines named, the PROVEN rung; return the JSON report of spec verdicts. Exit code 1 is a refuted or conflicting spec, not an error.\",\n inputSchema: {\n type: \"object\",\n properties: {\n dir: { type: \"string\", description: \"Directory to search; default: the working directory\" },\n provers: proversSchema,\n seed: { type: \"string\", description: \"Seed for the TESTED rung; default report\" },\n },\n additionalProperties: false,\n },\n async run(args, ctx, runners) {\n only(args, [\"dir\", \"provers\", \"seed\"]);\n const dir = str(args, \"dir\");\n const engines = strings(args, \"provers\");\n const seed = str(args, \"seed\");\n const r = await capture((stdout, stderr) =>\n runners.report({\n cwd: ctx.cwd,\n ...(dir === undefined ? {} : { dir }),\n ...(engines === undefined ? {} : { provers: engines }),\n ...(seed === undefined ? {} : { seed }),\n json: true,\n stdout,\n stderr,\n }),\n );\n return asResult({ exitCode: r.code, report: reported(\"report\", r) });\n },\n },\n {\n name: \"goals\",\n title: \"List the open proof goals\",\n description:\n \"Run the Lean engine on every spec file under a directory and list the properties it could not prove, each with the statement it tried; write each module's open goals beside its spec file as <spec>.goals.lean, a proof file with every proof open (copy it to <spec>.lean, add lemmas and tactics, then call prove). Needs the lean engine installed.\",\n inputSchema: {\n type: \"object\",\n properties: {\n dir: { type: \"string\", description: \"Directory to search; default: the working directory\" },\n },\n additionalProperties: false,\n },\n async run(args, ctx, runners) {\n only(args, [\"dir\"]);\n const dir = str(args, \"dir\");\n const r = await capture((stdout, stderr) =>\n runners.report({\n cwd: ctx.cwd,\n ...(dir === undefined ? {} : { dir }),\n provers: [\"lean\"],\n goals: true,\n json: true,\n stdout,\n stderr,\n }),\n );\n return asResult({ exitCode: r.code, report: reported(\"goals\", r) });\n },\n },\n {\n name: \"prove\",\n title: \"Check the proofs supplied for a spec file\",\n description:\n \"Run the Lean engine on one module, the one whose spec file (*.props.ts) is given, with the proofs supplied beside it in <spec>.lean, and return its spec verdicts: PROVEN where a proof closes (Lean's kernel checked it against the statement Eutaxy emitted), UNKNOWN with the reason where it does not, or where the proof file is stale (written for another version of the module or the spec).\",\n inputSchema: {\n type: \"object\",\n properties: {\n spec: {\n type: \"string\",\n description: \"Path of the spec file, relative to the working directory\",\n },\n },\n required: [\"spec\"],\n additionalProperties: false,\n },\n async run(args, ctx, runners) {\n only(args, [\"spec\"]);\n const spec = str(args, \"spec\", true) as string;\n const r = await capture((stdout, stderr) =>\n runners.report({\n cwd: ctx.cwd,\n dir: dirname(spec),\n only: spec,\n provers: [\"lean\"],\n json: true,\n stdout,\n stderr,\n }),\n );\n return asResult({ exitCode: r.code, report: reported(\"prove\", r) });\n },\n },\n {\n name: \"draft\",\n title: \"Draft a scenario\",\n description:\n \"Draft a scenario (*.sim.ts) from a wrangler config (JSON or JSONC) and the Worker module it names: the bindings become setup steps (a service binding whose Worker's config is found under the directory becomes a callee), the Worker's handlers the drive, the hosts its code fetches the externals; the invariants and the drive's events are holes marked TODO for you to fill before calling check. Returns the source, the draft as data and its notes (bindings not modelled, guesses made); with out, also writes the file, never over an existing one. Nothing is imported or run.\",\n inputSchema: {\n type: \"object\",\n properties: {\n config: {\n type: \"string\",\n description:\n \"Wrangler config path, relative to the working directory; default: wrangler.jsonc or wrangler.json there\",\n },\n worker: {\n type: \"string\",\n description: \"The Worker module; default: the config's main\",\n },\n out: {\n type: \"string\",\n description:\n \"Where to write the scenario; paths in it are relative to its directory. Default: not written\",\n },\n },\n additionalProperties: false,\n },\n async run(args, ctx) {\n only(args, [\"config\", \"worker\", \"out\"]);\n const config = str(args, \"config\");\n const worker = str(args, \"worker\");\n const out = str(args, \"out\");\n let stdout = \"\";\n let stderr = \"\";\n const code = runDraft({\n cwd: ctx.cwd,\n ...(config === undefined ? {} : { config }),\n ...(worker === undefined ? {} : { worker }),\n ...(out === undefined ? {} : { out }),\n json: true,\n stdout: (t) => {\n stdout += t;\n },\n stderr: (t) => {\n stderr += t;\n },\n });\n if (code !== 0) throw new ToolError(stderr.trim() || `draft exited ${code}`);\n return asResult(JSON.parse(stdout) as Json);\n },\n },\n {\n name: \"prover_status\",\n title: \"Which proof engines are installed\",\n description:\n \"For each proof engine (lean, smt): whether its pinned toolchain is installed and its version, or why not and how to install it (eutaxy prover install <name>).\",\n inputSchema: { type: \"object\", additionalProperties: false },\n async run(args, _ctx, runners) {\n only(args, []);\n return asResult(await runners.status());\n },\n },\n];\n\ninterface Response {\n readonly jsonrpc: \"2.0\";\n readonly id: string | number | null;\n readonly result?: Json;\n readonly error?: { readonly code: number; readonly message: string; readonly data?: Json };\n}\n\nconst errorResponse = (\n id: string | number | null,\n code: number,\n message: string,\n data?: Json,\n): Response => ({\n jsonrpc: \"2.0\",\n id,\n error: { code, message, ...(data === undefined ? {} : { data }) },\n});\n\n/** A result in the requester's era: the stateless one carries `resultType` and the server's identity. */\nconst resultResponse = (req: Request, result: { [key: string]: Json }): Response => ({\n jsonrpc: \"2.0\",\n id: req.id,\n result: req.modern\n ? { resultType: \"complete\", ...result, _meta: { [serverInfoKey]: serverInfo } }\n : result,\n});\n\nconst toolListing = (): Json =>\n tools.map((t) => ({\n name: t.name,\n title: t.title,\n description: t.description,\n inputSchema: t.inputSchema,\n }));\n\nasync function callTool(req: Request, ctx: McpContext): Promise<Response> {\n const name = req.params[\"name\"];\n const tool = tools.find((t) => t.name === name);\n if (typeof name !== \"string\" || !tool)\n return errorResponse(req.id, -32602, `Unknown tool: ${String(name)}`);\n const args = req.params[\"arguments\"] ?? {};\n if (typeof args !== \"object\" || args === null || Array.isArray(args))\n return errorResponse(req.id, -32602, \"arguments must be an object\");\n const runners: Runners = { ...realRunners, ...ctx.runners };\n let result: ToolResult;\n try {\n result = await tool.run(args as Params, ctx, runners);\n } catch (err) {\n // The tool itself failed: an execution error the model can act on, not a protocol error.\n const message = err instanceof Error ? err.message : String(err);\n result = { structured: { error: message }, text: message, isError: true };\n }\n return resultResponse(req, {\n content: [{ type: \"text\", text: result.text }],\n structuredContent: result.structured,\n isError: result.isError === true,\n });\n}\n\n/**\n * One line in, at most one line out: the response to a request, nothing\n * for a notification. A request of the stateless era whose version is not\n * served gets the `UnsupportedProtocolVersion` error with what is.\n */\nexport async function handleLine(line: string, ctx: McpContext): Promise<string | undefined> {\n let message: unknown;\n try {\n message = JSON.parse(line);\n } catch {\n return JSON.stringify(errorResponse(null, -32700, \"Parse error\"));\n }\n if (Array.isArray(message))\n return JSON.stringify(\n errorResponse(null, -32600, \"Invalid Request: batches are not supported\"),\n );\n if (typeof message !== \"object\" || message === null)\n return JSON.stringify(errorResponse(null, -32600, \"Invalid Request\"));\n const m = message as Record<string, unknown>;\n const id = m[\"id\"];\n const idOk = typeof id === \"string\" || typeof id === \"number\";\n if (m[\"jsonrpc\"] !== \"2.0\" || typeof m[\"method\"] !== \"string\")\n return JSON.stringify(\n errorResponse(idOk ? (id as string | number) : null, -32600, \"Invalid Request\"),\n );\n if (id === undefined) return undefined; // a notification: initialized, cancelled, progress; nothing to answer\n if (!idOk)\n return JSON.stringify(\n errorResponse(null, -32600, \"Invalid Request: id must be a string or a number\"),\n );\n const params = (\n typeof m[\"params\"] === \"object\" && m[\"params\"] !== null ? m[\"params\"] : {}\n ) as Params;\n const meta = (\n typeof params[\"_meta\"] === \"object\" && params[\"_meta\"] !== null ? params[\"_meta\"] : {}\n ) as Params;\n const requested = meta[protocolVersionKey];\n const req: Request = {\n id: id as string | number,\n method: m[\"method\"],\n params,\n modern: typeof requested === \"string\",\n };\n if (req.modern) {\n if (!modernVersions.includes(requested as string))\n return JSON.stringify(\n errorResponse(req.id, -32022, \"Unsupported protocol version\", {\n supported: [...modernVersions],\n requested: requested as string,\n }),\n );\n if (typeof meta[clientCapabilitiesKey] !== \"object\" || meta[clientCapabilitiesKey] === null)\n return JSON.stringify(\n errorResponse(req.id, -32602, `Invalid params: _meta.${clientCapabilitiesKey} is required`),\n );\n }\n let response: Response;\n try {\n response = await dispatch(req, ctx);\n } catch (err) {\n response = errorResponse(\n req.id,\n -32603,\n `Internal error: ${err instanceof Error ? err.message : String(err)}`,\n );\n }\n return JSON.stringify(response);\n}\n\nasync function dispatch(req: Request, ctx: McpContext): Promise<Response> {\n switch (req.method) {\n case \"initialize\": {\n const asked = req.params[\"protocolVersion\"];\n const version =\n typeof asked === \"string\" && legacyVersions.includes(asked)\n ? asked\n : (legacyVersions[0] as string);\n return resultResponse(req, {\n protocolVersion: version,\n capabilities: { tools: {} },\n serverInfo,\n instructions,\n });\n }\n case \"ping\":\n return resultResponse(req, {});\n case \"server/discover\":\n return resultResponse(req, {\n supportedVersions: [...modernVersions],\n capabilities: { tools: {} },\n instructions,\n });\n case \"tools/list\":\n return resultResponse(req, { tools: toolListing() });\n case \"tools/call\":\n return callTool(req, ctx);\n default:\n return errorResponse(req.id, -32601, `Method not found: ${req.method}`);\n }\n}\n\n/** Serve on the process's standard streams until stdin closes. Requests are answered one at a time, in order. */\nexport async function serveStdio(ctx: McpContext): Promise<number> {\n const lines = createInterface({ input: process.stdin, crlfDelay: Number.POSITIVE_INFINITY });\n for await (const line of lines) {\n if (line.trim().length === 0) continue;\n const out = await handleLine(line, ctx);\n if (out !== undefined) process.stdout.write(`${out}\\n`);\n }\n return exitCodes.BOUNDED;\n}\n"],"mappings":";;;;;;AACA,MAAa,gBAAgB;;;;;;;;;;;;;;;;;;ACwB7B,MAAa,iBAAoC,CAAC,YAAY;AAC9D,MAAa,iBAAoC;CAC/C;CACA;CACA;CACA;AACF;AAEA,MAAM,qBAAqB;AAC3B,MAAM,wBAAwB;AAC9B,MAAM,gBAAgB;AAEtB,MAAa,aAAa;CAAE,MAAM;CAAU,SAAS;AAAc;AAEnE,MAAa,eAAe;CAC1B;CACA;CACA;CACA;CACA;CACA;AACF,CAAC,CAAC,KAAK,IAAI;AAkCX,MAAM,cAAuB;CAC3B,OAAO;CAGP,QAAQ,OAAO,MAAM;EACnB,IAAI;GACF,OAAO,OAAO,MAAM,OAAO,yBAAA,CAAgB,UAAU,CAAC;EACxD,SAAS,KAAK;GACZ,IAAI,CAAC,kBAAkB,GAAG,GAAG,MAAM;GACnC,EAAE,OAAO,uBAAuB,iBA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