mcp

package
v0.7.13 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 2, 2026 License: MIT Imports: 13 Imported by: 0

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

View Source
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

type FatalError struct {
	Kind string
	Err  error
}

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 NewManager(ctx context.Context) *Manager

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

func (m *Manager) Start(name, command string, args, env []string) error

Start launches one server. Blocks until initialize + tools/list succeed, the process exits, or ctx deadline hits.

func (*Manager) StderrTail

func (m *Manager) StderrTail(name string) []byte

StderrTail returns the last ~1KB of a server's stderr output.

func (*Manager) Tools

func (m *Manager) Tools(name string) []Tool

Tools returns the read-only tool list for a named server.

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.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL