Documentation
¶
Overview ¶
Package mcp exposes the tools of an MCP (Model Context Protocol) server as a toolset; add a Client to Agent.Toolsets to use it.
It is built on the official Go SDK, which negotiates the protocol version (the stateless 2026-07-28 revision, falling back to the initialize handshake of older servers). Only tools are supported: resources, prompts, sampling, elicitation and roots are not.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Annotations ¶
type Annotations struct {
// Title is a human-readable name of the tool.
Title string
// ReadOnly reports that the tool does not modify its environment.
ReadOnly bool
// Destructive reports that the tool may perform destructive updates; meaningful only when ReadOnly is false.
Destructive bool
// Idempotent reports that repeating a call with the same arguments has no additional effect.
Idempotent bool
// OpenWorld reports that the tool interacts with external entities.
OpenWorld bool
}
Annotations are the behavior hints a server declares for a tool, with the protocol defaults filled in. They are untrusted unless the server is trusted, so the framework does not act on them.
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client connects to one MCP server and provides its tools as a tool.Toolset. One Client can be shared by any number of sessions and runs; Close it when it is no longer needed.
The connection is made on the first run and checked at the start of every run: when it has dropped, the Client reconnects. A server that cannot be reached does not fail the run: it contributes no tools, and the system prompt tells the model it is unavailable.
Tools are named mcp__{server}__{tool}, with characters other than letters, digits, '_' and '-' replaced by '_'. A tool whose name is still invalid (longer than 64 characters, or colliding with another tool of the server) is skipped and reported in the system prompt. The tool list is cached until the server reports a change or, on servers of the 2026-07-28 revision, the cache TTL it gives expires.
func New ¶
New creates a Client for the server reached through transport. name identifies the server in tool names and the system prompt; it should be short and unique among the servers of an Agent. New does not connect. An empty name is a programming error and panics.
func (*Client) Close ¶
Close disconnects from the server, stopping the subprocess of a Stdio transport. The Client cannot be used afterwards.
func (*Client) Instructions ¶
Instructions returns the server's instructions together with notes on skipped tools, or explains why the server is unavailable.
type Option ¶
type Option func(*Client)
Option configures a Client.
func WithFilter ¶
WithFilter exposes only the tools for which keep returns true; it receives the tool's name on the server.
func WithTimeout ¶
WithTimeout sets the timeout of every call to this server's tools, taking precedence over Agent.ToolTimeout.
func WithoutInstructions ¶
func WithoutInstructions() Option
WithoutInstructions stops the server's instructions from being appended to the system prompt.
type Tool ¶
type Tool struct {
// contains filtered or unexported fields
}
Tool is a tool of an MCP server. Middlewares can type-assert a tool.Tool to *Tool to see which server it belongs to and the behavior hints the server declared.
func (*Tool) Annotations ¶
func (t *Tool) Annotations() Annotations
Annotations returns the behavior hints the server declared for the tool.
func (*Tool) Execute ¶
Execute calls the tool on the server. A protocol or connection error is returned as an error, which the Agent gives to the model.
func (*Tool) RemoteName ¶
RemoteName returns the tool's name on the server.
type Transport ¶
type Transport struct {
// contains filtered or unexported fields
}
Transport is how a Client reaches its server. A new connection is made from it every time the Client connects.