mcp

package
v0.1.5 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package mcp implements a minimal MCP (Model Context Protocol) client. It supports stdio transport only — the most common MCP deployment pattern. Only the tools capability is implemented: tools/list and tools/call.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Conn

type Conn struct {
	// contains filtered or unexported fields
}

Conn is a synchronous JSON-RPC 2.0 connection over a stdio transport. It is NOT safe for concurrent use — Errata calls tools sequentially.

func NewConn

func NewConn(r io.Reader, w io.Writer) *Conn

NewConn wraps the given reader/writer as a JSON-RPC 2.0 connection. The caller is responsible for providing the subprocess stdin (w) and stdout (r) from exec.Cmd.

func (*Conn) Call

func (c *Conn) Call(method string, params, out any) error

Call sends a request with the given method and params, reads the response, and unmarshals result into out (if non-nil).

func (*Conn) CallTool

func (c *Conn) CallTool(name string, args map[string]any) (string, error)

CallTool calls tools/call with the given tool name and arguments. Returns the concatenated text from all content items.

func (*Conn) Handshake

func (c *Conn) Handshake() error

Handshake performs the MCP initialize / initialized exchange.

func (*Conn) ListTools

func (c *Conn) ListTools() ([]MCPTool, error)

ListTools calls tools/list and returns the server's tool definitions.

func (*Conn) Notify

func (c *Conn) Notify(method string, params any) error

Notify sends a notification (no ID, no response expected).

type Dispatcher

type Dispatcher = tools.MCPDispatcher

Dispatcher is an alias for tools.MCPDispatcher — a function that executes an MCP tool call.

type MCPTool

type MCPTool struct {
	Name        string         `json:"name"`
	Description string         `json:"description"`
	InputSchema map[string]any `json:"inputSchema"`
}

MCPTool is one entry from a tools/list response.

type Manager

type Manager struct {
	// contains filtered or unexported fields
}

Manager owns all running MCP server subprocesses.

func StartServers

func StartServers(configs []ServerConfig, env []string) (
	extra []tools.ToolDef,
	dispatchers map[string]Dispatcher,
	warnings []string,
	mgr *Manager,
)

StartServers launches the given MCP servers, performs the MCP handshake, and discovers their tools. Returns:

  • extra []tools.ToolDef: tool definitions to append to Errata's active set
  • dispatchers map[toolName]Dispatcher: call-time dispatch table
  • warnings []string: human-readable messages for servers that failed to start

On per-server failure a warning is appended and that server is skipped; the function never returns a fatal error so Errata can start without MCP.

func (*Manager) Shutdown

func (m *Manager) Shutdown()

Shutdown terminates all MCP server subprocesses.

type ServerConfig

type ServerConfig struct {
	// Name is a human-readable label used in logging.
	Name string
	// Args is the command and its arguments to launch the server subprocess.
	// e.g. ["npx", "@exa-ai/exa-mcp-server"]
	Args []string
}

ServerConfig holds the configuration for a single MCP server.

func ParseServerConfigs

func ParseServerConfigs(raw string) []ServerConfig

ParseServerConfigs parses the ERRATA_MCP_SERVERS env-var format:

name1:cmd1 arg1 arg2,name2:cmd2

Each entry is "name:command args..." separated by commas. Returns an empty slice for an empty input string.

Jump to

Keyboard shortcuts

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