MCP
@baleybots/mcp is a thin MCP (Model Context Protocol) client for Baleybots processors. It wraps @ai-sdk/mcp and adapts remote tools into the shape Baleybot expects: { name, description, inputSchema, execute }.
Tools returned by mcpTools() use execute — the deprecated function field was removed in core alpha.171.
Install
bun add @baleybots/mcp @baleybots/core ai zod
Dependencies: @ai-sdk/mcp ^2.0.9
Peer dependencies: @baleybots/core >=0.0.1-alpha.100, ai ^7.0.0, zod ^4.3.6
Exports
| Export | Purpose |
|---|---|
MCPClient | Connect to one MCP server (stdio, HTTP/SSE) |
MCPManager | Manage multiple servers, aggregate tools, idle disconnect |
DockerStdioTransport | Run MCP servers in Docker via stdio |
mcpTools | Adapt a connected client to Baleybot-compatible tools |
Connect and attach tools
import { Baleybot } from '@baleybots/core';
import { MCPClient, mcpTools } from '@baleybots/mcp';
const client = new MCPClient({
name: 'filesystem',
transport: {
type: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp/workspace'],
},
});
await client.connect();
const tools = await mcpTools(client);
const bot = Baleybot.create({
name: 'file-processor',
goal: 'Help with files in the MCP workspace.',
tools,
});
await bot.process('List the top-level files and summarize each one.');
await client.disconnect();
Prefix or filter tools when adapting:
const tools = await mcpTools(client, {
prefix: 'fs_',
filter: (t) => t.name.includes('read'),
});
Multiple servers
MCPManager connects several servers, caches tools, and auto-disconnects idle clients:
import { MCPManager } from '@baleybots/mcp';
const manager = new MCPManager();
await manager.addServer({
name: 'github',
transport: {
type: 'stdio',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-github'],
env: { GITHUB_TOKEN: process.env.GITHUB_TOKEN! },
},
toolPrefix: 'github_',
});
const tools = await manager.getTools();
const bot = Baleybot.create({
name: 'dev',
goal: 'Help with repos and local files.',
tools,
});
await manager.disconnectAll();
Resources and prompts
MCPClient also exposes AI SDK client methods: listTools, callTool, listResources, readResource, listPrompts, getPrompt. Use these when you need MCP primitives outside the tool loop.
Related
- Tools — tool loops and
stopWhen - Agent tools — local filesystem/bash (not MCP)
- Alpha 171 migration —
@ai-sdk/mcpupgrade notes