Skip to main content
MCP (Model Context Protocol) tools allow your agent to connect to external MCP servers and use their tools. This enables your agent to interact with various services and resources through standardized MCP tool interfaces.

Connecting to an MCP Server

To use MCP tools, you first need to create an MCP client using the mcpclient.NewClient function.:

Parameters

  • ctx: The context for the connection
  • endpoint: The SSE endpoint URL of the MCP server (e.g., "http://localhost:9001/sse")

Custom Headers

You can also configure the MCP Client to send custom HTTP headers while interacting with the MCP server.

Filtering Tools

You can optionally restrict which tools are exposed to the agent using the WithToolFilter(...) option. Only the named tools are surfaced; all others are dropped.

Deferred (Lazy-Loaded) Tools

Use WithDeferredTools(...) to mark tools as deferred. Deferred tools are not added to the LLM’s tool list upfront; instead they are discovered and activated on demand via the ToolSearch meta-tool. This keeps the prompt small when an MCP server exposes a large number of tools.
See Deferred Tools for how the activation flow works and when to defer a tool.

Schema Caching

By default, the client connects to the MCP server to fetch tool schemas on every ListTools call. You can cache schemas to avoid repeated round-trips:
  • WithCacheTTL(ttl time.Duration) sets how long cached schemas remain valid.
  • WithSchemaCache(cache SchemaCache) injects a SchemaCache implementation. When set, ListTools() checks the cache before connecting to the MCP server. Back it with Redis (or a similar shared store) to share cached schemas across multiple pods.

Approval-Required Tools

Use WithApprovalRequiredTools(...) to mark specific MCP tools as requiring human approval before they run. See the Human in the Loop page for the full approval flow.

Transport

You can set the transport to be used for the connection. Supported transports are SSE and Streamable HTTP. If not specified it defaults to SSE

Complete Example

Here’s a complete example of an agent using MCP tools: