Run and become indistinguishable from built-in tools inside the agent loop.
Tool names are namespaced as servername__toolname (e.g. fs__read_file) to avoid collisions across servers.
Streamable HTTP
The modern MCP transport used by Cursor, Claude Code, and hosted MCP services.Stdio
Launches a subprocess and communicates over stdin/stdout. Requires the command to be installed locally.Multiple servers
Run call.
Environment variables (Stdio)
Pass secrets to the subprocess without leaking them intoArgs:
Pre-warming connections
By default MCP servers connect lazily on the firstRun call. Call WarmMCP to pre-connect before serving traffic — useful in HTTP handlers where you want predictable first-request latency:
WarmMCP is idempotent — calling it multiple times (or mixing with Run) is safe. Returns nil immediately if no MCP servers are configured.
Cleanup
Always deferClose to terminate subprocesses and release HTTP connections:
Error handling & reconnection
| Scenario | Behavior |
|---|---|
| Server fails to connect | Error is held; retry by calling ReconnectMCP |
| Tool call returns an error | Non-fatal — error string fed to LLM as tool result |
| Context cancelled during connect | Propagates immediately |
Multiple concurrent Run calls | Internal mutex guarantees connect runs exactly once |
ReconnectMCP to reset the connection state and retry — without needing to create a new Agent:
ReconnectMCP is safe to call from multiple goroutines. Once it returns nil all subsequent Run and RunStream calls proceed without re-connecting.