Documentation
¶
Overview ¶
internal/protocol/change_notifications.go
internal/protocol/errors.go
internal/protocol/mcp_transport.go
internal/protocol/progress.go
internal/protocol/protocol.go
internal/protocol/resources.go
internal/protocol/roots.go
internal/protocol/sampling.go
internal/protocol/standard_methods.go
internal/protocol/subscriptions.go
internal/protocol/uri_templates.go
internal/protocol/websocket.go
Index ¶
- Constants
- func CreatePingResponse() map[string]interface{}
- func IsProgressSupported(method string) bool
- func IsStandardMethod(method string) bool
- func ValidateCapabilities(serverCapabilities CapabilitiesOpts, requiredCapabilities []string) error
- func ValidateInitializeRequest(params InitializeParams) error
- func ValidateMessage(msg MCPMessage) error
- func ValidateProgressParams(params ProgressParams) error
- type BatchInfo
- type CacheConfig
- type CachedResource
- type CapabilitiesOpts
- type Capability
- type ChangeNotification
- type ChangeNotificationManager
- func (cnm *ChangeNotificationManager) CleanupInactiveSubscribers(maxAge time.Duration)
- func (cnm *ChangeNotificationManager) ForceNotifyPromptChanges() error
- func (cnm *ChangeNotificationManager) ForceNotifyToolChanges() error
- func (cnm *ChangeNotificationManager) GetPromptSubscribers() map[string]*ChangeSubscriber
- func (cnm *ChangeNotificationManager) GetToolSubscribers() map[string]*ChangeSubscriber
- func (cnm *ChangeNotificationManager) SubscribeToPromptChanges(clientID, sessionID string, notifyFunc func(*ChangeNotification) error)
- func (cnm *ChangeNotificationManager) SubscribeToToolChanges(clientID, sessionID string, notifyFunc func(*ChangeNotification) error)
- func (cnm *ChangeNotificationManager) UnsubscribeFromPromptChanges(clientID string)
- func (cnm *ChangeNotificationManager) UnsubscribeFromToolChanges(clientID string)
- func (cnm *ChangeNotificationManager) UpdatePrompts(serverName string, prompts []PromptDefinition) error
- func (cnm *ChangeNotificationManager) UpdateTools(serverName string, tools []ToolDefinition) error
- type ChangeParams
- type ChangeSubscriber
- type ClientInfo
- type ClientSubscriptions
- type DefaultTextTransformer
- func (dt *DefaultTextTransformer) GetSupportedFormats() []string
- func (dt *DefaultTextTransformer) GetTransformationOptions(fromFormat, toFormat string) map[string]interface{}
- func (dt *DefaultTextTransformer) Transform(resource *Resource, targetFormat string, options map[string]interface{}) (*ResourceContentData, error)
- type EmbeddedPromptResource
- type EmbeddedResource
- type HTTPTransport
- func (h *HTTPTransport) Close() error
- func (h *HTTPTransport) GetLastActivity() time.Time
- func (h *HTTPTransport) GetType() string
- func (h *HTTPTransport) IsConnected() bool
- func (h *HTTPTransport) Receive() (MCPMessage, error)
- func (h *HTTPTransport) Send(msg MCPMessage) error
- func (h *HTTPTransport) SendProgress(notification *ProgressNotification) error
- func (h *HTTPTransport) SupportsProgress() bool
- type HumanControlConfig
- type HumanReviewResult
- type IndexingConfig
- type InitializeParams
- type InitializeResult
- type LoggingOpts
- type MCPError
- func NewAuthenticationError(details string) *MCPError
- func NewAuthorizationError(resource string, action string) *MCPError
- func NewCapabilityError(capability string, details string) *MCPError
- func NewConfigurationError(component string, details string) *MCPError
- func NewExecutionError(tool string, details string) *MCPError
- func NewInternalError(details string) *MCPError
- func NewInvalidParams(details string, params interface{}) *MCPError
- func NewInvalidRequest(details string) *MCPError
- func NewMCPError(code int, message string, data ...map[string]interface{}) *MCPError
- func NewMethodNotFound(method string) *MCPError
- func NewParseError(details string) *MCPError
- func NewProtocolError(expectedVersion string, actualVersion string) *MCPError
- func NewRateLimitError(limit string, window string) *MCPError
- func NewRequestTimeout(operation string, timeout string) *MCPError
- func NewResourceError(resource string, operation string, details string) *MCPError
- func NewSessionError(sessionId string, details string) *MCPError
- func NewStateError(expectedState string, actualState string) *MCPError
- func NewTransportError(transport string, details string) *MCPError
- func NewValidationError(field string, value interface{}, constraint string) *MCPError
- type MCPMessage
- type MCPNotification
- type MCPRequest
- type MCPResponse
- type MCPTransport
- type MessageType
- type ModelHint
- type ModelPreferences
- type ProgressListener
- type ProgressManager
- func (pm *ProgressManager) AddProgressListener(token string, listener ProgressListener)
- func (pm *ProgressManager) CompleteProgress(token string, message string) error
- func (pm *ProgressManager) FailProgress(token string, err error) error
- func (pm *ProgressManager) GenerateProgressToken(requestID interface{}) string
- func (pm *ProgressManager) IsValidToken(token string) bool
- func (pm *ProgressManager) UpdateDetailedProgress(token string, current, total int64, message string, details interface{}) error
- func (pm *ProgressManager) UpdateProgress(token string, progress float64, message string, details interface{}) error
- type ProgressNotification
- type ProgressParams
- type ProgressToken
- type PromptArgument
- type PromptContentItem
- type PromptDefinition
- type PromptMessage
- type PromptsOpts
- type Resource
- type ResourceContent
- type ResourceContentData
- type ResourceEmbedding
- type ResourceFilter
- type ResourceManager
- func (rm *ResourceManager) AddResource(resource *Resource) error
- func (rm *ResourceManager) CleanupCache()
- func (rm *ResourceManager) EmbedResourceInPrompt(uri string, strategy string, options map[string]interface{}) (*EmbeddedPromptResource, error)
- func (rm *ResourceManager) GetCacheStats() map[string]interface{}
- func (rm *ResourceManager) GetResource(uri string) (*Resource, error)
- func (rm *ResourceManager) RegisterTransformer(name string, transformer ResourceTransformer)
- func (rm *ResourceManager) Search(query string, filters map[string]interface{}) []*Resource
- func (rm *ResourceManager) TransformResource(uri string, targetFormat string, options map[string]interface{}) (*ResourceContentData, error)
- type ResourceMetadata
- type ResourcePermissions
- type ResourceSubscription
- type ResourceTemplate
- type ResourceTransformer
- type ResourceUpdate
- type ResourceUpdateNotification
- type ResourceUpdateParams
- type ResourcesOpts
- type Root
- type RootEntry
- type RootManager
- func (rm *RootManager) AddRoot(root Root, permissions *RootPermissions) error
- func (rm *RootManager) CheckRootAccess(path string, operation string) (*RootEntry, error)
- func (rm *RootManager) CreateDefaultRoots() error
- func (rm *RootManager) GetRoot(uri string) (*RootEntry, error)
- func (rm *RootManager) GetRootStats() map[string]interface{}
- func (rm *RootManager) ListRoots() []Root
- func (rm *RootManager) NotifyRootChange(uri string, event string)
- func (rm *RootManager) RemoveRoot(uri string) error
- func (rm *RootManager) UnwatchRoot(uri string) error
- func (rm *RootManager) WatchRoot(uri string, callback func(uri string, event string)) error
- type RootPermissions
- type RootWatcher
- type RootsListRequest
- type RootsListResponse
- type RootsOpts
- type SSETransport
- func (s *SSETransport) Close() error
- func (s *SSETransport) GetLastActivity() time.Time
- func (s *SSETransport) GetType() string
- func (s *SSETransport) Initialize() error
- func (s *SSETransport) IsConnected() bool
- func (s *SSETransport) Receive() (MCPMessage, error)
- func (s *SSETransport) Send(msg MCPMessage) error
- func (s *SSETransport) SendProgress(notification *ProgressNotification) error
- func (s *SSETransport) SupportsProgress() bool
- type SamplingCapabilities
- type SamplingContent
- type SamplingContext
- type SamplingHandler
- type SamplingManager
- func (sm *SamplingManager) ApproveRequest(requestID, reviewer, comments string) error
- func (sm *SamplingManager) CleanupOldRequests(maxAge time.Duration)
- func (sm *SamplingManager) CreateSamplingRequest(serverName string, messages []SamplingMessage, prefs ModelPreferences, ...) (*SamplingRequest, error)
- func (sm *SamplingManager) GetPendingRequests() []*SamplingRequest
- func (sm *SamplingManager) GetRequestStatus(requestID string) (string, error)
- func (sm *SamplingManager) ProcessSamplingRequest(requestID string) (*SamplingResponse, error)
- func (sm *SamplingManager) RegisterHandler(name string, handler SamplingHandler)
- func (sm *SamplingManager) RejectRequest(requestID, reviewer, reason string) error
- func (sm *SamplingManager) SetHumanControls(serverName string, config *HumanControlConfig)
- type SamplingMessage
- type SamplingOpts
- type SamplingRequest
- type SamplingResponse
- type SamplingUsage
- type ServerInfo
- type StandardMethodHandler
- func (h *StandardMethodHandler) GetCapabilities() CapabilitiesOpts
- func (h *StandardMethodHandler) GetRootManager() *RootManager
- func (h *StandardMethodHandler) GetServerInfo() ServerInfo
- func (h *StandardMethodHandler) HandleStandardMethod(method string, params json.RawMessage, requestID interface{}) (*MCPResponse, error)
- func (h *StandardMethodHandler) HandleStandardNotification(method string, params json.RawMessage) error
- func (h *StandardMethodHandler) IsInitialized() bool
- func (h *StandardMethodHandler) SetCapability(capability string, enabled bool, options interface{}) error
- type StdioTransport
- func (t *StdioTransport) Close() error
- func (t *StdioTransport) GetProgressManager() *ProgressManager
- func (t *StdioTransport) Receive() (MCPMessage, error)
- func (t *StdioTransport) Send(msg MCPMessage) error
- func (t *StdioTransport) SendProgress(notification *ProgressNotification) error
- func (t *StdioTransport) SupportsProgress() bool
- type SubscribeRequest
- type SubscribeResponse
- type SubscriptionManager
- func (sm *SubscriptionManager) CleanupExpiredSubscriptions(maxAge time.Duration)
- func (sm *SubscriptionManager) GetSubscriptions(clientID string) []*ResourceSubscription
- func (sm *SubscriptionManager) NotifyResourceUpdate(uri string, updateType string, content *ResourceContent, ...) error
- func (sm *SubscriptionManager) Subscribe(clientID, sessionID string, req SubscribeRequest, ...) (*SubscribeResponse, error)
- func (sm *SubscriptionManager) Unsubscribe(clientID string, req UnsubscribeRequest) error
- type SubscriptionOptions
- type TemplateExample
- type TemplateExpression
- type TemplateVariable
- type ToolDefinition
- type ToolsOpts
- type Transport
- type URITemplate
- type UnsubscribeRequest
- type VariableSpec
- type WebSocketConnection
- type WebSocketHandler
- type WebSocketServer
- func (ws *WebSocketServer) Close() error
- func (ws *WebSocketServer) GetConnections() map[string]*WebSocketTransport
- func (ws *WebSocketServer) GetHandler(name string) (WebSocketHandler, bool)
- func (ws *WebSocketServer) RegisterHandler(name string, handler WebSocketHandler)
- func (ws *WebSocketServer) UpgradeHTTP(w http.ResponseWriter, r *http.Request, handler WebSocketHandler) (*WebSocketTransport, error)
- type WebSocketTransport
- func (wst *WebSocketTransport) Close() error
- func (wst *WebSocketTransport) GetLastActivity() time.Time
- func (wst *WebSocketTransport) GetType() string
- func (wst *WebSocketTransport) IsConnected() bool
- func (wst *WebSocketTransport) Receive() (MCPMessage, error)
- func (wst *WebSocketTransport) Send(msg MCPMessage) error
- func (wst *WebSocketTransport) SendProgress(notification *ProgressNotification) error
- func (wst *WebSocketTransport) Start() error
- func (wst *WebSocketTransport) SupportsProgress() bool
Constants ¶
const ( ParseError = -32700 InvalidRequest = -32600 MethodNotFound = -32601 InvalidParams = -32602 InternalError = -32603 )
Standard JSON-RPC 2.0 error codes
const ( // Implementation-specific errors RequestFailed = -32000 RequestCancelled = -32001 RequestTimeout = -32002 // Extended MCP errors (using safe range > -32000) TransportError = -31999 SessionError = -31998 CapabilityError = -31997 ProtocolError = -31996 AuthenticationError = -31995 AuthorizationError = -31994 RateLimitError = -31993 ResourceError = -31992 ValidationError = -31991 ExecutionError = -31990 StateError = -31989 ConfigurationError = -31988 )
MCP-specific errors (following JSON-RPC reserved range)
const ( MethodInitialize = "initialize" MethodInitialized = "notifications/initialized" MethodPing = "ping" MethodResourcesList = "resources/list" MethodResourcesRead = "resources/read" MethodResourcesSubscribe = "resources/subscribe" MethodResourcesUnsubscribe = "resources/unsubscribe" MethodToolsList = "tools/list" MethodToolsCall = "tools/call" MethodPromptsList = "prompts/list" MethodPromptsGet = "prompts/get" MethodSamplingCreate = "sampling/createMessage" MethodLoggingSetLevel = "logging/setLevel" MethodRootsList = "roots/list" MethodCompletionComplete = "completion/complete" // Notifications NotificationCancelled = "notifications/cancelled" NotificationProgress = "notifications/progress" NotificationResourcesUpdated = "notifications/resources/updated" NotificationResourcesListChanged = "notifications/resources/list_changed" NotificationToolsListChanged = "notifications/tools/list_changed" NotificationPromptsListChanged = "notifications/prompts/list_changed" NotificationRootsListChanged = "notifications/roots/list_changed" )
Standard MCP methods
const MCPVersion = "2024-11-05"
MCPVersion represents the current Model Context Protocol version
Variables ¶
This section is empty.
Functions ¶
func CreatePingResponse ¶
func CreatePingResponse() map[string]interface{}
CreatePingResponse creates a proper ping response
func IsProgressSupported ¶
IsProgressSupported checks if a method supports progress reporting
func IsStandardMethod ¶
IsStandardMethod checks if a method is part of the MCP specification
func ValidateCapabilities ¶
func ValidateCapabilities(serverCapabilities CapabilitiesOpts, requiredCapabilities []string) error
ValidateCapabilities checks if the server capabilities match the given capabilities
func ValidateInitializeRequest ¶
func ValidateInitializeRequest(params InitializeParams) error
ValidateInitializeRequest validates an initialize request
func ValidateMessage ¶
func ValidateMessage(msg MCPMessage) error
ValidateMessage performs comprehensive MCP message validation
func ValidateProgressParams ¶
func ValidateProgressParams(params ProgressParams) error
ValidateProgressParams validates progress parameters
Types ¶
type BatchInfo ¶
type BatchInfo struct {
Total int `json:"total"`
Current int `json:"current"`
BatchID string `json:"batchId"`
LastBatch bool `json:"lastBatch"`
}
BatchInfo provides information about batched notifications
type CacheConfig ¶
type CacheConfig struct {
Enabled bool `json:"enabled"`
TTL time.Duration `json:"ttl,omitempty"`
Refreshable bool `json:"refreshable"`
Tags []string `json:"tags,omitempty"`
Key string `json:"key,omitempty"`
}
CacheConfig controls caching behavior for a resource
type CachedResource ¶
type CachedResource struct {
Resource *Resource `json:"resource"`
CachedAt time.Time `json:"cachedAt"`
ExpiresAt time.Time `json:"expiresAt"`
AccessCount int64 `json:"accessCount"`
LastAccess time.Time `json:"lastAccess"`
Tags []string `json:"tags"`
}
CachedResource represents a cached resource
type CapabilitiesOpts ¶
type CapabilitiesOpts struct {
Resources *ResourcesOpts `json:"resources,omitempty"`
Tools *ToolsOpts `json:"tools,omitempty"`
Prompts *PromptsOpts `json:"prompts,omitempty"`
Sampling *SamplingOpts `json:"sampling,omitempty"`
Logging *LoggingOpts `json:"logging,omitempty"`
Roots *RootsOpts `json:"roots,omitempty"`
}
CapabilitiesOpts represents MCP capability options with full specification compliance
func CapabilityOptsFromConfig ¶
func CapabilityOptsFromConfig(capOpt interface{}) CapabilitiesOpts
CapabilityOptsFromConfig converts capability configuration to MCP capability options
type Capability ¶
type Capability string
Capability represents an MCP capability
const ( // ResourcesCapability provides file system access ResourcesCapability Capability = "resources" // ToolsCapability provides function calling ToolsCapability Capability = "tools" // PromptsCapability provides prompt templates PromptsCapability Capability = "prompts" // SamplingCapability provides text generation SamplingCapability Capability = "sampling" // LoggingCapability provides logging LoggingCapability Capability = "logging" // RootsCapability provides root management RootsCapability Capability = "roots" )
type ChangeNotification ¶
type ChangeNotification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"` // "notifications/tools/list_changed" or "notifications/prompts/list_changed"
Params ChangeParams `json:"params"`
}
ChangeNotification represents a list changed notification
type ChangeNotificationManager ¶
type ChangeNotificationManager struct {
// contains filtered or unexported fields
}
ChangeNotificationManager manages tool and prompt change notifications
func NewChangeNotificationManager ¶
func NewChangeNotificationManager() *ChangeNotificationManager
NewChangeNotificationManager creates a new change notification manager
func (*ChangeNotificationManager) CleanupInactiveSubscribers ¶
func (cnm *ChangeNotificationManager) CleanupInactiveSubscribers(maxAge time.Duration)
CleanupInactiveSubscribers removes subscribers that haven't been seen recently
func (*ChangeNotificationManager) ForceNotifyPromptChanges ¶
func (cnm *ChangeNotificationManager) ForceNotifyPromptChanges() error
ForceNotifyPromptChanges forces a prompts/list_changed notification to all subscribers
func (*ChangeNotificationManager) ForceNotifyToolChanges ¶
func (cnm *ChangeNotificationManager) ForceNotifyToolChanges() error
ForceNotifyToolChanges forces a tools/list_changed notification to all subscribers
func (*ChangeNotificationManager) GetPromptSubscribers ¶
func (cnm *ChangeNotificationManager) GetPromptSubscribers() map[string]*ChangeSubscriber
GetPromptSubscribers returns the list of prompt change subscribers
func (*ChangeNotificationManager) GetToolSubscribers ¶
func (cnm *ChangeNotificationManager) GetToolSubscribers() map[string]*ChangeSubscriber
GetToolSubscribers returns the list of tool change subscribers
func (*ChangeNotificationManager) SubscribeToPromptChanges ¶
func (cnm *ChangeNotificationManager) SubscribeToPromptChanges(clientID, sessionID string, notifyFunc func(*ChangeNotification) error)
SubscribeToPromptChanges subscribes a client to prompt change notifications
func (*ChangeNotificationManager) SubscribeToToolChanges ¶
func (cnm *ChangeNotificationManager) SubscribeToToolChanges(clientID, sessionID string, notifyFunc func(*ChangeNotification) error)
SubscribeToToolChanges subscribes a client to tool change notifications
func (*ChangeNotificationManager) UnsubscribeFromPromptChanges ¶
func (cnm *ChangeNotificationManager) UnsubscribeFromPromptChanges(clientID string)
UnsubscribeFromPromptChanges unsubscribes a client from prompt change notifications
func (*ChangeNotificationManager) UnsubscribeFromToolChanges ¶
func (cnm *ChangeNotificationManager) UnsubscribeFromToolChanges(clientID string)
UnsubscribeFromToolChanges unsubscribes a client from tool change notifications
func (*ChangeNotificationManager) UpdatePrompts ¶
func (cnm *ChangeNotificationManager) UpdatePrompts(serverName string, prompts []PromptDefinition) error
UpdatePrompts checks for prompt changes and notifies subscribers
func (*ChangeNotificationManager) UpdateTools ¶
func (cnm *ChangeNotificationManager) UpdateTools(serverName string, tools []ToolDefinition) error
UpdateTools checks for tool changes and notifies subscribers
type ChangeParams ¶
type ChangeParams struct {
}
ChangeParams contains change notification parameters
type ChangeSubscriber ¶
type ChangeSubscriber struct {
ClientID string
SessionID string
NotifyFunc func(*ChangeNotification) error
Subscribed time.Time
LastNotify time.Time
}
ChangeSubscriber represents a client subscribed to change notifications
type ClientInfo ¶
ClientInfo represents information about the client
type ClientSubscriptions ¶
type ClientSubscriptions struct {
ClientID string
SessionID string
Subscriptions map[string]*ResourceSubscription
NotifyFunc func(*ResourceUpdateNotification) error
LastSeen time.Time
}
ClientSubscriptions tracks all subscriptions for a client
type DefaultTextTransformer ¶
type DefaultTextTransformer struct{}
DefaultTextTransformer provides basic text transformations
func (*DefaultTextTransformer) GetSupportedFormats ¶
func (dt *DefaultTextTransformer) GetSupportedFormats() []string
func (*DefaultTextTransformer) GetTransformationOptions ¶
func (dt *DefaultTextTransformer) GetTransformationOptions(fromFormat, toFormat string) map[string]interface{}
func (*DefaultTextTransformer) Transform ¶
func (dt *DefaultTextTransformer) Transform(resource *Resource, targetFormat string, options map[string]interface{}) (*ResourceContentData, error)
type EmbeddedPromptResource ¶
type EmbeddedPromptResource struct {
Type string `json:"type"` // "resource"
Resource *Resource `json:"resource"`
Inline bool `json:"inline"`
Transform string `json:"transform,omitempty"`
Context map[string]interface{} `json:"context,omitempty"`
}
EmbeddedPromptResource represents a resource embedded in a prompt
type EmbeddedResource ¶
type EmbeddedResource struct {
URI string `json:"uri"`
Name string `json:"name,omitempty"`
Description string `json:"description,omitempty"`
Content string `json:"content,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
EmbeddedResource represents a resource embedded in sampling content
type HTTPTransport ¶
type HTTPTransport struct {
// contains filtered or unexported fields
}
HTTPTransport implements MCP HTTP transport according to specification
func NewHTTPTransport ¶
func NewHTTPTransport(baseURL string) *HTTPTransport
NewHTTPTransport creates a new MCP-compliant HTTP transport
func (*HTTPTransport) Close ¶
func (h *HTTPTransport) Close() error
func (*HTTPTransport) GetLastActivity ¶
func (h *HTTPTransport) GetLastActivity() time.Time
func (*HTTPTransport) GetType ¶
func (h *HTTPTransport) GetType() string
func (*HTTPTransport) IsConnected ¶
func (h *HTTPTransport) IsConnected() bool
func (*HTTPTransport) Receive ¶
func (h *HTTPTransport) Receive() (MCPMessage, error)
func (*HTTPTransport) Send ¶
func (h *HTTPTransport) Send(msg MCPMessage) error
func (*HTTPTransport) SendProgress ¶
func (h *HTTPTransport) SendProgress(notification *ProgressNotification) error
func (*HTTPTransport) SupportsProgress ¶
func (h *HTTPTransport) SupportsProgress() bool
type HumanControlConfig ¶
type HumanControlConfig struct {
RequireApproval bool `json:"requireApproval"`
AutoApprovePatterns []string `json:"autoApprovePatterns,omitempty"`
BlockPatterns []string `json:"blockPatterns,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
AllowedModels []string `json:"allowedModels,omitempty"`
TimeoutSeconds int `json:"timeoutSeconds,omitempty"`
}
HumanControlConfig configures human-in-the-loop controls
type HumanReviewResult ¶
type HumanReviewResult struct {
Approved bool `json:"approved"`
Reviewer string `json:"reviewer"`
ReviewTime time.Time `json:"reviewTime"`
Comments string `json:"comments,omitempty"`
Modifications map[string]interface{} `json:"modifications,omitempty"`
}
HumanReviewResult represents the result of human review
type IndexingConfig ¶
type IndexingConfig struct {
Enabled bool `json:"enabled"`
FullText bool `json:"fullText"`
Keywords []string `json:"keywords,omitempty"`
Summary string `json:"summary,omitempty"`
Searchable bool `json:"searchable"`
}
IndexingConfig controls how a resource should be indexed
type InitializeParams ¶
type InitializeParams struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities CapabilitiesOpts `json:"capabilities"`
ClientInfo ClientInfo `json:"clientInfo"`
// Add roots support
Roots []Root `json:"roots,omitempty"`
}
InitializeParams represents the parameters for an initialize request
type InitializeResult ¶
type InitializeResult struct {
ProtocolVersion string `json:"protocolVersion"`
ServerInfo ServerInfo `json:"serverInfo"`
Capabilities CapabilitiesOpts `json:"capabilities"`
Instructions string `json:"instructions,omitempty"`
// Server can announce its roots
Roots []Root `json:"roots,omitempty"`
}
InitializeResult represents the result of an initialize request
func CreateInitializeResponse ¶
func CreateInitializeResponse(serverInfo ServerInfo, capabilities CapabilitiesOpts, roots []Root) InitializeResult
CreateInitializeResponse creates a proper initialize response
type MCPError ¶
type MCPError struct {
Code int `json:"code"`
Message string `json:"message"`
Data map[string]interface{} `json:"data,omitempty"`
}
MCPError represents a complete MCP protocol error
func NewAuthenticationError ¶
func NewAuthorizationError ¶
func NewCapabilityError ¶
func NewConfigurationError ¶
func NewExecutionError ¶
func NewInternalError ¶
func NewInvalidParams ¶
func NewInvalidRequest ¶
func NewMCPError ¶
NewMCPError creates a new MCP error with optional data
func NewMethodNotFound ¶
func NewParseError ¶
Standard JSON-RPC error constructors
func NewProtocolError ¶
func NewRateLimitError ¶
func NewRequestTimeout ¶
MCP-specific error constructors using safe error codes
func NewResourceError ¶
func NewSessionError ¶
func NewStateError ¶
func NewTransportError ¶
func NewValidationError ¶
func (*MCPError) GetRetryDelay ¶
GetRetryDelay suggests a delay before retry (in seconds)
func (*MCPError) IsRetryable ¶
IsRetryable returns true if the error is potentially retryable
func (*MCPError) IsTemporary ¶
IsTemporary returns true if the error is likely temporary
type MCPMessage ¶
type MCPMessage struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id,omitempty"`
Method string `json:"method,omitempty"`
Params json.RawMessage `json:"params,omitempty"`
Result json.RawMessage `json:"result,omitempty"`
Error *MCPError `json:"error,omitempty"`
// Progress support
ProgressToken string `json:"progressToken,omitempty"`
}
MCPMessage represents a generic MCP message
type MCPNotification ¶
type MCPNotification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
}
MCPNotification represents an MCP notification
func NewNotification ¶
func NewNotification(method string, params interface{}) (*MCPNotification, error)
NewNotification creates a new MCP notification
type MCPRequest ¶
type MCPRequest struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
// Progress support
ProgressToken string `json:"progressToken,omitempty"`
}
MCPRequest represents an MCP request
func NewRequest ¶
func NewRequest(id interface{}, method string, params interface{}, progressToken ...string) (*MCPRequest, error)
NewRequest creates a new MCP request with optional progress token
type MCPResponse ¶
type MCPResponse struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id"`
Result json.RawMessage `json:"result,omitempty"`
Error *MCPError `json:"error,omitempty"`
// Progress support
ProgressToken string `json:"progressToken,omitempty"`
}
MCPResponse represents an MCP response
func NewResponse ¶
func NewResponse(id interface{}, result interface{}, err *MCPError, progressToken ...string) (*MCPResponse, error)
NewResponse creates a new MCP response with optional progress token
type MCPTransport ¶
type MCPTransport interface {
Transport
// GetType returns the transport type
GetType() string
// IsConnected returns true if transport is connected
IsConnected() bool
// GetLastActivity returns the last activity timestamp
GetLastActivity() time.Time
}
MCPTransport implements MCP-compliant transport layer
type MessageType ¶
type MessageType string
MessageType defines the type of MCP message
const ( // Request is an RPC request Request MessageType = "request" // Response is an RPC response Response MessageType = "response" // Notification is a one-way notification Notification MessageType = "notification" )
type ModelHint ¶
type ModelHint struct {
Name string `json:"name"` // e.g., "claude-3-sonnet", "gpt-4"
}
ModelHint provides hints about desired model characteristics
type ModelPreferences ¶
type ModelPreferences struct {
Hints []ModelHint `json:"hints,omitempty"`
CostPriority string `json:"costPriority,omitempty"` // "low", "medium", "high"
SpeedPriority string `json:"speedPriority,omitempty"` // "low", "medium", "high"
IntelligencePriority string `json:"intelligencePriority,omitempty"` // "low", "medium", "high"
}
ModelPreferences specifies model preferences for sampling
type ProgressListener ¶
type ProgressListener func(token string, progress ProgressParams)
ProgressListener defines the interface for progress listeners
type ProgressManager ¶
type ProgressManager struct {
// contains filtered or unexported fields
}
ProgressManager manages progress tokens and notifications
func NewProgressManager ¶
func NewProgressManager() *ProgressManager
NewProgressManager creates a new progress manager
func (*ProgressManager) AddProgressListener ¶
func (pm *ProgressManager) AddProgressListener(token string, listener ProgressListener)
AddProgressListener adds a listener for progress updates
func (*ProgressManager) CompleteProgress ¶
func (pm *ProgressManager) CompleteProgress(token string, message string) error
CompleteProgress marks progress as complete and cleans up
func (*ProgressManager) FailProgress ¶
func (pm *ProgressManager) FailProgress(token string, err error) error
FailProgress marks progress as failed and cleans up
func (*ProgressManager) GenerateProgressToken ¶
func (pm *ProgressManager) GenerateProgressToken(requestID interface{}) string
GenerateProgressToken creates a new progress token
func (*ProgressManager) IsValidToken ¶
func (pm *ProgressManager) IsValidToken(token string) bool
IsValidToken checks if a progress token is valid
func (*ProgressManager) UpdateDetailedProgress ¶
func (pm *ProgressManager) UpdateDetailedProgress(token string, current, total int64, message string, details interface{}) error
UpdateDetailedProgress sends a progress notification with current/total counts
func (*ProgressManager) UpdateProgress ¶
func (pm *ProgressManager) UpdateProgress(token string, progress float64, message string, details interface{}) error
UpdateProgress sends a progress notification
type ProgressNotification ¶
type ProgressNotification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"` // "notifications/progress"
Params ProgressParams `json:"params"`
}
ProgressNotification represents a progress notification
func CreateProgressNotification ¶
func CreateProgressNotification(params ProgressParams) *ProgressNotification
CreateProgressNotification creates a JSON-RPC progress notification
func ParseProgressNotification ¶
func ParseProgressNotification(data []byte) (*ProgressNotification, error)
ParseProgressNotification parses a JSON-RPC progress notification
type ProgressParams ¶
type ProgressParams struct {
ProgressToken string `json:"progressToken"`
Progress float64 `json:"progress"` // 0.0 to 1.0
Total *int64 `json:"total,omitempty"`
Current *int64 `json:"current,omitempty"`
Message string `json:"message,omitempty"`
Details interface{} `json:"details,omitempty"`
}
ProgressParams contains progress notification parameters
type ProgressToken ¶
type ProgressToken struct {
Token string `json:"token"`
RequestID interface{} `json:"requestId"`
Created time.Time `json:"created"`
}
ProgressToken represents a progress tracking token
type PromptArgument ¶
type PromptArgument struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Required bool `json:"required,omitempty"`
}
PromptArgument represents a prompt argument
type PromptContentItem ¶
type PromptContentItem struct {
Type string `json:"type"` // "text", "image", "resource"
Text string `json:"text,omitempty"`
ImageURL string `json:"imageUrl,omitempty"`
Resource *EmbeddedPromptResource `json:"resource,omitempty"`
}
PromptContentItem represents an item of content in a prompt message
type PromptDefinition ¶
type PromptDefinition struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Arguments []PromptArgument `json:"arguments,omitempty"`
}
PromptDefinition represents a prompt definition for change detection
type PromptMessage ¶
type PromptMessage struct {
Role string `json:"role"`
Content []PromptContentItem `json:"content"`
Resources []*EmbeddedPromptResource `json:"resources,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
PromptMessage represents a prompt message with embedded resources
type PromptsOpts ¶
type PromptsOpts struct {
ListChanged bool `json:"listChanged,omitempty"`
}
PromptsOpts represents prompts capability options
type Resource ¶
type Resource struct {
URI string `json:"uri"`
Name string `json:"name"`
Description string `json:"description,omitempty"`
MimeType string `json:"mimeType,omitempty"`
Size int64 `json:"size,omitempty"`
Content *ResourceContentData `json:"content,omitempty"`
Metadata *ResourceMetadata `json:"metadata,omitempty"`
Annotations map[string]interface{} `json:"annotations,omitempty"`
Template *URITemplate `json:"template,omitempty"`
Embedding *ResourceEmbedding `json:"embedding,omitempty"`
Cache *CacheConfig `json:"cache,omitempty"`
Created time.Time `json:"created"`
Modified time.Time `json:"modified"`
Accessed time.Time `json:"accessed"`
}
Resource represents a complete MCP resource with full metadata and capabilities
type ResourceContent ¶
type ResourceContent struct {
Type string `json:"type"` // "text", "blob"
Data string `json:"data,omitempty"` // Base64 for blob, direct for text
MimeType string `json:"mimeType,omitempty"`
Size int64 `json:"size,omitempty"`
Encoding string `json:"encoding,omitempty"` // "utf-8", "base64"
}
ResourceContent represents resource content
type ResourceContentData ¶
type ResourceContentData struct {
Type string `json:"type"` // "text", "blob"
Data string `json:"data"` // Base64 for blob, direct for text
Encoding string `json:"encoding"` // "utf-8", "base64", etc.
Hash string `json:"hash,omitempty"` // Content hash
Compression string `json:"compression,omitempty"` // "gzip", "deflate", etc.
LastModified time.Time `json:"lastModified"`
}
ResourceContentData represents the actual content of a resource
type ResourceEmbedding ¶
type ResourceEmbedding struct {
Strategy string `json:"strategy"` // "inline", "reference", "summary"
MaxSize int64 `json:"maxSize,omitempty"`
Transform string `json:"transform,omitempty"` // "text", "markdown", "json"
Context map[string]interface{} `json:"context,omitempty"`
Fallback string `json:"fallback,omitempty"` // Fallback strategy if embedding fails
}
ResourceEmbedding contains information for embedding resources in prompts
type ResourceFilter ¶
type ResourceFilter struct {
Type string `json:"type"` // "glob", "regex", "exact", "prefix"
Pattern string `json:"pattern"` // Pattern to match
Property string `json:"property"` // Resource property to filter on
Value interface{} `json:"value"` // Expected value
}
ResourceFilter defines filtering criteria for subscriptions
type ResourceManager ¶
type ResourceManager struct {
// contains filtered or unexported fields
}
ResourceManager provides complete MCP resource capabilities
func NewResourceManager ¶
func NewResourceManager() *ResourceManager
NewResourceManager creates a new resource manager
func (*ResourceManager) AddResource ¶
func (rm *ResourceManager) AddResource(resource *Resource) error
AddResource adds a resource to the manager
func (*ResourceManager) CleanupCache ¶
func (rm *ResourceManager) CleanupCache()
CleanupCache removes expired cache entries
func (*ResourceManager) EmbedResourceInPrompt ¶
func (rm *ResourceManager) EmbedResourceInPrompt(uri string, strategy string, options map[string]interface{}) (*EmbeddedPromptResource, error)
EmbedResourceInPrompt embeds a resource in a prompt message
func (*ResourceManager) GetCacheStats ¶
func (rm *ResourceManager) GetCacheStats() map[string]interface{}
GetCacheStats returns cache statistics
func (*ResourceManager) GetResource ¶
func (rm *ResourceManager) GetResource(uri string) (*Resource, error)
GetResource retrieves a resource by URI
func (*ResourceManager) RegisterTransformer ¶
func (rm *ResourceManager) RegisterTransformer(name string, transformer ResourceTransformer)
RegisterTransformer registers a resource transformer
func (*ResourceManager) Search ¶
func (rm *ResourceManager) Search(query string, filters map[string]interface{}) []*Resource
Search searches for resources based on criteria
func (*ResourceManager) TransformResource ¶
func (rm *ResourceManager) TransformResource(uri string, targetFormat string, options map[string]interface{}) (*ResourceContentData, error)
TransformResource transforms a resource to a different format
type ResourceMetadata ¶
type ResourceMetadata struct {
Author string `json:"author,omitempty"`
Version string `json:"version,omitempty"`
Tags []string `json:"tags,omitempty"`
Language string `json:"language,omitempty"`
Encoding string `json:"encoding,omitempty"`
ContentType string `json:"contentType,omitempty"`
Permissions *ResourcePermissions `json:"permissions,omitempty"`
Indexing *IndexingConfig `json:"indexing,omitempty"`
Custom map[string]interface{} `json:"custom,omitempty"`
}
ResourceMetadata contains extended metadata about a resource
type ResourcePermissions ¶
type ResourcePermissions struct {
Read bool `json:"read"`
Write bool `json:"write"`
Execute bool `json:"execute"`
Delete bool `json:"delete"`
Roles []string `json:"roles,omitempty"`
Users []string `json:"users,omitempty"`
}
ResourcePermissions defines access permissions for a resource
type ResourceSubscription ¶
type ResourceSubscription struct {
ID string `json:"id"`
ClientID string `json:"clientId"`
SessionID string `json:"sessionId"`
URI string `json:"uri"`
IsTemplate bool `json:"isTemplate"`
Filters []ResourceFilter `json:"filters,omitempty"`
Options SubscriptionOptions `json:"options"`
Created time.Time `json:"created"`
LastNotified time.Time `json:"lastNotified,omitempty"`
}
ResourceSubscription represents a subscription to resource changes
type ResourceTemplate ¶
type ResourceTemplate struct {
URI string `json:"uri"` // Template URI
Name string `json:"name"` // Resource name template
Description string `json:"description"` // Description template
MimeType string `json:"mimeType,omitempty"`
Annotations map[string]interface{} `json:"annotations,omitempty"`
// Template-specific fields
Variables []TemplateVariable `json:"variables,omitempty"` // Template variables
Examples []TemplateExample `json:"examples,omitempty"` // Usage examples
}
ResourceTemplate represents a resource with URI template support
type ResourceTransformer ¶
type ResourceTransformer interface {
// Transform transforms resource content
Transform(resource *Resource, targetFormat string, options map[string]interface{}) (*ResourceContentData, error)
// GetSupportedFormats returns supported transformation formats
GetSupportedFormats() []string
// GetTransformationOptions returns available options for transformation
GetTransformationOptions(fromFormat, toFormat string) map[string]interface{}
}
ResourceTransformer defines the interface for transforming resources
type ResourceUpdate ¶
type ResourceUpdate struct {
URI string `json:"uri"`
Type string `json:"type"` // "created", "updated", "deleted"
Content *ResourceContent `json:"content,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
Timestamp time.Time `json:"timestamp"`
}
ResourceUpdate represents a single resource update
type ResourceUpdateNotification ¶
type ResourceUpdateNotification struct {
JSONRPC string `json:"jsonrpc"`
Method string `json:"method"` // "notifications/resources/updated"
Params ResourceUpdateParams `json:"params"`
}
ResourceUpdateNotification represents a resource update notification
type ResourceUpdateParams ¶
type ResourceUpdateParams struct {
Resources []ResourceUpdate `json:"resources"`
BatchInfo *BatchInfo `json:"batchInfo,omitempty"`
}
ResourceUpdateParams contains the notification parameters
type ResourcesOpts ¶
type ResourcesOpts struct {
ListChanged bool `json:"listChanged,omitempty"`
Subscribe bool `json:"subscribe,omitempty"`
}
ResourcesOpts represents resources capability options with subscription support
type RootEntry ¶
type RootEntry struct {
Root Root `json:"root"`
Added time.Time `json:"added"`
LastUsed time.Time `json:"lastUsed"`
Permissions *RootPermissions `json:"permissions,omitempty"`
}
RootEntry represents a managed root
type RootManager ¶
type RootManager struct {
// contains filtered or unexported fields
}
RootManager manages MCP roots according to specification
func (*RootManager) AddRoot ¶
func (rm *RootManager) AddRoot(root Root, permissions *RootPermissions) error
AddRoot adds a root to the manager
func (*RootManager) CheckRootAccess ¶
func (rm *RootManager) CheckRootAccess(path string, operation string) (*RootEntry, error)
CheckRootAccess checks if a path is within any managed roots
func (*RootManager) CreateDefaultRoots ¶
func (rm *RootManager) CreateDefaultRoots() error
CreateDefaultRoots creates default roots for common use cases
func (*RootManager) GetRoot ¶
func (rm *RootManager) GetRoot(uri string) (*RootEntry, error)
GetRoot retrieves a root by URI
func (*RootManager) GetRootStats ¶
func (rm *RootManager) GetRootStats() map[string]interface{}
GetRootStats returns statistics about root usage
func (*RootManager) ListRoots ¶
func (rm *RootManager) ListRoots() []Root
ListRoots returns all roots
func (*RootManager) NotifyRootChange ¶
func (rm *RootManager) NotifyRootChange(uri string, event string)
NotifyRootChange notifies watchers of a root change
func (*RootManager) RemoveRoot ¶
func (rm *RootManager) RemoveRoot(uri string) error
RemoveRoot removes a root from the manager
func (*RootManager) UnwatchRoot ¶
func (rm *RootManager) UnwatchRoot(uri string) error
UnwatchRoot stops watching a root
type RootPermissions ¶
type RootPermissions struct {
Read bool `json:"read"`
Write bool `json:"write"`
List bool `json:"list"`
Watch bool `json:"watch"`
}
RootPermissions defines what operations are allowed on a root
type RootWatcher ¶
type RootWatcher struct {
RootURI string
Callback func(uri string, event string)
LastChange time.Time
Active bool
}
RootWatcher monitors changes to a root
type RootsListRequest ¶
type RootsListRequest struct {
}
RootsListRequest represents a roots/list request
type RootsListResponse ¶
type RootsListResponse struct {
Roots []Root `json:"roots"`
}
RootsListResponse represents a roots/list response
type RootsOpts ¶
type RootsOpts struct {
ListChanged bool `json:"listChanged,omitempty"`
}
RootsOpts represents roots capability options
type SSETransport ¶
type SSETransport struct {
// contains filtered or unexported fields
}
SSETransport implements MCP SSE transport according to specification
func NewSSETransport ¶
func NewSSETransport(sseURL string) *SSETransport
NewSSETransport creates a new MCP-compliant SSE transport
func (*SSETransport) Close ¶
func (s *SSETransport) Close() error
func (*SSETransport) GetLastActivity ¶
func (s *SSETransport) GetLastActivity() time.Time
func (*SSETransport) GetType ¶
func (s *SSETransport) GetType() string
func (*SSETransport) Initialize ¶
func (s *SSETransport) Initialize() error
Initialize SSE connection
func (*SSETransport) IsConnected ¶
func (s *SSETransport) IsConnected() bool
func (*SSETransport) Receive ¶
func (s *SSETransport) Receive() (MCPMessage, error)
func (*SSETransport) Send ¶
func (s *SSETransport) Send(msg MCPMessage) error
func (*SSETransport) SendProgress ¶
func (s *SSETransport) SendProgress(notification *ProgressNotification) error
func (*SSETransport) SupportsProgress ¶
func (s *SSETransport) SupportsProgress() bool
type SamplingCapabilities ¶
type SamplingCapabilities struct {
Models []string `json:"models"`
MaxTokens int `json:"maxTokens"`
SupportsImages bool `json:"supportsImages"`
SupportsTools bool `json:"supportsTools"`
SupportsStreaming bool `json:"supportsStreaming"`
}
SamplingCapabilities describes what a sampling handler can do
type SamplingContent ¶
type SamplingContent struct {
Type string `json:"type"` // "text", "image", "resource"
Text string `json:"text,omitempty"`
ImageData string `json:"imageData,omitempty"` // base64
MimeType string `json:"mimeType,omitempty"`
Resource *EmbeddedResource `json:"resource,omitempty"`
}
SamplingContent represents content that can include text and embedded resources
type SamplingContext ¶
type SamplingContext struct {
ServerInfo map[string]interface{} `json:"serverInfo,omitempty"`
ToolContext []string `json:"toolContext,omitempty"` // Recently used tools
ResourceContext []string `json:"resourceContext,omitempty"` // Recently accessed resources
SessionContext map[string]interface{} `json:"sessionContext,omitempty"`
}
SamplingContext provides context for the sampling request
type SamplingHandler ¶
type SamplingHandler interface {
// HandleSamplingRequest processes a sampling request
HandleSamplingRequest(request *SamplingRequest) (*SamplingResponse, error)
// GetSupportedModels returns supported model names
GetSupportedModels() []string
// GetCapabilities returns handler capabilities
GetCapabilities() SamplingCapabilities
}
SamplingHandler defines the interface for handling sampling requests
type SamplingManager ¶
type SamplingManager struct {
// contains filtered or unexported fields
}
SamplingManager manages LLM sampling requests from MCP servers
func NewSamplingManager ¶
func NewSamplingManager() *SamplingManager
NewSamplingManager creates a new sampling manager
func (*SamplingManager) ApproveRequest ¶
func (sm *SamplingManager) ApproveRequest(requestID, reviewer, comments string) error
ApproveRequest approves a sampling request
func (*SamplingManager) CleanupOldRequests ¶
func (sm *SamplingManager) CleanupOldRequests(maxAge time.Duration)
CleanupOldRequests removes old completed/failed requests
func (*SamplingManager) CreateSamplingRequest ¶
func (sm *SamplingManager) CreateSamplingRequest(serverName string, messages []SamplingMessage, prefs ModelPreferences, context SamplingContext) (*SamplingRequest, error)
CreateSamplingRequest creates a new sampling request
func (*SamplingManager) GetPendingRequests ¶
func (sm *SamplingManager) GetPendingRequests() []*SamplingRequest
GetPendingRequests returns requests awaiting approval
func (*SamplingManager) GetRequestStatus ¶
func (sm *SamplingManager) GetRequestStatus(requestID string) (string, error)
GetRequestStatus returns the status of a request
func (*SamplingManager) ProcessSamplingRequest ¶
func (sm *SamplingManager) ProcessSamplingRequest(requestID string) (*SamplingResponse, error)
ProcessSamplingRequest processes a sampling request
func (*SamplingManager) RegisterHandler ¶
func (sm *SamplingManager) RegisterHandler(name string, handler SamplingHandler)
RegisterHandler registers a sampling handler for a specific model or provider
func (*SamplingManager) RejectRequest ¶
func (sm *SamplingManager) RejectRequest(requestID, reviewer, reason string) error
RejectRequest rejects a sampling request
func (*SamplingManager) SetHumanControls ¶
func (sm *SamplingManager) SetHumanControls(serverName string, config *HumanControlConfig)
SetHumanControls configures human-in-the-loop controls for a server
type SamplingMessage ¶
type SamplingMessage struct {
Role string `json:"role"` // "system", "user", "assistant"
Content SamplingContent `json:"content"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
SamplingMessage represents a message in the sampling request
type SamplingOpts ¶
type SamplingOpts struct {
}
SamplingOpts represents sampling capability options
type SamplingRequest ¶
type SamplingRequest struct {
ID string `json:"id"`
ServerName string `json:"serverName"`
Messages []SamplingMessage `json:"messages"`
ModelPrefs ModelPreferences `json:"modelPrefs,omitempty"`
MaxTokens int `json:"maxTokens,omitempty"`
StopSequence []string `json:"stopSequence,omitempty"`
Temperature float64 `json:"temperature,omitempty"`
Context SamplingContext `json:"context,omitempty"`
Created time.Time `json:"created"`
Status string `json:"status"` // "pending", "approved", "rejected", "completed", "failed"
HumanReview *HumanReviewResult `json:"humanReview,omitempty"`
}
SamplingRequest represents a sampling/createMessage request
type SamplingResponse ¶
type SamplingResponse struct {
Content SamplingContent `json:"content"`
Model string `json:"model,omitempty"`
StopReason string `json:"stopReason,omitempty"`
Usage SamplingUsage `json:"usage,omitempty"`
Metadata map[string]interface{} `json:"metadata,omitempty"`
}
SamplingResponse represents the response to a sampling request
type SamplingUsage ¶
type SamplingUsage struct {
InputTokens int `json:"inputTokens,omitempty"`
OutputTokens int `json:"outputTokens,omitempty"`
TotalTokens int `json:"totalTokens,omitempty"`
}
SamplingUsage provides token usage information
type ServerInfo ¶
ServerInfo represents information about the server
type StandardMethodHandler ¶
type StandardMethodHandler struct {
// contains filtered or unexported fields
}
StandardMethodHandler handles standard MCP methods
func NewStandardMethodHandler ¶
func NewStandardMethodHandler(serverInfo ServerInfo, capabilities CapabilitiesOpts, logger *logging.Logger) *StandardMethodHandler
NewStandardMethodHandler creates a new standard method handler
func (*StandardMethodHandler) GetCapabilities ¶
func (h *StandardMethodHandler) GetCapabilities() CapabilitiesOpts
GetCapabilities returns the server capabilities
func (*StandardMethodHandler) GetRootManager ¶
func (h *StandardMethodHandler) GetRootManager() *RootManager
GetRootManager returns the root manager
func (*StandardMethodHandler) GetServerInfo ¶
func (h *StandardMethodHandler) GetServerInfo() ServerInfo
GetServerInfo returns the server information
func (*StandardMethodHandler) HandleStandardMethod ¶
func (h *StandardMethodHandler) HandleStandardMethod(method string, params json.RawMessage, requestID interface{}) (*MCPResponse, error)
HandleStandardMethod handles a standard MCP method
func (*StandardMethodHandler) HandleStandardNotification ¶
func (h *StandardMethodHandler) HandleStandardNotification(method string, params json.RawMessage) error
HandleStandardNotification handles a standard MCP notification
func (*StandardMethodHandler) IsInitialized ¶
func (h *StandardMethodHandler) IsInitialized() bool
IsInitialized returns whether the handler has been initialized
func (*StandardMethodHandler) SetCapability ¶
func (h *StandardMethodHandler) SetCapability(capability string, enabled bool, options interface{}) error
SetCapability enables or disables a specific capability
type StdioTransport ¶
type StdioTransport struct {
// contains filtered or unexported fields
}
StdioTransport implements the stdio transport
func NewStdioTransport ¶
func NewStdioTransport(r io.Reader, w io.Writer) *StdioTransport
NewStdioTransport creates a new stdio transport
func (*StdioTransport) Close ¶
func (t *StdioTransport) Close() error
Close closes the stdio transport
func (*StdioTransport) GetProgressManager ¶
func (t *StdioTransport) GetProgressManager() *ProgressManager
GetProgressManager returns the progress manager
func (*StdioTransport) Receive ¶
func (t *StdioTransport) Receive() (MCPMessage, error)
Receive receives an MCP message via stdio
func (*StdioTransport) Send ¶
func (t *StdioTransport) Send(msg MCPMessage) error
Send sends an MCP message via stdio
func (*StdioTransport) SendProgress ¶
func (t *StdioTransport) SendProgress(notification *ProgressNotification) error
SendProgress sends a progress notification
func (*StdioTransport) SupportsProgress ¶
func (t *StdioTransport) SupportsProgress() bool
SupportsProgress returns true since stdio supports progress notifications
type SubscribeRequest ¶
type SubscribeRequest struct {
URI string `json:"uri"`
Filters []ResourceFilter `json:"filters,omitempty"`
Options SubscriptionOptions `json:"options,omitempty"`
}
SubscribeRequest represents a resources/subscribe request
type SubscribeResponse ¶
type SubscribeResponse struct {
SubscriptionID string `json:"subscriptionId"`
}
SubscribeResponse represents a resources/subscribe response
type SubscriptionManager ¶
type SubscriptionManager struct {
// contains filtered or unexported fields
}
SubscriptionManager manages MCP resource subscriptions
func NewSubscriptionManager ¶
func NewSubscriptionManager() *SubscriptionManager
NewSubscriptionManager creates a new subscription manager
func (*SubscriptionManager) CleanupExpiredSubscriptions ¶
func (sm *SubscriptionManager) CleanupExpiredSubscriptions(maxAge time.Duration)
CleanupExpiredSubscriptions removes expired client subscriptions
func (*SubscriptionManager) GetSubscriptions ¶
func (sm *SubscriptionManager) GetSubscriptions(clientID string) []*ResourceSubscription
GetSubscriptions returns all subscriptions for a client
func (*SubscriptionManager) NotifyResourceUpdate ¶
func (sm *SubscriptionManager) NotifyResourceUpdate(uri string, updateType string, content *ResourceContent, metadata map[string]interface{}) error
NotifyResourceUpdate sends notifications to matching subscriptions
func (*SubscriptionManager) Subscribe ¶
func (sm *SubscriptionManager) Subscribe(clientID, sessionID string, req SubscribeRequest, notifyFunc func(*ResourceUpdateNotification) error) (*SubscribeResponse, error)
Subscribe creates a new resource subscription
func (*SubscriptionManager) Unsubscribe ¶
func (sm *SubscriptionManager) Unsubscribe(clientID string, req UnsubscribeRequest) error
Unsubscribe removes a resource subscription
type SubscriptionOptions ¶
type SubscriptionOptions struct {
IncludeContent bool `json:"includeContent,omitempty"` // Include resource content in notifications
Debounce int `json:"debounce,omitempty"` // Debounce period in milliseconds
BatchSize int `json:"batchSize,omitempty"` // Max resources per notification
ContentTypes []string `json:"contentTypes,omitempty"` // Filter by content types
MaxSize int64 `json:"maxSize,omitempty"` // Max resource size to include
IncludeMetadata bool `json:"includeMetadata,omitempty"` // Include resource metadata
}
SubscriptionOptions configures subscription behavior
type TemplateExample ¶
type TemplateExample struct {
Description string `json:"description,omitempty"`
Variables map[string]interface{} `json:"variables"`
Result string `json:"result"` // Expected URI result
}
TemplateExample shows how to use the template
type TemplateExpression ¶
type TemplateExpression struct {
Operator string // "", "+", "#", ".", "/", ";", "?", "&"
Variables []VariableSpec // Variable specifications
Raw string // Raw expression text
StartPos int // Position in template
EndPos int // End position in template
}
TemplateExpression represents a single template expression
type TemplateVariable ¶
type TemplateVariable struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
Type string `json:"type,omitempty"` // "string", "number", "boolean"
Default interface{} `json:"default,omitempty"` // Default value
Required bool `json:"required,omitempty"`
Pattern string `json:"pattern,omitempty"` // Regex pattern for validation
Enum []string `json:"enum,omitempty"` // Allowed values
}
TemplateVariable describes a template variable
type ToolDefinition ¶
type ToolDefinition struct {
Name string `json:"name"`
Description string `json:"description"`
InputSchema map[string]interface{} `json:"inputSchema"`
}
ToolDefinition represents a tool definition for change detection
type ToolsOpts ¶
type ToolsOpts struct {
ListChanged bool `json:"listChanged,omitempty"`
}
ToolsOpts represents tools capability options
type Transport ¶
type Transport interface {
// Send sends an MCP message
Send(msg MCPMessage) error
// Receive receives an MCP message
Receive() (MCPMessage, error)
// Close closes the transport
Close() error
// SupportsProgress returns true if transport supports progress notifications
SupportsProgress() bool
// SendProgress sends a progress notification
SendProgress(notification *ProgressNotification) error
}
Transport defines the interface for MCP transports
type URITemplate ¶
type URITemplate struct {
Template string
Expressions []TemplateExpression
}
URITemplate represents an RFC 6570 URI template
func ParseURITemplate ¶
func ParseURITemplate(template string) (*URITemplate, error)
ParseURITemplate parses an RFC 6570 URI template
func (*URITemplate) Expand ¶
func (ut *URITemplate) Expand(variables map[string]interface{}) (string, error)
Expand expands the URI template with the given variables
func (*URITemplate) GetVariableNames ¶
func (ut *URITemplate) GetVariableNames() []string
GetVariableNames returns all variable names used in the template
func (*URITemplate) Validate ¶
func (ut *URITemplate) Validate() error
Validate validates the template syntax
type UnsubscribeRequest ¶
type UnsubscribeRequest struct {
SubscriptionID string `json:"subscriptionId"`
}
UnsubscribeRequest represents a resources/unsubscribe request
type VariableSpec ¶
type VariableSpec struct {
Name string
Modifier string // ":" for prefix, "*" for explode
MaxLength int // For prefix modifier
}
VariableSpec represents a variable specification
type WebSocketConnection ¶
type WebSocketConnection struct {
ID string
Transport *WebSocketTransport
ClientInfo *ClientInfo
ServerInfo *ServerInfo
Capabilities *CapabilitiesOpts
Initialized bool
LastActivity time.Time
Context map[string]interface{}
}
WebSocketConnection represents a WebSocket MCP connection
type WebSocketHandler ¶
type WebSocketHandler interface {
OnConnect(transport *WebSocketTransport) error
OnDisconnect(transport *WebSocketTransport) error
OnMessage(transport *WebSocketTransport, message MCPMessage) error
}
WebSocketHandler defines the interface for handling WebSocket MCP connections
type WebSocketServer ¶
type WebSocketServer struct {
// contains filtered or unexported fields
}
WebSocketServer manages WebSocket connections for MCP
func NewWebSocketServer ¶
func NewWebSocketServer() *WebSocketServer
NewWebSocketServer creates a new WebSocket MCP server
func (*WebSocketServer) Close ¶
func (ws *WebSocketServer) Close() error
Close closes all connections and shuts down the server
func (*WebSocketServer) GetConnections ¶
func (ws *WebSocketServer) GetConnections() map[string]*WebSocketTransport
GetConnections returns all active connections
func (*WebSocketServer) GetHandler ¶
func (ws *WebSocketServer) GetHandler(name string) (WebSocketHandler, bool)
GetHandler gets a registered handler
func (*WebSocketServer) RegisterHandler ¶
func (ws *WebSocketServer) RegisterHandler(name string, handler WebSocketHandler)
RegisterHandler registers a handler for WebSocket connections
func (*WebSocketServer) UpgradeHTTP ¶
func (ws *WebSocketServer) UpgradeHTTP(w http.ResponseWriter, r *http.Request, handler WebSocketHandler) (*WebSocketTransport, error)
UpgradeHTTP upgrades an HTTP connection to WebSocket MCP
type WebSocketTransport ¶
type WebSocketTransport struct {
// contains filtered or unexported fields
}
WebSocketTransport implements MCP transport over WebSocket (updated to be MCP compliant)
func NewWebSocketTransport ¶
func NewWebSocketTransport(url string) *WebSocketTransport
NewWebSocketTransport creates a WebSocket transport from a URL
func (*WebSocketTransport) Close ¶
func (wst *WebSocketTransport) Close() error
Close implements the Transport interface
func (*WebSocketTransport) GetLastActivity ¶
func (wst *WebSocketTransport) GetLastActivity() time.Time
GetLastActivity returns the last activity timestamp
func (*WebSocketTransport) GetType ¶
func (wst *WebSocketTransport) GetType() string
GetType returns the transport type
func (*WebSocketTransport) IsConnected ¶
func (wst *WebSocketTransport) IsConnected() bool
IsConnected returns true if transport is connected
func (*WebSocketTransport) Receive ¶
func (wst *WebSocketTransport) Receive() (MCPMessage, error)
Receive implements the Transport interface
func (*WebSocketTransport) Send ¶
func (wst *WebSocketTransport) Send(msg MCPMessage) error
Send implements the Transport interface
func (*WebSocketTransport) SendProgress ¶
func (wst *WebSocketTransport) SendProgress(notification *ProgressNotification) error
SendProgress implements the Transport interface
func (*WebSocketTransport) Start ¶
func (wst *WebSocketTransport) Start() error
Start starts the WebSocket transport
func (*WebSocketTransport) SupportsProgress ¶
func (wst *WebSocketTransport) SupportsProgress() bool
SupportsProgress implements the Transport interface