pool

package
v0.2.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 3, 2026 License: MIT Imports: 15 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

View Source
const (
	ErrCodeInternalError = -32603
	ErrCodeServerError   = -32000
	ErrCodeTimeout       = -32001
)

Variables

This section is empty.

Functions

This section is empty.

Types

type HealthCheckResult

type HealthCheckResult struct {
	ServerName string
	Status     HealthStatus
	LatencyMs  float64
	Error      string
	CheckedAt  time.Time
}

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) Start

func (hc *HealthChecker) Start(ctx context.Context, interval time.Duration)

func (*HealthChecker) Stop

func (hc *HealthChecker) Stop()

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 JSONRPCError

type JSONRPCError struct {
	Code    int             `json:"code"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data,omitempty"`
}

func (*JSONRPCError) Error

func (e *JSONRPCError) Error() string

type PingRequest

type PingRequest struct {
	ID      interface{} `json:"id"`
	JSONRPC string      `json:"jsonrpc"`
	Method  string      `json:"method"`
}

type PingResponse

type PingResponse struct {
	ID      interface{}     `json:"id"`
	JSONRPC string          `json:"jsonrpc"`
	Result  json.RawMessage `json:"result,omitempty"`
	Error   *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 Request

type Request struct {
	Method   string          `json:"method"`
	Params   json.RawMessage `json:"params,omitempty"`
	ID       interface{}     `json:"id"`
	Timeout  time.Duration
	ResultCh chan *Response
	ErrorCh  chan error
}

type RequestQueue

type RequestQueue struct {
	// contains filtered or unexported fields
}

func NewRequestQueue

func NewRequestQueue(maxSize int, timeout time.Duration, logger *slog.Logger) *RequestQueue

func (*RequestQueue) Dequeue

func (q *RequestQueue) Dequeue(ctx context.Context) (Request, bool)

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  *JSONRPCError   `json:"error,omitempty"`
	ID     interface{}     `json:"id"`
}

type ServerHandle

type ServerHandle struct {
	Name  string
	State ServerState
	Stats ServerStats
}

type ServerQueue

type ServerQueue struct {
	// contains filtered or unexported fields
}

func NewServerQueue

func NewServerQueue(name string, maxConcurrent int, queueTimeout time.Duration, logger *slog.Logger) *ServerQueue

func (*ServerQueue) Acquire

func (sq *ServerQueue) Acquire(timeout time.Duration) bool

func (*ServerQueue) Dequeue

func (sq *ServerQueue) Dequeue(ctx context.Context) (Request, bool)

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 ServerState

type ServerState string
const (
	StateIdle     ServerState = "idle"
	StateRunning  ServerState = "running"
	StateBusy     ServerState = "busy"
	StateStopping ServerState = "stopping"
	StateStopped  ServerState = "stopped"
	StateStarting ServerState = "starting"
	StateError    ServerState = "error"
)

type ServerStats

type ServerStats struct {
	RequestCount   int64
	ErrorCount     int64
	AvgLatencyMs   float64
	LastRequestAt  time.Time
	RestartCount   int
	CurrentBackoff time.Duration
}

type StdioPool

type StdioPool struct {
	// contains filtered or unexported fields
}

func NewStdioPool

func NewStdioPool(maxPerServer int, idleTimeout time.Duration, logger *slog.Logger) *StdioPool

func (*StdioPool) Close

func (p *StdioPool) Close() error

func (*StdioPool) GetServer

func (p *StdioPool) GetServer(name string) (*StdioServerV2, error)

func (*StdioPool) GetServerState

func (p *StdioPool) GetServerState(name string) (ServerState, error)

func (*StdioPool) GetServerStats

func (p *StdioPool) GetServerStats(name string) (ServerStats, error)

func (*StdioPool) ListServers

func (p *StdioPool) ListServers() []string

func (*StdioPool) PutRequest

func (p *StdioPool) PutRequest(name string, req Request) error

func (*StdioPool) RestartServer

func (p *StdioPool) RestartServer(ctx context.Context, name string) error

func (*StdioPool) SendRequest

func (p *StdioPool) SendRequest(ctx context.Context, serverName string, req *proxy.JSONRPCRequest, timeout time.Duration) (*proxy.JSONRPCResponse, error)

func (*StdioPool) ServerCount

func (p *StdioPool) ServerCount() int

func (*StdioPool) StartAllServers

func (p *StdioPool) StartAllServers(ctx context.Context, configs []*migrate.ServerConfig) error

func (*StdioPool) StartServer

func (p *StdioPool) StartServer(ctx context.Context, config *migrate.ServerConfig) error

func (*StdioPool) StopServer

func (p *StdioPool) StopServer(name string) error

type StdioServerConfig

type StdioServerConfig struct {
	Name           string
	Command        string
	Args           []string
	Env            []string
	CWD            string
	MaxConcurrent  int
	IdleTimeout    time.Duration
	RequestTimeout time.Duration
}

type StdioServerV2

type StdioServerV2 struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL