<!-- Generated by scripts/ax-docs.mts from the JSDoc in registry/ouro/ax/. Do not edit; run `pnpm run docs`. -->

# ax-mcp

The same definitions as an MCP server over stdio (newline-delimited JSON-RPC 2.0), with no dependencies: one tool per command, its inputSchema from the definition, calls checked before they run with the fix in the one error shape, effects as tool annotations, and results cut to a size an agent's context can hold. It follows [the MCP specification](https://modelcontextprotocol.io/specification/2025-06-18).

```sh
npx shadcn@latest add ourostack/ouro-ui/ax-mcp#v1.3.10
```

It installs `lib/ouro/ax/mcp.ts`, with `ax-cli`, `ax-command`, `ax-effects`, `ax-outcome`, `ax-output`, `ax-problem`, `ax-wait`. Its tests are `ax-mcp-tests`. Every item runs on Node 22.18 or later as it is copied: the files import each other as `./<file>.ts`. The [Ouro AX guide](ax.md) shows how they fit together.

## Exports

### `createMcpHandler`

Handles one JSON-RPC message; null for a notification, which gets no reply. Exposed for tests.

```ts
function createMcpHandler(options: McpOptions) => (message: unknown): Promise<Reply | null>
```

### `McpCall`

Runs one command for a tool call; the default runs the definition's run().

```ts
type McpCall = (cmd: CommandDef, input: Input) => Promise<McpCallResult>;
```

### `McpCallResult`

```ts
type McpCallResult = { ok: true; data: unknown; text?: string } | { ok: false; error: AxErrorShape };
```

### `McpOptions`

```ts
interface McpOptions {
  cli: Cli;
  version?: string;
  call?: McpCall;
  include?: (cmd: CommandDef) => boolean;
  maxChars?: number;
  concurrent?: boolean;
}
```

### `McpTool`

```ts
interface McpTool {
  name: string;
  title: string;
  description: string;
  inputSchema: ReturnType<typeof commandManifest>["inputSchema"];
  annotations: { title: string; readOnlyHint: boolean; destructiveHint: boolean; openWorldHint: boolean };
}
```

### `mcpTools`

```ts
function mcpTools(options: McpOptions): McpTool[]
```

### `PROTOCOL_VERSIONS`

The same definitions as an MCP server over stdio (newline-delimited JSON-RPC 2.0), with no dependencies: one tool per command, its inputSchema from the definition, calls checked before they run with the fix in the one error shape, effects as tool annotations, and results cut to a size an agent's context can hold. It follows [the MCP specification](https://modelcontextprotocol.io/specification/2025-06-18).

```ts
const PROTOCOL_VERSIONS: readonly ["2025-06-18", "2025-03-26", "2024-11-05"]
```

### `serveMcp`

Serves MCP on a byte stream until it ends: one JSON-RPC message per line in, one reply per line out.

```ts
function serveMcp(options: McpOptions & { input: AsyncIterable<string | Uint8Array<ArrayBufferLike>> | Iterable<string | Uint8Array<ArrayBufferLike>>; output: { write(s: string): unknown; }; }): Promise<void>
```

### `toolName`

"draft set" is the tool draft_set.

```ts
const toolName: (cmd: CommandDef<unknown, RunContext>) => string
```
