MCP
Connect Model Context Protocol servers over stdio or Streamable HTTP (with SSE fallback), then register their tools as normal tool() definitions.
Stdio transport
Spawns a local MCP server process. Use this for filesystem / desktop-style servers.
mcp-stdio.ts
typescript
import { mcpStdio, mcpTools, agent } from "@monorch/ai";
const session = await mcpStdio({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
});
const tools = await mcpTools(session, {
prefix: "fs_",
permission: { type: "roles", roles: ["agent"] },
});
const bot = agent({
model,
tools,
instructions: "Use filesystem tools when needed.",
});
// later
await session.close();HTTP transport
Connects to a remote MCP endpoint. Default mode tries Streamable HTTP, then falls back to legacy SSE.
mcp-http.ts
typescript
import { mcpHttp, mcpTools } from "@monorch/ai";
const session = await mcpHttp({
url: "https://mcp.example.com/mcp",
headers: { authorization: `Bearer ${token}` },
// transport: "streamable-http" | "sse" | "auto" (default)
});
const tools = await mcpTools(session, { prefix: "remote_" });
await session.close();Mock transport (tests)
mcp-mock.ts
typescript
import { mcpTools, mockMcp } from "@monorch/ai";
const remote = mockMcp([
{
name: "lookup_order",
description: "Look up an order",
inputSchema: {
type: "object",
properties: { orderId: { type: "string" } },
required: ["orderId"],
},
execute: (args) => ({ orderId: args.orderId, status: "paid" }),
},
]);
await mcpTools(remote, { prefix: "mcp_" });
// registers mcp_lookup_order with JSON Schema → Rust IRTransport shape
transport.ts
typescript
type McpTransport = {
listTools(): Promise<McpToolInfo[]> | McpToolInfo[];
callTool(name: string, args: unknown): Promise<JsonValue> | JsonValue;
};
type McpSession = McpTransport & { close(): Promise<void> };BYO transports still work — implement list/call yourself if you already wrap another SDK.