@ora-ai/cli 0.21.0 → 0.22.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 (108) hide show
  1. package/README.md +93 -1
  2. package/dist/auth-commands.d.ts.map +1 -1
  3. package/dist/auth-commands.js +12 -1
  4. package/dist/auth-commands.js.map +1 -1
  5. package/dist/core/auth.d.ts +24 -13
  6. package/dist/core/auth.d.ts.map +1 -1
  7. package/dist/core/auth.js +26 -15
  8. package/dist/core/auth.js.map +1 -1
  9. package/dist/core/credential-sources.d.ts +45 -0
  10. package/dist/core/credential-sources.d.ts.map +1 -0
  11. package/dist/core/credential-sources.js +65 -0
  12. package/dist/core/credential-sources.js.map +1 -0
  13. package/dist/core/github-actions-sign-in.d.ts +33 -0
  14. package/dist/core/github-actions-sign-in.d.ts.map +1 -0
  15. package/dist/core/github-actions-sign-in.js +54 -0
  16. package/dist/core/github-actions-sign-in.js.map +1 -0
  17. package/dist/core/output.js +14 -1
  18. package/dist/core/output.js.map +1 -1
  19. package/dist/core/run-operation.d.ts +11 -4
  20. package/dist/core/run-operation.d.ts.map +1 -1
  21. package/dist/core/run-operation.js +14 -9
  22. package/dist/core/run-operation.js.map +1 -1
  23. package/dist/core/sign-in.d.ts +34 -0
  24. package/dist/core/sign-in.d.ts.map +1 -0
  25. package/dist/core/sign-in.js +21 -0
  26. package/dist/core/sign-in.js.map +1 -0
  27. package/dist/generated/operations.d.ts +1 -1
  28. package/dist/generated/operations.d.ts.map +1 -1
  29. package/dist/generated/operations.js +1236 -70
  30. package/dist/generated/operations.js.map +1 -1
  31. package/dist/generated/types.d.ts +1426 -10
  32. package/dist/generated/types.d.ts.map +1 -1
  33. package/dist/generated/types.js +1 -1
  34. package/dist/mcp/mcp-call.d.ts +25 -0
  35. package/dist/mcp/mcp-call.d.ts.map +1 -0
  36. package/dist/mcp/mcp-call.js +44 -0
  37. package/dist/mcp/mcp-call.js.map +1 -0
  38. package/dist/mcp/mcp-command.d.ts +26 -0
  39. package/dist/mcp/mcp-command.d.ts.map +1 -0
  40. package/dist/mcp/mcp-command.js +91 -0
  41. package/dist/mcp/mcp-command.js.map +1 -0
  42. package/dist/mcp/mcp-install.d.ts +50 -0
  43. package/dist/mcp/mcp-install.d.ts.map +1 -0
  44. package/dist/mcp/mcp-install.js +71 -0
  45. package/dist/mcp/mcp-install.js.map +1 -0
  46. package/dist/mcp/mcp-protocol.d.ts +69 -0
  47. package/dist/mcp/mcp-protocol.d.ts.map +1 -0
  48. package/dist/mcp/mcp-protocol.js +96 -0
  49. package/dist/mcp/mcp-protocol.js.map +1 -0
  50. package/dist/mcp/mcp-stdio.d.ts +17 -0
  51. package/dist/mcp/mcp-stdio.d.ts.map +1 -0
  52. package/dist/mcp/mcp-stdio.js +39 -0
  53. package/dist/mcp/mcp-stdio.js.map +1 -0
  54. package/dist/mcp/mcp-tools.d.ts +81 -0
  55. package/dist/mcp/mcp-tools.d.ts.map +1 -0
  56. package/dist/mcp/mcp-tools.js +134 -0
  57. package/dist/mcp/mcp-tools.js.map +1 -0
  58. package/dist/program.d.ts +4 -9
  59. package/dist/program.d.ts.map +1 -1
  60. package/dist/program.js +9 -3
  61. package/dist/program.js.map +1 -1
  62. package/dist/render/index.js +6 -0
  63. package/dist/render/index.js.map +1 -1
  64. package/dist/render/study/counting-views.d.ts +46 -0
  65. package/dist/render/study/counting-views.d.ts.map +1 -0
  66. package/dist/render/study/counting-views.js +49 -0
  67. package/dist/render/study/counting-views.js.map +1 -0
  68. package/dist/render/study/gate-views.d.ts +56 -0
  69. package/dist/render/study/gate-views.d.ts.map +1 -0
  70. package/dist/render/study/gate-views.js +64 -0
  71. package/dist/render/study/gate-views.js.map +1 -0
  72. package/dist/render/study/renderers.d.ts +8 -0
  73. package/dist/render/study/renderers.d.ts.map +1 -0
  74. package/dist/render/study/renderers.js +31 -0
  75. package/dist/render/study/renderers.js.map +1 -0
  76. package/dist/render/study/series-views.d.ts +65 -0
  77. package/dist/render/study/series-views.d.ts.map +1 -0
  78. package/dist/render/study/series-views.js +116 -0
  79. package/dist/render/study/series-views.js.map +1 -0
  80. package/dist/render/study/study-format.d.ts +24 -0
  81. package/dist/render/study/study-format.d.ts.map +1 -0
  82. package/dist/render/study/study-format.js +42 -0
  83. package/dist/render/study/study-format.js.map +1 -0
  84. package/dist/study-ci/ci-command.d.ts +31 -0
  85. package/dist/study-ci/ci-command.d.ts.map +1 -0
  86. package/dist/study-ci/ci-command.js +134 -0
  87. package/dist/study-ci/ci-command.js.map +1 -0
  88. package/dist/study-ci/ci-rehearse-command.d.ts +11 -0
  89. package/dist/study-ci/ci-rehearse-command.d.ts.map +1 -0
  90. package/dist/study-ci/ci-rehearse-command.js +83 -0
  91. package/dist/study-ci/ci-rehearse-command.js.map +1 -0
  92. package/dist/study-ci/ci-rehearse.d.ts +62 -0
  93. package/dist/study-ci/ci-rehearse.d.ts.map +1 -0
  94. package/dist/study-ci/ci-rehearse.js +49 -0
  95. package/dist/study-ci/ci-rehearse.js.map +1 -0
  96. package/dist/study-ci/ci-run.d.ts +87 -0
  97. package/dist/study-ci/ci-run.d.ts.map +1 -0
  98. package/dist/study-ci/ci-run.js +131 -0
  99. package/dist/study-ci/ci-run.js.map +1 -0
  100. package/dist/study-ci/gate-report.d.ts +64 -0
  101. package/dist/study-ci/gate-report.d.ts.map +1 -0
  102. package/dist/study-ci/gate-report.js +80 -0
  103. package/dist/study-ci/gate-report.js.map +1 -0
  104. package/dist/study-ci/params.d.ts +8 -0
  105. package/dist/study-ci/params.d.ts.map +1 -0
  106. package/dist/study-ci/params.js +72 -0
  107. package/dist/study-ci/params.js.map +1 -0
  108. package/package.json +1 -1
