Skip to main content
MCP servers extend your agent with external tools that work identically to built-in tools across Run, Stream, and approval gates. At NewAgent, the SDK connects to each server, discovers tools, applies any tool filter, and validates the setup — failing fast if a server is unreachable.
MCP tool names use the prefix mcp_<serverKey>_<toolName> — for example, a server named "remote" with a search tool registers as mcp_remote_search. This prevents collisions when multiple servers expose tools with the same logical name.

Register MCP servers

Two equivalent paths. Use one or combine both — server names must be unique across both.

WithMCPConfig

Declare servers in a map — key is the stable server name:

WithMCPClients

Build clients with pkg/mcp/client for custom transport or pre-connected clients:
The packaged client is built on the official Go MCP SDK.

Transports

Stdio prerequisite: the MCP server runs as a subprocess. You need the server’s runtime installed (e.g. Node for npm-based servers, Python for uv/pip-based servers). The SDK launches and manages the subprocess — you only provide Command and Args.
Remote MCP servers widen the tool surface available to your LLM. In production:
  • Prefer TLS for streamable HTTP — avoid SkipTLSVerify outside local development
  • Store bearer tokens, OAuth credentials, and custom headers in environment variables or a secrets manager
  • Use ToolFilter to allowlist only the tools your agent actually needs

MCPConfig fields

Runtime changes

Add or remove MCP servers after NewAgent via a.MCPRegistry() — the next run picks up the current registry state.
Dynamic registry changes on the agent client process do not automatically propagate to a remote worker process. For split client/worker deployments, register matching MCP servers on both NewAgent and NewAgentWorker, or ensure workers see the same registry state before runs execute.

Examples

MCP Config

WithMCPConfig from environment

MCP Client

WithMCPClients with explicit clients

Tools

Native and custom tool registration

Approvals

MCP tools follow the same approval policy