Documentation
¶
Overview ¶
Package healthcheck provides common healthcheck functionality for ToolHive proxies. It includes MCP server status information and standardized response formats.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type HealthChecker ¶
type HealthChecker struct {
// contains filtered or unexported fields
}
HealthChecker provides health check functionality for proxies
func NewHealthChecker ¶
func NewHealthChecker(transport string, mcpPinger MCPPinger) *HealthChecker
NewHealthChecker creates a new health checker instance
func (*HealthChecker) CheckHealth ¶
func (hc *HealthChecker) CheckHealth(ctx context.Context) *HealthResponse
CheckHealth performs a comprehensive health check including MCP server status
func (*HealthChecker) ServeHTTP ¶
func (hc *HealthChecker) ServeHTTP(w http.ResponseWriter, r *http.Request)
ServeHTTP implements http.Handler for health check endpoints
type HealthResponse ¶
type HealthResponse struct {
// Status is the overall health status
Status HealthStatus `json:"status"`
// Timestamp is when the health check was performed
Timestamp time.Time `json:"timestamp"`
// Version contains ToolHive version information
Version versions.VersionInfo `json:"version"`
// Transport indicates the type of transport used by the MCP server (stdio, sse)
Transport string `json:"transport"`
// MCP contains MCP server status information
MCP *MCPStatus `json:"mcp,omitempty"`
}
HealthResponse represents the standardized health check response
type HealthStatus ¶
type HealthStatus string
HealthStatus represents the overall health status
const ( // StatusHealthy indicates the service is healthy StatusHealthy HealthStatus = "healthy" // StatusUnhealthy indicates the service is unhealthy StatusUnhealthy HealthStatus = "unhealthy" // StatusDegraded indicates the service is partially healthy StatusDegraded HealthStatus = "degraded" )
type MCPPinger ¶
type MCPPinger interface {
// Ping sends a ping request to the MCP server and returns the response time
// The implementation should send a JSON-RPC request with method "ping" and no parameters,
// and expect an empty response: {"jsonrpc": "2.0", "id": "123", "result": {}}
Ping(ctx context.Context) (time.Duration, error)
}
MCPPinger defines the interface for pinging MCP servers Implementations should follow the MCP ping specification: https://modelcontextprotocol.io/specification/2025-03-26/basic/utilities/ping
type MCPStatus ¶
type MCPStatus struct {
// Available indicates if the MCP server is reachable
Available bool `json:"available"`
// ResponseTime is the time taken to ping the MCP server (in milliseconds)
ResponseTime *int64 `json:"response_time_ms,omitempty"`
// Error contains any error message if the MCP server is not available
Error string `json:"error,omitempty"`
// LastChecked is the timestamp of the last health check
LastChecked time.Time `json:"last_checked"`
}
MCPStatus represents the status of an MCP server connection