Skip to main content
Same MCP env as MCP Config, but builds clients with pkg/mcp/client and passes them via WithMCPClients. Source: examples/agent_with_mcp_client/

What it demonstrates

  • mcpclient.NewClient with WithTimeout, WithRetryAttempts, WithToolFilter
  • Mixing config-based and client-based registration patterns
  • Pre-built clients for custom transport wiring

Run

From examples/:
go run ./agent_with_mcp_client
go run ./agent_with_mcp_client "List tools you can call."
Configure MCP_TRANSPORT, stdio or HTTP URLs, and auth in .env — see MCP Config for transport details and Configuration for the full variable reference.

Key code

client, err := mcpclient.NewClient(
    mcpclient.WithTransport(transport),
    mcpclient.WithTimeout(30 * time.Second),
    mcpclient.WithRetryAttempts(3),
    mcpclient.WithToolFilter(mcpclient.AllowTools("read_file", "list_directory")),
)

a, err := agent.NewAgent(
    agent.WithLLMClient(llmClient),
    agent.WithMCPClients(client),
)

Expected output

I have access to read_file and list_directory tools from the configured MCP server.
What would you like to do?

Learn more

MCP

MCP feature documentation

MCP Config

WithMCPConfig variant