src/mcp
The @cosyte/cli/mcp subpath export: the agent front door. Importing this module (or running
the cosyte-mcp bin) is the boundary at which the @modelcontextprotocol/sdk dependency is loaded;
the CLI's . entry point and cosyte parse path never reach it.
Interfaces
McpStructuredResult
The structured result of one tool call: the value-free outcome fields every tool carries, plus
that tool's own payload on a call that produced data. This is the object an MCP tools/call reply
carries as structuredContent, and the value whose serialization is the reply's text block.
Properties
code?
readonlyoptionalcode?:CliCode
The stable, value-free diagnostic code on a failed call; absent when data was produced.
data?
readonlyoptionaldata?:unknown
The tool's own payload (the parsed model, the verdict, the summary, the Bundle); absent on a failed call, which produced none.
exit
readonlyexit:number
The CLI exit code the underlying command resolved to (the documented exit-code contract).
ok
readonlyok:boolean
true iff the tool call succeeded (data was produced): distinct from a negative verdict.
status
readonlystatus:McpToolStatus
The three-way outcome a client branches on: see McpToolStatus.
McpTextContent
A single text content block in an MCP tool result.
Properties
text
readonlytext:string
type
readonlytype:"text"
McpToolDef
A tool advertised by the server: an agent-callable name, a human-readable title, a description, and the schemas of its input and of its structured result.
Properties
description
readonlydescription:string
inputSchema
readonlyinputSchema:McpToolInputSchema
name
readonlyname:string
outputSchema
readonlyoutputSchema:McpToolOutputSchema
title
readonlytitle:string
A human-readable title, so these four generic names stay distinguishable in an aggregating client.
McpToolInputSchema
A JSON-Schema description of a tool's input (the wire schema advertised to tools/list).
Properties
additionalProperties?
readonlyoptionaladditionalProperties?:boolean
properties
readonlyproperties:Readonly<Record<string,unknown>>
required?
readonlyoptionalrequired?: readonlystring[]
type
readonlytype:"object"
McpToolOutputSchema
A JSON-Schema description of a tool's structured result: the schema advertised alongside the
tool on tools/list and the one every reply from that tool conforms to. The protocol fixes the
root type as object; required and additionalProperties are declared (never omitted) so the
published contract states exactly which properties a client may rely on and forbids the rest.
Properties
additionalProperties
readonlyadditionalProperties:boolean
properties
readonlyproperties:Readonly<Record<string,unknown>>
required
readonlyrequired: readonlystring[]
type
readonlytype:"object"
McpToolResult
The value-free result of dispatching one MCP tool call. Structurally an MCP CallToolResult: a text
content channel carrying the serialized structured result, an isError flag, and the
McpStructuredResult itself.
Properties
content
readonlycontent: readonlyMcpTextContent[]
isError
readonlyisError:boolean
structuredContent
readonlystructuredContent:McpStructuredResult
Type Aliases
McpToolMeta
McpToolMeta =
McpStructuredResult
The historical name for a tool result's structured content, kept as the published alias of McpStructuredResult.
McpToolStatus
McpToolStatus =
"success"|"verdict"|"failed"
The outcome of a tool call, as the single property a client branches on with no text parsing:
success the operation completed cleanly, verdict the tool ran and reports a negative finding
about the message (an invalid resource, an error-severity conversion issue), failed the call
itself produced no data (a usage mistake, unparseable input, an unavailable parser, an internal
error). verdict and failed are the two a text blob could never reliably separate.
Variables
SERVER_INFO
constSERVER_INFO:object
The MCP server identity advertised to a client on connect.
Type Declaration
name
readonlyname:"cosyte"="cosyte"
version
readonlyversion:string=VERSION
TOOL_DEFS
constTOOL_DEFS: readonlyMcpToolDef[]
The tools this server exposes: the read/convert operations that share the core cleanly and whose
results are safe to hand an agent. redact/deid (gated on @cosyte/deid)
and map-codes are deliberately not exposed yet; they land when the terminal command's ground
layer and the tool's PHI shape are settled.
Functions
createMcpServer()
createMcpServer():
Server
Build the cosyte MCP Server with its two request handlers wired to the shared tool surface:
tools/list advertises the tool definitions, and tools/call routes to the same command handlers
the terminal uses. The returned server is not yet connected to a transport: the caller connects
it to stdio (in production) or to an in-memory transport (in tests), so the handler wiring is
drivable without a subprocess.
Both handlers are explicit about what reaches the wire: tools/list copies each tool's title,
description, input schema and output schema, and tools/call passes the whole structured result
through, so what a client validates is exactly what the tool declared and produced.
Returns
Server
A configured, unconnected Server.
Example
import { createMcpServer } from "@cosyte/cli/mcp";
const server = createMcpServer();
typeof server.connect; // => "function"
dispatchTool()
dispatchTool(
name,args,deps?):Promise<McpToolResult>
Dispatch one MCP tool call to the shared command layer and return a value-free McpToolResult.
This is the agent-surface analogue of run: it validates the arguments, feeds the inline
content through the same command handlers the terminal uses (under the always-on VALUE_FREE
posture), and maps the RunResult onto an MCP result. An unknown tool name or a missing
content argument is a value-free usage error, never a thrown stack trace carrying input.
Every path returns an McpStructuredResult conforming to the called tool's declared McpToolDef.outputSchema, with the same value serialized into the text content block. An unknown tool name has no schema of its own, so it answers with the shared outcome fields alone, which every tool's schema declares.
Parameters
name
string
The tool name (one of TOOL_DEFS).
args
Readonly<Record<string, unknown>>
The tool-call arguments object.
deps?
Optional RunDeps override (tests inject fakes); defaults to feeding content as
stdin. Its writeStdout sink, if any, is not used: the tool result is the only data channel, so a
record stream comes back in it. An unexpected throw from a command is mapped to a value-free
CLI_INTERNAL result, never propagated to the SDK (which would surface the raw message).
Returns
Promise<McpToolResult>
A value-free McpToolResult; this function never throws.
Example
import { dispatchTool } from "@cosyte/cli/mcp";
const r = await dispatchTool("parse", { content: '{"resourceType":"Patient"}' });
r.isError; // => false
r.structuredContent.status; // => "success"
startStdioServer()
startStdioServer():
Promise<void>
Start the cosyte MCP server on stdio and resolve once the transport is connected. The process
then stays alive serving requests until its stdin closes. This is the entry both the cosyte-mcp
bin and the cosyte mcp subcommand call.
Returns
Promise<void>
A promise that resolves when the stdio transport is connected.
Example
import { startStdioServer } from "@cosyte/cli/mcp";
typeof startStdioServer; // => "function"