Documentation
¶
Overview ¶
Package health provides unified health status calculation for upstream MCP servers.
Package health provides unified health status calculation for upstream MCP servers.
IMPORTANT: These constants are mirrored in TypeScript. When adding or modifying health levels, admin states, or actions, update cmd/generate-types/main.go and regenerate frontend/src/types/contracts.ts by running: go run ./cmd/generate-types
Index ¶
- Constants
- func CalculateHealth(input HealthCalculatorInput, cfg *HealthCalculatorConfig) *contracts.HealthStatus
- func ExtractMissingSecret(lastError string) string
- func ExtractOAuthConfigError(lastError string) string
- func IsHealthy(health *contracts.HealthStatus, legacyConnected bool) bool
- type HealthCalculatorConfig
- type HealthCalculatorInput
Constants ¶
const ( LevelHealthy = "healthy" LevelDegraded = "degraded" LevelUnhealthy = "unhealthy" )
Health levels
const ( StateEnabled = "enabled" StateDisabled = "disabled" StateQuarantined = "quarantined" )
Admin states
const ( ActionNone = "" ActionLogin = "login" ActionRestart = "restart" ActionEnable = "enable" ActionApprove = "approve" ActionViewLogs = "view_logs" ActionSetSecret = "set_secret" ActionConfigure = "configure" )
Actions - suggested remediation for health issues
Variables ¶
This section is empty.
Functions ¶
func CalculateHealth ¶
func CalculateHealth(input HealthCalculatorInput, cfg *HealthCalculatorConfig) *contracts.HealthStatus
CalculateHealth calculates the unified health status for a server. The algorithm uses a priority-based approach where admin state is checked first, followed by connection state, then OAuth state.
func ExtractMissingSecret ¶
ExtractMissingSecret extracts the secret name from an error message if the error indicates a missing secret reference (e.g., unresolved environment variable). Returns the secret name or empty string if the error is not about missing secrets.
func ExtractOAuthConfigError ¶
ExtractOAuthConfigError extracts an OAuth configuration error from the error message. Returns the config error description or empty string if not an OAuth config issue.
Types ¶
type HealthCalculatorConfig ¶
type HealthCalculatorConfig struct {
// ExpiryWarningDuration is the duration before token expiry to show degraded status.
// Default: 1 hour
ExpiryWarningDuration time.Duration
}
HealthCalculatorConfig contains configurable thresholds for health calculation.
func DefaultHealthConfig ¶
func DefaultHealthConfig() *HealthCalculatorConfig
DefaultHealthConfig returns the default health calculator configuration.
type HealthCalculatorInput ¶
type HealthCalculatorInput struct {
// Server identification
Name string
// Admin state
Enabled bool
Quarantined bool
// Connection state
State string // "connected", "connecting", "error", "idle", "disconnected"
Connected bool
LastError string
// OAuth state (only for OAuth-enabled servers)
OAuthRequired bool
OAuthStatus string // "authenticated", "expired", "error", "none"
TokenExpiresAt *time.Time // When token expires
HasRefreshToken bool // True if refresh token exists
UserLoggedOut bool // True if user explicitly logged out
// Secret/config detection
MissingSecret string // Secret name if unresolved (e.g., "GITHUB_TOKEN")
OAuthConfigErr string // OAuth config error (e.g., "requires 'resource' parameter")
// Tool info
ToolCount int
}
HealthCalculatorInput contains all fields needed to calculate health status. This struct normalizes data from different sources (StateView, storage, config).