Documentation
¶
Overview ¶
Package mcp implements a minimal, dependency-free Model Context Protocol server over stdio (newline-delimited JSON-RPC 2.0). It supports exactly the lifecycle and methods the `volcano docs` tool surface needs — initialize, notifications/initialized, ping, tools/list, tools/call — and nothing more.
The protocol loop is exposed as Serve(ctx, reader, writer, info, handler) so it can be driven directly with in-memory streams in tests, without spawning a subprocess. Domain logic lives entirely behind the Handler interface.
Index ¶
Constants ¶
const ( CodeParseError = -32700 CodeInvalidRequest = -32600 CodeMethodNotFound = -32601 CodeInvalidParams = -32602 CodeInternalError = -32603 )
JSON-RPC 2.0 standard error codes.
const ProtocolVersion = "2025-06-18"
ProtocolVersion is the MCP spec revision this server advertises.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Error ¶
Error is a protocol-level error a Handler may return to produce a JSON-RPC error response (e.g. unknown tool, invalid arguments). Domain failures should instead be returned as a ToolResult with IsError=true.
type Handler ¶
type Handler interface {
Tools() []Tool
Call(ctx context.Context, name string, args json.RawMessage) (ToolResult, error)
}
Handler supplies the tool surface backing the server.
type ServerInfo ¶
ServerInfo identifies this server to the client during initialize.
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema json.RawMessage `json:"inputSchema"`
}
Tool describes one callable tool advertised via tools/list.
type ToolResult ¶
type ToolResult struct {
Content []Content `json:"content"`
StructuredContent any `json:"structuredContent,omitempty"`
IsError bool `json:"isError,omitempty"`
}
ToolResult is the payload returned from a successful tools/call. IsError signals a domain-level failure (the call completed but the operation failed), as distinct from a protocol error.
func TextResult ¶
func TextResult(v any, isError bool) (ToolResult, error)
TextResult builds a ToolResult carrying one JSON text content item plus the same value as structuredContent.