mcp

package
v0.9.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 19, 2026 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ProtocolVersion20250326 = "2025-03-26"
	ProtocolVersion20241105 = "2024-11-05"
	LatestProtocolVersion   = ProtocolVersion20241105
	JSPNRPCVersion          = "2.0"
)

Protocol versions

View Source
const (
	Initialize              = "initialize"
	NotificationInitialized = "notifications/initialized"
	Ping                    = "ping"
	ToolsList               = "tools/list"
	ToolsCall               = "tools/call"
	PromptsList             = "prompts/list"
	PromptsGet              = "prompts/get"
)

Methods

View Source
const (
	Accepted = "Accepted"

	NotificationRootsListChanged    = "notifications/roots/list_changed"
	NotificationCancelled           = "notifications/cancelled"
	NotificationProgress            = "notifications/progress"
	NotificationMessage             = "notifications/message"
	NotificationResourceUpdated     = "notifications/resources/updated"
	NotificationResourceListChanged = "notifications/resources/list_changed"
	NotificationToolListChanged     = "notifications/tools/list_changed"
	NotificationPromptListChanged   = "notifications/prompts/list_changed"

	SamplingCreateMessage = "sampling/createMessage"
	LoggingSetLevel       = "logging/setLevel"

	ResourcesList          = "resources/list"
	ResourcesTemplatesList = "resources/templates/list"
	ResourcesRead          = "resources/read"
)

Response

View Source
const (
	ErrorCodeParseError     = -32700
	ErrorCodeInvalidRequest = -32600
	ErrorCodeMethodNotFound = -32601
	ErrorCodeInvalidParams  = -32602
	ErrorCodeInternalError  = -32603
)

Error codes for MCP protocol Standard JSON-RPC error codes

View Source
const (
	ErrorCodeConnectionClosed = -32000
	ErrorCodeRequestTimeout   = -32001
)

SDKs and applications error codes

