Documentation
¶
Overview ¶
Package pool provides stdio MCP server subprocess pooling and management. It handles concurrent request processing, health monitoring, and lifecycle management for multiple stdio-based MCP servers.
Index ¶
- type HTTPClientPool
- func (p *HTTPClientPool) Close() error
- func (p *HTTPClientPool) GetServerState(name string) (ServerState, error)
- func (p *HTTPClientPool) HasServer(name string) bool
- func (p *HTTPClientPool) IsServerMCPInitialized(name string) bool
- func (p *HTTPClientPool) ListServers() []string
- func (p *HTTPClientPool) MarkServerMCPInitialized(name string)
- func (p *HTTPClientPool) RestartServer(ctx context.Context, name string) error
- func (p *HTTPClientPool) SendRequest(ctx context.Context, serverName string, req *proxy.JSONRPCRequest, ...) (*proxy.JSONRPCResponse, error)
- func (p *HTTPClientPool) SendRequestToServer(ctx context.Context, name string, method string, params json.RawMessage, ...) (*Response, error)
- func (p *HTTPClientPool) SendRequestToServerWithID(ctx context.Context, name string, method string, params json.RawMessage, ...) (*Response, error)
- func (p *HTTPClientPool) SendServerNotification(ctx context.Context, name string, method string, params map[string]interface{}) error
- func (p *HTTPClientPool) ServerCount() int
- func (p *HTTPClientPool) StartServer(ctx context.Context, config *migrate.ServerConfig) error
- type HTTPClientServer
- func (s *HTTPClientServer) CallTool(ctx context.Context, name string, args map[string]interface{}) (*mcp.CallToolResult, error)
- func (s *HTTPClientServer) Close() error
- func (s *HTTPClientServer) Initialize(ctx context.Context) error
- func (s *HTTPClientServer) ListTools(ctx context.Context) ([]mcp.Tool, error)
- type HealthCheckResult
- type HealthChecker
- func (hc *HealthChecker) CheckServer(ctx context.Context, name string) HealthCheckResult
- func (hc *HealthChecker) GetAllHealth() map[string]HealthCheckResult
- func (hc *HealthChecker) GetServerHealth(name string) (HealthStatus, error)
- func (hc *HealthChecker) RegisterServer(name string)
- func (hc *HealthChecker) SetMaxFailures(n int)
- func (hc *HealthChecker) Start(ctx context.Context, interval time.Duration)
- func (hc *HealthChecker) Stop()
- func (hc *HealthChecker) UnregisterServer(name string)
- type HealthStatus
- type PingRequest
- type PingResponse
- type PoolQueueManager
- func (qm *PoolQueueManager) GetOrCreateQueue(name string, maxConcurrent int, queueTimeout time.Duration) *ServerQueue
- func (qm *PoolQueueManager) GetQueueStats(name string) (active int, pending int, atCapacity bool)
- func (qm *PoolQueueManager) ListQueues() []string
- func (qm *PoolQueueManager) RemoveQueue(name string)
- type ReconnectSettings
- type Request
- type RequestQueue
- type Response
- type SSEPool
- func (p *SSEPool) Close() error
- func (p *SSEPool) GetServerState(name string) (ServerState, error)
- func (p *SSEPool) HasServer(name string) bool
- func (p *SSEPool) IsServerMCPInitialized(name string) bool
- func (p *SSEPool) ListServers() []string
- func (p *SSEPool) MarkServerMCPInitialized(name string)
- func (p *SSEPool) RestartServer(ctx context.Context, name string) error
- func (p *SSEPool) SendRequest(ctx context.Context, serverName string, req *proxy.JSONRPCRequest, ...) (*proxy.JSONRPCResponse, error)
- func (p *SSEPool) SendRequestToServer(ctx context.Context, name string, method string, params json.RawMessage, ...) (*Response, error)
- func (p *SSEPool) SendRequestToServerWithID(ctx context.Context, name string, method string, params json.RawMessage, ...) (*Response, error)
- func (p *SSEPool) SendServerNotification(ctx context.Context, name string, method string, params map[string]interface{}) error
- func (p *SSEPool) ServerCount() int
- func (p *SSEPool) StartServer(ctx context.Context, config *migrate.ServerConfig) error
- type SSEServer
- type ServerHandle
- type ServerQueue
- type ServerSource
- type ServerState
- type ServerStats
- type StdioPool
- func (p *StdioPool) Close() error
- func (p *StdioPool) GetOrStartServer(ctx context.Context, name string) (*StdioServerV2, error)
- func (p *StdioPool) GetServer(name string) (*StdioServerV2, error)
- func (p *StdioPool) GetServerState(name string) (ServerState, error)
- func (p *StdioPool) GetServerStats(name string) (ServerStats, error)
- func (p *StdioPool) HasServer(name string) bool
- func (p *StdioPool) IsServerMCPInitialized(name string) bool
- func (p *StdioPool) ListServers() []string
- func (p *StdioPool) MarkServerMCPInitialized(name string)
- func (p *StdioPool) PutRequest(name string, req Request) error
- func (p *StdioPool) RestartServer(ctx context.Context, name string) error
- func (p *StdioPool) SendNotificationToServer(ctx context.Context, name string, method string, params json.RawMessage) error
- func (p *StdioPool) SendRequest(ctx context.Context, serverName string, req *proxy.JSONRPCRequest, ...) (*proxy.JSONRPCResponse, error)
- func (p *StdioPool) SendRequestToServer(ctx context.Context, name string, method string, params json.RawMessage, ...) (*Response, error)
- func (p *StdioPool) SendRequestToServerWithID(ctx context.Context, name string, method string, params json.RawMessage, ...) (*Response, error)
- func (p *StdioPool) SendServerNotification(ctx context.Context, name string, method string, params map[string]interface{}) error
- func (p *StdioPool) ServerCount() int
- func (p *StdioPool) SetReconnect(settings ReconnectSettings)
- func (p *StdioPool) StartAllServers(ctx context.Context, configs []*migrate.ServerConfig) error
- func (p *StdioPool) StartServer(ctx context.Context, config *migrate.ServerConfig) error
- func (p *StdioPool) StopServer(name string) error
- type StdioServerConfig
- type StdioServerV2
- type UnifiedPool
- func (p *UnifiedPool) Close() error
- func (p *UnifiedPool) GetServerState(name string) (ServerState, error)
- func (p *UnifiedPool) IsServerMCPInitialized(name string) bool
- func (p *UnifiedPool) ListServers() []string
- func (p *UnifiedPool) MarkServerMCPInitialized(name string)
- func (p *UnifiedPool) RestartServer(ctx context.Context, name string) error
- func (p *UnifiedPool) SendRequest(ctx context.Context, serverName string, req *proxy.JSONRPCRequest, ...) (*proxy.JSONRPCResponse, error)
- func (p *UnifiedPool) SendRequestToServer(ctx context.Context, name string, method string, params json.RawMessage, ...) (*Response, error)
- func (p *UnifiedPool) SendRequestToServerWithID(ctx context.Context, name string, method string, params json.RawMessage, ...) (*Response, error)
- func (p *UnifiedPool) SendServerNotification(ctx context.Context, name string, method string, params map[string]interface{}) error
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HTTPClientPool ¶ added in v0.5.0
type HTTPClientPool struct {
// contains filtered or unexported fields
}
func NewHTTPClientPool ¶ added in v0.5.0
func NewHTTPClientPool(logger *slog.Logger) *HTTPClientPool
func (*HTTPClientPool) Close ¶ added in v0.5.0
func (p *HTTPClientPool) Close() error
func (*HTTPClientPool) GetServerState ¶ added in v0.5.0
func (p *HTTPClientPool) GetServerState(name string) (ServerState, error)
func (*HTTPClientPool) HasServer ¶ added in v0.5.0
func (p *HTTPClientPool) HasServer(name string) bool
func (*HTTPClientPool) IsServerMCPInitialized ¶ added in v0.7.1
func (p *HTTPClientPool) IsServerMCPInitialized(name string) bool
func (*HTTPClientPool) ListServers ¶ added in v0.5.0
func (p *HTTPClientPool) ListServers() []string
func (*HTTPClientPool) MarkServerMCPInitialized ¶ added in v0.7.1
func (p *HTTPClientPool) MarkServerMCPInitialized(name string)
func (*HTTPClientPool) RestartServer ¶ added in v0.5.0
func (p *HTTPClientPool) RestartServer(ctx context.Context, name string) error
func (*HTTPClientPool) SendRequest ¶ added in v0.5.0
func (p *HTTPClientPool) SendRequest(ctx context.Context, serverName string, req *proxy.JSONRPCRequest, timeout time.Duration) (*proxy.JSONRPCResponse, error)
func (*HTTPClientPool) SendRequestToServer ¶ added in v0.5.0
func (*HTTPClientPool) SendRequestToServerWithID ¶ added in v0.5.0
func (*HTTPClientPool) SendServerNotification ¶ added in v0.5.0
func (*HTTPClientPool) ServerCount ¶ added in v0.5.0
func (p *HTTPClientPool) ServerCount() int
func (*HTTPClientPool) StartServer ¶ added in v0.5.0
func (p *HTTPClientPool) StartServer(ctx context.Context, config *migrate.ServerConfig) error
type HTTPClientServer ¶ added in v0.5.0
type HTTPClientServer struct {
// contains filtered or unexported fields
}
func NewHTTPClientServer ¶ added in v0.5.0
func NewHTTPClientServer(name string, config *migrate.ServerConfig, logger *slog.Logger) *HTTPClientServer
func (*HTTPClientServer) CallTool ¶ added in v0.5.0
func (s *HTTPClientServer) CallTool(ctx context.Context, name string, args map[string]interface{}) (*mcp.CallToolResult, error)
func (*HTTPClientServer) Close ¶ added in v0.5.0
func (s *HTTPClientServer) Close() error
func (*HTTPClientServer) Initialize ¶ added in v0.5.0
func (s *HTTPClientServer) Initialize(ctx context.Context) error
type HealthCheckResult ¶
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
func NewHealthChecker ¶
func NewHealthChecker(pool *StdioPool, logger *slog.Logger) *HealthChecker
func (*HealthChecker) CheckServer ¶
func (hc *HealthChecker) CheckServer(ctx context.Context, name string) HealthCheckResult
func (*HealthChecker) GetAllHealth ¶
func (hc *HealthChecker) GetAllHealth() map[string]HealthCheckResult
func (*HealthChecker) GetServerHealth ¶
func (hc *HealthChecker) GetServerHealth(name string) (HealthStatus, error)
func (*HealthChecker) RegisterServer ¶
func (hc *HealthChecker) RegisterServer(name string)
func (*HealthChecker) SetMaxFailures ¶ added in v0.9.0
func (hc *HealthChecker) SetMaxFailures(n int)
func (*HealthChecker) Start ¶
func (hc *HealthChecker) Start(ctx context.Context, interval time.Duration)
func (*HealthChecker) Stop ¶
func (hc *HealthChecker) Stop()
Stop signals the checker loop to exit. It is idempotent.
func (*HealthChecker) UnregisterServer ¶
func (hc *HealthChecker) UnregisterServer(name string)
type HealthStatus ¶
type HealthStatus string
const ( HealthUnknown HealthStatus = "unknown" HealthHealthy HealthStatus = "healthy" HealthDegraded HealthStatus = "degraded" HealthUnhealthy HealthStatus = "unhealthy" HealthError HealthStatus = "error" )
type PingRequest ¶
type PingResponse ¶
type PingResponse struct {
ID interface{} `json:"id"`
JSONRPC string `json:"jsonrpc"`
Result json.RawMessage `json:"result,omitempty"`
Error *errors.JSONRPCError `json:"error,omitempty"`
}
type PoolQueueManager ¶
type PoolQueueManager struct {
// contains filtered or unexported fields
}
func NewPoolQueueManager ¶
func NewPoolQueueManager(logger *slog.Logger) *PoolQueueManager
func (*PoolQueueManager) GetOrCreateQueue ¶
func (qm *PoolQueueManager) GetOrCreateQueue(name string, maxConcurrent int, queueTimeout time.Duration) *ServerQueue
func (*PoolQueueManager) GetQueueStats ¶
func (qm *PoolQueueManager) GetQueueStats(name string) (active int, pending int, atCapacity bool)
func (*PoolQueueManager) ListQueues ¶
func (qm *PoolQueueManager) ListQueues() []string
func (*PoolQueueManager) RemoveQueue ¶
func (qm *PoolQueueManager) RemoveQueue(name string)
type ReconnectSettings ¶ added in v0.9.0
type ReconnectSettings struct {
// Disabled is the reconnect.enabled=false master switch: crashed servers
// are left in the error state instead of being auto-restarted. Explicit
// restarts (request- or operator-triggered) still work.
Disabled bool
MaxRestartAttempts int
RestartBackoff time.Duration
StableWindow time.Duration
}
ReconnectSettings controls the automatic restart behavior of stdio servers.
type Request ¶
type Request struct {
Method string `json:"method"`
Params json.RawMessage `json:"params,omitempty"`
ID interface{} `json:"id"`
Timeout time.Duration `json:"-"`
ResultCh chan *Response `json:"-"`
ErrorCh chan error `json:"-"`
}
Request represents a JSON-RPC request for an MCP server.
func (Request) MarshalJSON ¶ added in v0.3.0
MarshalJSON serializes the Request to JSON with JSON-RPC 2.0 formatting.
type RequestQueue ¶
type RequestQueue struct {
// contains filtered or unexported fields
}
func NewRequestQueue ¶
func (*RequestQueue) Enqueue ¶
func (q *RequestQueue) Enqueue(req Request) bool
func (*RequestQueue) IsEmpty ¶
func (q *RequestQueue) IsEmpty() bool
func (*RequestQueue) IsFull ¶
func (q *RequestQueue) IsFull() bool
func (*RequestQueue) Size ¶
func (q *RequestQueue) Size() int
type Response ¶
type Response struct {
Result json.RawMessage `json:"result,omitempty"`
Error *errors.JSONRPCError `json:"error,omitempty"`
ID interface{} `json:"id"`
}
Response represents a JSON-RPC response from an MCP server.
type SSEPool ¶ added in v0.5.0
type SSEPool struct {
// contains filtered or unexported fields
}
func NewSSEPool ¶ added in v0.5.0
func (*SSEPool) GetServerState ¶ added in v0.5.0
func (p *SSEPool) GetServerState(name string) (ServerState, error)
func (*SSEPool) IsServerMCPInitialized ¶ added in v0.7.1
func (*SSEPool) ListServers ¶ added in v0.5.0
func (*SSEPool) MarkServerMCPInitialized ¶ added in v0.7.1
func (*SSEPool) RestartServer ¶ added in v0.5.0
func (*SSEPool) SendRequest ¶ added in v0.5.0
func (*SSEPool) SendRequestToServer ¶ added in v0.5.0
func (*SSEPool) SendRequestToServerWithID ¶ added in v0.5.0
func (*SSEPool) SendServerNotification ¶ added in v0.5.0
func (*SSEPool) ServerCount ¶ added in v0.5.0
func (*SSEPool) StartServer ¶ added in v0.5.0
type SSEServer ¶ added in v0.5.0
type SSEServer struct {
// contains filtered or unexported fields
}
func NewSSEServer ¶ added in v0.5.0
func (*SSEServer) Initialize ¶ added in v0.5.0
type ServerHandle ¶
type ServerHandle struct {
Name string
State ServerState
Stats ServerStats
}
type ServerQueue ¶
type ServerQueue struct {
// contains filtered or unexported fields
}
func NewServerQueue ¶
func (*ServerQueue) Enqueue ¶
func (sq *ServerQueue) Enqueue(req Request) bool
func (*ServerQueue) IsAtCapacity ¶
func (sq *ServerQueue) IsAtCapacity() bool
func (*ServerQueue) PendingCount ¶
func (sq *ServerQueue) PendingCount() int
func (*ServerQueue) Release ¶
func (sq *ServerQueue) Release()
type ServerSource ¶ added in v0.5.0
type ServerSource interface {
SendRequestToServer(ctx context.Context, name string, method string, params json.RawMessage, timeout time.Duration) (*Response, error)
SendRequestToServerWithID(ctx context.Context, name string, method string, params json.RawMessage, timeout time.Duration, id int) (*Response, error)
SendServerNotification(ctx context.Context, name string, method string, params map[string]interface{}) error
ListServers() []string
GetServerState(name string) (ServerState, error)
RestartServer(ctx context.Context, name string) error
IsServerMCPInitialized(name string) bool
MarkServerMCPInitialized(name string)
Close() error
}
ServerSource is the interface for sending requests to MCP servers.
type ServerState ¶
type ServerState string
ServerState represents the current state of an MCP server.
const ( StateIdle ServerState = "idle" StateRunning ServerState = "running" StateBusy ServerState = "busy" StateStopping ServerState = "stopping" StateStopped ServerState = "stopped" StateStarting ServerState = "starting" StateError ServerState = "error" StateDisconnected ServerState = "disconnected" StateUnknown ServerState = "unknown" )
type ServerStats ¶
type StdioPool ¶
type StdioPool struct {
// contains filtered or unexported fields
}
StdioPool manages multiple stdio-based MCP server subprocesses.
func NewStdioPool ¶
NewStdioPool creates a new StdioPool with the specified maximum servers per name and idle timeout.
func (*StdioPool) GetOrStartServer ¶ added in v0.6.1
func (*StdioPool) GetServerState ¶
func (p *StdioPool) GetServerState(name string) (ServerState, error)
func (*StdioPool) GetServerStats ¶
func (p *StdioPool) GetServerStats(name string) (ServerStats, error)
func (*StdioPool) IsServerMCPInitialized ¶ added in v0.7.1
func (*StdioPool) ListServers ¶
func (*StdioPool) MarkServerMCPInitialized ¶ added in v0.7.1
func (*StdioPool) RestartServer ¶
func (*StdioPool) SendNotificationToServer ¶ added in v0.3.0
func (*StdioPool) SendRequest ¶
func (*StdioPool) SendRequestToServer ¶ added in v0.3.0
func (*StdioPool) SendRequestToServerWithID ¶ added in v0.3.0
func (*StdioPool) SendServerNotification ¶ added in v0.3.0
func (*StdioPool) ServerCount ¶
func (*StdioPool) SetReconnect ¶ added in v0.9.0
func (p *StdioPool) SetReconnect(settings ReconnectSettings)
SetReconnect applies reconnect settings to the pool. It takes effect on servers already in the pool and on every server started afterwards.
func (*StdioPool) StartAllServers ¶
func (*StdioPool) StartServer ¶
func (*StdioPool) StopServer ¶
type StdioServerConfig ¶
type StdioServerV2 ¶
type StdioServerV2 struct {
// contains filtered or unexported fields
}
func (*StdioServerV2) IsMCPInitialized ¶ added in v0.7.1
func (s *StdioServerV2) IsMCPInitialized() bool
func (*StdioServerV2) SetMCPInitialized ¶ added in v0.7.1
func (s *StdioServerV2) SetMCPInitialized()
type UnifiedPool ¶ added in v0.5.0
type UnifiedPool struct {
// contains filtered or unexported fields
}
func NewUnifiedPool ¶ added in v0.5.0
func NewUnifiedPool(stdio *StdioPool, http *HTTPClientPool, sse *SSEPool, logger *slog.Logger) *UnifiedPool
func (*UnifiedPool) Close ¶ added in v0.5.0
func (p *UnifiedPool) Close() error
func (*UnifiedPool) GetServerState ¶ added in v0.5.0
func (p *UnifiedPool) GetServerState(name string) (ServerState, error)
func (*UnifiedPool) IsServerMCPInitialized ¶ added in v0.7.1
func (p *UnifiedPool) IsServerMCPInitialized(name string) bool
func (*UnifiedPool) ListServers ¶ added in v0.5.0
func (p *UnifiedPool) ListServers() []string
func (*UnifiedPool) MarkServerMCPInitialized ¶ added in v0.7.1
func (p *UnifiedPool) MarkServerMCPInitialized(name string)
func (*UnifiedPool) RestartServer ¶ added in v0.5.0
func (p *UnifiedPool) RestartServer(ctx context.Context, name string) error
func (*UnifiedPool) SendRequest ¶ added in v0.5.0
func (p *UnifiedPool) SendRequest(ctx context.Context, serverName string, req *proxy.JSONRPCRequest, timeout time.Duration) (*proxy.JSONRPCResponse, error)