Documentation
¶
Index ¶
- func Exists(id string) bool
- func GetClientMapping(id string) (*types.MappingData, error)
- func ListClients() []string
- func RemoveClientMappingItems(id string, toolNames []string, resourceNames []string, promptNames []string) error
- func UnloadClient(id string)
- func UpdateClientMapping(id string, tools map[string]*types.ToolSchema, ...) error
- type Client
- func GetClient(id string) Client
- func LoadClient(path, id string) (Client, error)
- func LoadClientSource(dsl, id string, mappingData ...*types.MappingData) (Client, error)
- func LoadClientSourceWithType(dsl, id, clientType string, mappingData ...*types.MappingData) (Client, error)
- func LoadClientWithType(path, id, clientType string) (Client, error)
- func Select(id string) (Client, error)
- type Closer
- type EventBus
- type HealthChecker
- type Logger
- type LoggingProvider
- type MessageHandler
- type MetricsCollector
- type NotificationProvider
- type ProgressProvider
- type PromptProvider
- type Registry
- type ResourceProvider
- type SampleProvider
- type Serializer
- type Server
- type ToolProvider
- type TransportFactory
- type Validator
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetClientMapping ¶
func GetClientMapping(id string) (*types.MappingData, error)
GetClientMapping returns the mapping data for a process-based MCP client
func RemoveClientMappingItems ¶
func RemoveClientMappingItems(id string, toolNames []string, resourceNames []string, promptNames []string) error
RemoveClientMappingItems removes specific tools/resources/prompts from a process-based MCP client
func UpdateClientMapping ¶
func UpdateClientMapping(id string, tools map[string]*types.ToolSchema, resources map[string]*types.ResourceSchema, prompts map[string]*types.PromptSchema) error
UpdateClientMapping updates the mapping data for a process-based MCP client
Types ¶
type Client ¶
type Client interface {
// Client information
Info() *types.ClientInfo
// Connection management
Connect(ctx context.Context, options ...types.ConnectionOptions) error
Disconnect(ctx context.Context) error
IsConnected() bool
State() types.ConnectionState
// Protocol initialization
Initialize(ctx context.Context) (*types.InitializeResponse, error)
Initialized(ctx context.Context) error
// Resource operations
ListResources(ctx context.Context, cursor string) (*types.ListResourcesResponse, error)
ReadResource(ctx context.Context, uri string) (*types.ReadResourceResponse, error)
SubscribeResource(ctx context.Context, uri string) error
UnsubscribeResource(ctx context.Context, uri string) error
// Tool operations
ListTools(ctx context.Context, cursor string) (*types.ListToolsResponse, error)
CallTool(ctx context.Context, name string, arguments interface{}, extraArgs ...interface{}) (*types.CallToolResponse, error)
CallTools(ctx context.Context, tools []types.ToolCall, extraArgs ...interface{}) (*types.CallToolsResponse, error)
CallToolsParallel(ctx context.Context, tools []types.ToolCall, extraArgs ...interface{}) (*types.CallToolsResponse, error)
// Prompt operations
ListPrompts(ctx context.Context, cursor string) (*types.ListPromptsResponse, error)
GetPrompt(ctx context.Context, name string, arguments map[string]interface{}) (*types.GetPromptResponse, error)
// Sample operations - List and get training samples from .jsonl files
// itemType: types.SampleTool or types.SampleResource
ListSamples(ctx context.Context, itemType types.SampleItemType, itemName string) (*types.ListSamplesResponse, error)
GetSample(ctx context.Context, itemType types.SampleItemType, itemName string, index int) (*types.SampleData, error)
// Logging operations
SetLogLevel(ctx context.Context, level types.LogLevel) error
// Request cancellation
CancelRequest(ctx context.Context, requestID interface{}) error
// Progress tracking
CreateProgress(ctx context.Context, total uint64) (uint64, error)
UpdateProgress(ctx context.Context, token uint64, progress uint64) error
// Event handling
OnEvent(eventType string, handler func(event types.Event))
OnNotification(method string, handler types.NotificationHandler)
OnError(handler types.ErrorHandler)
// Get meta info
GetMetaInfo() gouTypes.MetaInfo
}
Client the MCP client interface
func GetClient ¶
GetClient get the client by id (similar to model.Select but without throwing exception)
func LoadClientSource ¶
func LoadClientSource(dsl, id string, mappingData ...*types.MappingData) (Client, error)
LoadClientSource load the mcp client source with optional mapping data
func LoadClientSourceWithType ¶
func LoadClientSourceWithType(dsl, id, clientType string, mappingData ...*types.MappingData) (Client, error)
LoadClientSourceWithType load the mcp client source with type and optional mapping data
func LoadClientWithType ¶
LoadClientWithType load the mcp client from file with a specific type
type EventBus ¶
type EventBus interface {
// Subscribe to event
Subscribe(eventType string, handler func(event types.Event)) error
// Unsubscribe from event
Unsubscribe(eventType string, handler func(event types.Event)) error
// Publish event
Publish(event types.Event) error
// Close event bus
Close() error
}
EventBus provides event publishing and subscription
type HealthChecker ¶
type HealthChecker interface {
// Check if component is healthy
IsHealthy(ctx context.Context) bool
// Get health status
GetHealth(ctx context.Context) map[string]interface{}
// Register health check
RegisterHealthCheck(name string, check func(ctx context.Context) bool) error
}
HealthChecker checks component health
type Logger ¶
type Logger interface {
// Log debug message
Debug(ctx context.Context, msg string, args ...interface{})
// Log info message
Info(ctx context.Context, msg string, args ...interface{})
// Log warning message
Warn(ctx context.Context, msg string, args ...interface{})
// Log error message
Error(ctx context.Context, msg string, args ...interface{})
// Log with specific level
Log(ctx context.Context, level types.LogLevel, msg string, args ...interface{})
}
Logger provides logging functionality
type LoggingProvider ¶
type LoggingProvider interface {
// Set log level
SetLogLevel(ctx context.Context, level types.LogLevel) error
// Send log message
SendLogMessage(ctx context.Context, message types.LogMessage) error
// Get current log level
GetLogLevel() types.LogLevel
}
LoggingProvider provides logging functionality
type MessageHandler ¶
type MessageHandler interface {
// Handle JSON-RPC request
HandleRequest(ctx context.Context, request types.Message) (interface{}, error)
// Handle JSON-RPC notification
HandleNotification(ctx context.Context, notification types.Message) error
// Handle transport error
HandleError(ctx context.Context, err error) error
}
MessageHandler handles incoming messages
type MetricsCollector ¶
type MetricsCollector interface {
// Increment counter
IncrementCounter(name string, tags map[string]string) error
// Set gauge value
SetGauge(name string, value float64, tags map[string]string) error
// Record histogram value
RecordHistogram(name string, value float64, tags map[string]string) error
// Get metrics
GetMetrics() map[string]interface{}
}
MetricsCollector collects metrics
type NotificationProvider ¶
type NotificationProvider interface {
// Send resource updated notification
SendResourceUpdated(ctx context.Context, uri string) error
// Send tools changed notification
SendToolsChanged(ctx context.Context) error
// Send prompts changed notification
SendPromptsChanged(ctx context.Context) error
// Send roots changed notification
SendRootsChanged(ctx context.Context) error
// Send custom notification
SendNotification(ctx context.Context, method string, params interface{}) error
}
NotificationProvider provides notification functionality
type ProgressProvider ¶
type ProgressProvider interface {
// Create progress token
CreateProgress(ctx context.Context, total uint64) (uint64, error)
// Update progress
UpdateProgress(ctx context.Context, token uint64, progress uint64) error
// Complete progress
CompleteProgress(ctx context.Context, token uint64) error
}
ProgressProvider provides progress tracking functionality
type PromptProvider ¶
type PromptProvider interface {
// List all available prompts
ListPrompts(ctx context.Context, cursor string) ([]types.Prompt, string, error)
// Get prompt with arguments
GetPrompt(ctx context.Context, name string, arguments map[string]interface{}) (*types.GetPromptResponse, error)
// Check if prompt exists
HasPrompt(ctx context.Context, name string) bool
// Get prompt schema
GetPromptSchema(ctx context.Context, name string) (types.Prompt, error)
}
PromptProvider provides prompt functionality
type Registry ¶
type Registry interface {
// Register resource provider
RegisterResourceProvider(name string, provider ResourceProvider) error
// Register tool provider
RegisterToolProvider(name string, provider ToolProvider) error
// Register prompt provider
RegisterPromptProvider(name string, provider PromptProvider) error
// Register sample provider
RegisterSampleProvider(name string, provider SampleProvider) error
// Get resource provider
GetResourceProvider(name string) (ResourceProvider, bool)
// Get tool provider
GetToolProvider(name string) (ToolProvider, bool)
// Get prompt provider
GetPromptProvider(name string) (PromptProvider, bool)
// Get sample provider
GetSampleProvider(name string) (SampleProvider, bool)
// List all providers
ListProviders() map[string]interface{}
}
Registry manages MCP components
type ResourceProvider ¶
type ResourceProvider interface {
// List all available resources
ListResources(ctx context.Context, cursor string) ([]types.Resource, string, error)
// Read specific resource content
ReadResource(ctx context.Context, uri string) ([]types.ResourceContent, error)
// Check if resource exists
HasResource(ctx context.Context, uri string) bool
// Subscribe to resource updates
SubscribeToResource(ctx context.Context, uri string) error
// Unsubscribe from resource updates
UnsubscribeFromResource(ctx context.Context, uri string) error
}
ResourceProvider provides resource functionality
type SampleProvider ¶
type SampleProvider interface {
// List available samples for a tool or resource
ListSamples(ctx context.Context, itemType types.SampleItemType, itemName string) (*types.ListSamplesResponse, error)
// Get a specific sample by index
GetSample(ctx context.Context, itemType types.SampleItemType, itemName string, index int) (*types.SampleData, error)
// Check if samples are supported
SupportsSamples() bool
}
SampleProvider provides sample data functionality
type Serializer ¶
type Serializer interface {
// Serialize message to bytes
Serialize(message types.Message) ([]byte, error)
// Deserialize bytes to message
Deserialize(data []byte) (types.Message, error)
// Serialize any object to bytes
Marshal(obj interface{}) ([]byte, error)
// Deserialize bytes to object
Unmarshal(data []byte, obj interface{}) error
}
Serializer handles message serialization
type Server ¶
type Server interface {
// Server information
GetServerInfo() types.ServerInfo
GetCapabilities() types.ServerCapabilities
// Server lifecycle
Start(ctx context.Context, transport types.Transport) error
Stop(ctx context.Context) error
HandleInitialize(ctx context.Context, request types.InitializeRequest) (*types.InitializeResponse, error)
HandleInitialized(ctx context.Context) error
// Resource handlers
HandleListResources(ctx context.Context, request types.ListResourcesRequest) (*types.ListResourcesResponse, error)
HandleReadResource(ctx context.Context, request types.ReadResourceRequest) (*types.ReadResourceResponse, error)
HandleSubscribeResource(ctx context.Context, uri string) error
HandleUnsubscribeResource(ctx context.Context, uri string) error
// Tool handlers
HandleListTools(ctx context.Context, request types.ListToolsRequest) (*types.ListToolsResponse, error)
HandleCallTool(ctx context.Context, request types.CallToolRequest) (*types.CallToolResponse, error)
// Prompt handlers
HandleListPrompts(ctx context.Context, request types.ListPromptsRequest) (*types.ListPromptsResponse, error)
HandleGetPrompt(ctx context.Context, request types.GetPromptRequest) (*types.GetPromptResponse, error)
// Sample handlers - List and get training samples
HandleListSamples(ctx context.Context, toolName string) (*types.ListSamplesResponse, error)
HandleGetSample(ctx context.Context, toolName string, index int) (*types.SampleData, error)
// Logging handlers
HandleSetLogLevel(ctx context.Context, request types.SetLogLevelRequest) error
SendLogMessage(ctx context.Context, message types.LogMessage) error
// Cancellation handlers
HandleCancelRequest(ctx context.Context, request types.CancelRequest) error
// Progress handlers
HandleCreateProgress(ctx context.Context, total uint64) (uint64, error)
SendProgressNotification(ctx context.Context, notification types.ProgressNotification) error
// Notification sending
SendResourceUpdated(ctx context.Context, uri string) error
SendToolsChanged(ctx context.Context) error
SendPromptsChanged(ctx context.Context) error
SendRootsChanged(ctx context.Context) error
// Request handling
HandleRequest(ctx context.Context, request types.Message) (interface{}, error)
HandleNotification(ctx context.Context, notification types.Message) error
// Transport operations
SetTransport(transport types.Transport)
Send(ctx context.Context, message types.Message) error
Close() error
}
Server the MCP service interface
func LoadServerSource ¶
LoadServerSource load the mcp server source
type ToolProvider ¶
type ToolProvider interface {
// List all available tools
ListTools(ctx context.Context, cursor string) ([]types.Tool, string, error)
// Execute a tool with given arguments
// extraArgs are optional additional arguments that will be appended to the process call
CallTool(ctx context.Context, name string, arguments interface{}, extraArgs ...interface{}) ([]types.ToolContent, error)
// Check if tool exists
HasTool(ctx context.Context, name string) bool
// Get tool schema
GetToolSchema(ctx context.Context, name string) (types.Tool, error)
}
ToolProvider provides tool functionality
type TransportFactory ¶
type TransportFactory interface {
// Create transport from config
CreateTransport(config types.Config) (types.Transport, error)
// Create stdio transport
CreateStdioTransport() (types.Transport, error)
// Create websocket transport
CreateWebSocketTransport(url string) (types.Transport, error)
// Create tcp transport
CreateTCPTransport(address string) (types.Transport, error)
}
TransportFactory creates transport instances
type Validator ¶
type Validator interface {
// Validate message structure
ValidateMessage(message types.Message) error
// Validate request parameters
ValidateRequest(method string, params interface{}) error
// Validate response result
ValidateResponse(method string, result interface{}) error
// Validate capabilities
ValidateCapabilities(capabilities interface{}) error
}
Validator validates MCP protocol messages