MCP bridge (bidirectional)
Consume any MCP server as AgentsKit tools, or expose your AgentsKit tools to MCP hosts — over stdio or any transport.
Model Context Protocol (MCP) is the emerging open standard for
connecting LLM hosts (Claude Desktop, Cursor, Zed, IDEs) to external
tool servers. @agentskit/tools/mcp ships a minimal bidirectional
bridge — consume MCP servers as AgentsKit tools, and expose your
AgentsKit tools to any MCP host.
This is a protocol subset: initialize + tools/list + tools/call
over JSON-RPC 2.0. Full MCP (resources, prompts, sampling) is a
follow-up.
Install
npm install @agentskit/toolsTransports are framework-agnostic — bring your own stdio, WebSocket, or SSE + POST. An in-memory transport pair ships for tests.
Consume an MCP server
import { spawn } from 'node:child_process'
import {
createMcpClient,
createStdioTransport,
toolsFromMcpClient,
} from '@agentskit/tools/mcp'
import { createRuntime } from '@agentskit/runtime'
const child = spawn('my-mcp-server', ['--flag'], { stdio: ['pipe', 'pipe', 'inherit'] })
const transport = createStdioTransport(child)
const client = createMcpClient({ transport })
await client.initialize()
const tools = await toolsFromMcpClient(client)
const runtime = createRuntime({ adapter, tools })
// Later:
await client.close()toolsFromMcpClient advertises every MCP tool as a native
ToolDefinition — schemas pass through, errors propagate, results
are flattened from the MCP content[] array into a single string.
Publish AgentsKit tools as an MCP server
import { createMcpServer, createStdioTransport } from '@agentskit/tools/mcp'
import { webSearch, fetchUrl } from '@agentskit/tools'
const transport = createStdioTransport(process as unknown as {
stdin: typeof process.stdin
stdout: typeof process.stdout
on?: typeof process.on
})
createMcpServer({
transport,
tools: [webSearch(), fetchUrl()],
serverInfo: { name: 'my-agentskit-mcp', version: '1.0.0' },
onEvent: e => console.error('[mcp]', e),
})Your process now speaks MCP on stdin/stdout. Point Claude Desktop, Cursor, or any MCP host at the binary and your AgentsKit tools show up as first-class.
Transports
| Transport | Provider |
|---|---|
createStdioTransport(child) | newline-delimited JSON over stdin/stdout |
createInMemoryTransportPair() | paired in-process transports — tests, in-process bridges |
| Your own | implement the McpTransport contract (send + onMessage + optional onClose + close) — WebSocket, SSE + POST, etc. |
See also
- Tool composer — chain N tools into one macro tool
- Mandatory sandbox — enforce policy on imported MCP tools
- More providers