Documentation
¶
Overview ¶
Package mcp connects an agent to MCP servers. It starts a local server over stdio, or talks to one over HTTP ("streamable HTTP"), lists its tools and turns each into an ordinary tool that calls the server. The same adapter lives in the TS package (agentenkit/adapters/mcp).
Index ¶
Constants ¶
const ProtocolVersion = "2025-06-18"
ProtocolVersion is the MCP version we ask for. A server may answer with an older one; we only use initialize, tools/list and tools/call, which every version has.
Variables ¶
This section is empty.
Functions ¶
func ContentText ¶
func ContentText(res CallResult) string
ContentText is what the model reads back: the text parts joined, and a short note for anything that is not text. With no content, the structured result.
Types ¶
type CallResult ¶
type CallResult struct {
Content []Content `json:"content"`
StructuredContent json.RawMessage `json:"structuredContent,omitempty"`
IsError bool `json:"isError,omitempty"`
}
CallResult is what tools/call answers.
type Connection ¶
type Connection struct {
Name string
// Tools are ready to put in an agent's Tools.
Tools []ports.Tool
// contains filtered or unexported fields
}
Connection is a live server and its tools.
func Connect ¶
func Connect(ctx context.Context, s Server) (*Connection, error)
Connect connects to one server, lists its tools and wraps each one. Keep the connection for as long as the workers run, and Close it on shutdown.
func ConnectAll ¶
func ConnectAll(ctx context.Context, servers ...Server) (*Connection, error)
ConnectAll connects to several servers and merges their tools. Two tools with the same final name fail, so one never hides the other.
func (*Connection) Close ¶
func (c *Connection) Close() error
Close stops the server process, or ends the HTTP session.
type Content ¶
type Content struct {
Type string `json:"type"`
Text string `json:"text,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Resource *struct {
URI string `json:"uri,omitempty"`
Text *string `json:"text,omitempty"`
} `json:"resource,omitempty"`
}
Content is one part of a tool's answer.
type Server ¶
type Server struct {
// Name is short, like "github". It is the default prefix of the tool
// names, so two servers can both have a "search" tool.
Name string
// Set exactly one of Stdio and HTTP.
Stdio *Stdio
HTTP *HTTP
// Prefix goes before each tool's name. nil means Name + "_"; point it
// at "" for none.
Prefix *string
// Tools keeps only these tools (by the server's own names). Empty: all.
Tools []string
// RequiresConfirmation parks these tools behind an approval (§2.5), by
// the server's own names. ConfirmAll parks every one.
RequiresConfirmation []string
ConfirmAll bool
// Timeout is how long one request may take. Zero means 60s.
Timeout time.Duration
}
Server says how to reach one MCP server and which of its tools to use.