01Add an MCP server
MCPRegistry holds MCP server connections. addServer(config) starts a server and returns an MCPClient. getTools() returns the tools from every registered server.
TS
import { Agent, AnthropicProvider, MCPRegistry, ToolRegistry } from '@lov3kaizen/agentsea-core';
const mcpRegistry = new MCPRegistry();
await mcpRegistry.addServer({
name: 'filesystem',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-filesystem', '/tmp'],
transport: 'stdio',
});
const mcpTools = mcpRegistry.getTools();
const toolRegistry = new ToolRegistry();
toolRegistry.registerMany(mcpTools);
const agent = new Agent(
{ name: 'files', description: 'Filesystem assistant', model: 'claude-sonnet-4-6', provider: 'anthropic', tools: mcpTools },
new AnthropicProvider(),
toolRegistry,
);02Transport
The example passes name, command, args and transport to addServer. Other transports and options are not covered here.
03Environment variables for servers
Stdio servers receive only a small set of variables from the parent process, such as HOME, PATH, TMPDIR and proxy settings. Provider API keys are not passed. To give a server a variable, name it in passEnv, or set it with env.
TS
await mcpRegistry.addServer({
name: 'github',
command: 'npx',
args: ['-y', '@modelcontextprotocol/server-github'],
transport: 'stdio',
passEnv: ['GITHUB_TOKEN'],
});Note
passEnv copies a variable from the parent environment. Set the variable in the shell that runs the app. Do not print its value in logs.