Documentation
¶
Index ¶
- Constants
- Variables
- type Client
- type ClientCapabilities
- type ClientOptions
- type Content
- type ElicitationCapability
- type Implementation
- type InitializeRequest
- type InitializeResponse
- type JSONRPCError
- type JSONRPCMessage
- type LoggingCapability
- type PromptsCapability
- type Registry
- type RegistryImpl
- func (r *RegistryImpl) Close() error
- func (r *RegistryImpl) GetClient(ctx context.Context, serverName string) (Client, error)
- func (r *RegistryImpl) GetClientForTool(ctx context.Context, toolName string) (Client, error)
- func (r *RegistryImpl) GetToolSchema(ctx context.Context, toolName string) (*Tool, error)
- func (r *RegistryImpl) ListAllTools(ctx context.Context) (map[string][]Tool, error)
- func (r *RegistryImpl) ListServers() []string
- func (r *RegistryImpl) RegisterServer(config ServerConfig) error
- type ResourcesCapability
- type SamplingCapability
- type ServerCapabilities
- type ServerConfig
- type ServerConfigData
- type StdioClient
- func (c *StdioClient) CallTool(ctx context.Context, name string, arguments json.RawMessage) (*ToolCallResponse, error)
- func (c *StdioClient) Close() error
- func (c *StdioClient) Initialize(ctx context.Context) (*InitializeResponse, error)
- func (c *StdioClient) IsAlive() bool
- func (c *StdioClient) ListTools(ctx context.Context) ([]Tool, error)
- type Tool
- type ToolCallRequest
- type ToolCallResponse
- type ToolsCapability
- type ToolsListRequest
- type ToolsListResponse
Constants ¶
const ProtocolVersion = "2025-06-18"
ProtocolVersion defines the MCP protocol version (as of 2025-06-18).
Variables ¶
var ( // ErrClientNotInitialized is returned when attempting operations on uninitialized client ErrClientNotInitialized = errors.New("mcp: client not initialized") // ErrClientClosed is returned when attempting operations on closed client ErrClientClosed = errors.New("mcp: client closed") // ErrServerUnresponsive is returned when server doesn't respond ErrServerUnresponsive = errors.New("mcp: server unresponsive") // ErrProcessDied is returned when server process dies unexpectedly ErrProcessDied = errors.New("mcp: server process died") )
Functions ¶
This section is empty.
Types ¶
type Client ¶
type Client interface {
// Initialize establishes the MCP connection and negotiates capabilities
Initialize(ctx context.Context) (*InitializeResponse, error)
// ListTools retrieves all available tools from the server
ListTools(ctx context.Context) ([]Tool, error)
// CallTool executes a tool with the given arguments
CallTool(ctx context.Context, name string, arguments json.RawMessage) (*ToolCallResponse, error)
// Close terminates the connection to the MCP server
Close() error
// IsAlive checks if the connection is still active
IsAlive() bool
}
Client interface defines the MCP client operations
type ClientCapabilities ¶
type ClientCapabilities struct {
Elicitation *ElicitationCapability `json:"elicitation,omitempty"`
Sampling *SamplingCapability `json:"sampling,omitempty"`
Logging *LoggingCapability `json:"logging,omitempty"`
}
ClientCapabilities describes what the client supports
type ClientOptions ¶
type ClientOptions struct {
// RequestTimeout is the default timeout for RPC requests
RequestTimeout time.Duration
// InitTimeout is the timeout for the initialization handshake
InitTimeout time.Duration
// MaxRetries is the number of times to retry failed requests
MaxRetries int
// RetryDelay is the initial delay between retries (exponential backoff)
RetryDelay time.Duration
// EnableGracefulDegradation allows operations to continue even if MCP is unavailable
EnableGracefulDegradation bool
}
ClientOptions configures MCP client behavior
func DefaultClientOptions ¶
func DefaultClientOptions() ClientOptions
DefaultClientOptions returns sensible defaults
type Content ¶
type Content struct {
Type string `json:"type"` // "text", "image", "resource", etc.
Text string `json:"text,omitempty"`
Data string `json:"data,omitempty"` // Base64 encoded data
MimeType string `json:"mimeType,omitempty"` // MIME type for data
URI string `json:"uri,omitempty"` // URI for resources
}
Content represents a content item in MCP responses
type ElicitationCapability ¶
type ElicitationCapability struct{}
ElicitationCapability indicates the client supports elicitation
type Implementation ¶
Implementation describes client or server implementation details
type InitializeRequest ¶
type InitializeRequest struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ClientCapabilities `json:"capabilities"`
ClientInfo Implementation `json:"clientInfo"`
}
InitializeRequest represents the initialization request params
type InitializeResponse ¶
type InitializeResponse struct {
ProtocolVersion string `json:"protocolVersion"`
Capabilities ServerCapabilities `json:"capabilities"`
ServerInfo Implementation `json:"serverInfo"`
}
InitializeResponse represents the initialization response
type JSONRPCError ¶
type JSONRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data interface{} `json:"data,omitempty"`
}
JSONRPCError represents a JSON-RPC 2.0 error
type JSONRPCMessage ¶
type JSONRPCMessage struct {
JSONRPC string `json:"jsonrpc"`
ID interface{} `json:"id,omitempty"` // Request ID (number or string)
Method string `json:"method,omitempty"` // Method name for requests/notifications
Params json.RawMessage `json:"params,omitempty"` // Parameters for method
Result json.RawMessage `json:"result,omitempty"` // Result for responses
Error *JSONRPCError `json:"error,omitempty"` // Error for error responses
}
JSONRPCMessage represents a JSON-RPC 2.0 message
type LoggingCapability ¶
type LoggingCapability struct{}
LoggingCapability indicates the client supports logging
type PromptsCapability ¶
type PromptsCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
PromptsCapability indicates the server supports prompts
type Registry ¶
type Registry interface {
// RegisterServer adds a new MCP server configuration
RegisterServer(config ServerConfig) error
// GetClient returns an active client for the given server name
GetClient(ctx context.Context, serverName string) (Client, error)
// GetClientForTool returns the client that provides the specified tool
GetClientForTool(ctx context.Context, toolName string) (Client, error)
// ListServers returns all registered server names
ListServers() []string
// ListAllTools returns all tools from all connected servers
ListAllTools(ctx context.Context) (map[string][]Tool, error)
// Close shuts down all MCP servers and connections
Close() error
}
Registry interface defines the MCP server registry operations
type RegistryImpl ¶
type RegistryImpl struct {
// contains filtered or unexported fields
}
RegistryImpl implements the Registry interface
func NewRegistryWithServers ¶
func NewRegistryWithServers(serverConfigs []ServerConfigData) (*RegistryImpl, error)
NewRegistryWithServers creates a registry and registers multiple servers. Returns error if any server registration fails.
func (*RegistryImpl) Close ¶
func (r *RegistryImpl) Close() error
Close shuts down all MCP servers and connections
func (*RegistryImpl) GetClientForTool ¶
GetClientForTool returns the client that provides the specified tool
func (*RegistryImpl) GetToolSchema ¶
GetToolSchema returns the schema for a specific tool
func (*RegistryImpl) ListAllTools ¶
ListAllTools returns all tools from all connected servers
func (*RegistryImpl) ListServers ¶
func (r *RegistryImpl) ListServers() []string
ListServers returns all registered server names
func (*RegistryImpl) RegisterServer ¶
func (r *RegistryImpl) RegisterServer(config ServerConfig) error
RegisterServer adds a new MCP server configuration
type ResourcesCapability ¶
type ResourcesCapability struct {
ListChanged bool `json:"listChanged,omitempty"`
}
ResourcesCapability indicates the server supports resources
type SamplingCapability ¶
type SamplingCapability struct{}
SamplingCapability indicates the client supports sampling
type ServerCapabilities ¶
type ServerCapabilities struct {
Tools *ToolsCapability `json:"tools,omitempty"`
Resources *ResourcesCapability `json:"resources,omitempty"`
Prompts *PromptsCapability `json:"prompts,omitempty"`
}
ServerCapabilities describes what the server supports
type ServerConfig ¶
type ServerConfig struct {
Name string `json:"name" yaml:"name"` // Unique identifier for this server
Command string `json:"command" yaml:"command"` // Command to execute
Args []string `json:"args,omitempty" yaml:"args,omitempty"`
Env map[string]string `json:"env,omitempty" yaml:"env,omitempty"`
}
ServerConfig represents configuration for an MCP server
type ServerConfigData ¶
ServerConfigData holds MCP server configuration matching config.MCPServerConfig
type StdioClient ¶
type StdioClient struct {
// contains filtered or unexported fields
}
StdioClient implements the MCP Client interface using stdio transport
func NewStdioClient ¶
func NewStdioClient(config ServerConfig) *StdioClient
NewStdioClient creates a new MCP client using stdio transport
func NewStdioClientWithOptions ¶
func NewStdioClientWithOptions(config ServerConfig, options ClientOptions) *StdioClient
NewStdioClientWithOptions creates a client with custom options
func (*StdioClient) CallTool ¶
func (c *StdioClient) CallTool(ctx context.Context, name string, arguments json.RawMessage) (*ToolCallResponse, error)
CallTool executes a tool with the given arguments
func (*StdioClient) Close ¶
func (c *StdioClient) Close() error
Close terminates the connection to the MCP server
func (*StdioClient) Initialize ¶
func (c *StdioClient) Initialize(ctx context.Context) (*InitializeResponse, error)
Initialize establishes the MCP connection and negotiates capabilities
func (*StdioClient) IsAlive ¶
func (c *StdioClient) IsAlive() bool
IsAlive checks if the connection is still active
type Tool ¶
type Tool struct {
Name string `json:"name"`
Description string `json:"description,omitempty"`
InputSchema json.RawMessage `json:"inputSchema"` // JSON Schema for tool input
}
Tool represents an MCP tool definition
type ToolCallRequest ¶
type ToolCallRequest struct {
Name string `json:"name"`
Arguments json.RawMessage `json:"arguments,omitempty"`
}
ToolCallRequest represents a request to execute a tool
type ToolCallResponse ¶
type ToolCallResponse struct {
Content []Content `json:"content"`
IsError bool `json:"isError,omitempty"`
}
ToolCallResponse represents the response from a tool execution
type ToolsCapability ¶
type ToolsCapability struct {
ListChanged bool `json:"listChanged,omitempty"` // Server can send notifications
}
ToolsCapability indicates the server supports tools
type ToolsListRequest ¶
type ToolsListRequest struct {
}
ToolsListRequest represents a request to list available tools
type ToolsListResponse ¶
type ToolsListResponse struct {
Tools []Tool `json:"tools"`
}
ToolsListResponse represents the response to a tools/list request