Documentation
¶
Overview ¶
Package mcp connects an agent to Model Context Protocol (MCP) servers and exposes their tools through the SDK's tools.Tool interface. Servers are declared in configuration (never chosen by the model) and connected at load time over either the stdio or streamable-HTTP transport, using the official github.com/modelcontextprotocol/go-sdk client.
Index ¶
Constants ¶
const ( TransportStdio = "stdio" TransportHTTP = "http" )
Transport names.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client is a connected MCP session and its adapted tools.
func Connect ¶
Connect dials the server described by cfg and lists its tools. A nil logger disables logging.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager holds connections to multiple MCP servers and aggregates their tools.
func ConnectAll ¶
ConnectAll connects to every server in cfgs. If any connection fails, all already-opened connections are closed and the error is returned. A nil logger disables logging.
type ServerConfig ¶
type ServerConfig struct {
// Name namespaces the server's tools (exposed as "<name>_<tool>").
Name string `yaml:"name"`
// Transport is "stdio" or "http".
Transport string `yaml:"transport"`
// Command is the subprocess to run for the stdio transport, e.g.
// ["npx", "-y", "@modelcontextprotocol/server-github"].
Command []string `yaml:"command"`
// Env sets extra environment variables for a stdio server (in addition to
// the inherited process environment). Values are expanded with $VAR syntax.
Env map[string]string `yaml:"env"`
// URL is the endpoint for the http (streamable-HTTP) transport.
URL string `yaml:"url"`
// Headers are sent on every HTTP request. Values are expanded with $VAR.
Headers map[string]string `yaml:"headers"`
// Tools optionally restricts which of the server's tools are exposed
// (by raw tool name). Empty means expose all.
Tools []string `yaml:"tools"`
}
ServerConfig declares a single MCP server.