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 Content
- type Implementation
- type Reply
- type Result
- 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 Content ¶ added in v1.98.0
type Content struct {
Type string `json:"type"`
Text string `json:"text,omitzero"`
Data string `json:"data,omitzero"`
MimeType string `json:"mimeType,omitzero"`
}
Content is a block of a tool's result besides the text its structured content is given as: an image the model is shown, say. Data is base64-encoded, as the protocol carries it.
func ImageContent ¶ added in v1.98.0
ImageContent is an image block of the given bytes and type.
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 Result ¶ added in v1.98.0
Result is what a tool answers with to give blocks besides its structured content: Structured is what it would have answered with otherwise, and Content goes after the text of it, in order.
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, or with a *Result to give more blocks besides; a *ToolError is a refusal, and any other error the server's.