View Source
const (
	TextContentType  = "text"
	ImageContentType = "image"
	AudioContentType = "audio"
)
View Source
const (
	HeaderMcpSessionID = "Mcp-Session-Id"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type AudioContent

type AudioContent struct {
	// Must be "audio"
	Type string `json:"type"`
	// The audio data in base64 format
	Data string `json:"data"`
	// The MIME type of the audio. e.g., "audio/wav", "audio/mpeg"
	MimeType string `json:"mimeType"`
}

func (*AudioContent) GetType

func (i *AudioContent) GetType() string

type BaseRequestParams

type BaseRequestParams struct {
	// Meta information for the request
	Meta RequestMeta `json:"_meta"`
}

BaseRequestParams represents the base parameters for all requests

type CallToolParams

type CallToolParams struct {
	BaseRequestParams
	// The name of the tool to call
	Name string `json:"name"`
	// The arguments to pass to the tool
	Arguments json.RawMessage `json:"arguments"`
}

CallToolParams represents parameters for a tools/call request

type CallToolRequest added in v0.8.0

type CallToolRequest struct {
	JSONRPCRequest
	Params CallToolParams `json:"params"`
}

CallToolRequest represents a tools/call request

type CallToolResult

type CallToolResult struct {
	Content []Content `json:"content"`
	IsError bool      `json:"isError"`
}

CallToolResult represents the result of a tools/call request

func NewCallToolResult

func NewCallToolResult(content []Content, isError bool) *CallToolResult

NewCallToolResult creates a new CallToolResult @param content the content of the result @param isError indicates if the result is an error @return *CallToolResult the CallToolResult object

func NewCallToolResultAudio

func NewCallToolResultAudio(audioData, mimeType string) *CallToolResult

NewCallToolResultAudio creates a new CallToolResult with an audio content @param audioData the audio data in base64 format @param mimeType the MIME type of the audio (e.g., "audio/wav", "audio/mpeg") @return *CallToolResult the CallToolResult object with the audio content

func NewCallToolResultError

func NewCallToolResultError(text string) *CallToolResult

NewCallToolResultError creates a new CallToolResult with an error message @param text the error message @return *CallToolResult the CallToolResult object with the error message

func NewCallToolResultImage

func NewCallToolResultImage(imageData, mimeType string) *CallToolResult

NewCallToolResultImage creates a new CallToolResult with an image content @param imageData the image data in base64 format @param mimeType the MIME type of the image (e.g., "image/png", "image/jpeg") @return *CallToolResult the CallToolResult object with the image content

func NewCallToolResultText

func NewCallToolResultText(text string) *CallToolResult

NewCallToolResultText creates a new CallToolResult with text content @param text the text content @return *CallToolResult the CallToolResult object with the text content

type CapabilitiesInfo added in v0.9.0

type CapabilitiesInfo struct {
	Tools             []MCPTool             `json:"tools"`
	Prompts           []MCPPrompt           `json:"prompts"`
	Resources         []MCPResource         `json:"resources"`
	ResourceTemplates []MCPResourceTemplate `json:"resourceTemplates"`
	LastSynced        time.Time             `json:"lastSynced"`
	ServerInfo        ImplementationSchema  `json:"serverInfo"`
}

CapabilitiesInfo represents the capabilities information for an MCP server

type ClientCapabilitiesSchema

type ClientCapabilitiesSchema struct {
	Experimental map[string]any        `json:"experimental"`
	Sampling     map[string]any        `json:"sampling"`
	Roots        RootsCapabilitySchema `json:"roots"`
}

ClientCapabilitiesSchema represents capabilities a client may support

type Content

type Content interface {
	// GetType returns the type of the content
	GetType() string
}

Content represents a content item in a tool call result

type ExperimentalCapabilitySchema

type ExperimentalCapabilitySchema struct {
}

type ImageContent

type ImageContent struct {
	// Must be "image"
	Type string `json:"type"`
	// The image data in base64 format
	Data string `json:"data"`
	// The MIME type of the image. e.g., "image/png", "image/jpeg"
	MimeType string `json:"mimeType"`
}

func (*ImageContent) GetType

func (i *ImageContent) GetType() string

type ImplementationSchema

type ImplementationSchema struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

ImplementationSchema describes the name and version of an MCP implementation

type InitializeRequestParams

type InitializeRequestParams struct {
	BaseRequestParams
	// The latest version of the Model Context Protocol that the client supports
	ProtocolVersion string `json:"protocolVersion"`
	// Client capabilities
	Capabilities ClientCapabilitiesSchema `json:"capabilities"`
	// Client implementation information
	ClientInfo ImplementationSchema `json:"clientInfo"`
}

InitializeRequestParams represents parameters for initialize request

type InitializeRequestSchema

type InitializeRequestSchema struct {
	JSONRPCRequest
}

InitializeRequestSchema represents an initialize request

func NewInitializeRequest

func NewInitializeRequest(id int64, params InitializeRequestParams) InitializeRequestSchema

NewInitializeRequest creates a new initialize request

type InitializeResult

type InitializeResult struct {
	JSONRPCBaseResult
	Result InitializedResult `json:"result"`
}

InitializeResult represents the result of an initialize request

type InitializedNotification

type InitializedNotification struct {
	JSONRPCRequest
}

InitializedNotification represents an initialized notification

type InitializedResult

type InitializedResult struct {
	// The version of the Model Context Protocol that the server wants to use
	ProtocolVersion string `json:"protocolVersion"`
	// Server capabilities
	Capabilities ServerCapabilitiesSchema `json:"capabilities"`
	// Server implementation information
	ServerInfo ImplementationSchema `json:"serverInfo"`
	// Instructions describing how to use the server and its features
	Instructions string `json:"instructions"`
}

type JSONRPCBaseResult

type JSONRPCBaseResult struct {
	JSONRPC string `json:"jsonrpc"`
	ID      any    `json:"id"`
}

func NewJSONRPCBaseResult

func NewJSONRPCBaseResult() JSONRPCBaseResult

func (JSONRPCBaseResult) WithID

type JSONRPCError

type JSONRPCError struct {
	// The error type that occurred
	Code int `json:"code"`
	// A short description of the error
	Message string `json:"message"`
	// Additional information about the error
	Data any `json:"data,omitempty"`
}

JSONRPCError represents an error in a JSON-RPC response

type JSONRPCErrorSchema

type JSONRPCErrorSchema struct {
	JSONRPCBaseResult
	Error JSONRPCError `json:"error"`
}

type JSONRPCNotification

type JSONRPCNotification struct {
	JSONRPCBaseResult
	Method string          `json:"method"`
	Params json.RawMessage `json:"params"`
}

JSONRPCNotification represents a JSON-RPC notification

type JSONRPCRequest

type JSONRPCRequest struct {
	// JSONRPC version, must be "2.0"
	JSONRPC string `json:"jsonrpc"`
	// A uniquely identifying ID for a request in JSON-RPC
	Id any `json:"id"`
	// The method to be invoked
	Method string `json:"method"`
	// The parameters to be passed to the method
	Params json.RawMessage `json:"params"`
}

JSONRPCRequest represents a JSON-RPC request that expects a response

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPCBaseResult
	Result any `json:"result"`
}

JSONRPCResponse represents a JSON-RPC response

type ListToolsResult

type ListToolsResult struct {
	Tools []ToolSchema `json:"tools"`
}

ListToolsResult represents the result of a tools/list request

type LoggingCapabilitySchema

type LoggingCapabilitySchema struct {
}

type MCPPrompt added in v0.9.0

type MCPPrompt struct {
	Name        string                 `json:"name"`
	Description string                 `json:"description"`
	Arguments   []PromptArgumentSchema `json:"arguments"`
	LastSynced  time.Time              `json:"lastSynced"`
}

MCPPrompt represents a prompt in MCP capabilities

type MCPResource added in v0.9.0

