@cosyte/cli 0.0.6 → 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/mcp.d.cts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
- import { R as RunDeps } from './io-B2EobRzC.cjs';
2
+ import { C as CliCode, R as RunDeps } from './io-C9bSG2zF.cjs';
3
3
  import 'node:stream';
4
4
 
5
5
  /**
@@ -29,6 +29,10 @@ declare const SERVER_INFO: {
29
29
  * the caller connects it to stdio (in production) or to an in-memory transport (in tests), so the
30
30
  * handler wiring is drivable without a subprocess.
31
31
  *
32
+ * Both handlers are **explicit about what reaches the wire**: `tools/list` copies each tool's title,
33
+ * description, input schema and **output schema**, and `tools/call` passes the whole structured result
34
+ * through, so what a client validates is exactly what the tool declared and produced.
35
+ *
32
36
  * @returns A configured, unconnected {@link Server}.
33
37
  * @example
34
38
  * ```ts
@@ -73,6 +77,14 @@ declare function startStdioServer(): Promise<void>;
73
77
  * carries only the value-free diagnostic the command already produced (a stable code + positional
74
78
  * context), never an input value.
75
79
  *
80
+ * **The published contract.** Every tool declares an {@link McpToolOutputSchema}, and every dispatch
81
+ * path returns {@link McpStructuredResult} conforming to the schema its own tool declared, so a client
82
+ * validates an object instead of pattern-matching prose. The text content block carries the serialized
83
+ * JSON of that same structured value. On a **failed** call every field of the structured result is
84
+ * drawn from a fixed enumeration (the outcome vocabulary, the exit-code contract, the
85
+ * {@link CLI_CODES} registry), so no part of the caller's input can appear in it; the tool's own
86
+ * payload is present only on a call that produced data, which is the explicit request.
87
+ *
76
88
  * @packageDocumentation
77
89
  */
78
90
 
@@ -81,21 +93,46 @@ interface McpTextContent {
81
93
  readonly type: "text";
82
94
  readonly text: string;
83
95
  }
