proxy

package
v0.9.2 Latest Latest
Warning

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

Go to latest
Published: Aug 30, 2026 License: MIT Imports: 18 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

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func IsBatchRequest

func IsBatchRequest(data []byte) bool

func IsGetToolSchemaRequest added in v0.2.0

func IsGetToolSchemaRequest(method string) bool

func StreamableHTTPHandler added in v0.7.0

func StreamableHTTPHandler(handler MCPHandler, logger *slog.Logger) http.Handler

Types

type HTTPTransport added in v0.7.0

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

func NewHTTPTransport added in v0.7.0

func NewHTTPTransport(config HTTPTransportConfig, opts ...HTTPTransportOption) *HTTPTransport

func (*HTTPTransport) Close added in v0.7.0

func (t *HTTPTransport) Close() error

func (*HTTPTransport) GetAddr added in v0.7.0

func (t *HTTPTransport) GetAddr() string

func (*HTTPTransport) IsRunning added in v0.7.0

func (t *HTTPTransport) IsRunning() bool

func (*HTTPTransport) ListenAndServe added in v0.7.0

func (t *HTTPTransport) ListenAndServe() error

func (*HTTPTransport) ListenAndServeContext added in v0.7.0

func (t *HTTPTransport) ListenAndServeContext(ctx context.Context) error

func (*HTTPTransport) RegisterHandler added in v0.7.0

func (t *HTTPTransport) RegisterHandler(pattern string, handler http.Handler)

type HTTPTransportConfig added in v0.7.0

type HTTPTransportConfig struct {
	Port           string
	ReadTimeout    time.Duration
	WriteTimeout   time.Duration
	MaxHeaderBytes int
}

func DefaultHTTPTransportConfig added in v0.7.0

func DefaultHTTPTransportConfig() HTTPTransportConfig

type HTTPTransportOption added in v0.7.0

type HTTPTransportOption func(*HTTPTransport)

func WithHTTPLogger added in v0.7.0

func WithHTTPLogger(logger *slog.Logger) HTTPTransportOption

type HealthConfig added in v0.2.0

type HealthConfig struct {
	CheckInterval      time.Duration
	ResponseTimeout    time.Duration
	MaxRestartAttempts int
	RestartBackoff     time.Duration
}

func DefaultHealthConfig added in v0.2.0

func DefaultHealthConfig() *HealthConfig

type HealthMonitor added in v0.2.0

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

func NewHealthMonitor added in v0.2.0

func NewHealthMonitor(config *HealthConfig, logger *slog.Logger) *HealthMonitor

func (*HealthMonitor) GetStatus added in v0.2.0

func (hm *HealthMonitor) GetStatus() ServerStatusList

func (*HealthMonitor) RegisterServer added in v0.2.0

func (hm *HealthMonitor) RegisterServer(server ManagedServer)

func (*HealthMonitor) Start added in v0.2.0

func (hm *HealthMonitor) Start() error

func (*HealthMonitor) Stop added in v0.2.0

func (hm *HealthMonitor) Stop()

func (*HealthMonitor) UnregisterServer added in v0.2.0

func (hm *HealthMonitor) UnregisterServer(name string)

func (*HealthMonitor) WatchStatus added in v0.2.0

func (hm *HealthMonitor) WatchStatus(ctx context.Context, interval time.Duration) <-chan ServerStatusList

type JITConfig added in v0.2.0

type JITConfig struct {
	Enabled   bool
	CacheSize int
	CacheTTL  string
}

type JITHandler added in v0.2.0

type JITHandler struct {
	// contains filtered or unexported fields
}
Example
cache := newMockSchemaCache()
registry := newMockRegistry()
forwarder := newMockForwarder()

forwarder.response = JSONRPCResponse{
	JSONRPC: "2.0",
	Result:  json.RawMessage(`{"name":"example-tool"}`),
	ID:      1,
}

registry.AddSchema("myserver", "example-tool", json.RawMessage(`{"name":"example-tool","description":"Example"}`))

handler := NewJITHandler(cache, registry, forwarder, nil, "myserver", true)

params := json.RawMessage(`{"name":"example-tool"}`)
req := JSONRPCRequest{
	JSONRPC: "2.0",
	Method:  "get_tool_schema",
	Params:  params,
	ID:      1,
}

resp, _ := handler.HandleGetToolSchema(context.Background(), req)
_ = resp

cached, _ := cache.Get("myserver/example-tool")
_ = cached

func NewJITHandler added in v0.2.0

func NewJITHandler(cache SchemaCache, registry RegistryGetter, forward RequestForwarder, logger *slog.Logger, serverName string, enabled bool) *JITHandler

func (*JITHandler) HandleGetToolSchema added in v0.2.0

func (h *JITHandler) HandleGetToolSchema(ctx context.Context, req JSONRPCRequest) (JSONRPCResponse, error)

type JSONRPCRequest

type JSONRPCRequest struct {
	JSONRPC string          `json:"jsonrpc"`
	Method  string          `json:"method"`
	Params  json.RawMessage `json:"params,omitempty"`
	ID      interface{}     `json:"id"`
}

func ParseJSONRPCBatchRequest

func ParseJSONRPCBatchRequest(data []byte, maxBatchSize int) ([]JSONRPCRequest, error)

func ParseJSONRPCRequest

func ParseJSONRPCRequest(data []byte) (*JSONRPCRequest, error)

type JSONRPCResponse

