MCP stdio / HTTP
Bridge MCP tools into Monorch tool() defs via mcpTools. Use stdio for local processes or mcpHttp for Streamable HTTP / SSE.
stdio
mcp-stdio.ts
typescript
import { agent, mcpStdio, mcpTools } from "@monorch/ai";
import { openai } from "@monorch/ai/openai";
const session = await mcpStdio({
command: "npx",
args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"],
});
const tools = await mcpTools(session, { prefix: "mcp_" });
const bot = agent({
name: "files",
model: openai("gpt-4.1-mini"),
tools,
instructions: "Use MCP tools when needed.",
});
await bot.run("List files in /tmp");
await session.close();HTTP (Streamable + SSE fallback)
mcp-http.ts
typescript
import { agent, mcpHttp, mcpTools } from "@monorch/ai";
import { openai } from "@monorch/ai/openai";
const session = await mcpHttp({
url: process.env.MCP_URL ?? "http://127.0.0.1:3101/mcp",
// headers?: { authorization: "Bearer …" }
});
const tools = await mcpTools(session, { prefix: "remote_" });
const bot = agent({
name: "remote",
model: openai("gpt-4.1-mini"),
tools,
});
await bot.run("Call the remote ping tool");
await session.close();Notes
Prefer a prefix to avoid colliding with local tool names. For tests, mockMcp skips a real process. Connect failures surface as MCP_CONNECT — see Errors & failure modes.