type MCPResource struct {
	Uri         string    `json:"uri"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	MimeType    string    `json:"mimeType"`
	LastSynced  time.Time `json:"lastSynced"`
}

MCPResource represents a resource in MCP capabilities

type MCPResourceTemplate added in v0.9.0

type MCPResourceTemplate struct {
	UriTemplate string    `json:"uriTemplate"`
	Name        string    `json:"name"`
	Description string    `json:"description"`
	MimeType    string    `json:"mimeType"`
	LastSynced  time.Time `json:"lastSynced"`
}

MCPResourceTemplate represents a resource template in MCP capabilities

type MCPTool added in v0.9.0

type MCPTool struct {
	Name        string           `json:"name"`
	Description string           `json:"description"`
	InputSchema ToolInputSchema  `json:"inputSchema"`
	Annotations *ToolAnnotations `json:"annotations,omitempty"`
	Enabled     bool             `json:"enabled"`
	LastSynced  time.Time        `json:"lastSynced"`
}

MCPTool represents a tool in MCP capabilities

type PingRequest

type PingRequest struct {
	JSONRPCRequest
}

PingRequest represents a ping request

func NewPingRequest

func NewPingRequest(id int64) PingRequest

NewPingRequest creates a new ping request

type PromptArgumentSchema added in v0.8.0

type PromptArgumentSchema struct {
	Name        string `json:"name" yaml:"name"`
	Description string `json:"description" yaml:"description"`
	Required    bool   `json:"required" yaml:"required"`
}

type PromptResponseContentSchema added in v0.8.0

type PromptResponseContentSchema struct {
	Type string `json:"type" yaml:"type"`
	Text string `json:"text" yaml:"text"`
}

type PromptResponseSchema added in v0.8.0

type PromptResponseSchema struct {
	Role    string                      `json:"role" yaml:"role"`
	Content PromptResponseContentSchema `json:"content" yaml:"content"`
}

type PromptSchema added in v0.8.0

type PromptSchema struct {
	Name           string                 `json:"name" yaml:"name"`
	Description    string                 `json:"description" yaml:"description"`
	Arguments      []PromptArgumentSchema `json:"arguments" yaml:"arguments"`
	PromptResponse []PromptResponseSchema `json:"promptResponse,omitempty" yaml:"promptResponse,omitempty"`
}

type PromptsCapabilitySchema

type PromptsCapabilitySchema struct {
	ListChanged bool `json:"listChanged"`
}

PromptsCapabilitySchema represents prompts-related capabilities

type RequestMeta

type RequestMeta struct {
	// Progress token for tracking request progress
	// Can be string or number
	ProgressToken any `json:"progressToken"`
}

RequestMeta represents the meta information for a request

type ResourcesCapabilitySchema

type ResourcesCapabilitySchema struct {
	Subscribe   bool `json:"subscribe"`
	ListChanged bool `json:"listChanged"`
}

ResourcesCapabilitySchema represents resources-related capabilities

type RootsCapabilitySchema

type RootsCapabilitySchema struct {
	ListChanged bool `json:"listChanged"`
}

RootsCapabilitySchema represents roots-related capabilities

type ServerCapabilitiesSchema

type ServerCapabilitiesSchema struct {
	Experimental ExperimentalCapabilitySchema `json:"experimental"`
	Logging      LoggingCapabilitySchema      `json:"logging"`
	Prompts      PromptsCapabilitySchema      `json:"prompts"`
	Resources    ResourcesCapabilitySchema    `json:"resources"`
	Tools        ToolsCapabilitySchema        `json:"tools"`
}

ServerCapabilitiesSchema represents capabilities a server may support

type TextContent

type TextContent struct {
	// Must be "text"
	Type string `json:"type"`
	// The text content
	Text string `json:"text"`
}

TextContent represents a text content item

func (*TextContent) GetType

func (t *TextContent) GetType() string

type ToolAnnotations added in v0.9.0

type ToolAnnotations struct {
	DestructiveHint bool `json:"destructiveHint,omitempty"`
	IdempotentHint  bool `json:"idempotentHint,omitempty"`
	OpenWorldHint   bool `json:"openWorldHint,omitempty"`
	ReadOnlyHint    bool `json:"readOnlyHint,omitempty"`
	// A human-readable title for the tool.
	Title string `json:"title,omitempty"`
}

https://github.com/modelcontextprotocol/modelcontextprotocol/blob/main/schema/2025-03-26/schema.json

type ToolInputSchema

type ToolInputSchema struct {
	Type       string         `json:"type"`
	Properties map[string]any `json:"properties"`
	Required   []string       `json:"required,omitempty"`
	Title      string         `json:"title"`
	Enum       []any          `json:"enum,omitempty"`
}

type ToolSchema

type ToolSchema struct {
	// The name of the tool
	Name string `json:"name"`
	// A human-readable description of the tool
	Description string `json:"description"`
	// A JSON Schema object defining the expected parameters for the tool
	InputSchema ToolInputSchema `json:"inputSchema"`
	// Annotations for the tool
	Annotations *ToolAnnotations `json:"annotations,omitempty"`
	// Meta information for the tool
	// https://github.com/modelcontextprotocol/python-sdk/blob/main/src/mcp/types.py
	Meta map[string]any `json:"_meta,omitempty"`
}

ToolSchema represents a tool definition

type ToolsCapabilitySchema

type ToolsCapabilitySchema struct {
	ListChanged bool `json:"listChanged"`
}

ToolsCapabilitySchema represents tools-related capabilities

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL