Documentation
¶
Overview ¶
Package mcptools connects a session's worker to the MCP servers the operator configures, through elelem's mcp package.
Servers are read from .agents/mcp.json in PEEN_CONFIG_DIR and, when the operator allows it, in the session workspace. A stdio server runs as a child of the worker, with the agent's access. A Streamable HTTP server is reached from the worker's network. The Manager exposes each server's tools, instructions, resources, and prompts, and routes a server's elicitation to the Elicitor the agent runtime sets. Roots, sampling, and logging, which MCP 2026-07-28 deprecates, are never offered.
Index ¶
- Constants
- Variables
- func Load(options LoadOptions) ([]Server, []Status)
- type Elicitor
- type Feature
- type LoadOptions
- type Manager
- func (m *Manager) Close() error
- func (m *Manager) Configured() bool
- func (m *Manager) GetPrompt(ctx context.Context, server, name string, arguments map[string]string) (mcp.PromptResult, error)
- func (m *Manager) Instructions() []ServerInstructions
- func (m *Manager) ListPrompts(ctx context.Context, server, cursor string) (mcp.PromptPage, error)
- func (m *Manager) ListResourceTemplates(ctx context.Context, server, cursor string) (mcp.ResourceTemplatePage, error)
- func (m *Manager) ListResources(ctx context.Context, server, cursor string) (mcp.ResourcePage, error)
- func (m *Manager) PromptServers() []string
- func (m *Manager) ReadResource(ctx context.Context, server, uri string) ([]mcp.ResourceContents, error)
- func (m *Manager) Refresh(ctx context.Context)
- func (m *Manager) ResourceServers() []string
- func (m *Manager) SetElicitor(elicitor Elicitor)
- func (m *Manager) Start(ctx context.Context)
- func (m *Manager) Status(ctx context.Context) []Status
- func (m *Manager) Tools() []elelem.Tool
- type Options
- type PromptArgumentInfo
- type PromptInfo
- type Server
- type ServerInfo
- type ServerInstructions
- type Source
- type State
- type Status
- type Transport
Constants ¶
const ( // FileName is the MCP configuration file inside a layer's .agents // directory. FileName = "mcp.json" // DefaultStartTimeout bounds starting one server and listing its tools. DefaultStartTimeout = 30 * time.Second )
Variables ¶
var ( // ErrInvalidConfig marks an mcp.json file or server entry Peen refuses. ErrInvalidConfig = errors.New("invalid MCP configuration") ErrServerUnavailable = errors.New("MCP server unavailable") )
Functions ¶
func Load ¶
func Load(options LoadOptions) ([]Server, []Status)
Load reads the config directory's mcp.json and, when allowed, the workspace's. A file or entry that fails validation does not stop the others: it comes back as a failed status that names the problem.
Types ¶
type Elicitor ¶ added in v0.54.0
type Elicitor func( ctx context.Context, server string, request mcp.ElicitRequest, ) (mcp.ElicitResult, error)
Elicitor asks the user a server's question and returns the answer. server is the name of the server that asked. It runs while the request that needed the answer waits.
type Feature ¶ added in v0.54.0
type Feature = string
Feature is an MCP capability a server advertised.
type LoadOptions ¶
type LoadOptions struct {
// ConfigDirectory is PEEN_CONFIG_DIR. Its .agents/mcp.json is trusted.
ConfigDirectory string
// Workspace is the session workspace. Its .agents/mcp.json is read only
// when WorkspaceEnabled is set, and a stdio server runs there.
Workspace string
WorkspaceEnabled bool
// SecretEnv lists the variables envFrom and bearerTokenEnv may name.
SecretEnv []string
}
LoadOptions says where to read mcp.json and what it may use.
type Manager ¶
type Manager struct {
// contains filtered or unexported fields
}
Manager owns a worker's MCP server connections. Start connects them, Status starts them if nothing has, and Close stops them.
func (*Manager) Configured ¶
Configured reports whether any server or refused entry exists, so a caller can skip MCP work for a session that configures none.
func (*Manager) GetPrompt ¶ added in v0.54.0
func (m *Manager) GetPrompt( ctx context.Context, server, name string, arguments map[string]string, ) (mcp.PromptResult, error)
GetPrompt fills in one of a server's prompts.
func (*Manager) Instructions ¶ added in v0.54.0
func (m *Manager) Instructions() []ServerInstructions
Instructions returns the instructions of every running server that sent some and whose mcp.json entry leaves instructions on, in configuration order. With MaxInstructionsBytes zero it returns none.
func (*Manager) ListPrompts ¶ added in v0.54.0
func (m *Manager) ListPrompts( ctx context.Context, server, cursor string, ) (mcp.PromptPage, error)
ListPrompts lists one page of a server's prompts.
func (*Manager) ListResourceTemplates ¶ added in v0.54.0
func (m *Manager) ListResourceTemplates( ctx context.Context, server, cursor string, ) (mcp.ResourceTemplatePage, error)
ListResourceTemplates lists one page of a server's resource templates.
func (*Manager) ListResources ¶ added in v0.54.0
func (m *Manager) ListResources( ctx context.Context, server, cursor string, ) (mcp.ResourcePage, error)
ListResources lists one page of a server's resources.
func (*Manager) PromptServers ¶ added in v0.54.0
PromptServers names the running servers that offer prompts and whose mcp.json entry leaves prompts on, in configuration order.
func (*Manager) ReadResource ¶ added in v0.54.0
func (m *Manager) ReadResource( ctx context.Context, server, uri string, ) ([]mcp.ResourceContents, error)
ReadResource reads one resource from a server.
func (*Manager) Refresh ¶ added in v0.39.0
Refresh brings the servers up to date at the start of a turn, so a turn sees the current configuration and tool lists. It starts the servers if nothing has. When the configuration changed it restarts every server. A server that ran and stopped restarts. A server that never started is tried again only when the configuration changes, so a server that cannot start does not cost every turn its start timeout. Every running server lists its tools and prompts again, which picks up a server's own changes.
func (*Manager) ResourceServers ¶ added in v0.54.0
ResourceServers names the running servers that offer resources and whose mcp.json entry leaves resources on, in configuration order.
func (*Manager) SetElicitor ¶ added in v0.54.0
SetElicitor routes every server's questions to elicitor. Nil declines them.
func (*Manager) Start ¶
Start connects every server, once. Later calls wait for the first to finish. ctx bounds the starts, not the connections, which live until Close.
type Options ¶
type Options struct {
Servers []Server
// Failures are the entries Load refused. They are reported in Status.
Failures []Status
// BaseEnvironment is the environment every stdio server starts with,
// before its env and envFrom. It is the agent command environment, so
// it holds no Peen secret.
BaseEnvironment []string
// LookupEnv reads the worker variables envFrom and bearerTokenEnv name.
LookupEnv func(string) (string, bool)
// StartTimeout bounds starting one server and listing its tools.
StartTimeout time.Duration
// HTTPTransport carries Streamable HTTP requests. Nil takes
// http.DefaultTransport.
HTTPTransport http.RoundTripper
// Reload reads the configuration again, for Refresh. Nil keeps the
// configuration the Manager was built with.
Reload func() ([]Server, []Status)
// MaxInstructionsBytes is PEEN_MCP_MAX_INSTRUCTIONS_BYTES: the most of
// each server's instructions Instructions returns. Zero returns none.
MaxInstructionsBytes int
}
Options builds a Manager.
type PromptArgumentInfo ¶ added in v0.54.0
type PromptArgumentInfo struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required"`
}
PromptArgumentInfo is one argument a prompt takes.
type PromptInfo ¶ added in v0.54.0
type PromptInfo struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Description string `json:"description,omitempty"`
Arguments []PromptArgumentInfo `json:"arguments"`
}
PromptInfo is one prompt a server offers, with its texts cut to maxPromptTextBytes.
type Server ¶
type Server struct {
Name string
Source Source
Transport Transport
Command string
Args []string
Env map[string]string
// EnvFrom maps a variable the server receives to the worker variable
// that holds its value, so a secret never sits in mcp.json.
EnvFrom map[string]string
// Directory is where a stdio server runs. It is absolute.
Directory string
URL string
Headers map[string]string
// BearerTokenEnv names the worker variable sent as
// "Authorization: Bearer <value>".
BearerTokenEnv string
// Tools limits the server's tools to these names. Empty keeps them all.
Tools []string
// Instructions, Resources, and Prompts say whether the agent gets the
// server's instructions, resources, and prompts. Each is on unless
// mcp.json sets it to false.
Instructions bool
Resources bool
Prompts bool
}
Server is one validated MCP server entry.
type ServerInfo ¶ added in v0.54.0
type ServerInfo struct {
Name string `json:"name"`
Title string `json:"title,omitempty"`
Version string `json:"version,omitempty"`
}
ServerInfo is a server's own name, title, and version, each cut to maxServerInfoBytes.
type ServerInstructions ¶ added in v0.54.0
ServerInstructions is one ready server's instructions for the system prompt: at most Limit bytes of them, with Cut set when they were longer.
type Status ¶
type Status struct {
// Name is the server name. It is empty when a whole mcp.json file failed.
Name string `json:"name"`
Source Source `json:"source"`
Transport Transport `json:"transport,omitempty"`
State State `json:"state"`
// Tools lists the exposed names of the server's tools.
Tools []string `json:"tools"`
// Error says why the server failed.
Error string `json:"error,omitempty"`
// Warnings lists problems that did not stop the server, such as a tool
// in the allowlist the server does not offer.
Warnings []string `json:"warnings,omitempty"`
// ProtocolVersion is the MCP version the connection speaks.
ProtocolVersion string `json:"protocolVersion,omitempty"`
// ServerInfo is what the server says it is.
ServerInfo *ServerInfo `json:"serverInfo,omitempty"`
// Features lists the capabilities the server advertised.
Features []Feature `json:"features,omitempty"`
// InstructionsBytes is the size of the instructions the server sent,
// after the PEEN_MCP_MAX_INSTRUCTIONS_BYTES cut. InstructionsIncluded
// says they reach the system prompt, and InstructionsCut that they were
// longer than the limit.
InstructionsBytes int `json:"instructionsBytes,omitempty"`
InstructionsIncluded bool `json:"instructionsIncluded,omitempty"`
InstructionsCut bool `json:"instructionsCut,omitempty"`
// Prompts lists the prompts the user can invoke, at most
// maxStatusPrompts.
Prompts []PromptInfo `json:"prompts,omitempty"`
}
Status is what a session's worker knows about one configured server.