Skip to main content

MCP protocol types

Types in pkg/mcp that model the protocol. Most code uses the client and never builds these directly. They matter when you write a transport or a server-side bridge.

JSON-RPC messages​

mcp.MCPMessage is a generic JSON-RPC 2.0 message.

FieldTypeDescription
JSONRpcstring
IDinterface{}
Methodstring
Paramsjson.RawMessage
Resultjson.RawMessage
Error*MCPError
FunctionDescription
mcp.CreateRequest(id, method, params) (*MCPMessage, error)Builds a request.
mcp.CreateNotification(method, params) (*MCPMessage, error)Builds a notification (no ID).
mcp.CreateResponse(id, result) (*MCPMessage, error)Builds a success response.
mcp.CreateErrorResponse(id, code, message, data) *MCPMessageBuilds an error response.
mcp.ValidateJSONRPCMessage(raw []byte) (*MCPMessage, error)Checks that raw is a well-formed request, notification or response.
mcp.IsRequest(msg), mcp.IsNotification(msg), mcp.IsResponse(msg), mcp.IsError(msg)Classify a message.
mcp.GetError(msg) errorReturns the error from an error response.
mcp.ParseParams(msg, target), mcp.ParseResult(msg, target)Decode params or result into target.
mcp.NewIDGenerator() *IDGeneratorCreates a generator. Next() returns a new request ID.

Initialize and discover​

TypeDescription
mcp.InitializeParamsParameters of the initialize request.
mcp.InitializeResultResult of initialize.
mcp.ClientInfo, mcp.ServerInfoName and version of each side.
mcp.ClientCapabilitiesWhat the client supports.
mcp.ServerCapabilitiesWhat the server supports.
mcp.DiscoverResultResult of server/discover.
FieldTypeDescription
Experimentalmap[string]interface{}
Extensionsmap[string]interface{}
Roots*RootsCapability
Sampling*SamplingCapability
Elicitationmap[string]interface{}
FieldTypeDescription
Experimentalmap[string]interface{}
Logging*LoggingCapability
Completions*CompletionsCapabilityCompletions advertises support for the completion/complete method (hash 68a739a). See (*MCPClient).Complete.
Prompts*PromptsCapability
Resources*ResourcesCapability
Tools*ToolsCapability

The capability types are mcp.RootsCapability, mcp.SamplingCapability, mcp.ToolsCapability, mcp.ResourcesCapability, mcp.PromptsCapability, mcp.LoggingCapability and mcp.CompletionsCapability.

Tools​

FieldTypeDescription
Namestring
Titlestring
Descriptionstring
InputSchemamap[string]interface{}
OutputSchemamap[string]interface{}
Annotationsmap[string]interface{}
Metamap[string]interface{}
TypeDescription
mcp.ListToolsParams, mcp.ListToolsResultParameters and result of tools/list, including pagination.
mcp.CallToolParams, mcp.CallToolResultParameters and result of tools/call.
mcp.ToolResultContentOne content item in a tool result.
FieldTypeDescription
Content[]ToolResultContent
StructuredContentinterface{}
ToolResultinterface{}
IsErrorbool
Metadatamap[string]interface{}

Resources, prompts and completions​

See MCP client for MCPResource, MCPResourceTemplate, ReadResourceParams, ReadResourceResult, ResourceContent, MCPPrompt, PromptMessage, CompleteRequestParams and related types.

Logging​

A client can set the server's log level and receive log messages.

ConstantValueDescription
LoggingLevelDebug"debug"
LoggingLevelInfo"info"
LoggingLevelNotice"notice"
LoggingLevelWarning"warning"
LoggingLevelError"error"
LoggingLevelCritical"critical"
LoggingLevelAlert"alert"
LoggingLevelEmergency"emergency"
FieldTypeDescription
LevelLoggingLevel
FieldTypeDescription
LevelLoggingLevel
Loggerstring
Datainterface{}