Help us shape the future of Go! Take the 2026 Go Developer Survey

mcp

package
v0.1.16 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2026 License: MIT Imports: 8 Imported by: 0

Documentation

Overview

Package mcp exposes the operations of a registry that set MCP: true as MCP tools, over stdio or streamable HTTP.

A tool's name is the operation name with dots replaced by underscores, its input schema is the registry's wire schema (including apply and confirm, without cli-only inputs), and its annotations follow the effect. Every call goes through the same op.Entry.CallJSON path as HTTP, so validation, the cli-only, apply and confirm rules and authorization are identical. A failed call is an isError result whose text is {"error": {code, message, suggestions}}, plus the provider details of op.Error that are set. The call's request _meta reaches the handler as op.Request.Meta.

Index

Constants

View Source
const MetaCLIConfirmed = "toolkit/cli_confirmed"

MetaCLIConfirmed is the tool _meta key set to true for an operation with CLIConfirmed. It is informational: the MCP tool still needs apply and confirm.

View Source
const MetaCLIImmediate = "toolkit/cli_immediate"

MetaCLIImmediate is the tool _meta key set to true for an operation with CLIImmediate. It is informational: the MCP tool still needs apply.

Variables

This section is empty.

Functions

func Handler

func Handler(reg *op.Registry, opts Options) http.Handler

Handler serves MCP over streamable HTTP, stateless with JSON responses, so it works behind a plain reverse proxy.

func NewServer

func NewServer(reg *op.Registry, auth op.Authorizer, httpReq *http.Request) *sdk.Server

NewServer returns an MCP server with one fresh tool per MCP operation. Only the immutable schema copies are shared between servers. httpReq is the inbound HTTP request for authorizers, or nil for local transports. A nil auth means op.DenyWrites.

func ServeStdio

func ServeStdio(ctx context.Context, reg *op.Registry, opts Options) error

ServeStdio serves MCP on stdin and stdout until the client disconnects or ctx is done.

func Tool

func Tool(e *op.Entry) *sdk.Tool

Tool is the MCP tool definition of e. The output schema is set only when the output is always a JSON object, as MCP requires. Any other output, including an op.Op whose Out is any or json.RawMessage, has no output schema, and its result is the JSON text alone, without structured content.

Types

type ErrorBody

type ErrorBody struct {
	Error  *op.Error `json:"error"`
	Result any       `json:"result,omitempty"`
}

ErrorBody is the text payload of an isError result. Result is the operation's partial output when the error carries one (op.Error.Result).

type Options

type Options struct {
	// Authorizer decides whether a caller may run an operation. Nil means the
	// transport default: op.AllowAll for stdio, whose caller already runs the
	// binary as the user, and op.DenyWrites for HTTP.
	Authorizer op.Authorizer
}

Options configures the MCP surface.

Jump to

Keyboard shortcuts

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