Documentation
¶
Index ¶
- Constants
- func IsBatchRequest(data []byte) bool
- func IsGetToolSchemaRequest(method string) bool
- type HealthConfig
- type HealthMonitor
- func (hm *HealthMonitor) GetStatus() ServerStatusList
- func (hm *HealthMonitor) RegisterServer(server ManagedServer)
- func (hm *HealthMonitor) Start() error
- func (hm *HealthMonitor) Stop()
- func (hm *HealthMonitor) UnregisterServer(name string)
- func (hm *HealthMonitor) WatchStatus(ctx context.Context, interval time.Duration) <-chan ServerStatusList
- type JITConfig
- type JITHandler
- type JSONRPCError
- type JSONRPCRequest
- type JSONRPCResponse
- type ManagedServer
- type ProcessHealth
- type ProcessHealthChecker
- type Proxy
- type RegistryGetter
- type RequestForwarder
- type SchemaCache
- type ServerHealthStatus
- type ServerStatus
- type ServerStatusList
Examples ¶
Constants ¶
View Source
const ( ErrCodeParseError = -32700 ErrCodeInvalidRequest = -32600 ErrCodeMethodNotFound = -32601 ErrCodeInvalidParams = -32602 ErrCodeInternalError = -32603 )
Variables ¶
This section is empty.
Functions ¶
func IsBatchRequest ¶
func IsGetToolSchemaRequest ¶ added in v0.2.0
Types ¶
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 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
time.Sleep(1 * time.Millisecond)
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 JSONRPCError ¶
type JSONRPCError struct {
Code int `json:"code"`
Message string `json:"message"`
Data json.RawMessage `json:"data,omitempty"`
}
func NewJSONRPCError ¶
func NewJSONRPCError(code int, message string) *JSONRPCError
func (*JSONRPCError) Error ¶
func (e *JSONRPCError) Error() string
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) ([]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 *JSONRPCError `json:"error,omitempty"`
ID interface{} `json:"id"`
}
func ParseJSONRPCResponse ¶
func ParseJSONRPCResponse(data []byte) (*JSONRPCResponse, error)
type ManagedServer ¶ added in v0.2.0
type ProcessHealth ¶ added in v0.2.0
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 (*Proxy) ForwardLoop ¶
type RegistryGetter ¶ added in v0.2.0
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"`
}
Click to show internal directories.
Click to hide internal directories.