84
- /** Value-free metadata every tool result carries so an agent can branch on the outcome. */
85
- interface McpToolMeta {
86
- /** The CLI exit code the underlying command resolved to (the documented exit-code contract). */
87
- readonly exit: number;
96
+ /**
97
+ * The outcome of a tool call, as the single property a client branches on with **no text parsing**:
98
+ * `success` the operation completed cleanly, `verdict` the tool ran and reports a negative finding
99
+ * *about the message* (an invalid resource, an error-severity conversion issue), `failed` the call
100
+ * itself produced no data (a usage mistake, unparseable input, an unavailable parser, an internal
101
+ * error). `verdict` and `failed` are the two a text blob could never reliably separate.
102
+ */
103
+ type McpToolStatus = "success" | "verdict" | "failed";
104
+ /**
105
+ * The **structured result** of one tool call: the value-free outcome fields every tool carries, plus
106
+ * that tool's own payload on a call that produced data. This is the object an MCP `tools/call` reply
107
+ * carries as `structuredContent`, and the value whose serialization is the reply's text block.
108
+ */
109
+ interface McpStructuredResult {
88
110
  /** `true` iff the tool *call* succeeded (data was produced): distinct from a negative verdict. */
89
111
  readonly ok: boolean;
112
+ /** The three-way outcome a client branches on: see {@link McpToolStatus}. */
113
+ readonly status: McpToolStatus;
114
+ /** The CLI exit code the underlying command resolved to (the documented exit-code contract). */
115
+ readonly exit: number;
116
+ /** The stable, value-free diagnostic code on a failed call; absent when data was produced. */
117
+ readonly code?: CliCode;
118
+ /** The tool's own payload (the parsed model, the verdict, the summary, the Bundle); absent on a
119
+ * failed call, which produced none. */
120
+ readonly data?: unknown;
90
121
  }
122
+ /**
123
+ * The historical name for a tool result's structured content, kept as the published alias of
124
+ * {@link McpStructuredResult}.
125
+ */
126
+ type McpToolMeta = McpStructuredResult;
91
127
  /**
92
128
  * The value-free result of dispatching one MCP tool call. Structurally an MCP `CallToolResult`: a text
93
- * content channel, an `isError` flag, and value-free `structuredContent` metadata.
129
+ * content channel carrying the serialized structured result, an `isError` flag, and the
130
+ * {@link McpStructuredResult} itself.
94
131
  */
95
132
  interface McpToolResult {
96
133
  readonly content: readonly McpTextContent[];
97
134
  readonly isError: boolean;
98
- readonly structuredContent: McpToolMeta;
135
+ readonly structuredContent: McpStructuredResult;
99
136
  }
100
137
  /** A JSON-Schema description of a tool's input (the wire schema advertised to `tools/list`). */
101
138
  interface McpToolInputSchema {
@@ -104,11 +141,29 @@ interface McpToolInputSchema {
104
141
  readonly required?: readonly string[];
105
142
  readonly additionalProperties?: boolean;
106
143
  }
107
- /** A tool advertised by the server: an agent-callable name, a description, and its input schema. */
144
+ /**
145
+ * A JSON-Schema description of a tool's **structured result**: the schema advertised alongside the
146
+ * tool on `tools/list` and the one every reply from that tool conforms to. The protocol fixes the
147
+ * root type as `object`; `required` and `additionalProperties` are declared (never omitted) so the
148
+ * published contract states exactly which properties a client may rely on and forbids the rest.
149
+ */
150
+ interface McpToolOutputSchema {
151
+ readonly type: "object";
152
+ readonly properties: Readonly<Record<string, unknown>>;
153
+ readonly required: readonly string[];
154
+ readonly additionalProperties: boolean;
155
+ }
156
+ /**
157
+ * A tool advertised by the server: an agent-callable name, a human-readable title, a description, and
158
+ * the schemas of its input and of its structured result.
159
+ */
108
160
  interface McpToolDef {
109
161
  readonly name: string;
162
+ /** A human-readable title, so these four generic names stay distinguishable in an aggregating client. */
163
+ readonly title: string;
110
164
  readonly description: string;
111
165
  readonly inputSchema: McpToolInputSchema;
166
+ readonly outputSchema: McpToolOutputSchema;
112
167
  }
113
168
  /**
114
169
  * The tools this server exposes: the read/convert operations that share the `core` cleanly and whose
@@ -124,6 +179,11 @@ declare const TOOL_DEFS: readonly McpToolDef[];
124
179
  * posture), and maps the {@link RunResult} onto an MCP result. An unknown tool name or a missing
125
180
  * `content` argument is a value-free usage error, never a thrown stack trace carrying input.
126
181
  *
182
+ * Every path returns an {@link McpStructuredResult} conforming to the called tool's declared
183
+ * {@link McpToolDef.outputSchema}, with the same value serialized into the text content block. An
184
+ * unknown tool name has no schema of its own, so it answers with the shared outcome fields alone,
185
+ * which every tool's schema declares.
186
+ *
127
187
  * @param name - The tool name (one of {@link TOOL_DEFS}).
128
188
  * @param args - The tool-call arguments object.
129
189
  * @param deps - Optional {@link RunDeps} override (tests inject fakes); defaults to feeding `content` as
@@ -136,8 +196,9 @@ declare const TOOL_DEFS: readonly McpToolDef[];
136
196
  *
137
197
  * const r = await dispatchTool("parse", { content: '{"resourceType":"Patient"}' });
138
198
  * r.isError; // => false
199
+ * r.structuredContent.status; // => "success"
139
200
  * ```
140
201
  */
141
202
  declare function dispatchTool(name: string, args: Readonly<Record<string, unknown>>, deps?: RunDeps): Promise<McpToolResult>;
142
203
 
143
- export { type McpTextContent, type McpToolDef, type McpToolInputSchema, type McpToolMeta, type McpToolResult, SERVER_INFO, TOOL_DEFS, createMcpServer, dispatchTool, startStdioServer };
204
+ export { type McpStructuredResult, type McpTextContent, type McpToolDef, type McpToolInputSchema, type McpToolMeta, type McpToolOutputSchema, type McpToolResult, type McpToolStatus, SERVER_INFO, TOOL_DEFS, createMcpServer, dispatchTool, startStdioServer };
package/dist/mcp.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { Server } from '@modelcontextprotocol/sdk/server/index.js';
2
- import { R as RunDeps } from './io-B2EobRzC.js';
2
+ import { C as CliCode, R as RunDeps } from './io-C9bSG2zF.js';
3
3
  import 'node:stream';
4
4
 
5
5
  /**
@@ -29,6 +29,10 @@ declare const SERVER_INFO: {
29
29
  * the caller connects it to stdio (in production) or to an in-memory transport (in tests), so the
30
30
  * handler wiring is drivable without a subprocess.
31
31
  *
32
+ * Both handlers are **explicit about what reaches the wire**: `tools/list` copies each tool's title,
33
+ * description, input schema and **output schema**, and `tools/call` passes the whole structured result
34
+ * through, so what a client validates is exactly what the tool declared and produced.
35
+ *
32
36
  * @returns A configured, unconnected {@link Server}.
33
37
  * @example
34
38
  * ```ts
@@ -73,6 +77,14 @@ declare function startStdioServer(): Promise<void>;
73
77
  * carries only the value-free diagnostic the command already produced (a stable code + positional
74
78
  * context), never an input value.
75
79
  *
80
+ * **The published contract.** Every tool declares an {@link McpToolOutputSchema}, and every dispatch
81
+ * path returns {@link McpStructuredResult} conforming to the schema its own tool declared, so a client
82
+ * validates an object instead of pattern-matching prose. The text content block carries the serialized
83
+ * JSON of that same structured value. On a **failed** call every field of the structured result is
84
+ * drawn from a fixed enumeration (the outcome vocabulary, the exit-code contract, the
85
+ * {@link CLI_CODES} registry), so no part of the caller's input can appear in it; the tool's own
86
+ * payload is present only on a call that produced data, which is the explicit request.
87
+ *
76
88
  * @packageDocumentation
77
89
  */
78
90
 
@@ -81,21 +93,46 @@ interface McpTextContent {
81
93
  readonly type: "text";
82
94
  readonly text: string;
83
95
  }
84
- /** Value-free metadata every tool result carries so an agent can branch on the outcome. */
85
- interface McpToolMeta {
86
- /** The CLI exit code the underlying command resolved to (the documented exit-code contract). */
87
- readonly exit: number;
96
+ /**
97
+ * The outcome of a tool call, as the single property a client branches on with **no text parsing**:
98
+ * `success` the operation completed cleanly, `verdict` the tool ran and reports a negative finding
99
+ * *about the message* (an invalid resource, an error-severity conversion issue), `failed` the call
100
+ * itself produced no data (a usage mistake, unparseable input, an unavailable parser, an internal
101
+ * error). `verdict` and `failed` are the two a text blob could never reliably separate.
102
+ */
103
+ type McpToolStatus = "success" | "verdict" | "failed";
104
+ /**
105
+ * The **structured result** of one tool call: the value-free outcome fields every tool carries, plus
106
+ * that tool's own payload on a call that produced data. This is the object an MCP `tools/call` reply
107
+ * carries as `structuredContent`, and the value whose serialization is the reply's text block.
108
+ */
109
+ interface McpStructuredResult {
88
110
  /** `true` iff the tool *call* succeeded (data was produced): distinct from a negative verdict. */
89
111
  readonly ok: boolean;
112
+ /** The three-way outcome a client branches on: see {@link McpToolStatus}. */
113
+ readonly status: McpToolStatus;
114
+ /** The CLI exit code the underlying command resolved to (the documented exit-code contract). */
115
+ readonly exit: number;
116
+ /** The stable, value-free diagnostic code on a failed call; absent when data was produced. */
117
+ readonly code?: CliCode;
118
+ /** The tool's own payload (the parsed model, the verdict, the summary, the Bundle); absent on a
119
+ * failed call, which produced none. */
120
+ readonly data?: unknown;
90
121
  }
122
+ /**
123
+ * The historical name for a tool result's structured content, kept as the published alias of
124
+ * {@link McpStructuredResult}.
125
+ */
126
+ type McpToolMeta = McpStructuredResult;
91
127
  /**
92
128
  * The value-free result of dispatching one MCP tool call. Structurally an MCP `CallToolResult`: a text
93
- * content channel, an `isError` flag, and value-free `structuredContent` metadata.
129
+ * content channel carrying the serialized structured result, an `isError` flag, and the
130
+ * {@link McpStructuredResult} itself.
94
131
  */
95
132
  interface McpToolResult {
96
133
  readonly content: readonly McpTextContent[];
97
134
  readonly isError: boolean;
98
- readonly structuredContent: McpToolMeta;
135
+ readonly structuredContent: McpStructuredResult;
99
136
  }
100
137
  /** A JSON-Schema description of a tool's input (the wire schema advertised to `tools/list`). */
101
138
  interface McpToolInputSchema {
@@ -104,11 +141,29 @@ interface McpToolInputSchema {
104
141
  readonly required?: readonly string[];
105
142
  readonly additionalProperties?: boolean;
106
143
  }
107
- /** A tool advertised by the server: an agent-callable name, a description, and its input schema. */
144
+ /**
145
+ * A JSON-Schema description of a tool's **structured result**: the schema advertised alongside the
146
+ * tool on `tools/list` and the one every reply from that tool conforms to. The protocol fixes the
147
+ * root type as `object`; `required` and `additionalProperties` are declared (never omitted) so the
148
+ * published contract states exactly which properties a client may rely on and forbids the rest.
149
+ */
150
+ interface McpToolOutputSchema {
151
+ readonly type: "object";
152
+ readonly properties: Readonly<Record<string, unknown>>;
153
+ readonly required: readonly string[];
154
+ readonly additionalProperties: boolean;
155
+ }
156
+ /**
157
+ * A tool advertised by the server: an agent-callable name, a human-readable title, a description, and
158
+ * the schemas of its input and of its structured result.
159
+ */
108
160
  interface McpToolDef {
109
161
  readonly name: string;
162
+ /** A human-readable title, so these four generic names stay distinguishable in an aggregating client. */
163
+ readonly title: string;
110
164
  readonly description: string;
111
165
  readonly inputSchema: McpToolInputSchema;
166
+ readonly outputSchema: McpToolOutputSchema;
112
167
  }
113
168
  /**
114
169
  * The tools this server exposes: the read/convert operations that share the `core` cleanly and whose
@@ -124,6 +179,11 @@ declare const TOOL_DEFS: readonly McpToolDef[];
124
179
  * posture), and maps the {@link RunResult} onto an MCP result. An unknown tool name or a missing
125
180
  * `content` argument is a value-free usage error, never a thrown stack trace carrying input.
126
181
  *
182
+ * Every path returns an {@link McpStructuredResult} conforming to the called tool's declared
183
+ * {@link McpToolDef.outputSchema}, with the same value serialized into the text content block. An
184
+ * unknown tool name has no schema of its own, so it answers with the shared outcome fields alone,
185
+ * which every tool's schema declares.
186
+ *
127
187
  * @param name - The tool name (one of {@link TOOL_DEFS}).
128
188
  * @param args - The tool-call arguments object.
129
189
  * @param deps - Optional {@link RunDeps} override (tests inject fakes); defaults to feeding `content` as
@@ -136,8 +196,9 @@ declare const TOOL_DEFS: readonly McpToolDef[];
136
196
  *
137
197
  * const r = await dispatchTool("parse", { content: '{"resourceType":"Patient"}' });
138
198
  * r.isError; // => false
199
+ * r.structuredContent.status; // => "success"
139
200
  * ```
140
201
  */
141
202
  declare function dispatchTool(name: string, args: Readonly<Record<string, unknown>>, deps?: RunDeps): Promise<McpToolResult>;
142
203
 
143
- export { type McpTextContent, type McpToolDef, type McpToolInputSchema, type McpToolMeta, type McpToolResult, SERVER_INFO, TOOL_DEFS, createMcpServer, dispatchTool, startStdioServer };
204
+ export { type McpStructuredResult, type McpTextContent, type McpToolDef, type McpToolInputSchema, type McpToolMeta, type McpToolOutputSchema, type McpToolResult, type McpToolStatus, SERVER_INFO, TOOL_DEFS, createMcpServer, dispatchTool, startStdioServer };