WithMCPConfig and agent.MCPServers — transport and credentials from env (MCP_*). Contrast with MCP Client, which uses mcpclient.NewClient + WithMCPClients.
Source: examples/agent_with_mcp_config/
What it demonstrates
MCPStdioandMCPStreamableHTTPtransports from env- Tool filters, timeouts, retries per server
- Local stdio MCP using defaults in
.env.defaults— filesystem server pointed atmcp-filesystem-sandbox/(sample data only, not a separate example)
Configure MCP
Transport — setMCP_TRANSPORT to stdio or streamable_http.
Remote (streamable_http):
MCP_STREAMABLE_HTTP_URL— required- Auth:
MCP_BEARER_TOKEN, or OAuth trioMCP_CLIENT_ID+MCP_CLIENT_SECRET+MCP_TOKEN_URL(OAuth wins when all three set) MCP_SKIP_TLS_VERIFY=true— dev TLS only
stdio):
MCP_STDIO_COMMANDand optionalMCP_STDIO_ARGS(JSON array),MCP_STDIO_ENV(JSON object)
MCP_SERVER_NAME, MCP_TIMEOUT_SECONDS, MCP_RETRY_ATTEMPTS, MCP_ALLOW_TOOLS / MCP_BLOCK_TOOLS (comma-separated; only one list type). See Configuration and committed .env.defaults in the repo for every variable.
Run
Fromexamples/:
Testing against a real HTTP MCP server
This repo does not start an MCP server — point.env at your server.
Example with a TypeScript streamable HTTP server on port 8123:
curl -sS -o /dev/null -w "%{http_code}\n" "http://localhost:8123/mcp"
For stdio, set MCP_STDIO_COMMAND (and args/env if needed). The SDK spawns the subprocess and speaks MCP over stdin/stdout.
Expected output
With the default stdio filesystem MCP server and no prompt:Learn more
MCP
MCP feature documentation
MCP Client
WithMCPClients variant