agentskit.js
Recipes

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, Codex, OpenClaw, 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/tools

Transports 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.

#Run the published AgentsKit MCP server

For a ready-made stdio server, install @agentskit/mcp instead of writing a transport wrapper:

npx -y @agentskit/mcp@0.3.9 --tools fetch,search

Use the smallest tool set that fits the task. filesystem, sqlite, and especially shell are opt-in capabilities and should not be enabled by a copy-paste recipe without a scoped root or explicit permission.

#Claude Desktop and Cursor

Use this JSON in Claude Desktop or .cursor/mcp.json in a project:

{
  "mcpServers": {
    "agentskit": {
      "command": "npx",
      "args": ["-y", "@agentskit/mcp@0.3.9", "--tools", "fetch,search"]
    }
  }
}

#Codex

Codex uses TOML configuration, not the JSON wrapper above:

[mcp_servers.agentskit]
command = "npx"
args = ["-y", "@agentskit/mcp@0.3.9", "--tools", "fetch,search"]

#OpenClaw

OpenClaw can save and probe the stdio server directly:

openclaw mcp add agentskit \
  --command npx \
  --arg -y \
  --arg @agentskit/mcp@0.3.9 \
  --arg --tools \
  --arg fetch,search
openclaw mcp doctor agentskit --probe

These recipes prove host configuration, not marketplace inclusion or product adoption. Pi is intentionally not listed as a native MCP host here; its integration path requires a separate extension or package.

#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, Codex, OpenClaw, or any MCP host at the binary and your AgentsKit tools show up as first-class.

#Transports

TransportProvider
createStdioTransport(child)newline-delimited JSON over stdin/stdout
createInMemoryTransportPair()paired in-process transports — tests, in-process bridges
Your ownimplement the McpTransport contract (send + onMessage + optional onClose + close) — WebSocket, SSE + POST, etc.

#See also

Explore nearby

✎ Edit this page on GitHub·Found a problem? Open an issue →·How to contribute →

On this page

Ask the docs
Ask anything about AgentsKit. Answers come from the docs corpus and cite their sources.