Documentation
¶
Index ¶
- Constants
- type BlobResourceContents
- type CallToolRequest
- type CallToolResult
- type ClientCapabilities
- type CreateMessageRequest
- type CreateMessageResult
- type Cursor
- type EmbeddedResource
- type ErrorResponse
- type GetPromptRequest
- type GetPromptResult
- type ID
- type ImageContent
- type Implementation
- type InitializeRequest
- type InitializeResult
- type InitializedNotification
- type ListPromptsRequest
- type ListPromptsResult
- type ListResourceTemplatesRequest
- type ListResourceTemplatesResult
- type ListResourcesRequest
- type ListResourcesResult
- type ListRootsRequest
- type ListRootsResult
- type ListToolsRequest
- type ListToolsResult
- type LoggingServerCapabilities
- type McpTool
- type Message
- type MessageContent
- type ModelHint
- type ModelPreferences
- type Notification
- type NotificationMeta
- type PaginatedRequest
- type PaginatedResult
- type ProgressToken
- type Prompt
- type PromptArgument
- type PromptListChangedNotification
- type PromptMessage
- type PromptsServerCapabilities
- type ReadResourceRequest
- type ReadResourceResult
- type Request
- type RequestMeta
- type Resource
- type ResourceContent
- type ResourceContents
- type ResourceListChangedNotification
- type ResourceTemplate
- type ResourceUpdatedNotification
- type ResourcesServerCapabilities
- type Result
- type ResultMeta
- type Role
- type Root
- type RootsClientCapabilities
- type RootsListChangedNotification
- type SamplingClientCapabilities
- type SamplingHandler
- type SamplingMessage
- type ServerCapabilities
- type SubscribeRequest
- type TextContent
- type TextResourceContents
- type Tool
- type ToolHandler
- type ToolInputSchema
- type ToolListChangedNotification
- type ToolsServerCapabilities
- type TypedTool
- type TypedToolHandler
- type UnsubscribeRequest
Constants ¶
const ( // LatestProtocolVersion represents the latest supported MCP version LatestProtocolVersion = "2024-11-05" // JSONRPCVersion represents the JSON-RPC version used by MCP JSONRPCVersion = "2.0" )
const ( ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 )
Standard JSON-RPC error codes
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type BlobResourceContents ¶
type BlobResourceContents struct {
ResourceContents
Blob string `json:"blob"` // base64-encoded data
}
BlobResourceContents represents binary resource contents
func NewBlobContents ¶
func NewBlobContents(uri string, mimeType string, data []byte) BlobResourceContents
NewBlobContents creates a new BlobResourceContents from raw binary data
func (*BlobResourceContents) GetData ¶
func (b *BlobResourceContents) GetData() ([]byte, error)
GetData decodes the blob data
type CallToolRequest ¶
type CallToolRequest struct {
Method string `json:"method"`
Name string `json:"name"`
Arguments map[string]interface{} `json:"arguments,omitempty"`
}
CallToolRequest represents a request to call a specific tool
type CallToolResult ¶
type CallToolResult struct {
Content []interface{} `json:"content"` // Can be TextContent, ImageContent, or EmbeddedResource
IsError bool `json:"isError,omitempty"`
}
CallToolResult represents the response from a tool call
type ClientCapabilities ¶
type ClientCapabilities struct {
// Experimental features support
Experimental map[string]interface{} `json:"experimental,omitempty"`
// Roots capability
Roots *RootsClientCapabilities `json:"roots,omitempty"`
// Sampling capability
Sampling *SamplingClientCapabilities `json:"sampling,omitempty"`
}
ClientCapabilities represents the capabilities a client supports
type CreateMessageRequest ¶
type CreateMessageRequest struct {
Method string `json:"method"`
Messages []SamplingMessage `json:"messages"`
ModelPreferences *ModelPreferences `json:"modelPreferences,omitempty"`
SystemPrompt string `json:"systemPrompt,omitempty"`
IncludeContext string `json:"includeContext,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
MaxTokens int `json:"maxTokens"`
StopSequences []string `json:"stopSequences,omitempty"`
Metadata interface{} `json:"metadata,omitempty"`
}
CreateMessageRequest represents a request to sample from an LLM
type CreateMessageResult ¶
type CreateMessageResult struct {
Role Role `json:"role"`
Content MessageContent `json:"content"` // Using the same MessageContent interface from prompts
Model string `json:"model"`
StopReason string `json:"stopReason,omitempty"`
}
CreateMessageResult represents the response from a sampling request
func (CreateMessageResult) MarshalJSON ¶
func (r CreateMessageResult) MarshalJSON() ([]byte, error)
MarshalJSON marshals a CreateMessageResult
func (*CreateMessageResult) UnmarshalJSON ¶
func (r *CreateMessageResult) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals a CreateMessageResult
type EmbeddedResource ¶
type EmbeddedResource struct {
Type string `json:"type"`
Resource ResourceContents `json:"resource"`
}
EmbeddedResource represents a resource embedded in a prompt
type ErrorResponse ¶
type ErrorResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
ErrorResponse represents a JSON-RPC 2.0 error response
func NewError ¶
func NewError(code int, message string, data ...interface{}) *ErrorResponse
NewError creates a new ErrorResponse with the given code and message
func (*ErrorResponse) Error ¶
func (e *ErrorResponse) Error() string
Error implements the error interface.
type GetPromptRequest ¶
type GetPromptRequest struct {
Method string `json:"method"`
Name string `json:"name"`
Arguments map[string]string `json:"arguments,omitempty"`
}
GetPromptRequest represents a request to get a specific prompt
type GetPromptResult ¶
type GetPromptResult struct {
Description string `json:"description,omitempty"`
Messages []PromptMessage `json:"messages"`
}
GetPromptResult represents the response to a prompts/get request
type ImageContent ¶
type ImageContent struct {
Type string `json:"type"`
Data string `json:"data"` // base64-encoded
MimeType string `json:"mimeType"`
}
ImageContent represents an image provided to/from an LLM
type Implementation ¶
Implementation describes the name and version of an MCP implementation
type InitializeRequest ¶
type InitializeRequest struct {
// The latest version of MCP that the client supports
ProtocolVersion string `json:"protocolVersion"`
Capabilities ClientCapabilities `json:"capabilities"`
ClientInfo Implementation `json:"clientInfo"`
}
InitializeRequest represents the initial request sent from client to server
type InitializeResult ¶
type InitializeResult struct {
// The version of MCP that the server will use
ProtocolVersion string `json:"protocolVersion"`
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo Implementation `json:"serverInfo"`
// Optional instructions for using the server
Instructions string `json:"instructions,omitempty"`
}
InitializeResult represents the server's response to initialization
type InitializedNotification ¶
type InitializedNotification struct {
Method string `json:"method"`
}
InitializedNotification represents the notification sent after successful initialization
type ListPromptsRequest ¶
type ListPromptsRequest struct {
Method string `json:"method"`
Cursor *Cursor `json:"cursor,omitempty"`
}
ListPromptsRequest represents a request to list available prompts
type ListPromptsResult ¶
type ListPromptsResult struct {
Prompts []Prompt `json:"prompts"`
NextCursor *Cursor `json:"nextCursor,omitempty"`
}
ListPromptsResult represents the response to a prompts/list request
type ListResourceTemplatesRequest ¶
type ListResourceTemplatesRequest struct {
Method string `json:"method"`
Cursor *Cursor `json:"cursor,omitempty"`
}
ListResourceTemplatesRequest represents a request to list resource templates
type ListResourceTemplatesResult ¶
type ListResourceTemplatesResult struct {
ResourceTemplates []ResourceTemplate `json:"resourceTemplates"`
NextCursor *Cursor `json:"nextCursor,omitempty"`
}
ListResourceTemplatesResult represents the response to a resources/templates/list request
type ListResourcesRequest ¶
type ListResourcesRequest struct {
Method string `json:"method"`
Cursor *Cursor `json:"cursor,omitempty"`
}
ListResourcesRequest represents a request to list available resources
type ListResourcesResult ¶
type ListResourcesResult struct {
Resources []Resource `json:"resources"`
NextCursor *Cursor `json:"nextCursor,omitempty"`
}
ListResourcesResult represents the response to a resources/list request
type ListRootsRequest ¶
type ListRootsRequest struct {
Method string `json:"method"`
}
ListRootsRequest represents a request to list available roots
type ListRootsResult ¶
type ListRootsResult struct {
Roots []Root `json:"roots"`
}
ListRootsResult represents the response to a roots/list request
type ListToolsRequest ¶
type ListToolsRequest struct {
Method string `json:"method"`
Cursor *Cursor `json:"cursor,omitempty"`
}
ListToolsRequest represents a request to list available tools
type ListToolsResult ¶
type ListToolsResult struct {
Tools []Tool `json:"tools"`
NextCursor *Cursor `json:"nextCursor,omitempty"`
}
ListToolsResult represents the response to a tools/list request
type LoggingServerCapabilities ¶
type LoggingServerCapabilities struct {
}
LoggingServerCapabilities represents logging-specific server capabilities
type McpTool ¶
type McpTool interface {
GetName() string
GetDescription() string
GetDefinition() Tool
GetHandler() ToolHandler
}
McpTool defines the interface for a typed MCP tool
type Message ¶
type Message struct {
JSONRPC string `json:"jsonrpc"`
ID *ID `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params *json.RawMessage `json:"params,omitempty"`
Result *json.RawMessage `json:"result,omitempty"`
Error *ErrorResponse `json:"error,omitempty"`
}
Message represents either a Request, Notification, or Response
func (*Message) UnmarshalResult ¶
UnmarshalResult unmarshals the result into the provided interface
type MessageContent ¶
type MessageContent interface {
// contains filtered or unexported methods
}
MessageContent is an interface that all content types must implement
type ModelHint ¶
type ModelHint struct {
Name string `json:"name,omitempty"`
}
ModelHint provides hints for model selection
type ModelPreferences ¶
type ModelPreferences struct {
// Optional hints for model selection
Hints []ModelHint `json:"hints,omitempty"`
// Priority values between 0 and 1
CostPriority float64 `json:"costPriority,omitempty"`
SpeedPriority float64 `json:"speedPriority,omitempty"`
IntelligencePriority float64 `json:"intelligencePriority,omitempty"`
}
ModelPreferences represents server preferences for model selection
type Notification ¶
type Notification struct {
Method string `json:"method"`
Params *json.RawMessage `json:"params,omitempty"`
Meta *NotificationMeta `json:"_meta,omitempty"`
}
Notification represents a base MCP notification
type NotificationMeta ¶
type NotificationMeta map[string]interface{}
NotificationMeta contains metadata for notifications
type PaginatedRequest ¶
type PaginatedRequest struct {
Cursor *Cursor `json:"cursor,omitempty"`
}
PaginatedRequest represents a request that supports pagination
type PaginatedResult ¶
type PaginatedResult struct {
NextCursor *Cursor `json:"nextCursor,omitempty"`
}
PaginatedResult represents a paginated response
type ProgressToken ¶
type ProgressToken interface{} // string or number
ProgressToken represents a token for tracking progress of long-running operations
type Prompt ¶
type Prompt struct {
// Name uniquely identifies the prompt
Name string `json:"name"`
// Optional description
Description string `json:"description,omitempty"`
// Optional arguments for templating
Arguments []PromptArgument `json:"arguments,omitempty"`
}
Prompt represents a prompt or prompt template
type PromptArgument ¶
type PromptArgument struct {
// Name of the argument
Name string `json:"name"`
// Optional description
Description string `json:"description,omitempty"`
// Whether this argument is required
Required bool `json:"required,omitempty"`
}
PromptArgument describes an argument a prompt can accept
type PromptListChangedNotification ¶
type PromptListChangedNotification struct {
Method string `json:"method"`
}
PromptListChangedNotification represents a notification that the prompt list has changed
type PromptMessage ¶
type PromptMessage struct {
Role Role `json:"role"`
Content MessageContent `json:"content"`
}
PromptMessage represents a message in a prompt
func (PromptMessage) MarshalJSON ¶
func (m PromptMessage) MarshalJSON() ([]byte, error)
MarshalJSON marshals a PromptMessage
func (*PromptMessage) UnmarshalJSON ¶
func (m *PromptMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals a PromptMessage
type PromptsServerCapabilities ¶
type PromptsServerCapabilities struct {
// Whether the server supports notifications for changes to the prompt list
ListChanged bool `json:"listChanged,omitempty"`
}
PromptsServerCapabilities represents prompts-specific server capabilities
type ReadResourceRequest ¶
ReadResourceRequest represents a request to read a specific resource
type ReadResourceResult ¶
type ReadResourceResult struct {
Contents []ResourceContent `json:"contents"` // Can be TextResourceContents or BlobResourceContents
}
ReadResourceResult represents the response to a resources/read request
func (*ReadResourceResult) UnmarshalJSON ¶
func (r *ReadResourceResult) UnmarshalJSON(data []byte) error
UnmarshalJSON implements json.Unmarshaler for ReadResourceResult
type Request ¶
type Request struct {
Method string `json:"method"`
Params *json.RawMessage `json:"params,omitempty"`
Meta *RequestMeta `json:"_meta,omitempty"`
}
Request represents a base MCP request
type RequestMeta ¶
type RequestMeta struct {
ProgressToken ProgressToken `json:"progressToken,omitempty"`
}
RequestMeta contains metadata for requests
type Resource ¶
type Resource struct {
// URI identifying this resource
URI string `json:"uri"`
// Human-readable name
Name string `json:"name"`
// Optional description
Description string `json:"description,omitempty"`
// Optional MIME type
MimeType string `json:"mimeType,omitempty"`
}
Resource represents a known resource that the server can read
type ResourceContent ¶
type ResourceContent interface {
// contains filtered or unexported methods
}
ResourceContent is an interface each content struct implements.
type ResourceContents ¶
type ResourceContents struct {
// URI identifying this resource
URI string `json:"uri"`
// Optional MIME type
MimeType string `json:"mimeType,omitempty"`
}
ResourceContents represents the contents of a specific resource
type ResourceListChangedNotification ¶
type ResourceListChangedNotification struct {
Method string `json:"method"`
}
ResourceListChangedNotification represents a notification that the resource list has changed
type ResourceTemplate ¶
type ResourceTemplate struct {
// URI template for constructing resource URIs
URITemplate string `json:"uriTemplate"`
// Human-readable name
Name string `json:"name"`
// Optional description
Description string `json:"description,omitempty"`
// Optional MIME type
MimeType string `json:"mimeType,omitempty"`
}
ResourceTemplate represents a template for available resources
type ResourceUpdatedNotification ¶
ResourceUpdatedNotification represents a notification that a resource has been updated
type ResourcesServerCapabilities ¶
type ResourcesServerCapabilities struct {
// Whether the server supports subscribing to resource updates
Subscribe bool `json:"subscribe,omitempty"`
// Whether the server supports notifications for changes to the resource list
ListChanged bool `json:"listChanged,omitempty"`
}
ResourcesServerCapabilities represents resources-specific server capabilities
type Result ¶
type Result struct {
Meta *ResultMeta `json:"_meta,omitempty"`
}
Result represents a base MCP result
type Root ¶
type Root struct {
// URI identifying the root. Must start with file:// for now
URI string `json:"uri"`
// Optional name for the root
Name string `json:"name,omitempty"`
}
Root represents a root directory or file that the server can operate on
type RootsClientCapabilities ¶
type RootsClientCapabilities struct {
// Whether the client supports notifications for changes to the roots list
ListChanged bool `json:"listChanged,omitempty"`
}
RootsClientCapabilities represents roots-specific client capabilities
type RootsListChangedNotification ¶
type RootsListChangedNotification struct {
Method string `json:"method"`
}
RootsListChangedNotification represents a notification that the roots list has changed
type SamplingClientCapabilities ¶
type SamplingClientCapabilities struct {
}
SamplingClientCapabilities represents sampling-specific client capabilities
type SamplingHandler ¶
type SamplingHandler func(ctx context.Context, req *CreateMessageRequest) (*CreateMessageResult, error)
SamplingHandler is a function that handles a sampling request
type SamplingMessage ¶
type SamplingMessage struct {
Role Role `json:"role"`
Content MessageContent `json:"content"` // Using the same MessageContent interface
}
SamplingMessage represents a message in a sampling request
func (SamplingMessage) MarshalJSON ¶
func (m SamplingMessage) MarshalJSON() ([]byte, error)
MarshalJSON marshals a SamplingMessage
func (*SamplingMessage) UnmarshalJSON ¶
func (m *SamplingMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON unmarshals a SamplingMessage
type ServerCapabilities ¶
type ServerCapabilities struct {
// Experimental features support
Experimental map[string]interface{} `json:"experimental,omitempty"`
// Logging capability
Logging *LoggingServerCapabilities `json:"logging,omitempty"`
// Prompts capability
Prompts *PromptsServerCapabilities `json:"prompts,omitempty"`
// Resources capability
Resources *ResourcesServerCapabilities `json:"resources,omitempty"`
// Tools capability
Tools *ToolsServerCapabilities `json:"tools,omitempty"`
}
ServerCapabilities represents the capabilities a server supports
type SubscribeRequest ¶
SubscribeRequest represents a request to subscribe to resource changes
type TextContent ¶
TextContent represents text provided to/from an LLM
type TextResourceContents ¶
type TextResourceContents struct {
ResourceContents
Text string `json:"text"`
}
TextResourceContents represents text-based resource contents
type Tool ¶
type Tool struct {
// Name of the tool
Name string `json:"name"`
// Optional description
Description string `json:"description,omitempty"`
// JSON Schema defining expected parameters
InputSchema ToolInputSchema `json:"inputSchema"`
}
Tool represents a tool that can be called by the client
type ToolHandler ¶
type ToolHandler func(ctx context.Context, arguments map[string]interface{}) (*CallToolResult, error)
ToolHandler is a function that handles tool invocations
type ToolInputSchema ¶
type ToolInputSchema struct {
Type string `json:"type"`
Properties map[string]interface{} `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
}
ToolInputSchema represents the input schema for a tool
type ToolListChangedNotification ¶
type ToolListChangedNotification struct {
Method string `json:"method"`
}
ToolListChangedNotification represents a notification that the tool list has changed
type ToolsServerCapabilities ¶
type ToolsServerCapabilities struct {
// Whether the server supports notifications for changes to the tool list
ListChanged bool `json:"listChanged,omitempty"`
}
ToolsServerCapabilities represents tools-specific server capabilities
type TypedTool ¶
type TypedTool[T any] struct { // contains filtered or unexported fields }
TypedTool is a generic implementation of McpTool
func NewTool ¶
func NewTool[T any](name, description string, handler TypedToolHandler[T]) *TypedTool[T]
NewTool creates a new typed MCP tool
func (*TypedTool[T]) GetDefinition ¶
func (*TypedTool[T]) GetDescription ¶
func (*TypedTool[T]) GetHandler ¶
func (t *TypedTool[T]) GetHandler() ToolHandler
type TypedToolHandler ¶
type TypedToolHandler[T any] func(ctx context.Context, input T) (*CallToolResult, error)
TypedToolHandler is a function that processes a tool's input and returns a result
type UnsubscribeRequest ¶
UnsubscribeRequest represents a request to unsubscribe from resource changes