Documentation
¶
Overview ¶
Package protocol defines the structures and constants for the Model Context Protocol (MCP).
Package protocol defines the structures and constants for the Model Context Protocol (MCP).
Package protocol defines the structures and constants for the Model Context Protocol (MCP), based on the JSON-RPC 2.0 specification.
Package protocol defines the structures and constants for the Model Context Protocol (MCP).
Package protocol defines the structures and constants for the Model Context Protocol (MCP).
Package protocol defines the structures and constants for the Model Context Protocol (MCP).
Package protocol defines the structures and constants for the Model Context Protocol (MCP).
Package protocol defines compatibility structures for older MCP versions.
Index ¶
- Constants
- func BoolPtr(b bool) *bool
- func IntPtr(i int) *int
- func StringPtr(s string) *string
- func UnmarshalPayload(payload interface{}, target interface{}) error
- type Annotations
- type AudioContent
- type AudioResourceContents
- type BlobResourceContents
- type CallToolRequestParams
- type CallToolResult
- type CallToolResultV2024
- type CancelledParams
- type ClientCapabilities
- type CompleteRequest
- type CompleteResult
- type Completion
- type CompletionArgument
- type CompletionReference
- type Content
- type ContentAnnotations
- type ContentTypeDetect
- type CreateMessageRequestParams
- type CreateMessageRequestParamsV20250326
- type CreateMessageResult
- type CreateMessageResultV20250326
- type EmbeddedResourceContent
- type ErrorCode
- type ErrorMessage
- type ErrorPayload
- type GetPromptRequestParams
- type GetPromptResult
- type ImageContent
- type Implementation
- type InitializeRequestParams
- type InitializeResult
- type InitializedNotificationParams
- type JSONRPCNotification
- type JSONRPCRequest
- type JSONRPCResponse
- type ListPromptsRequestParams
- type ListPromptsResult
- type ListResourceTemplatesRequestParams
- type ListResourceTemplatesResult
- type ListResourcesRequestParams
- type ListResourcesResult
- type ListRootsRequestParams
- type ListRootsResult
- type ListToolsRequestParams
- type ListToolsResult
- type LoggingLevel
- type LoggingMessageParams
- type MCPError
- type ModelHint
- type ModelHintV20250326
- type ModelPreferences
- type ModelPreferencesV20250326
- type ProgressParams
- type Prompt
- type PromptArgument
- type PromptMessage
- type PromptReference
- type PromptsListChangedParams
- type PropertyDetail
- type ReadResourceRequestParams
- type ReadResourceResult
- type ReferenceType
- type RequestMeta
- type Resource
- type ResourceContents
- type ResourceKind
- type ResourceTemplate
- type ResourceUpdatedParams
- type ResourcesListChangedParams
- type Root
- type RootsListChangedParams
- type SamplingCapability
- type SamplingMessage
- type SamplingRequestParams
- type SamplingResult
- type ServerCapabilities
- type SetLevelRequestParams
- type SubscribeResourceParams
- type SubscribeResourceResult
- type TextContent
- type TextResourceContents
- type Tool
- type ToolAnnotations
- type ToolCall
- type ToolError
- type ToolInputSchema
- type ToolsListChangedParams
- type UnsubscribeResourceParams
- type UnsubscribeResourceResult
- type WorkspaceFolder
Constants ¶
const ( // --- Protocol Versions --- CurrentProtocolVersion = "2025-03-26" OldProtocolVersion = "2024-11-05" // --- Standard JSON-RPC Error Codes --- CodeParseError ErrorCode = -32700 CodeInvalidRequest ErrorCode = -32600 CodeMethodNotFound ErrorCode = -32601 CodeInvalidParams ErrorCode = -32602 CodeInternalError ErrorCode = -32603 // --- MCP Specific Error Codes (Example Range: -32000 to -32099) --- CodeMCPAuthenticationFailed ErrorCode = -32000 CodeMCPToolNotFound ErrorCode = -32001 // Added for tool not found CodeMCPToolExecutionError ErrorCode = -32002 // Added for tool execution errors CodeMCPResourceNotFound ErrorCode = -32003 CodeMCPUnsupportedResourceKind ErrorCode = -32004 CodeMCPOperationFailed ErrorCode = -32005 CodeMCPRateLimitExceeded ErrorCode = -32006 CodeMCPServerOverloaded ErrorCode = -32007 CodeMCPBillingError ErrorCode = -32008 // Resource Kinds ResourceKindFile ResourceKind = "file" ResourceKindDir ResourceKind = "dir" ResourceKindBlob ResourceKind = "blob" ResourceKindText ResourceKind = "text" // Added based on ReadResourceResult content types ResourceKindAudio ResourceKind = "audio" // --- Request Methods --- MethodInitialize = "initialize" MethodShutdown = "shutdown" MethodPing = "ping" MethodListTools = "tools/list" // List available tools MethodCallTool = "tools/call" MethodListResources = "resources/list" MethodReadResource = "resources/read" MethodSubscribeResource = "resources/subscribe" MethodUnsubscribeResource = "resources/unsubscribe" MethodResourcesListTemplates = "resources/templates/list" MethodListPrompts = "prompts/list" MethodGetPrompt = "prompts/get" MethodLoggingSetLevel = "logging/set_level" // V2025 Method (Server -> Client Request) MethodSamplingCreateMessage = "sampling/createMessage" // --- Notification Methods --- MethodInitialized = "initialized" MethodExit = "exit" MethodCancelled = "$/cancelled" MethodProgress = "$/progress" MethodNotificationMessage = "notifications/message" // Client -> Server log message MethodNotifyResourcesListChanged = "notifications/resources/list_changed" MethodNotifyResourceUpdated = "notifications/resources/updated" MethodNotifyPromptsListChanged = "notifications/prompts/list_changed" MethodNotifyToolsListChanged = "notifications/tools/list_changed" )
const MethodCompletionComplete = "completion/complete"
MethodCompletionComplete defines the JSON-RPC method name for argument completion.
Variables ¶
This section is empty.
Functions ¶
func BoolPtr ¶ added in v0.1.11
BoolPtr is a helper function to return a pointer to a boolean value.
func StringPtr ¶ added in v0.1.11
StringPtr is a helper function to return a pointer to a string value.
func UnmarshalPayload ¶
func UnmarshalPayload(payload interface{}, target interface{}) error
UnmarshalPayload is a helper function to unmarshal the payload field from a received JSON-RPC params or result field (which is interface{}) into a specific Go struct pointed to by 'target'. It handles the case where the payload might be nil or needs re-marshalling.
Types ¶
type Annotations ¶ added in v0.1.11
type Annotations struct {
Audience []string `json:"audience,omitempty"` // Describes who the intended customer is
Priority *float64 `json:"priority,omitempty"` // Importance of the data (0-1)
}
Annotations provides optional annotations for the client (2025-03-26).
type AudioContent ¶
type AudioContent struct {
Type string `json:"type"` // Should always be "audio"
Data string `json:"data"`
MediaType string `json:"mediaType"`
Annotations *ContentAnnotations `json:"annotations,omitempty"`
}
AudioContent represents audio content.
func (AudioContent) GetType ¶
func (ac AudioContent) GetType() string
type AudioResourceContents ¶ added in v0.1.11
type AudioResourceContents struct {
ContentType string `json:"mimeType"` // e.g., "audio/mpeg", "audio/wav"
Audio string `json:"audio"` // Base64 encoded string
URI string `json:"uri"` // Required by schema
}
func (AudioResourceContents) GetContentType ¶ added in v0.1.11
func (arc AudioResourceContents) GetContentType() string
type BlobResourceContents ¶
type BlobResourceContents struct {
ContentType string `json:"mimeType"` // e.g., "image/png", "application/octet-stream"
Blob string `json:"blob"` // Base64 encoded string
URI string `json:"uri"` // Required by schema
}
BlobResourceContents holds binary resource content (base64 encoded).
func (BlobResourceContents) GetContentType ¶
func (brc BlobResourceContents) GetContentType() string
type CallToolRequestParams ¶ added in v0.1.11
type CallToolRequestParams struct {
// V2025 format
ToolCall *ToolCall `json:"tool_call,omitempty"`
Meta *RequestMeta `json:"_meta,omitempty"`
// V2024 format (for backward compatibility)
Name string `json:"name,omitempty"`
Arguments json.RawMessage `json:"arguments,omitempty"`
}
CallToolRequestParams defines the parameters for a 'tools/call' request. Supports both schema versions: - 2024-11-05: { "name": "...", "arguments": { ... } } - 2025-03-26: { "tool_call": { "id": "...", "tool_name": "...", "input": { ... } } }
func (*CallToolRequestParams) UnmarshalJSON ¶ added in v0.1.11
func (p *CallToolRequestParams) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshaling to handle both V2024 and V2025 formats
type CallToolResult ¶
type CallToolResult struct {
ToolCallID string `json:"tool_call_id"`
Output json.RawMessage `json:"output,omitempty"`
Error *ToolError `json:"error,omitempty"`
Meta *RequestMeta `json:"_meta,omitempty"`
}
CallToolResult defines the result payload for a 'tools/call' response (Schema 2025-03-26).
type CallToolResultV2024 ¶ added in v0.1.11
type CallToolResultV2024 struct {
ToolCallID string `json:"tool_call_id"` // Assuming tool_call_id was implicitly present or intended
Content []Content `json:"content"` // Result content (SLICE of structured parts)
IsError bool `json:"isError,omitempty"` // Indicates if the tool call failed
Meta *RequestMeta `json:"_meta,omitempty"` // Propagate meta if needed
}
CallToolResultV2024 defines the result payload for a 'tools/call' response according to the 2024-11-05 schema. Note: This schema used 'content' (structured) and 'isError' instead of 'output' (raw) and 'error' (structured).
type CancelledParams ¶
type CancelledParams struct {
ID interface{} `json:"id"`
Reason *string `json:"reason,omitempty"` // Added for 2025-03-26
}
CancelledParams defines the parameters for the '$/cancelled' notification.
type ClientCapabilities ¶
type ClientCapabilities struct {
Experimental map[string]interface{} `json:"experimental,omitempty"`
Logging *struct{} `json:"logging,omitempty"` // Added based on ServerCapabilities
Prompts *struct {
ListChanged bool `json:"listChanged,omitempty"`
} `json:"prompts,omitempty"` // Added based on ServerCapabilities
Resources *struct {
Subscribe bool `json:"subscribe,omitempty"`
ListChanged bool `json:"listChanged,omitempty"`
} `json:"resources,omitempty"` // Added based on ServerCapabilities
Tools *struct {
ListChanged bool `json:"listChanged,omitempty"`
} `json:"tools,omitempty"` // Added based on ServerCapabilities
Roots *struct {
ListChanged bool `json:"listChanged,omitempty"`
} `json:"roots,omitempty"`
Sampling *SamplingCapability `json:"sampling,omitempty"` // Corrected type
Authorization *struct {
} `json:"authorization,omitempty"`
}
ClientCapabilities describes features the client supports.
type CompleteRequest ¶ added in v0.1.11
type CompleteRequest struct {
Ref CompletionReference `json:"ref"`
Argument CompletionArgument `json:"argument"`
}
CompleteRequest defines the parameters for a completion/complete request.
type CompleteResult ¶ added in v0.1.11
type CompleteResult struct {
Completion Completion `json:"completion"`
}
CompleteResult defines the structure of a successful completion/complete response.
type Completion ¶ added in v0.1.11
type Completion struct {
Values []string `json:"values"` // Array of completion suggestions (max 100).
Total *int `json:"total,omitempty"` // Optional total number of available matches.
HasMore *bool `json:"hasMore,omitempty"` // Optional flag indicating if more results exist beyond the returned Values.
}
Completion holds the results of an argument completion request.
type CompletionArgument ¶ added in v0.1.11
CompletionArgument holds the name and current value of the argument being completed.
type CompletionReference ¶ added in v0.1.11
type CompletionReference struct {
Type ReferenceType `json:"type"`
Name string `json:"name,omitempty"` // Used for RefTypePrompt
URI string `json:"uri,omitempty"` // Used for RefTypeResource
}
CompletionReference is a union type for prompt or resource references. Use Type to determine which field (Name or URI) is relevant.
type Content ¶
type Content interface {
GetType() string
}
Content defines the interface for different types of content in results/prompts.
type ContentAnnotations ¶
type ContentAnnotations struct {
Title *string `json:"title,omitempty"`
Audience []string `json:"audience,omitempty"`
Priority *float64 `json:"priority,omitempty"`
}
ContentAnnotations defines optional metadata for content parts.
type ContentTypeDetect ¶ added in v1.1.2
type ContentTypeDetect struct {
Type string `json:"type,omitempty"`
Text string `json:"text,omitempty"`
Tool json.RawMessage `json:"tool,omitempty"`
Data json.RawMessage `json:"data,omitempty"`
Parts []json.RawMessage `json:"parts,omitempty"`
Function json.RawMessage `json:"function,omitempty"`
}
ContentTypeDetect provides helper functionality for detecting content types.
type CreateMessageRequestParams ¶
type CreateMessageRequestParams struct {
Context []SamplingMessage `json:"context"` // Renamed to 'messages' in 2025-03-26
Preferences *ModelPreferences `json:"preferences,omitempty"`
}
CreateMessageRequestParams represents the 2024-11-05 structure.
type CreateMessageRequestParamsV20250326 ¶ added in v0.1.11
type CreateMessageRequestParamsV20250326 struct {
Messages []SamplingMessage `json:"messages"` // Renamed from 'context'
ModelPreferences *ModelPreferencesV20250326 `json:"modelPreferences,omitempty"` // Use new struct
SystemPrompt *string `json:"systemPrompt,omitempty"` // Added field
MaxTokens *int `json:"maxTokens,omitempty"` // Added field
}
CreateMessageRequestParamsV20250326 represents the 2025-03-26 structure.
type CreateMessageResult ¶
type CreateMessageResult struct {
Message SamplingMessage `json:"message"`
ModelHint *ModelHint `json:"modelHint,omitempty"`
}
CreateMessageResult represents the 2024-11-05 structure.
type CreateMessageResultV20250326 ¶ added in v0.1.11
type CreateMessageResultV20250326 struct {
Role string `json:"role"` // Added field (e.g., "assistant")
Content []Content `json:"content"` // Added field (replaces Message.Content)
Model *string `json:"model,omitempty"` // Added field (replaces ModelHint.ModelURI)
StopReason *string `json:"stopReason,omitempty"` // Added field (replaces ModelHint.FinishReason)
}
CreateMessageResultV20250326 represents the 2025-03-26 structure.
type EmbeddedResourceContent ¶
type EmbeddedResourceContent struct {
Type string `json:"type"` // Should always be "resource"
Resource Resource `json:"resource"`
Annotations *ContentAnnotations `json:"annotations,omitempty"`
}
EmbeddedResourceContent represents an embedded resource.
func (EmbeddedResourceContent) GetType ¶
func (erc EmbeddedResourceContent) GetType() string
type ErrorCode ¶ added in v0.1.11
type ErrorCode int
ErrorCode defines the type for JSON-RPC error codes.
type ErrorMessage ¶
type ErrorMessage struct {
Payload ErrorPayload `json:"error"` // Field name MUST be "error" for JSON-RPC compliance
}
ErrorMessage represents an MCP Error message conceptually. The actual message sent is a JSONRPCResponse with the 'error' field populated.
type ErrorPayload ¶
type ErrorPayload struct {
Code ErrorCode `json:"code"` // Use ErrorCode type
Message string `json:"message"` // Short error description
Data interface{} `json:"data,omitempty"` // Optional additional error details
}
ErrorPayload defines the structure for the 'error' object within a JSONRPCError response, aligning with the JSON-RPC 2.0 specification used by MCP.
type GetPromptRequestParams ¶
type GetPromptRequestParams struct {
URI string `json:"uri"`
Name string `json:"name,omitempty"` // Added for 2025-03-26 schema
Arguments map[string]interface{} `json:"arguments,omitempty"`
}
GetPromptRequestParams defines parameters for 'prompts/get'.
type GetPromptResult ¶
type GetPromptResult struct {
Messages []PromptMessage `json:"messages"`
Description string `json:"description,omitempty"`
}
GetPromptResult defines the result for 'prompts/get'.
type ImageContent ¶
type ImageContent struct {
Type string `json:"type"` // Should always be "image"
Data string `json:"data"`
MediaType string `json:"mediaType"`
Annotations *ContentAnnotations `json:"annotations,omitempty"`
}
ImageContent represents image content.
func (ImageContent) GetType ¶
func (ic ImageContent) GetType() string
type Implementation ¶
Implementation describes the name and version of an MCP implementation (client or server).
type InitializeRequestParams ¶
type InitializeRequestParams struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ClientCapabilities `json:"capabilities"`
ClientInfo Implementation `json:"clientInfo"`
Trace *string `json:"trace,omitempty"`
WorkspaceFolders []WorkspaceFolder `json:"workspaceFolders,omitempty"`
}
InitializeRequestParams defines the parameters for the 'initialize' request.
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo Implementation `json:"serverInfo"`
Instructions string `json:"instructions,omitempty"`
}
InitializeResult defines the result payload for a successful 'initialize' response.
type InitializedNotificationParams ¶
type InitializedNotificationParams struct{}
InitializedNotificationParams is the payload for the 'initialized' notification (empty).
type JSONRPCNotification ¶
type JSONRPCNotification struct {
JSONRPC string `json:"jsonrpc"` // MUST be "2.0"
Method string `json:"method"` // Method name (e.g., "initialized", "notifications/...")
Params interface{} `json:"params,omitempty"` // Parameters (struct or array)
}
JSONRPCNotification represents a standard JSON-RPC notification object.
func NewNotification ¶ added in v0.1.11
func NewNotification(method string, params interface{}) *JSONRPCNotification
NewNotification creates a new JSON-RPC notification object.
type JSONRPCRequest ¶
type JSONRPCRequest struct {
JSONRPC string `json:"jsonrpc"` // MUST be "2.0"
ID interface{} `json:"id"` // Request ID (string, number, or null)
Method string `json:"method"` // Method name (e.g., "initialize", "tools/call")
Params interface{} `json:"params,omitempty"` // Parameters (struct or array)
}
JSONRPCRequest represents a standard JSON-RPC request object.
type JSONRPCResponse ¶
type JSONRPCResponse struct {
JSONRPC string `json:"jsonrpc"` // MUST be "2.0"
ID interface{} `json:"id"` // MUST be the same as the request ID (or null if error before ID parsing)
Result interface{} `json:"result,omitempty"` // Result object (on success)
Error *ErrorPayload `json:"error,omitempty"` // Error object (on failure)
}
JSONRPCResponse represents a standard JSON-RPC response object.
func NewErrorResponse ¶ added in v0.1.11
func NewErrorResponse(id interface{}, code ErrorCode, message string, data interface{}) *JSONRPCResponse
NewErrorResponse creates a new JSON-RPC error response object.
func NewSuccessResponse ¶ added in v0.1.11
func NewSuccessResponse(id interface{}, result interface{}) *JSONRPCResponse
NewSuccessResponse creates a new JSON-RPC success response object.
type ListPromptsRequestParams ¶
type ListPromptsRequestParams struct {
Filter map[string]interface{} `json:"filter,omitempty"`
Cursor string `json:"cursor,omitempty"`
}
ListPromptsRequestParams defines parameters for 'prompts/list'.
type ListPromptsResult ¶
type ListPromptsResult struct {
Prompts []Prompt `json:"prompts"`
NextCursor string `json:"nextCursor,omitempty"`
}
ListPromptsResult defines the result for 'prompts/list'.
type ListResourceTemplatesRequestParams ¶ added in v0.1.11
type ListResourceTemplatesRequestParams struct{}
ListResourceTemplatesRequestParams defines parameters for 'resources/list_templates'. (Empty)
type ListResourceTemplatesResult ¶ added in v0.1.11
type ListResourceTemplatesResult struct {
ResourceTemplates []ResourceTemplate `json:"resourceTemplates"`
}
ListResourceTemplatesResult defines the result for 'resources/templates/list'.
type ListResourcesRequestParams ¶
type ListResourcesRequestParams struct {
Filter map[string]interface{} `json:"filter,omitempty"`
Cursor string `json:"cursor,omitempty"`
}
ListResourcesRequestParams defines parameters for 'resources/list'.
type ListResourcesResult ¶
type ListResourcesResult struct {
Resources []Resource `json:"resources"`
NextCursor string `json:"nextCursor,omitempty"`
}
ListResourcesResult defines the result for 'resources/list'.
type ListRootsRequestParams ¶
type ListRootsRequestParams struct{}
ListRootsRequestParams defines parameters for 'roots/list'. (Currently empty)
type ListRootsResult ¶
type ListRootsResult struct {
Roots []Root `json:"roots"`
}
ListRootsResult defines the result for 'roots/list'.
type ListToolsRequestParams ¶
type ListToolsRequestParams struct {
Cursor string `json:"cursor,omitempty"`
}
ListToolsRequestParams defines the parameters for a 'tools/list' request.
type ListToolsResult ¶
type ListToolsResult struct {
Tools []Tool `json:"tools"`
NextCursor string `json:"nextCursor,omitempty"`
}
ListToolsResult defines the result payload for a successful 'tools/list' response.
type LoggingLevel ¶
type LoggingLevel string
LoggingLevel defines the possible logging levels.
const ( // Syslog levels based on RFC 5424, used in 2025-03-26 spec LogLevelEmergency LoggingLevel = "emergency" LogLevelAlert LoggingLevel = "alert" LogLevelCritical LoggingLevel = "critical" LogLevelError LoggingLevel = "error" LogLevelWarn LoggingLevel = "warning" // Renamed from 'warn' LogLevelNotice LoggingLevel = "notice" LogLevelInfo LoggingLevel = "info" LogLevelDebug LoggingLevel = "debug" )
type LoggingMessageParams ¶
type LoggingMessageParams struct {
Level LoggingLevel `json:"level"`
Message string `json:"message,omitempty"` // Kept for 2024-11-05 compatibility
Logger *string `json:"logger,omitempty"` // Added for 2025-03-26
Data interface{} `json:"data,omitempty"` // Added for 2025-03-26 (JSON object)
}
LoggingMessageParams defines parameters for 'notifications/message'. This struct now includes fields for both 2024-11-05 (Level, Message) and 2025-03-26 (Level, Logger, Data). Consuming code must check negotiatedVersion to determine which fields are expected/valid.
type MCPError ¶
type MCPError struct {
ErrorPayload
}
MCPError wraps ErrorPayload to implement the error interface. Handlers can return this type to provide specific JSON-RPC error details.
func NewInvalidParamsError ¶ added in v0.1.11
Helper function to create a new MCPError for Invalid Params
func NewMethodNotFoundError ¶ added in v0.1.11
Helper function to create a new MCPError for Method Not Found
type ModelHint ¶
type ModelHint struct {
ModelURI string `json:"modelUri"`
InputTokens *int `json:"inputTokens,omitempty"`
OutputTokens *int `json:"outputTokens,omitempty"`
FinishReason *string `json:"finishReason,omitempty"`
}
ModelHint represents the 2024-11-05 structure.
type ModelHintV20250326 ¶ added in v0.1.11
type ModelHintV20250326 struct {
Name string `json:"name"`
}
ModelHintV20250326 represents a model hint for 2025-03-26.
type ModelPreferences ¶
type ModelPreferences struct {
ModelURI string `json:"modelUri,omitempty"`
Temperature *float64 `json:"temperature,omitempty"`
TopP *float64 `json:"topP,omitempty"`
TopK *int `json:"topK,omitempty"`
}
ModelPreferences represents the 2024-11-05 structure.
type ModelPreferencesV20250326 ¶ added in v0.1.11
type ModelPreferencesV20250326 struct {
Hints []ModelHintV20250326 `json:"hints,omitempty"`
CostPriority *float64 `json:"costPriority,omitempty"` // 0-1
SpeedPriority *float64 `json:"speedPriority,omitempty"` // 0-1
IntelligencePriority *float64 `json:"intelligencePriority,omitempty"` // 0-1
}
ModelPreferencesV20250326 represents the 2025-03-26 structure.
type ProgressParams ¶
type ProgressParams struct {
Token string `json:"token"`
Value interface{} `json:"value"`
Message *string `json:"message,omitempty"` // Ensure omitempty is present (relevant for 2025-03-26)
}
ProgressParams defines the parameters for the '$/progress' notification.
type Prompt ¶
type Prompt struct {
URI string `json:"uri"`
Name string `json:"name"` // Human-readable name
Description string `json:"description,omitempty"` // Longer description
Arguments []PromptArgument `json:"arguments,omitempty"`
Messages []PromptMessage `json:"messages"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Prompt represents a prompt template available from the server.
type PromptArgument ¶
type PromptArgument struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Type string `json:"type"` // e.g., "string", "number", "boolean"
Required bool `json:"required,omitempty"`
}
PromptArgument defines an input parameter for a prompt template.
type PromptMessage ¶
type PromptMessage struct {
Role string `json:"role"` // Must be "user" or "assistant" per schema
Content Content `json:"content"` // Must be a single Content object per schema
}
PromptMessage represents a single message within a prompt sequence.
func (PromptMessage) MarshalJSON ¶ added in v0.1.11
func (pm PromptMessage) MarshalJSON() ([]byte, error)
MarshalJSON implements custom marshalling for PromptMessage to ensure proper format.
func (*PromptMessage) UnmarshalJSON ¶
func (pm *PromptMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshalling for PromptMessage.
type PromptReference ¶
type PromptReference struct {
URI string `json:"uri"`
Arguments map[string]interface{} `json:"arguments,omitempty"`
}
PromptReference allows referencing a prompt, potentially with arguments.
type PromptsListChangedParams ¶
type PromptsListChangedParams struct{}
PromptsListChangedParams defines parameters for 'notifications/prompts/list_changed'.
type PropertyDetail ¶
type PropertyDetail struct {
Type string `json:"type"`
Description string `json:"description,omitempty"`
Enum []interface{} `json:"enum,omitempty"` // Possible values for the property
Format string `json:"format,omitempty"` // Specific format (e.g., "date-time", "email")
}
PropertyDetail describes a single parameter within a ToolInputSchema.
type ReadResourceRequestParams ¶
type ReadResourceRequestParams struct {
URI string `json:"uri"`
Version string `json:"version,omitempty"`
}
ReadResourceRequestParams defines parameters for 'resources/read'.
type ReadResourceResult ¶
type ReadResourceResult struct {
Resource Resource `json:"resource"`
Contents []ResourceContents `json:"contents"` // Actual content (Text, Blob, or Audio) - Array for 2024-11-05 and 2025-03-26
}
ReadResourceResult defines the result for 'resources/read'.
func (*ReadResourceResult) UnmarshalJSON ¶ added in v0.1.11
func (r *ReadResourceResult) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshalling for ReadResourceResult to handle the Contents interface slice.
type ReferenceType ¶ added in v0.1.11
type ReferenceType string
ReferenceType defines the type of reference being completed.
const ( // RefTypePrompt indicates a reference to a prompt. RefTypePrompt ReferenceType = "ref/prompt" // RefTypeResource indicates a reference to a resource. RefTypeResource ReferenceType = "ref/resource" )
type RequestMeta ¶
type RequestMeta struct {
// Use interface{} to accept string or number, per spec.
ProgressToken interface{} `json:"progressToken,omitempty"`
}
RequestMeta contains metadata associated with a request, like a progress token.
type Resource ¶
type Resource struct {
URI string `json:"uri"` // Unique identifier (e.g., "file:///path/to/file", "git://...?rev=...")
Kind string `json:"kind,omitempty"` // e.g., "file", "git_commit", "api_spec"
Name string `json:"name"` // Human-readable name (required by MCP spec)
Description string `json:"description,omitempty"` // Longer description
Version string `json:"version,omitempty"` // Opaque version string (changes when content changes)
Metadata map[string]interface{} `json:"metadata,omitempty"` // Additional arbitrary metadata
Size *int `json:"size,omitempty"` // Optional size in bytes (added in 2025-03-26)
Annotations Annotations `json:"annotations,omitempty"` // Added in 2025-03-26
}
Resource represents a piece of context available from the server.
type ResourceContents ¶
type ResourceContents interface {
GetContentType() string
}
ResourceContents defines the interface for different types of resource content.
type ResourceKind ¶ added in v0.1.11
type ResourceKind string
ResourceKind defines the type for resource kinds.
type ResourceTemplate ¶ added in v0.1.11
type ResourceTemplate struct {
Kind string `json:"kind"` // Kind of resource the template creates
Name string `json:"name"` // Human-readable name (required by MCP spec)
Description string `json:"description,omitempty"` // Longer description
Metadata map[string]interface{} `json:"metadata,omitempty"` // Default metadata or parameters needed
URITemplate string `json:"uriTemplate"` // URI template for constructing resource URLs
}
ResourceTemplate describes a template for creating resources (Placeholder structure)
type ResourceUpdatedParams ¶
type ResourceUpdatedParams struct {
Resource Resource `json:"resource"`
}
ResourceUpdatedParams defines parameters for 'notifications/resources/updated'.
type ResourcesListChangedParams ¶
type ResourcesListChangedParams struct{}
ResourcesListChangedParams defines parameters for 'notifications/resources/list_changed'.
type Root ¶
type Root struct {
URI string `json:"uri"`
Kind string `json:"kind,omitempty"`
Name string `json:"name"` // Human-readable name
Description string `json:"description,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
Root represents a root context or workspace available on the client.
type RootsListChangedParams ¶
type RootsListChangedParams struct{}
RootsListChangedParams defines parameters for 'notifications/roots/list_changed'.
type SamplingCapability ¶ added in v0.1.11
type SamplingCapability struct {
Enabled bool `json:"enabled,omitempty"` // Indicates if the client supports handling sampling/request
}
SamplingCapability defines capabilities related to sampling.
type SamplingMessage ¶
type SamplingMessage struct {
Role string `json:"role"`
Content []Content `json:"content"`
Name *string `json:"name,omitempty"`
}
SamplingMessage represents a message in the context provided for sampling.
func (*SamplingMessage) UnmarshalJSON ¶
func (sm *SamplingMessage) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshalling for SamplingMessage to handle the Content interface slice.
type SamplingRequestParams ¶ added in v0.1.11
type SamplingRequestParams struct {
Messages []SamplingMessage `json:"messages"`
ModelPreferences *ModelPreferencesV20250326 `json:"modelPreferences,omitempty"`
SystemPrompt *string `json:"systemPrompt,omitempty"`
MaxTokens *int `json:"maxTokens,omitempty"`
Meta *RequestMeta `json:"_meta,omitempty"` // Allow progress reporting
}
SamplingRequestParams defines the parameters for a 'sampling/request'. Note: This structure aligns with the 2025-03-26 spec's 'sampling/create_message' request. If supporting 2024-11-05 sampling is needed, separate handling might be required.
type SamplingResult ¶ added in v0.1.11
type SamplingResult struct {
Role string `json:"role"`
Content []Content `json:"content"`
Model *string `json:"model,omitempty"`
StopReason *string `json:"stopReason,omitempty"`
Meta *RequestMeta `json:"_meta,omitempty"` // Allow progress reporting
}
SamplingResult defines the result payload for a successful 'sampling/request' response. Note: This structure aligns with the 2025-03-26 spec's 'sampling/create_message' result.
func (*SamplingResult) UnmarshalJSON ¶ added in v0.1.11
func (sr *SamplingResult) UnmarshalJSON(data []byte) error
UnmarshalJSON implements custom unmarshalling for SamplingResult to handle the Content interface slice.
type ServerCapabilities ¶
type ServerCapabilities struct {
Experimental map[string]interface{} `json:"experimental,omitempty"`
Logging *struct{} `json:"logging,omitempty"`
Prompts *struct {
ListChanged bool `json:"listChanged,omitempty"`
} `json:"prompts,omitempty"`
Resources *struct {
Subscribe bool `json:"subscribe,omitempty"`
ListChanged bool `json:"listChanged,omitempty"`
} `json:"resources,omitempty"`
Tools *struct {
ListChanged bool `json:"listChanged,omitempty"`
} `json:"tools,omitempty"`
Authorization *struct {
} `json:"authorization,omitempty"`
Completions *struct {
} `json:"completions,omitempty"`
}
ServerCapabilities describes features the server supports.
type SetLevelRequestParams ¶
type SetLevelRequestParams struct {
Level LoggingLevel `json:"level"`
}
SetLevelRequestParams defines parameters for 'logging/set_level'.
type SubscribeResourceParams ¶
type SubscribeResourceParams struct {
URIs []string `json:"uris"`
}
SubscribeResourceParams defines parameters for 'resources/subscribe'.
type SubscribeResourceResult ¶
type SubscribeResourceResult struct{}
SubscribeResourceResult defines the result for 'resources/subscribe'. (Currently empty)
type TextContent ¶
type TextContent struct {
Type string `json:"type"` // Should always be "text"
Text string `json:"text"`
Annotations *ContentAnnotations `json:"annotations,omitempty"`
}
TextContent represents textual content.
func (TextContent) GetType ¶
func (tc TextContent) GetType() string
type TextResourceContents ¶
type TextResourceContents struct {
ContentType string `json:"mimeType"` // e.g., "text/plain", "application/json"
Text string `json:"text"` // Changed from Content to Text with json tag "text"
URI string `json:"uri"` // Required by schema
}
TextResourceContents holds text-based resource content.
func (TextResourceContents) GetContentType ¶
func (trc TextResourceContents) GetContentType() string
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema ToolInputSchema `json:"inputSchema"`
Annotations ToolAnnotations `json:"annotations,omitempty"`
}
Tool defines a tool offered by the server.
type ToolAnnotations ¶
type ToolAnnotations struct {
Title string `json:"title,omitempty"` // Optional human-readable title for the tool.
ReadOnlyHint *bool `json:"readOnlyHint,omitempty"` // Use pointer for optional boolean
DestructiveHint *bool `json:"destructiveHint,omitempty"` // Use pointer for optional boolean
IdempotentHint *bool `json:"idempotentHint,omitempty"` // Use pointer for optional boolean
OpenWorldHint *bool `json:"openWorldHint,omitempty"` // Use pointer for optional boolean
}
ToolAnnotations provides optional hints about tool behavior.
type ToolCall ¶ added in v0.1.11
type ToolCall struct {
ID string `json:"id"`
ToolName string `json:"tool_name"`
Input json.RawMessage `json:"input,omitempty"`
}
ToolCall defines the structure for a tool call request (mirrors types.ToolCall).
type ToolError ¶ added in v0.1.11
type ToolError struct {
Code ErrorCode `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
ToolError defines the structure for reporting errors during tool execution (Schema 2025-03-26).
type ToolInputSchema ¶
type ToolInputSchema struct {
Type string `json:"type"` // Typically "object"
Properties map[string]PropertyDetail `json:"properties,omitempty"`
Required []string `json:"required,omitempty"`
}
ToolInputSchema defines the expected input structure for a tool (JSON Schema subset).
type ToolsListChangedParams ¶
type ToolsListChangedParams struct{}
ToolsListChangedParams defines parameters for 'notifications/tools/list_changed'.
type UnsubscribeResourceParams ¶
type UnsubscribeResourceParams struct {
URIs []string `json:"uris"`
}
UnsubscribeResourceParams defines parameters for 'resources/unsubscribe'.
type UnsubscribeResourceResult ¶
type UnsubscribeResourceResult struct{}
UnsubscribeResourceResult defines the result for 'resources/unsubscribe'. (Currently empty)
type WorkspaceFolder ¶
WorkspaceFolder represents a workspace folder as defined by LSP.