Documentation
¶
Overview ¶
Package mcp is a thin idiomatic Go wrapper around the mark3labs MCP SDK with forge-style typed tool registration: an MCP tool is defined by a Go struct (input) + Go struct (output) and a typed handler; the JSON Schema exposed to clients is generated from the input struct via reflection.
Typical use:
srv := mcp.New(mcp.Config{Name: "my-server", Version: "0.1"})
mcp.Register(srv, mcp.Tool[EchoIn, EchoOut]{
Name: "echo",
Description: "Echoes its argument back.",
Handler: func(ctx context.Context, in EchoIn) (EchoOut, error) { ... },
})
_ = srv.Run(ctx)
Transports: stdio (default), HTTP. The package never imports kit/unreal/* or any project service so unrelated MCP projects (trading-bot, ops MCPs, unreal-mcp) can all share the harness.
Index ¶
Constants ¶
This section is empty.
Variables ¶
var ErrHTTPClosed = errors.New("mcp: HTTP transport closed")
ErrHTTPClosed is returned by HTTP transport when the server stops because the context was cancelled. Wraps net/http's ErrServerClosed semantics so callers can branch cleanly.
var ErrSchemaUnsupported = errors.New("mcp: type not mappable to JSON Schema")
ErrSchemaUnsupported is returned by schema introspection helpers when a field's Go type can't be mapped to JSON Schema. The schema generator itself never returns this — it falls back to a generic object — but it's exported so callers can implement strict checks.
Functions ¶
func SchemaFor ¶
func SchemaFor[T any]() json.RawMessage
SchemaFor returns a JSON-Schema document describing the public fields of T (recursively). Field metadata is read from struct tags:
json:"name,omitempty" — sets the property name (and omitempty makes
the field optional).
desc:"…" — human-readable description for the field.
required:"true" — force-include in the schema's required list
regardless of omitempty.
Unsupported field types fall back to `{"type":"object"}` so the schema is always well-formed.
Types ¶
type Config ¶
type Config struct {
// Name is the server name advertised to clients.
Name string
// Version is the server version advertised to clients.
Version string
// Transport selects the wire protocol. Defaults to Stdio.
Transport Transport
}
Config configures a Server.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a typed MCP server. Internally it owns a mark3labs/mcp-go MCPServer; the wrapper exists so consumers don't bind to mcp-go's API directly and so we can add forge concerns (typed registration, schema generation, lifecycle integration) without forking upstream.
type Tool ¶
type Tool[In, Out any] struct { // Name is the MCP tool identifier. Required. Name string // Description is shown to MCP clients (and to the LLM). Required. Description string // Handler runs the tool. Errors are mapped to MCP error responses. Handler func(ctx context.Context, in In) (Out, error) }
Tool is a typed MCP tool. The input/output schemas exposed to clients are derived from In and Out via reflection (see SchemaFor). The handler is invoked with the decoded In and its returned Out is JSON-marshalled into a structured CallToolResult.
type Transport ¶
type Transport interface {
// contains filtered or unexported methods
}
Transport abstracts the wire on which the server speaks MCP. Implementations are produced by Stdio(), HTTP(), etc.