Documentation
¶
Overview ¶
Package mcp adapts external Model Context Protocol servers into the harness's local Tool interface. Stdio (subprocess) and HTTP transports are both supported; the wrapping bridge in register.go is the same.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client struct {
Name string
// contains filtered or unexported fields
}
Client wraps an MCP session and the transport it was opened on. One Client corresponds to one connected server; Close terminates it.
func NewHTTPClient ¶
func NewHTTPClient(ctx context.Context, name, endpoint string, headers map[string]string) (*Client, error)
NewHTTPClient connects to a remote MCP server over the Streamable HTTP transport. Headers (auth tokens, API keys) are injected via a RoundTripper so they ride every request the session makes.
func NewStdioClient ¶
NewStdioClient launches command/args as a subprocess and connects over its stdin/stdout. The Connect call blocks until the server has responded to the initialize handshake or the context is canceled.
func Register ¶
func Register(ctx context.Context, cfg *Config, registry *tool.Registry, progress ProgressFunc) []*Client
Register connects to every server in cfg and registers their tools into the supplied Registry. Returns the open clients so main can defer Close. Server failures are logged to stderr and skipped — losing one MCP server shouldn't kill the harness. Pass a non-nil progress to receive per-server lifecycle events; pass nil if you don't care.
func (*Client) CallTool ¶
CallTool dispatches a tool invocation to the remote server. The result's content blocks (the SDK supports text, image, audio, etc.) are concatenated to a single string — our Tool interface returns one string. Anything that isn't text is summarized rather than dropped silently.
type Config ¶
type Config struct {
Servers []ServerConfig `json:"servers"`
}
Config is the top-level JSON shape.
func LoadConfig ¶
LoadConfig reads a JSON config file. Missing file returns (nil, nil) — MCP is opt-in; absence is not an error.
type MCPTool ¶
MCPTool wraps one remote tool so the agent's local Registry can dispatch to it. The agent loop sees a Tool like any other.
func (*MCPTool) Definition ¶
type ProgressFunc ¶
type ProgressFunc func(server string, status ProgressStatus, total int)
ProgressFunc reports background progress while Register is iterating the server list. server is the current server's name (empty on Begin/Done); total is the constant count of servers in the config.
type ProgressStatus ¶
type ProgressStatus int
ProgressStatus is one phase of MCP server bring-up. A ProgressFunc gets called once per phase per server, plus ProgressBegin/ProgressDone bracketing the whole batch, so the TUI can render a loading indicator.
const ( ProgressBegin ProgressStatus = iota // sent once before any server work ProgressConnecting // about to dial the named server ProgressConnected // server connected + tools listed ProgressFailed // server skipped due to error ProgressDone // all servers processed )
type ServerConfig ¶
type ServerConfig struct {
Name string `json:"name"`
Transport string `json:"transport"` // "stdio" or "http"
Command string `json:"command,omitempty"`
Args []string `json:"args,omitempty"`
URL string `json:"url,omitempty"`
Headers map[string]string `json:"headers,omitempty"`
}
ServerConfig describes one MCP server to connect to. Either Command (with optional Args) for stdio, or URL (with optional Headers) for HTTP. The loader expands ${VAR} in args, header values, and the URL.