Documentation
¶
Overview ¶
Package mcp implements a minimal MCP (Model Context Protocol) server using JSON-RPC 2.0 over stdio.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Request ¶
type Request struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id,omitempty"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
Request represents a JSON-RPC 2.0 request.
type Response ¶
type Response struct {
JSONRPC string `json:"jsonrpc"`
ID json.RawMessage `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *RPCError `json:"error,omitempty"`
}
Response represents a JSON-RPC 2.0 response.
type Server ¶
type Server struct {
// contains filtered or unexported fields
}
Server is a minimal MCP server that dispatches JSON-RPC 2.0 requests over stdio.
func (*Server) CallTool ¶
CallTool invokes a registered tool by name. Returns an error if the tool is unknown.
func (*Server) RegisterTool ¶
func (s *Server) RegisterTool(def ToolDef, handler ToolHandler)
RegisterTool adds a tool to the server's registry.
type ToolDef ¶
type ToolDef struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema json.RawMessage `json:"inputSchema"`
}
ToolDef describes a tool's metadata for the tools/list response.
type ToolHandler ¶
type ToolHandler func(args json.RawMessage) (any, error)
ToolHandler is a function that handles a tool call and returns a result.