@@ -1,5 +1,5 @@
1
1
  // GENERATED by scripts/generate.mjs — DO NOT EDIT.
2
- // Source: openapi/ora-public.openapi.json (sha256 ee29522797d8e1778a89c012c6d689545368cb697235d6e336df270fdc8ed359)
2
+ // Source: openapi/ora-public.openapi.json (sha256 0f479e1012ff3fef63b1aed942d4aefabae3782a892c336f372e7b03b0bbb9bd)
3
3
  // Regenerate: yarn nx run ora-cli:generate
4
4
  export {};
5
5
  //# sourceMappingURL=types.js.map
@@ -0,0 +1,25 @@
1
+ /**
2
+ * ONE TOOL CALL — the operation run through the CLI's own HTTP client (the
3
+ * same token exchange, the same single retry on a 401, never a retry of a
4
+ * write), answered as an MCP result.
5
+ *
6
+ * WHAT COMES BACK IS THE API'S OWN ANSWER, as JSON text. A refusal is the
7
+ * API's error as a tool error (`isError`): its status, its code and whatever
8
+ * it said, so the agent reads `study_behaviors_unsupported` exactly as a
9
+ * person reads it from the command.
10
+ *
11
+ * AN ANSWER TOO LARGE TO READ IS SAID, NOT CUT. Half a JSON document is worse
12
+ * than none: past {@link MAX_RESULT_CHARS} the tool answers its size and
13
+ * points at a narrower command.
14
+ */
15
+ import { type CallOptions } from "../core/http.js";
16
+ import type { OperationMeta } from "../generated/operations.js";
17
+ import type { McpToolResult } from "./mcp-protocol.js";
18
+ /** The largest answer handed to an agent whole. */
19
+ export declare const MAX_RESULT_CHARS = 200000;
20
+ /** The slice of the CLI's client a tool call needs. */
21
+ export interface ToolCallClient {
22
+ call(opts: CallOptions): Promise<unknown>;
23
+ }
24
+ export declare function callOperationTool(meta: OperationMeta, args: unknown, client: ToolCallClient): Promise<McpToolResult>;
25
+ //# sourceMappingURL=mcp-call.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-call.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAY,KAAK,WAAW,EAAE,MAAM,iBAAiB,CAAC;AAE7D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAChE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAGvD,mDAAmD;AACnD,eAAO,MAAM,gBAAgB,SAAU,CAAC;AAExC,uDAAuD;AACvD,MAAM,WAAW,cAAc;IAC7B,IAAI,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;CAC3C;AAID,wBAAsB,iBAAiB,CAAC,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CAuB1H"}
@@ -0,0 +1,44 @@
1
+ /**
2
+ * ONE TOOL CALL — the operation run through the CLI's own HTTP client (the
3
+ * same token exchange, the same single retry on a 401, never a retry of a
4
+ * write), answered as an MCP result.
5
+ *
6
+ * WHAT COMES BACK IS THE API'S OWN ANSWER, as JSON text. A refusal is the
7
+ * API's error as a tool error (`isError`): its status, its code and whatever
8
+ * it said, so the agent reads `study_behaviors_unsupported` exactly as a
9
+ * person reads it from the command.
10
+ *
11
+ * AN ANSWER TOO LARGE TO READ IS SAID, NOT CUT. Half a JSON document is worse
12
+ * than none: past {@link MAX_RESULT_CHARS} the tool answers its size and
13
+ * points at a narrower command.
14
+ */
15
+ import { ApiError } from "../core/http.js";
16
+ import { buildPath } from "../core/run-operation.js";
17
+ import { toolArgumentsOf } from "./mcp-tools.js";
18
+ /** The largest answer handed to an agent whole. */
19
+ export const MAX_RESULT_CHARS = 200_000;
20
+ const text = (value, isError = false) => ({ content: [{ type: "text", text: value }], ...(isError ? { isError: true } : {}) });
21
+ export async function callOperationTool(meta, args, client) {
22
+ const parsed = toolArgumentsOf(meta, args);
23
+ if (!parsed.ok)
24
+ return text(parsed.message, true);
25
+ const { positionals, query, body } = parsed.values;
26
+ try {
27
+ const data = await client.call({ method: meta.method, path: buildPath(meta, positionals), query, ...(body !== undefined ? { body } : {}) });
28
+ const rendered = JSON.stringify(data ?? null, null, 2);
29
+ if (rendered.length > MAX_RESULT_CHARS) {
30
+ return text(`The answer is ${rendered.length} characters, more than this tool hands over at once (${MAX_RESULT_CHARS}). ` +
31
+ "Ask a narrower question: a paged or filtered command, or one that answers a summary.", true);
32
+ }
33
+ return text(rendered);
34
+ }
35
+ catch (error) {
36
+ if (error instanceof ApiError) {
37
+ // The API's own answer where it sent one; never a header, a token or the request.
38
+ const answer = { status: error.status, code: error.code, error: error.message, ...(error.details ? { details: error.details } : {}) };
39
+ return text(JSON.stringify(answer, null, 2), true);
40
+ }
41
+ return text(error instanceof Error ? error.message : "The call failed.", true);
42
+ }
43
+ }
44
+ //# sourceMappingURL=mcp-call.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-call.js","sourceRoot":"","sources":["../../src/mcp/mcp-call.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AAEH,OAAO,EAAE,QAAQ,EAAoB,MAAM,iBAAiB,CAAC;AAC7D,OAAO,EAAE,SAAS,EAAE,MAAM,0BAA0B,CAAC;AAGrD,OAAO,EAAE,eAAe,EAAE,MAAM,gBAAgB,CAAC;AAEjD,mDAAmD;AACnD,MAAM,CAAC,MAAM,gBAAgB,GAAG,OAAO,CAAC;AAOxC,MAAM,IAAI,GAAG,CAAC,KAAa,EAAE,OAAO,GAAG,KAAK,EAAiB,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,CAAC,EAAE,GAAG,CAAC,OAAO,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC;AAEtJ,MAAM,CAAC,KAAK,UAAU,iBAAiB,CAAC,IAAmB,EAAE,IAAa,EAAE,MAAsB;IAChG,MAAM,MAAM,GAAG,eAAe,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;IAC3C,IAAI,CAAC,MAAM,CAAC,EAAE;QAAE,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAClD,MAAM,EAAE,WAAW,EAAE,KAAK,EAAE,IAAI,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC;IACnD,IAAI,CAAC;QACH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AACH,CAAC"}
@@ -0,0 +1,26 @@
1
+ /**
2
+ * `ora mcp serve | config | install` — the CLI's own commands, served to a
3
+ * coding agent over the Model Context Protocol.
4
+ *
5
+ * Hand-written beside the generated `ora mcp servers …` (as `ora tunnel` is
6
+ * beside `ora tunnels`): `serve` starts the server on stdio, `config` prints
7
+ * the entry an agent's configuration needs, `install` writes it for an agent
8
+ * this CLI knows. What the server offers is decided by the manifest and the
9
+ * two flags; what a call may DO is decided by the api key, as for a command.
10
+ */
11
+ import type { Command } from "commander";
12
+ import type { Readable, Writable } from "node:stream";
13
+ import type { ResolvedDeps } from "../program.js";
14
+ import { type ServeOptions } from "./mcp-install.js";
15
+ import { type ToolBinding } from "./mcp-tools.js";
16
+ /** The name an agent lists the server under. */
17
+ export declare const MCP_SERVER_NAME = "ora";
18
+ /** What the server tells an agent once, at initialize. */
19
+ export declare function instructionsOf(bindings: readonly ToolBinding[], options: ServeOptions): string;
20
+ export interface McpIo {
21
+ readonly input: Readable;
22
+ readonly output: Writable;
23
+ readonly cwd: () => string;
24
+ }
25
+ export declare function attachMcp(program: Command, deps: ResolvedDeps, version: string, io?: McpIo): void;
26
+ //# sourceMappingURL=mcp-command.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-command.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACzC,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AAItD,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,OAAO,EAAsE,KAAK,YAAY,EAAE,MAAM,kBAAkB,CAAC;AAGzH,OAAO,EAAkB,KAAK,WAAW,EAAE,MAAM,gBAAgB,CAAC;AAElE,gDAAgD;AAChD,eAAO,MAAM,eAAe,QAAQ,CAAC;AAUrC,0DAA0D;AAC1D,wBAAgB,cAAc,CAAC,QAAQ,EAAE,SAAS,WAAW,EAAE,EAAE,OAAO,EAAE,YAAY,GAAG,MAAM,CAW9F;AAED,MAAM,WAAW,KAAK;IACpB,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;IAC1B,QAAQ,CAAC,GAAG,EAAE,MAAM,MAAM,CAAC;CAC5B;AAUD,wBAAgB,SAAS,CAAC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,YAAY,EAAE,OAAO,EAAE,MAAM,EAAE,EAAE,GAAE,KAAiB,GAAG,IAAI,CAoD5G"}
@@ -0,0 +1,91 @@
1
+ /**
2
+ * `ora mcp serve | config | install` — the CLI's own commands, served to a
3
+ * coding agent over the Model Context Protocol.
4
+ *
5
+ * Hand-written beside the generated `ora mcp servers …` (as `ora tunnel` is
6
+ * beside `ora tunnels`): `serve` starts the server on stdio, `config` prints
7
+ * the entry an agent's configuration needs, `install` writes it for an agent
8
+ * this CLI knows. What the server offers is decided by the manifest and the
9
+ * two flags; what a call may DO is decided by the api key, as for a command.
10
+ */
11
+ import { renderError } from "../core/output.js";
12
+ import { credentials } from "../core/run-operation.js";
13
+ import { OPERATIONS, SPEC } from "../generated/operations.js";
14
+ import { callOperationTool } from "./mcp-call.js";
15
+ import { MCP_TARGET_KEYS, installMcpServer, resolveMcpTarget, serverEntryOf } from "./mcp-install.js";
16
+ import { McpServer } from "./mcp-protocol.js";
17
+ import { serveStdio } from "./mcp-stdio.js";
18
+ import { toolBindingsOf } from "./mcp-tools.js";
19
+ /** The name an agent lists the server under. */
20
+ export const MCP_SERVER_NAME = "ora";
21
+ const collect = (value, previous) => [...previous, value];
22
+ const serveOptionsOf = (opts) => ({ products: opts.product, readOnly: opts.readOnly === true });
23
+ /** What the server tells an agent once, at initialize. */
24
+ export function instructionsOf(bindings, options) {
25
+ const scope = [
26
+ options.products.length > 0 ? `the ${options.products.join(", ")} commands` : "every command",
27
+ options.readOnly ? "reads only" : "reads and writes",
28
+ ].join(", ");
29
+ return [
30
+ `These ${bindings.length} tools are the ora CLI's commands (${scope}). A tool named a_b_c runs the command \`${SPEC.bin} a b c\` and answers the API's JSON.`,
31
+ "A tool error carries the API's own refusal (status, code and what it said): read it, fix the call, and try again.",
32
+ "Read before you write: get or list the thing first, and for a study run its preflight before creating it.",
33
+ "A write is not retried by the server. Launching a study starts real agent runs and spends the organization's usage.",
34
+ ].join(" ");
35
+ }
36
+ const processIo = { input: process.stdin, output: process.stdout, cwd: () => process.cwd() };
37
+ function scoped(command) {
38
+ return command
39
+ .option("--product <key>", "serve only this product's commands (repeatable): studio, study, experiment, platform", collect, [])
40
+ .option("--read-only", "serve only the commands that read");
41
+ }
42
+ export function attachMcp(program, deps, version, io = processIo) {
43
+ const group = program.commands.find((c) => c.name() === "mcp") ?? program.command("mcp").description("mcp commands");
44
+ scoped(group.command("serve"))
45
+ .description("Serve the CLI's commands to a coding agent as MCP tools, on stdio")
46
+ .option("--api-url <url>", "override the API base URL")
47
+ .action(async (opts) => {
48
+ const creds = credentials(deps, opts.apiUrl);
49
+ if (!creds)
50
+ return;
51
+ const options = serveOptionsOf(opts);
52
+ const bindings = toolBindingsOf(OPERATIONS, options);
53
+ if (bindings.length === 0) {
54
+ deps.errOut(`No command matches ${options.products.map((p) => `--product ${p}`).join(" ") || "these flags"}. Nothing to serve.`);
55
+ process.exitCode = 1;
56
+ return;
57
+ }
58
+ const byName = new Map(bindings.map((binding) => [binding.tool.name, binding]));
59
+ const client = deps.makeClient(creds);
60
+ const server = new McpServer({ name: MCP_SERVER_NAME, version, instructions: instructionsOf(bindings, options) }, {
61
+ listTools: () => bindings.map((binding) => binding.tool),
62
+ callTool: async (name, args) => {
63
+ const binding = byName.get(name);
64
+ return binding ? callOperationTool(binding.meta, args, client) : null;
65
+ },
66
+ });
67
+ // For a person watching the agent's logs. On stderr: stdout is the protocol's alone.
68
+ deps.errOut(`ora mcp: serving ${bindings.length} tools on stdio`);
69
+ await serveStdio(server, io);
70
+ });
71
+ scoped(group.command("config"))
72
+ .description("Print the entry an agent's MCP configuration needs to start this server")
73
+ .action((opts) => {
74
+ deps.out(JSON.stringify({ mcpServers: { [MCP_SERVER_NAME]: serverEntryOf(SPEC.bin, serveOptionsOf(opts)) } }, null, 2));
75
+ });
76
+ scoped(group.command("install"))
77
+ .description("Add this server to a coding agent's MCP configuration for this project")
78
+ .option("--agent <name>", `the agent: ${MCP_TARGET_KEYS.join(", ")}`, MCP_TARGET_KEYS[0])
79
+ .action((opts) => {
80
+ try {
81
+ const done = installMcpServer(resolveMcpTarget(opts.agent), io.cwd(), MCP_SERVER_NAME, serverEntryOf(SPEC.bin, serveOptionsOf(opts)));
82
+ deps.out(`${done.replaced ? "Updated" : "Added"} the "${MCP_SERVER_NAME}" server for ${done.target.label}: ${done.path}`);
83
+ deps.out("It uses the api key this CLI has (`ora login`, or ORA_API_KEY in the agent's environment). No key was written.");
84
+ }
85
+ catch (err) {
86
+ deps.errOut(renderError(err));
87
+ process.exitCode = 1;
88
+ }
89
+ });
90
+ }
91
+ //# sourceMappingURL=mcp-command.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-command.js","sourceRoot":"","sources":["../../src/mcp/mcp-command.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAIH,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAE,UAAU,EAAE,IAAI,EAAE,MAAM,4BAA4B,CAAC;AAE9D,OAAO,EAAE,iBAAiB,EAAE,MAAM,eAAe,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,gBAAgB,EAAE,gBAAgB,EAAE,aAAa,EAAqB,MAAM,kBAAkB,CAAC;AACzH,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAC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,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;SAC7B,WAAW,CAAC,wEAAwE,CAAC;SACrF,MAAM,CAAC,gBAAgB,EAAE,cAAc,eAAe,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,EAAE,eAAe,CAAC,CAAC,CAAC,CAAC;SACxF,MAAM,CAAC,CAAC,IAAoC,EAAE,EAAE;QAC/C,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,gBAAgB,CAAC,gBAAgB,CAAC,IAAI,CAAC,KAAK,CAAC,EAAE,EAAE,CAAC,GAAG,EAAE,EAAE,eAAe,EAAE,aAAa,CAAC,IAAI,CAAC,GAAG,EAAE,cAAc,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;YACtI,IAAI,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC,QAAQ,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,OAAO,SAAS,eAAe,gBAAgB,IAAI,CAAC,MAAM,CAAC,KAAK,KAAK,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;YAC1H,IAAI,CAAC,GAAG,CAAC,gHAAgH,CAAC,CAAC;QAC7H,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC;YAC9B,OAAO,CAAC,QAAQ,GAAG,CAAC,CAAC;QACvB,CAAC;IACH,CAAC,CAAC,CAAC;AACP,CAAC"}
@@ -0,0 +1,50 @@
1
+ /**
2
+ * REGISTERING THE SERVER WITH AN AGENT — the entry an agent's configuration
3
+ * needs to start `ora mcp serve`, and the file it lives in.
4
+ *
5
+ * A REGISTRY OF TARGETS, like the skills installer's (agent-skills/
6
+ * install-targets.ts): an agent is a file path and a way to merge one entry
7
+ * into that file. Adding an agent is one entry here.
8
+ *
9
+ * THE FILE IS MERGED, NEVER REPLACED. Every other server in it and every other
10
+ * key stay as they were. A file that is not a JSON object is refused: writing
11
+ * over something this command cannot read would lose it.
12
+ *
13
+ * NO KEY IS EVER WRITTEN. The entry names the command and its flags; the
14
+ * server reads the api key the CLI already has (`ora login`, or ORA_API_KEY in
15
+ * the agent's own environment).
16
+ */
17
+ /** How an agent starts the server. */
18
+ export interface McpServerEntry {
19
+ command: string;
20
+ args: string[];
21
+ }
22
+ export interface ServeOptions {
23
+ readonly products: readonly string[];
24
+ readonly readOnly: boolean;
25
+ }
26
+ /** The flags of `ora mcp serve` for these options: what `serve` itself parses. */
27
+ export declare function serveArgsOf(options: ServeOptions): string[];
28
+ export declare const serverEntryOf: (bin: string, options: ServeOptions) => McpServerEntry;
29
+ export interface McpInstallTarget {
30
+ readonly key: string;
31
+ readonly label: string;
32
+ /** The configuration file, for a project at `cwd`. */
33
+ configPath(cwd: string): string;
34
+ /** The key of the file's object that holds its servers by name. */
35
+ readonly serversKey: string;
36
+ }
37
+ export declare const MCP_INSTALL_TARGETS: readonly McpInstallTarget[];
38
+ export declare const MCP_TARGET_KEYS: readonly string[];
39
+ export declare function resolveMcpTarget(key: string): McpInstallTarget;
40
+ /** The configuration with the server's entry set under `name`: everything else as it was. */
41
+ export declare function mergeServerEntry(existing: unknown, serversKey: string, name: string, entry: McpServerEntry): Record<string, unknown>;
42
+ export interface InstalledMcpServer {
43
+ readonly target: McpInstallTarget;
44
+ readonly path: string;
45
+ /** True when the file already held an entry of this name, now replaced. */
46
+ readonly replaced: boolean;
47
+ }
48
+ /** Write the entry into the agent's configuration for the project at `cwd`. */
49
+ export declare function installMcpServer(target: McpInstallTarget, cwd: string, name: string, entry: McpServerEntry): InstalledMcpServer;
50
+ //# sourceMappingURL=mcp-install.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-install.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAKH,sCAAsC;AACtC,MAAM,WAAW,cAAc;IAC7B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,E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,EAAE,cAAc,GAAG,kBAAkB,CAqB/H"}
@@ -0,0 +1,71 @@
1
+ /**
2
+ * REGISTERING THE SERVER WITH AN AGENT — the entry an agent's configuration
3
+ * needs to start `ora mcp serve`, and the file it lives in.
4
+ *
5
+ * A REGISTRY OF TARGETS, like the skills installer's (agent-skills/
6
+ * install-targets.ts): an agent is a file path and a way to merge one entry
7
+ * into that file. Adding an agent is one entry here.
8
+ *
9
+ * THE FILE IS MERGED, NEVER REPLACED. Every other server in it and every other
10
+ * key stay as they were. A file that is not a JSON object is refused: writing
11
+ * over something this command cannot read would lose it.
12
+ *
13
+ * NO KEY IS EVER WRITTEN. The entry names the command and its flags; the
14
+ * server reads the api key the CLI already has (`ora login`, or ORA_API_KEY in
15
+ * the agent's own environment).
16
+ */
17
+ import { existsSync, mkdirSync, readFileSync, writeFileSync } from "node:fs";
18
+ import { dirname, join } from "node:path";
19
+ /** The flags of `ora mcp serve` for these options: what `serve` itself parses. */
20
+ export function serveArgsOf(options) {
21
+ return ["mcp", "serve", ...options.products.flatMap((product) => ["--product", product]), ...(options.readOnly ? ["--read-only"] : [])];
22
+ }
23
+ export const serverEntryOf = (bin, options) => ({ command: bin, args: serveArgsOf(options) });
24
+ export const MCP_INSTALL_TARGETS = [
25
+ { key: "claude", label: "Claude Code", configPath: (cwd) => join(cwd, ".mcp.json"), serversKey: "mcpServers" },
26
+ { key: "cursor", label: "Cursor", configPath: (cwd) => join(cwd, ".cursor", "mcp.json"), serversKey: "mcpServers" },
27
+ ];
28
+ export const MCP_TARGET_KEYS = MCP_INSTALL_TARGETS.map((target) => target.key);
29
+ export function resolveMcpTarget(key) {
30
+ const target = MCP_INSTALL_TARGETS.find((candidate) => candidate.key === key);
31
+ if (!target)
32
+ throw new Error(`Unknown agent "${key}". Use one of: ${MCP_TARGET_KEYS.join(", ")}, or \`ora mcp config\` to print the entry.`);
33
+ return target;
34
+ }
35
+ const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
36
+ /** The configuration with the server's entry set under `name`: everything else as it was. */
37
+ export function mergeServerEntry(existing, serversKey, name, entry) {
38
+ if (existing !== undefined && !isRecord(existing))
39
+ throw new Error("the file is not a JSON object");
40
+ const config = existing ?? {};
41
+ const servers = config[serversKey];
42
+ if (servers !== undefined && !isRecord(servers))
43
+ throw new Error(`its "${serversKey}" is not an object`);
44
+ return { ...config, [serversKey]: { ...(servers ?? {}), [name]: entry } };
45
+ }
46
+ /** Write the entry into the agent's configuration for the project at `cwd`. */
47
+ export function installMcpServer(target, cwd, name, entry) {
48
+ const path = target.configPath(cwd);
49
+ let existing;
50
+ if (existsSync(path)) {
51
+ const raw = readFileSync(path, "utf8");
52
+ try {
53
+ existing = raw.trim() === "" ? undefined : JSON.parse(raw);
54
+ }
55
+ catch {
56
+ throw new Error(`${path} is not valid JSON. Fix or remove it, then run this again: nothing was written.`);
57
+ }
58
+ }
59
+ let merged;
60
+ try {
61
+ merged = mergeServerEntry(existing, target.serversKey, name, entry);
62
+ }
63
+ catch (error) {
64
+ throw new Error(`${path} cannot be merged (${error instanceof Error ? error.message : "unreadable"}): nothing was written.`, { cause: error });
65
+ }
66
+ const servers = isRecord(existing) && isRecord(existing[target.serversKey]) ? existing[target.serversKey] : {};
67
+ mkdirSync(dirname(path), { recursive: true });
68
+ writeFileSync(path, `${JSON.stringify(merged, null, 2)}\n`);
69
+ return { target, path, replaced: isRecord(servers) && name in servers };
70
+ }
71
+ //# sourceMappingURL=mcp-install.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-install.js","sourceRoot":"","sources":["../../src/mcp/mcp-install.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,YAAY,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AAC7E,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAa1C,kFAAkF;AAClF,MAAM,UAAU,WAAW,CAAC,OAAqB;IA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one message out. Transport-agnostic and pure but for
4
+ * the handlers it is given: the stdio loop (mcp-stdio.ts) feeds it lines.
5
+ *
6
+ * WRITTEN BY HAND, deliberately: the published CLI has four runtime
7
+ * dependencies, and the reference SDK would add a web server and a schema
8
+ * library to every install for a server that lists and calls tools. What the
9
+ * server must speak is small — `initialize`, `ping`, `tools/list`,
10
+ * `tools/call` — and compatibility is PROVED rather than assumed: an e2e spec
11
+ * drives the built CLI with the reference SDK's own client.
12
+ *
13
+ * A TOOL FAILURE IS A RESULT, NOT A PROTOCOL ERROR. An API refusal, a missing
14
+ * argument and a failed call all answer `isError: true` with words the agent
15
+ * can read and act on. A JSON-RPC error is kept for what the protocol itself
16
+ * got wrong: an unknown method, an unknown tool, a malformed request.
17
+ */
18
+ import type { McpTool } from "./mcp-tools.js";
19
+ /** The protocol versions this server speaks, newest first. */
20
+ export declare const MCP_PROTOCOL_VERSIONS: readonly ["2025-06-18", "2025-03-26", "2024-11-05"];
21
+ export declare const JSON_RPC_ERRORS: {
22
+ readonly parse: -32700;
23
+ readonly invalidRequest: -32600;
24
+ readonly methodNotFound: -32601;
25
+ readonly invalidParams: -32602;
26
+ readonly internal: -32603;
27
+ };
28
+ export type JsonRpcId = string | number | null;
29
+ export interface JsonRpcResponse {
30
+ jsonrpc: "2.0";
31
+ id: JsonRpcId;
32
+ result?: unknown;
33
+ error?: {
34
+ code: number;
35
+ message: string;
36
+ };
37
+ }
38
+ export interface McpToolResult {
39
+ content: {
40
+ type: "text";
41
+ text: string;
42
+ }[];
43
+ isError?: boolean;
44
+ }
45
+ export interface McpServerInfo {
46
+ readonly name: string;
47
+ readonly version: string;
48
+ /** What the server tells an agent about its tools, once, at initialize. */
49
+ readonly instructions: string;
50
+ }
51
+ export interface McpHandlers {
52
+ listTools(): readonly McpTool[];
53
+ /** Null = no such tool. Never rejects for a failed call: that is a result with `isError`. */
54
+ callTool(name: string, args: unknown): Promise<McpToolResult | null>;
55
+ }
56
+ /** A response for a line that was not JSON at all. */
57
+ export declare const parseErrorResponse: () => JsonRpcResponse;
58
+ export declare class McpServer {
59
+ private readonly info;
60
+ private readonly handlers;
61
+ constructor(info: McpServerInfo, handlers: McpHandlers);
62
+ /** One incoming message. Null = nothing to answer (a notification, or a response that was sent to us). */
63
+ handle(message: unknown): Promise<JsonRpcResponse | null>;
64
+ private dispatch;
65
+ /** The client's protocol version when this server speaks it, else this server's newest: the client decides whether to go on. */
66
+ private initialize;
67
+ private callTool;
68
+ }
69
+ //# sourceMappingURL=mcp-protocol.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-protocol.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAE9C,8DAA8D;AAC9D,eAAO,MAAM,qBAAqB,qDAAsD,CAAC;AAEzF,eAAO,MAAM,eAAe;;;;;;CAMlB,CAAC;AAEX,MAAM,MAAM,SAAS,GAAG,MAAM,GAAG,MAAM,GAAG,IAAI,CAAC;AAE/C,MAAM,WAAW,eAAe;IAC9B,OAAO,EAAE,KAAK,CAAC;IACf,EAAE,EAAE,SAAS,CAAC;IACd,MAAM,CAAC,EAAE,OAAO,CAAC;IACjB,KAAK,CAAC,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;CAC3C;AAED,MAAM,WAAW,aAAa;IAC5B,OAAO,EAAE;QAAE,IAAI,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC;IAC1C,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB;AAED,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,OAAO,EAAE,MAAM,CAAC;IACzB,2EAA2E;IAC3E,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,MAAM,WAAW,WAAW;IAC1B,SAAS,IAAI,SAAS,OAAO,EAAE,CAAC;IAChC,6FAA6F;IAC7F,QAAQ,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,OAAO,GAAG,OAAO,CAAC,aAAa,GAAG,IAAI,CAAC,CAAC;CACtE;AAQD,sDAAsD;AACtD,eAAO,MAAM,kBAAkB,QAAO,eAAgG,CAAC;AAEvI,qBAAa,SAAS;IAElB,OAAO,CAAC,QAAQ,CAAC,IAAI;IACrB,OAAO,CAAC,QAAQ,CAAC,QAAQ;gBADR,IAAI,EAAE,aAAa,EACnB,QAAQ,EAAE,WAAW;IAGxC,0GAA0G;IACpG,MAAM,CAAC,OAAO,EAAE,OAAO,GAAG,OAAO,CAAC,eAAe,GAAG,IAAI,CAAC;YAmBjD,QAAQ;IAetB,gIAAgI;IAChI,OAAO,CAAC,UAAU;YAWJ,QAAQ;CAQvB"}
@@ -0,0 +1,96 @@
1
+ /**
2
+ * THE MCP PROTOCOL, AS FAR AS A TOOLS-ONLY SERVER NEEDS IT — JSON-RPC 2.0
3
+ * messages in, at most one message out. Transport-agnostic and pure but for
4
+ * the handlers it is given: the stdio loop (mcp-stdio.ts) feeds it lines.
5
+ *
6
+ * WRITTEN BY HAND, deliberately: the published CLI has four runtime
7
+ * dependencies, and the reference SDK would add a web server and a schema
8
+ * library to every install for a server that lists and calls tools. What the
9
+ * server must speak is small — `initialize`, `ping`, `tools/list`,
10
+ * `tools/call` — and compatibility is PROVED rather than assumed: an e2e spec
11
+ * drives the built CLI with the reference SDK's own client.
12
+ *
13
+ * A TOOL FAILURE IS A RESULT, NOT A PROTOCOL ERROR. An API refusal, a missing
14
+ * argument and a failed call all answer `isError: true` with words the agent
15
+ * can read and act on. A JSON-RPC error is kept for what the protocol itself
16
+ * got wrong: an unknown method, an unknown tool, a malformed request.
17
+ */
18
+ /** The protocol versions this server speaks, newest first. */
19
+ export const MCP_PROTOCOL_VERSIONS = ["2025-06-18", "2025-03-26", "2024-11-05"];
20
+ export const JSON_RPC_ERRORS = {
21
+ parse: -32700,
22
+ invalidRequest: -32600,
23
+ methodNotFound: -32601,
24
+ invalidParams: -32602,
25
+ internal: -32603,
26
+ };
27
+ const isRecord = (value) => value !== null && typeof value === "object" && !Array.isArray(value);
28
+ const errorOf = (id, code, message) => ({ jsonrpc: "2.0", id, error: { code, message } });
29
+ const resultOf = (id, result) => ({ jsonrpc: "2.0", id, result });
30
+ /** A response for a line that was not JSON at all. */
31
+ export const parseErrorResponse = () => errorOf(null, JSON_RPC_ERRORS.parse, "Parse error: the message is not JSON.");
32
+ export class McpServer {
33
+ info;
34
+ handlers;
35
+ constructor(info, handlers) {
36
+ this.info = info;
37
+ this.handlers = handlers;
38
+ }
39
+ /** One incoming message. Null = nothing to answer (a notification, or a response that was sent to us). */
40
+ async handle(message) {
41
+ if (!isRecord(message) || message.jsonrpc !== "2.0") {
42
+ return errorOf(null, JSON_RPC_ERRORS.invalidRequest, "Invalid request: not a JSON-RPC 2.0 message.");
43
+ }
44
+ const { id, method, params } = message;
45
+ // A message with no method is a response to something this server never asked: nothing to say.
46
+ if (typeof method !== "string")
47
+ return null;
48
+ // A request has an id; a notification has none and is never answered, whatever it names.
49
+ if (id === undefined)
50
+ return null;
51
+ if (typeof id !== "string" && typeof id !== "number") {
52
+ return errorOf(null, JSON_RPC_ERRORS.invalidRequest, "Invalid request: the id must be a string or a number.");
53
+ }
54
+ try {
55
+ return await this.dispatch(id, method, params);
56
+ }
57
+ catch (error) {
58
+ return errorOf(id, JSON_RPC_ERRORS.internal, error instanceof Error ? error.message : "Internal error.");
59
+ }
60
+ }
61
+ async dispatch(id, method, params) {
62
+ switch (method) {
63
+ case "initialize":
64
+ return resultOf(id, this.initialize(params));
65
+ case "ping":
66
+ return resultOf(id, {});
67
+ case "tools/list":
68
+ return resultOf(id, { tools: this.handlers.listTools() });
69
+ case "tools/call":
70
+ return this.callTool(id, params);
71
+ default:
72
+ return errorOf(id, JSON_RPC_ERRORS.methodNotFound, `Method not found: ${method}`);
73
+ }
74
+ }
75
+ /** The client's protocol version when this server speaks it, else this server's newest: the client decides whether to go on. */
76
+ initialize(params) {
77
+ const asked = isRecord(params) && typeof params.protocolVersion === "string" ? params.protocolVersion : null;
78
+ const protocolVersion = MCP_PROTOCOL_VERSIONS.includes(asked ?? "") ? asked : MCP_PROTOCOL_VERSIONS[0];
79
+ return {
80
+ protocolVersion,
81
+ capabilities: { tools: {} },
82
+ serverInfo: { name: this.info.name, version: this.info.version },
83
+ instructions: this.info.instructions,
84
+ };
85
+ }
86
+ async callTool(id, params) {
87
+ if (!isRecord(params) || typeof params.name !== "string") {
88
+ return errorOf(id, JSON_RPC_ERRORS.invalidParams, "Invalid params: tools/call needs the tool's name.");
89
+ }
90
+ const result = await this.handlers.callTool(params.name, params.arguments);
91
+ if (result === null)
92
+ return errorOf(id, JSON_RPC_ERRORS.invalidParams, `Unknown tool: ${params.name}`);
93
+ return resultOf(id, result);
94
+ }
95
+ }
96
+ //# sourceMappingURL=mcp-protocol.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-protocol.js","sourceRoot":"","sources":["../../src/mcp/mcp-protocol.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;GAgBG;AAIH,8DAA8D;AAC9D,MAAM,CAAC,MAAM,qBAAqB,GAAG,CAAC,YAAY,EAAE,YAAY,EAAE,YAAY,CAAU,CAAC;AAEzF,MAAM,CAAC,MAAM,eAAe,GAAG;IAC7B,KAAK,EAAE,CAAC,KAAK;IACb,cAAc,EAAE,CAAC,KAAK;IACtB,cAAc,EAAE,CAAC,KAAK;IACtB,aAAa,EAAE,CAAC,KAAK;IACrB,QAAQ,EAAE,CAAC,KAAK;CACR,CAAC;AA6BX,MAAM,QAAQ,GAAG,CAAC,KAAc,EAAoC,EAAE,CACpE,KAAK,KAAK,IAAI,IAAI,OAAO,KAAK,KAAK,QAAQ,IAAI,CAAC,KAAK,CAAC,OAAO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AE,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,qBAAqB,CAAC,CAAC,CAAC,CAAC;QAC9H,OAAO;YACL,eAAe;YACf,YAAY,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE;YAC3B,UAAU,EAAE,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,EAAE,IAAI,CAAC,IAAI,CAAC,OAAO,EAAE;YAChE,YAAY,EAAE,IAAI,CAAC,IAAI,CAAC,YAAY;SACrC,CAAC;IACJ,CAAC;IAEO,KAAK,CAAC,QAAQ,CAAC,EAAmB,EAAE,MAAe;QACzD,IAAI,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,EAAE,CAAC;YACzD,OAAO,OAAO,CAAC,EAAE,EAAE,eAAe,CAAC,aAAa,EAAE,mDAAmD,CAAC,CAAC;QACzG,CAAC;QACD,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,QAAQ,CAAC,QAAQ,CAAC,MAAM,CAAC,IAAI,EAAE,MAAM,CAAC,SAAS,CAAC,CAAC;QAC3E,IAAI,MAAM,KAAK,IAAI;YAAE,OAAO,OAAO,CAAC,EAAE,EAAE,eAAe,CAAC,aAAa,EAAE,iBAAiB,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC;QACvG,OAAO,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC,CAAC;IAC9B,CAAC;CACF"}
@@ -0,0 +1,17 @@
1
+ /**
2
+ * THE STDIO TRANSPORT — one JSON-RPC message per line in, one per line out.
3
+ *
4
+ * STDOUT CARRIES THE PROTOCOL AND NOTHING ELSE: a stray log line there is a
5
+ * message the client cannot parse. Anything for a person goes to stderr.
6
+ * Messages are answered in the order they finish, each on its own line, and a
7
+ * line that is not JSON answers a parse error instead of ending the session.
8
+ */
9
+ import type { Readable, Writable } from "node:stream";
10
+ import { type McpServer } from "./mcp-protocol.js";
11
+ export interface StdioStreams {
12
+ readonly input: Readable;
13
+ readonly output: Writable;
14
+ }
15
+ /** Serve until the input ends. Resolves when every message already read has been answered. */
16
+ export declare function serveStdio(server: McpServer, { input, output }: StdioStreams): Promise<void>;
17
+ //# sourceMappingURL=mcp-stdio.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-stdio.d.ts","sourceRoot":"","sources":["../../src/mcp/mcp-stdio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAGH,OAAO,KAAK,EAAE,QAAQ,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtD,OAAO,EAA4C,KAAK,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAE7F,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,KAAK,EAAE,QAAQ,CAAC;IACzB,QAAQ,CAAC,MAAM,EAAE,QAAQ,CAAC;CAC3B;AAED,8FAA8F;AAC9F,wBAAsB,UAAU,CAAC,MAAM,EAAE,SAAS,EAAE,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,YAAY,GAAG,OAAO,CAAC,IAAI,CAAC,CAuBlG"}
@@ -0,0 +1,39 @@
1
+ /**
2
+ * THE STDIO TRANSPORT — one JSON-RPC message per line in, one per line out.
3
+ *
4
+ * STDOUT CARRIES THE PROTOCOL AND NOTHING ELSE: a stray log line there is a
5
+ * message the client cannot parse. Anything for a person goes to stderr.
6
+ * Messages are answered in the order they finish, each on its own line, and a
7
+ * line that is not JSON answers a parse error instead of ending the session.
8
+ */
9
+ import { createInterface } from "node:readline";
10
+ import { parseErrorResponse } from "./mcp-protocol.js";
11
+ /** Serve until the input ends. Resolves when every message already read has been answered. */
12
+ export async function serveStdio(server, { input, output }) {
13
+ const write = (response) => {
14
+ if (response !== null)
15
+ output.write(`${JSON.stringify(response)}\n`);
16
+ };
17
+ const pending = new Set();
18
+ const lines = createInterface({ input, crlfDelay: Infinity });
19
+ for await (const line of lines) {
20
+ if (line.trim() === "")
21
+ continue;
22
+ let message;
23
+ try {
24
+ message = JSON.parse(line);
25
+ }
26
+ catch {
27
+ write(parseErrorResponse());
28
+ continue;
29
+ }
30
+ // Not awaited: a slow tool call must not hold up a ping. Each answer is one whole line whenever it lands.
31
+ const answered = server
32
+ .handle(message)
33
+ .then(write)
34
+ .finally(() => pending.delete(answered));
35
+ pending.add(answered);
36
+ }
37
+ await Promise.all(pending);
38
+ }
39
+ //# sourceMappingURL=mcp-stdio.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"mcp-stdio.js","sourceRoot":"","sources":["../../src/mcp/mcp-stdio.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,eAAe,EAAE,MAAM,eAAe,CAAC;AAEhD,OAAO,EAAE,kBAAkB,EAAwC,MAAM,mBAAmB,CAAC;AAO7F,8FAA8F;AAC9F,MAAM,CAAC,KAAK,UAAU,UAAU,CAAC,MAAiB,EAAE,EAAE,KAAK,EAAE,MAAM,EAAgB;IACjF,MAAM,KAAK,GAAG,CAAC,QAAgC,EAAQ,EAAE;QACvD,IAAI,QAAQ,KAAK,IAAI;YAAE,MAAM,CAAC,KAAK,CAAC,GAAG,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC;IACvE,CAAC,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,GAAG,EAAiB,CAAC;IACzC,MAAM,KAAK,GAAG,eAAe,CAAC,EAAE,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,CAAC,CAAC;IAC9D,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,KAAK,EAAE,CAAC;QAC/B,IAAI,IAAI,CAAC,IAAI,EAAE,KAAK,EAAE;YAAE,SAAS;QACjC,IAAI,OAAgB,CAAC;QACrB,IAAI,CAAC;YACH,OAAO,GAAG,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC;QAC7B,CAAC;QAAC,MAAM,CAAC;YACP,KAAK,CAAC,kBAAkB,EAAE,CAAC,CAAC;YAC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