Documentation
¶
Overview ¶
Package mcp implements a minimal MCP 2024-11-05 stdio client: just enough of the protocol to initialize a server, enumerate its tools, call tools, and cancel in-flight calls. Resources, prompts, sampling, and roots are intentionally out of scope (see deferred in the spec).
Index ¶
- Constants
- type CallResult
- type FatalError
- type Manager
- func (m *Manager) DispatchAll(ctx context.Context, calls []ToolUse, perToolTimeout time.Duration) ([]CallResult, *FatalError)
- func (m *Manager) Shutdown()
- func (m *Manager) Start(name, command string, args, env []string) error
- func (m *Manager) StderrTail(name string) []byte
- func (m *Manager) Tools(name string) []Tool
- type Tool
- type ToolUse
Constants ¶
const ( FatalKindServerCrashed = "mcp_server_crashed" FatalKindToolTimeout = "mcp_tool_timeout" FatalKindInvalidName = "mcp_tool_invalid_name" FatalKindCallCancelled = "mcp_call_cancelled" )
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type CallResult ¶
type CallResult struct {
ID string
ResultJSON json.RawMessage
IsError bool
DurationMS int64
}
CallResult is the outcome of a single tool dispatch.
type FatalError ¶
FatalError is a failure that the run cannot recover from (server crash, per-call timeout, etc.). The runner treats this as a fatal run failure and fails with the given Kind (one of the FatalKind* constants).
func (*FatalError) Error ¶
func (e *FatalError) Error() string
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns one-or-more MCP servers for the lifetime of a single run.
func NewManager ¶
func (*Manager) DispatchAll ¶
func (m *Manager) DispatchAll(ctx context.Context, calls []ToolUse, perToolTimeout time.Duration) ([]CallResult, *FatalError)
DispatchAll runs all calls in parallel, each bounded by perToolTimeout. Returns per-call results and an optional FatalError describing the first fatal condition observed.
func (*Manager) Shutdown ¶
func (m *Manager) Shutdown()
Shutdown terminates every server. Idempotent.
func (*Manager) Start ¶
Start launches one server. Blocks until initialize + tools/list succeed, the process exits, or ctx deadline hits.
func (*Manager) StderrTail ¶
StderrTail returns the last ~1KB of a server's stderr output.
type Tool ¶
type Tool struct {
Name string
Description string
InputSchema json.RawMessage
}
Tool is the public representation of an MCP-advertised tool, exposed to Manager consumers.
type ToolUse ¶
type ToolUse struct {
ID string
Name string // namespaced "<server>__<tool>"
Input json.RawMessage
}
ToolUse is the subset of an LLM-emitted tool call that Manager needs to dispatch. Mirrors internal/llm.ToolUse, kept local to avoid a dependency cycle. The runner converts between the two.