type JSONRPCResponse struct {
	JSONRPC string               `json:"jsonrpc"`
	Result  json.RawMessage      `json:"result,omitempty"`
	Error   *errors.JSONRPCError `json:"error,omitempty"`
	ID      interface{}          `json:"id"`
}

func ParseJSONRPCResponse

func ParseJSONRPCResponse(data []byte) (*JSONRPCResponse, error)

type MCPHandler added in v0.7.0

type MCPHandler func(ctx context.Context, req *JSONRPCRequest) (*JSONRPCResponse, error)

type ManagedServer added in v0.2.0

type ManagedServer interface {
	Name() string
	PID() int
	IsRunning() bool
	StartTime() time.Time
	LastResponseTime() time.Time
	RequestCount() int64
	ErrorCount() int64
	OnCrash(callback func())
	OnRestart(callback func())
}

type ProcessHealth added in v0.2.0

type ProcessHealth struct {
	PID        int
	MemoryMB   int64
	CPUPercent float64
	Status     string
	IsAlive    bool
}

type ProcessHealthChecker added in v0.2.0

type ProcessHealthChecker struct {
}

func NewProcessHealthChecker added in v0.2.0

func NewProcessHealthChecker() *ProcessHealthChecker

func (*ProcessHealthChecker) CheckProcessHealth added in v0.2.0

func (phc *ProcessHealthChecker) CheckProcessHealth(pid int) ProcessHealth

type Proxy

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

func NewProxy

func NewProxy(upstreamAddr string, logger *slog.Logger) *Proxy

func (*Proxy) Close

func (p *Proxy) Close() error

func (*Proxy) Connect

func (p *Proxy) Connect(ctx context.Context) error

func (*Proxy) ForwardLoop

func (p *Proxy) ForwardLoop(ctx context.Context, ideConn net.Conn) error

func (*Proxy) ForwardLoopWithJSONRPC

func (p *Proxy) ForwardLoopWithJSONRPC(ctx context.Context, ideConn net.Conn) error

type RegistryGetter added in v0.2.0

type RegistryGetter interface {
	GetToolSchema(ctx context.Context, serverID, toolName string) (json.RawMessage, error)
}

type RequestForwarder added in v0.2.0

type RequestForwarder interface {
	ForwardRequest(ctx context.Context, req JSONRPCRequest) (JSONRPCResponse, error)
}

type SchemaCache added in v0.2.0

type SchemaCache interface {
	Get(key string) (json.RawMessage, bool)
	Set(key string, schema json.RawMessage)
	Delete(key string)
	Clear()
}

type ServerHealthStatus added in v0.2.0

type ServerHealthStatus string
const (
	StatusRunning      ServerHealthStatus = "running"
	StatusError        ServerHealthStatus = "error"
	StatusStopped      ServerHealthStatus = "stopped"
	StatusStarting     ServerHealthStatus = "starting"
	StatusUnresponsive ServerHealthStatus = "unresponsive"
)

type ServerStatus added in v0.2.0

type ServerStatus struct {
	Name             string             `json:"name"`
	Status           ServerHealthStatus `json:"status"`
	Uptime           time.Duration      `json:"uptime"`
	LastResponseTime time.Time          `json:"last_response_time"`
	LastError        string             `json:"last_error,omitempty"`
	RestartCount     int                `json:"restart_count"`
	RequestCount     int64              `json:"request_count"`
	ErrorRate        float64            `json:"error_rate"`
	MemoryMB         int64              `json:"memory_mb,omitempty"`
	CPUPercent       float64            `json:"cpu_percent,omitempty"`
}

type ServerStatusList added in v0.2.0

type ServerStatusList struct {
	Timestamp time.Time      `json:"timestamp"`
	Servers   []ServerStatus `json:"servers"`
}

type SessionCache added in v0.7.0

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

func NewSessionCache added in v0.7.0

func NewSessionCache(ttl time.Duration, maxSize int) *SessionCache

func (*SessionCache) Clear added in v0.7.0

func (sc *SessionCache) Clear()

func (*SessionCache) GetOrCreateSession added in v0.7.0

func (sc *SessionCache) GetOrCreateSession(serverName string) (*SessionState, error)

func (*SessionCache) GetSession added in v0.7.0

func (sc *SessionCache) GetSession(serverName string) (*SessionState, bool)

func (*SessionCache) ListSessions added in v0.7.0

func (sc *SessionCache) ListSessions() []string

func (*SessionCache) RemoveSession added in v0.7.0

func (sc *SessionCache) RemoveSession(serverName string)

func (*SessionCache) RestoreSession added in v0.7.0

func (sc *SessionCache) RestoreSession(state *SessionState) error

func (*SessionCache) Size added in v0.7.0

func (sc *SessionCache) Size() int

type SessionState added in v0.7.0

type SessionState struct {
	ServerName       string          `json:"server_name"`
	ClientID         string          `json:"client_id"`
	Capabilities     []string        `json:"capabilities,omitempty"`
	InitializeParams json.RawMessage `json:"init_params,omitempty"`
	CreatedAt        time.Time       `json:"created_at"`
	LastUsedAt       time.Time       `json:"last_used_at"`
}

func DeserializeSessionState added in v0.7.0

func DeserializeSessionState(data []byte) (*SessionState, error)

func (*SessionState) Serialize added in v0.7.0

func (ss *SessionState) Serialize() ([]byte, error)

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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