Skip to content

Add health monitoring and circuit breaker to vMCP server #2853

Closed

Description

@JAORMX

Description

Implement health monitoring and circuit breaker patterns to detect and handle backend failures gracefully.

Scope:

  • Periodic health checks for backend MCP servers
  • Backend health status tracking and reporting
  • Circuit breaker implementation for failing backends
  • Automatic backend removal/restoration based on health
  • Health status reflected in vMCP status and capabilities

Key Components

1. Backend Health Checks

  • Periodic health check requests to each backend
  • Configurable check interval (default: 30s)
  • Track consecutive failures
  • Mark backend unhealthy after threshold (default: 3 failures)
  • Health check endpoint: MCP ping or tools/list

2. Health Status Tracking

  • Per-backend health state: healthy, unhealthy, unknown
  • Last successful health check timestamp
  • Failure count and error messages
  • Health status exposed in vMCP status/metrics

3. Circuit Breaker

  • Three states: closed (normal), open (failing), half-open (testing recovery)
  • Configurable failure threshold (default: 5 failures)
  • Configurable timeout for open state (default: 60s)
  • Automatic transition to half-open for recovery testing
  • Track circuit breaker state per backend

4. Backend Availability Management

  • Remove unhealthy backend tools from aggregated capabilities
  • Return error when routing to unavailable backend
  • Automatically restore backend when health recovers
  • Log backend state transitions (healthy ↔ unhealthy)
  • Emit metrics for monitoring systems

5. Failure Modes

  • fail mode (default): Fail entire request if backend unavailable
  • best_effort mode: Return partial results, include errors for failed backends
  • Configurable per vMCP instance

6. Integration Points

  • Update aggregated capabilities when backend health changes
  • Routing layer checks health before forwarding
  • Status reporting includes backend health summary
  • Metrics exported for Prometheus/observability

Implementation Notes

  • Health checks run in background goroutines
  • Use context for cancellation on shutdown
  • Circuit breaker prevents cascading failures
  • Health status should be cached to avoid repeated checks
  • Transition events should be logged and emitted as metrics
  • Follow existing ToolHive observability patterns in pkg/telemetry/
  • Consider using sony/gobreaker or similar library

Reference

Acceptance Criteria

  • Periodic health check implementation
  • Configurable health check interval
  • Backend health state tracking (healthy/unhealthy/unknown)
  • Consecutive failure counting
  • Unhealthy threshold configuration
  • Circuit breaker implementation (closed/open/half-open states)
  • Configurable failure threshold for circuit breaker
  • Configurable timeout for open state
  • Automatic transition to half-open for recovery testing
  • Remove unhealthy backend tools from capabilities
  • Error response when routing to unavailable backend
  • Automatic restoration when backend recovers
  • Health state transition logging
  • Partial failure mode support (fail vs best_effort)
  • Metrics emission for observability
  • Unit tests for health check logic
  • Unit tests for circuit breaker state machine
  • Integration tests with flaky mock backends
  • E2E tests with backend failure and recovery scenarios

Activity

  1. added
    enhancement
    vmcp
    on Dec 2, 2025
  2. added
    go
    api
    on Dec 2, 2025
  3. slyt3 commented on Dec 8, 2025

    @slyt3
    Contributor

    Hello, Can you assign me to this? I was working this whole night and i need another 1-2 days to fix some issues for it.

    Still have some bugs and issues but i am working on it

  4. jhrozek commented on Dec 8, 2025

    @jhrozek
    Contributor

    Hello, Can you assign me to this? I was working this whole night and i need another 1-2 days to fix some issues for it.

    Still have some bugs and issues but i am working on it

    Thank you for the continued interest in contributing to toolhive! This is an issue that requires an insight into how vMCP will be operationalized as well as it's a big issue that will most likely be split down into a bunch of smaller ones.

    If you filter toolhive issues by "good first issue" there usually are a bunch that are a better fit to learn more about toolhive and can be completed in less amount of time. If there are none, I'm sure we can add more

  5. slyt3 commented on Dec 8, 2025

    @slyt3
    Contributor

    @jhrozek I understand this is a large issue that will be split into smaller pieces. I've implemented the status reporting foundation that this issue requires.

    What I Built

    I've created a separate PR (#2949) that implements the status reporting mechanism mentioned in this issue's Integration Points:

    "Status reporting includes backend health summary"

    PR scope:
    -StatusReporter interface (platform-agnostic)
    -K8sReporter (updates VirtualMCPServer.status)
    -LogReporter (CLI environments)
    -Data structures for health data (RuntimeStatus, BackendHealthReport)
    -15 unit tests, lint clean, tested in kind

    What it does NOT include:
    It doesnt include health checking logic, circuit breakers and backend monitoring

    this just provides the reporting infrastructure this issue needs. The actual health monitoring implementation can build on top of this foundation.

    How They Connect

    ┌─────────────────────────────┐
    │  Issue #2853 (Future)       │
    │  - Health checks            │
    │  - Circuit breakers         │
    │  - Backend monitoring       │
    │  └──┬──────────────────────┘
    │     │ Populates
    │     ▼
    │  RuntimeStatus {
    │    Backends: [...]  ← Health data goes here
    │  }
    │     │
    │     │ Reports
    │     ▼
    │  ┌─────────────────────────┐
    │  │  My PR                  │
    │  │  - StatusReporter       │
    │  │  - K8s/CLI reporting    │
    │  └─────────────────────────┘
    

    Next Steps

    If this approach makes sense, I'm happy to try to implement

    1. Continue with health checking implementation (this issue's core)
    2. Work on other split-out pieces
    3. Help with whatever is most valuable

    Let me know if you'd like me to continue contributing to this issue's implementation! I spent a lot of time on it.

    PR: #2949

  6. jhrozek commented on Dec 11, 2025

    @jhrozek
    Contributor

    Related Issues

    This issue can integrate with the vMCP K8s-aware refactor work:

    These are not hard dependencies - health monitoring can be implemented independently. But the integration is cleaner if these exist first.

  7. slyt3 commented on Dec 11, 2025

    @slyt3
    Contributor

    @jhrozek should i still look on that pr and fix everything and would love to spent time on it.

  8. jhrozek commented on Dec 11, 2025

    @jhrozek
    Contributor

    @jhrozek should i still look on that pr and fix everything and would love to spent time on it.

    I honestly think that this is pretty involved work that would better be done by someone from the core team. Your contributions are appreciated, but I think it's better to start small and gradually ramp up.

  9. slyt3 commented on Dec 12, 2025

    @slyt3
    Contributor

    @jhrozek should i still look on that pr and fix everything and would love to spent time on it.

    I honestly think that this is pretty involved work that would better be done by someone from the core team. Your contributions are appreciated, but I think it's better to start small and gradually ramp up.

    Okey I understand it, thankyou for replay and honest answer. If someone from the core team will take this issue. I would love to help with some tasks.

  10. self-assigned this
    on Dec 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

apienhancementgotelemetryvmcp

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions