Documentation
¶
Overview ¶
Package mcp is the v1 vocabulary for declaring Model Context Protocol (MCP) servers a host attaches to an agent, replacing hand-written configuration structs with one-line constructors:
adaptor.WithMCP(
mcp.HTTP("docs", "https://example.com/mcp"),
mcp.Stdio("repo-tools", "npx", mcp.Args("repo-mcp")),
)
The package is a pure declaration facade: Server is the existing driver-level server spec under its consumer-facing name, and the HTTP, SSE, and Stdio constructors only fill in its fields. Validation, driver-capability checks, profile materialization, and fingerprinting are unchanged and happen inside the SDK when a run is prepared, and per-call WithMCP keeps its replace (not append) merge semantics.
Index ¶
Constants ¶
const ( // TransportStdio starts a local command and speaks MCP over stdio. TransportStdio = driver.MCPTransportStdio // TransportHTTP connects to an HTTP MCP endpoint. TransportHTTP = driver.MCPTransportHTTP // TransportSSE connects to an SSE-based MCP endpoint. TransportSSE = driver.MCPTransportSSE )
Re-exported transport values so Server literals and field checks do not need a driver import.
Variables ¶
var ( ErrInvalidConfig = errors.New("agentadaptor: invalid MCP configuration") ErrUnsupported = errors.New("agentadaptor: MCP unsupported by driver") ErrTransportUnsupported = errors.New("agentadaptor: MCP transport unsupported by driver") )
MCP declaration and capability sentinels live with the public MCP vocabulary. Engine and root re-exports reference these exact values.
Functions ¶
This section is empty.
Types ¶
type Option ¶
type Option func(*Server)
Option customizes a Server produced by Stdio, HTTP, or SSE.
Options are transport-scoped by the fields they set. Args and Env are valid only for stdio servers; WithHeader, WithHeaders, and WithBearerTokenEnv are valid only for HTTP/SSE servers; Required is valid for every transport. Applying an option to the wrong constructor is not silently ignored: it leaves the incompatible field on Server so the SDK's normal MCP validation returns ErrInvalidMCPConfig before launch.
func Args ¶
Args replaces the process arguments for a stdio server. The input is copied when Args is called and copied again for each server, so neither caller mutation nor option reuse can alias a Server's state. Calling Args with no values clears an earlier Args option.
func Env ¶
Env adds process environment entries for a stdio server. Later Env options overwrite earlier values for the same key. The map is copied when Env is called and its entries are copied again for each server, so option reuse cannot alias a Server's state. A nil or empty map has no effect.
func Required ¶
Required marks the server as one the host expects to be present for the run, with a human-readable reason surfaced when it is not.
func WithBearerTokenEnv ¶
WithBearerTokenEnv names the environment variable whose value is presented as the bearer token when connecting to a remote server. The token itself never enters the declaration.
func WithHeader ¶
WithHeader adds one HTTP header sent on every request to a remote server. Later options overwrite earlier values for the same key.
func WithHeaders ¶
WithHeaders adds every entry of headers to the server's request headers. The map is copied; later mutation of the caller's map is not observed.
type Server ¶
type Server = driver.MCPServerSpec
Server declares one MCP server for the run. It is the consumer-facing name for driver.MCPServerSpec, so values built here are accepted anywhere the SDK or the driver SPI takes the spec today, and every configuration knob remains an exported struct field.
For stdio servers, Command, Args, and Env describe the process to launch. For HTTP/SSE servers, URL, Headers, and BearerTokenEnvVar describe the remote endpoint. Required (with RequiredReason) marks servers the host expects to be present for the run.
func HTTP ¶
HTTP declares a remote MCP server reached over HTTP. name becomes the server key (must be unique within one WithMCP declaration) and url the endpoint. Nil options are ignored.
func SSE ¶
SSE declares a remote MCP server reached over server-sent events. It is identical to HTTP except for the transport.
func Stdio ¶
Stdio declares a local MCP server launched as a subprocess speaking MCP over stdio. name becomes the server key and command the executable. Use Args, Env, and Required to finish the declaration in one expression:
srv := mcp.Stdio("repo-tools", "npx",
mcp.Args("repo-mcp", "--verbose"),
mcp.Env(map[string]string{"REPO_TOKEN_FILE": "/run/secrets/repo"}),
mcp.Required("repository access is mandatory"),
)
Nil options are ignored. Option inputs are snapshotted, and applying the same option to multiple servers produces independent slices and maps.
type Transport ¶
type Transport = driver.MCPTransport
Transport identifies how an MCP server is reached. It is the consumer-facing name for driver.MCPTransport.