@cosyte/cli 0.0.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/CHANGELOG.md +326 -0
- package/LICENSE +21 -0
- package/README.md +265 -0
- package/dist/bin/cosyte-mcp.cjs +1160 -0
- package/dist/bin/cosyte-mcp.cjs.map +1 -0
- package/dist/bin/cosyte-mcp.d.cts +1 -0
- package/dist/bin/cosyte-mcp.d.ts +1 -0
- package/dist/bin/cosyte-mcp.mjs +1158 -0
- package/dist/bin/cosyte-mcp.mjs.map +1 -0
- package/dist/bin/cosyte.cjs +1785 -0
- package/dist/bin/cosyte.cjs.map +1 -0
- package/dist/bin/cosyte.d.cts +1 -0
- package/dist/bin/cosyte.d.ts +1 -0
- package/dist/bin/cosyte.mjs +1783 -0
- package/dist/bin/cosyte.mjs.map +1 -0
- package/dist/index.cjs +1462 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +1360 -0
- package/dist/index.d.ts +1360 -0
- package/dist/index.mjs +1414 -0
- package/dist/index.mjs.map +1 -0
- package/dist/io-B2EobRzC.d.cts +57 -0
- package/dist/io-B2EobRzC.d.ts +57 -0
- package/dist/mcp.cjs +1161 -0
- package/dist/mcp.cjs.map +1 -0
- package/dist/mcp.d.cts +143 -0
- package/dist/mcp.d.ts +143 -0
- package/dist/mcp.mjs +1155 -0
- package/dist/mcp.mjs.map +1 -0
- package/package.json +131 -0
package/dist/mcp.d.ts
ADDED
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
import { Server } from '@modelcontextprotocol/sdk/server/index.js';
|
|
2
|
+
import { R as RunDeps } from './io-B2EobRzC.js';
|
|
3
|
+
import 'node:stream';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* The **stdio MCP server**: the JSON-RPC/stdio adapter over the same shared `core`/`commands` the
|
|
7
|
+
* `cosyte` terminal command drives. This is the **only** module that touches
|
|
8
|
+
* `@modelcontextprotocol/sdk`, so the SDK (the CLI's single third-party runtime dependency) stays
|
|
9
|
+
* **isolated behind the `./mcp` subpath and lazy-loaded**: a `cosyte parse` invocation never imports
|
|
10
|
+
* this file and therefore never loads the SDK (proven by `mcp-isolation.test.ts`).
|
|
11
|
+
*
|
|
12
|
+
* The server is a **local stdio subprocess**, implicitly trusted by the user/agent that launched it,
|
|
13
|
+
* not a hosted network endpoint. It is **stateless per call**: each tool request is one operation
|
|
14
|
+
* over the wrapped libraries, with the same value-free PHI posture the CLI proves once and both
|
|
15
|
+
* adapters inherit.
|
|
16
|
+
*
|
|
17
|
+
* @packageDocumentation
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/** The MCP server identity advertised to a client on connect. */
|
|
21
|
+
declare const SERVER_INFO: {
|
|
22
|
+
readonly name: "cosyte";
|
|
23
|
+
readonly version: "0.0.0";
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Build the cosyte MCP {@link Server} with its two request handlers wired to the shared tool surface:
|
|
27
|
+
* `tools/list` advertises {@link TOOL_DEFS}, and `tools/call` routes to {@link dispatchTool} (the same
|
|
28
|
+
* command handlers the terminal uses). The returned server is **not yet connected** to a transport:
|
|
29
|
+
* the caller connects it to stdio (in production) or to an in-memory transport (in tests), so the
|
|
30
|
+
* handler wiring is drivable without a subprocess.
|
|
31
|
+
*
|
|
32
|
+
* @returns A configured, unconnected {@link Server}.
|
|
33
|
+
* @example
|
|
34
|
+
* ```ts
|
|
35
|
+
* import { createMcpServer } from "@cosyte/cli/mcp";
|
|
36
|
+
*
|
|
37
|
+
* const server = createMcpServer();
|
|
38
|
+
* typeof server.connect; // => "function"
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
declare function createMcpServer(): Server;
|
|
42
|
+
/**
|
|
43
|
+
* Start the cosyte MCP server on **stdio** and resolve once the transport is connected. The process
|
|
44
|
+
* then stays alive serving requests until its stdin closes. This is the entry both the `cosyte-mcp`
|
|
45
|
+
* bin and the `cosyte mcp` subcommand call.
|
|
46
|
+
*
|
|
47
|
+
* @returns A promise that resolves when the stdio transport is connected.
|
|
48
|
+
* @example
|
|
49
|
+
* ```ts
|
|
50
|
+
* import { startStdioServer } from "@cosyte/cli/mcp";
|
|
51
|
+
*
|
|
52
|
+
* typeof startStdioServer; // => "function"
|
|
53
|
+
* ```
|
|
54
|
+
*/
|
|
55
|
+
declare function startStdioServer(): Promise<void>;
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The **agent-facing tool surface** of the cosyte MCP server: the *second adapter* over the same
|
|
59
|
+
* `core`/`commands` the `cosyte` terminal command drives. This module
|
|
60
|
+
* is deliberately **SDK-free**: it declares the tools (name, description, JSON-Schema input) and maps a
|
|
61
|
+
* tool call onto the existing command handlers, returning a plain, value-free MCP-shaped result. The
|
|
62
|
+
* `@modelcontextprotocol/sdk` wiring lives one layer up in `./server.ts`, so the tool *logic* is unit-
|
|
63
|
+
* testable without the SDK and the SDK stays isolated behind the `./mcp` subpath.
|
|
64
|
+
*
|
|
65
|
+
* **The shared-core guarantee.** A tool does not re-implement anything: `parse` calls
|
|
66
|
+
* {@link parseCommand}, `validate` calls {@link validateCommand}, etc., each with `--json` so the
|
|
67
|
+
* library's result lands as machine JSON, so `cosyte parse` and the MCP `parse` tool agree by
|
|
68
|
+
* construction. The tool feeds the caller's `content` string in as if it were piped on stdin (`-`).
|
|
69
|
+
*
|
|
70
|
+
* **The PHI posture (load-bearing).** Every tool runs under the {@link VALUE_FREE} posture. There is
|
|
71
|
+
* **no** `--unsafe-show-values` door on the agent surface. A tool's *result* carries the requested data
|
|
72
|
+
* (the parsed model / converted bundle: the explicit request, the data channel), but a tool *error*
|
|
73
|
+
* carries only the value-free diagnostic the command already produced (a stable code + positional
|
|
74
|
+
* context), never an input value.
|
|
75
|
+
*
|
|
76
|
+
* @packageDocumentation
|
|
77
|
+
*/
|
|
78
|
+
|
|
79
|
+
/** A single text content block in an MCP tool result. */
|
|
80
|
+
interface McpTextContent {
|
|
81
|
+
readonly type: "text";
|
|
82
|
+
readonly text: string;
|
|
83
|
+
}
|
|
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;
|
|
88
|
+
/** `true` iff the tool *call* succeeded (data was produced): distinct from a negative verdict. */
|
|
89
|
+
readonly ok: boolean;
|
|
90
|
+
}
|
|
91
|
+
/**
|
|
92
|
+
* 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.
|
|
94
|
+
*/
|
|
95
|
+
interface McpToolResult {
|
|
96
|
+
readonly content: readonly McpTextContent[];
|
|
97
|
+
readonly isError: boolean;
|
|
98
|
+
readonly structuredContent: McpToolMeta;
|
|
99
|
+
}
|
|
100
|
+
/** A JSON-Schema description of a tool's input (the wire schema advertised to `tools/list`). */
|
|
101
|
+
interface McpToolInputSchema {
|
|
102
|
+
readonly type: "object";
|
|
103
|
+
readonly properties: Readonly<Record<string, unknown>>;
|
|
104
|
+
readonly required?: readonly string[];
|
|
105
|
+
readonly additionalProperties?: boolean;
|
|
106
|
+
}
|
|
107
|
+
/** A tool advertised by the server: an agent-callable name, a description, and its input schema. */
|
|
108
|
+
interface McpToolDef {
|
|
109
|
+
readonly name: string;
|
|
110
|
+
readonly description: string;
|
|
111
|
+
readonly inputSchema: McpToolInputSchema;
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* The tools this server exposes: the read/convert operations that share the `core` cleanly and whose
|
|
115
|
+
* results are safe to hand an agent. `redact`/`deid` (gated on `@cosyte/deid`)
|
|
116
|
+
* and `map-codes` are deliberately **not** exposed yet; they land when the terminal command's ground
|
|
117
|
+
* layer and the tool's PHI/So shape are settled.
|
|
118
|
+
*/
|
|
119
|
+
declare const TOOL_DEFS: readonly McpToolDef[];
|
|
120
|
+
/**
|
|
121
|
+
* Dispatch one MCP tool call to the shared command layer and return a value-free {@link McpToolResult}.
|
|
122
|
+
* This is the agent-surface analogue of {@link run}: it validates the arguments, feeds the inline
|
|
123
|
+
* `content` through the same command handlers the terminal uses (under the always-on {@link VALUE_FREE}
|
|
124
|
+
* posture), and maps the {@link RunResult} onto an MCP result. An unknown tool name or a missing
|
|
125
|
+
* `content` argument is a value-free usage error, never a thrown stack trace carrying input.
|
|
126
|
+
*
|
|
127
|
+
* @param name - The tool name (one of {@link TOOL_DEFS}).
|
|
128
|
+
* @param args - The tool-call arguments object.
|
|
129
|
+
* @param deps - Optional {@link RunDeps} override (tests inject fakes); defaults to feeding `content` as
|
|
130
|
+
* stdin. An unexpected throw from a command is mapped to a value-free `CLI_INTERNAL` result, never
|
|
131
|
+
* propagated to the SDK (which would surface the raw message).
|
|
132
|
+
* @returns A value-free {@link McpToolResult}; this function never throws.
|
|
133
|
+
* @example
|
|
134
|
+
* ```ts
|
|
135
|
+
* import { dispatchTool } from "@cosyte/cli/mcp";
|
|
136
|
+
*
|
|
137
|
+
* const r = await dispatchTool("parse", { content: '{"resourceType":"Patient"}' });
|
|
138
|
+
* r.isError; // => false
|
|
139
|
+
* ```
|
|
140
|
+
*/
|
|
141
|
+
declare function dispatchTool(name: string, args: Readonly<Record<string, unknown>>, deps?: RunDeps): Promise<McpToolResult>;
|
|
142
|
+
|
|
143
|
+
export { type McpTextContent, type McpToolDef, type McpToolInputSchema, type McpToolMeta, type McpToolResult, SERVER_INFO, TOOL_DEFS, createMcpServer, dispatchTool, startStdioServer };
|