Documentation
¶
Overview ¶
Package mcp is a Model Context Protocol server over Streamable HTTP, as much of one as a server of tools needs: every message a POST, every answer one JSON object, no stream, no session.
It speaks both eras of the protocol on the one endpoint. A request carrying its protocol version in its _meta is of 2026-07-28 -- stateless, every request saying who is asking and how, its headers repeating its method and tool -- and is answered so. Anything else is of the eras before, which open with initialize; with no session to remember what it settled, each request after is answered on what it says itself.
Index ¶
- Constants
- func ObjectSchema(properties map[string]any, required ...string) map[string]any
- func PropertySchema(jsonType any, description string, more map[string]any) map[string]any
- func ReadArguments(arguments jsontext.Value, input any) error
- func WithCaller(ctx context.Context, caller *Caller) context.Context
- type Annotations
- type Caller
- type Implementation
- type Reply
- type Server
- type Tool
- type ToolError
Constants ¶
const ( // ModernVersion is the revision served statelessly, its version in every request. ModernVersion = "2026-07-28" // LatestLegacyVersion is what an initialize asking for a version not served is offered. LatestLegacyVersion = "2025-11-25" )
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 CodeHeaderMismatch = -32020 CodeUnsupportedProtocolVersion = -32022 )
JSON-RPC's error codes, and those MCP reserves.
Variables ¶
This section is empty.
Functions ¶
func ObjectSchema ¶
ObjectSchema is the schema of a tool's arguments: an object of the properties, the required among them, and no others.
func PropertySchema ¶
PropertySchema is the schema of one argument, of the JSON type -- a name, or a list of names for one of several -- with what else it says.
func ReadArguments ¶
ReadArguments reads a call's arguments into input, refusing a member the tool does not take, as a *ToolError the model is shown.
Types ¶
type Annotations ¶
type Annotations struct {
Title string `json:"title,omitzero"`
ReadOnlyHint bool `json:"readOnlyHint"`
DestructiveHint bool `json:"destructiveHint"`
IdempotentHint bool `json:"idempotentHint"`
OpenWorldHint bool `json:"openWorldHint"`
}
Annotations are what a client is told of a tool's effects. Every hint is sent, whether true or not: Claude requires readOnlyHint and destructiveHint declared, and lets a read-only tool run without asking.
func ReadOnly ¶
func ReadOnly(title string) *Annotations
ReadOnly is the annotations of a tool that changes nothing, which a client may run without asking.
type Caller ¶
Caller is whom a tool call is for: the account whose data it reaches, and the client asking, as the request's access token names them.
type Implementation ¶
type Reply ¶
Reply is what answers a POST: a status, and a JSON body unless the status is 202. Method and Tool say what was asked, for the log.
type Server ¶
type Server struct {
Info *Implementation
Instructions string
Tools []*Tool
// AllowedOrigins are the origins a request may come with. One coming with no Origin is not a
// browser's and is let through; one with another origin is refused, which is what keeps a page
// from reaching the server through its visitor's browser.
AllowedOrigins []string
// ListTtl is how long a client may keep the tool list before asking again.
ListTtl time.Duration
}
type Tool ¶
type Tool struct {
Name string `json:"name"`
Title string `json:"title,omitzero"`
Description string `json:"description,omitzero"`
InputSchema map[string]any `json:"inputSchema"`
OutputSchema map[string]any `json:"outputSchema,omitzero"`
Annotations *Annotations `json:"annotations,omitzero"`
Call func(ctx context.Context, arguments jsontext.Value) (any, error) `json:"-"`
}
Tool is a tool the server offers. Call answers with what becomes the result's structured content, a JSON object, and its text; a *ToolError is a refusal, and any other error the server's.