Skip to main content

Production-grade hot-load registry for MCP providers

Project description

MCP Hangar

Tests PyPI Python 3.11+ License: MIT Documentation

Production-grade MCP infrastructure with auto-discovery, observability, and resilience patterns.

Overview

MCP Hangar is a lifecycle management platform for Model Context Protocol providers, built for platform teams running MCP at scale. It replaces ad-hoc provider management with a unified control plane featuring auto-discovery from Kubernetes, Docker, and filesystem sources; circuit breakers and saga-based recovery for resilience; and first-class observability through Langfuse, OpenTelemetry, and Prometheus. The architecture follows Domain-Driven Design with CQRS and Event Sourcing, providing full audit trails for compliance-heavy environments.

Why MCP Hangar?

Challenge Without MCP Hangar With MCP Hangar
Provider lifecycle Manual start/stop, no health monitoring State machine with circuit breaker, health checks, automatic GC
Observability None or DIY Built-in Langfuse, OpenTelemetry, Prometheus metrics
Dynamic environments Restart required for new providers Auto-discovery from K8s, Docker, filesystem, entrypoints
Failure handling Cascading failures Circuit breaker, saga-based recovery and failover
Audit & compliance None Event sourcing with full audit trail
Cold start latency Wait for provider startup Predefined tools visible immediately, lazy loading
Multi-provider routing Manual coordination Load balancing with weighted round-robin, priority, least connections

Key Features

๐Ÿ”„ Lifecycle Management

Provider lifecycle follows a strict state machine:

COLD โ†’ INITIALIZING โ†’ READY โ‡„ DEGRADED โ†’ DEAD
  • Lazy loading โ€” Providers start on first invocation, not at boot
  • Predefined tools โ€” Tool schemas visible before provider starts (no cold start for discovery)
  • Automatic GC โ€” Idle providers shutdown after configurable TTL
  • Graceful shutdown โ€” Clean termination with timeout enforcement
๐Ÿ” Auto-Discovery

Automatically detect and register providers from multiple sources:

Source Configuration
Kubernetes Pod annotations (mcp.hangar.io/*) with namespace filtering
Docker/Podman Container labels (mcp.hangar.*)
Filesystem YAML configs with file watching
Python entrypoints mcp.providers entry point group

Discovery modes:

  • additive โ€” Only adds providers, never removes (safe for static environments)
  • authoritative โ€” Adds and removes (for dynamic environments like K8s)

Conflict resolution: Static config > Kubernetes > Docker > Filesystem > Entrypoints

๐Ÿ“Š Observability

Full observability stack for production operations:

Langfuse Integration

  • End-to-end LLM tracing from prompt to provider response
  • Cost attribution per provider, tool, user, or session
  • Quality scoring and automated evals

OpenTelemetry

  • Distributed tracing with context propagation
  • OTLP export to Jaeger, Zipkin, or any collector

Prometheus Metrics

  • Tool invocation latency and error rates
  • Provider state transitions and cold starts
  • Circuit breaker state and trip counts
  • Health check results

Health Endpoints

  • /health โ€” Liveness check
  • /ready โ€” Readiness check (K8s compatible)
  • /metrics โ€” Prometheus scrape endpoint
๐Ÿ›ก๏ธ Resilience

Production-grade failure handling:

Circuit Breaker

  • Opens after configurable failure threshold
  • Auto-reset after timeout period
  • Prevents cascading failures to healthy providers

Saga-Based Recovery

  • ProviderRecoverySaga โ€” Automatic restart with exponential backoff
  • ProviderFailoverSaga โ€” Failover to backup providers with auto-failback
  • GroupRebalanceSaga โ€” Rebalance traffic when members change

Health Monitoring

  • Configurable check intervals
  • Consecutive failure thresholds
  • Automatic state transitions (READY โ†’ DEGRADED)
๐Ÿ”’ Security

Enterprise security controls:

  • Rate limiting โ€” Per-provider request limits
  • Input validation โ€” Schema validation before provider invocation
  • Secrets management โ€” Environment variable injection, never in config files
  • Container isolation โ€” Read-only filesystems, resource limits, network policies
  • Discovery security โ€” Namespace filtering, max providers per source, quarantine on failure
๐Ÿ—๏ธ Architecture

Domain-Driven Design with clean layer separation:

domain/         Core business logic, state machines, events, value objects
application/    Use cases, commands, queries, sagas
infrastructure/ Adapters for containers, subprocess, persistence, event bus
server/         MCP protocol handlers and validation
bootstrap/      Runtime initialization and dependency injection
  • CQRS โ€” Separate command and query paths
  • Event Sourcing โ€” All state changes emit domain events
  • Port/Adapter โ€” Extensible infrastructure layer
  • Thread-safe โ€” Lock hierarchy for concurrent access

Quick Start

Install:

pip install mcp-hangar

Configure (config.yaml):

providers:
  math:
    mode: subprocess
    command: [python, -m, my_math_server]
    idle_ttl_s: 300
    
  sqlite:
    mode: container
    image: ghcr.io/modelcontextprotocol/server-sqlite:latest
    volumes:
      - "/data/sqlite:/data:rw"

Run:

# Stdio mode (Claude Desktop, Cursor, etc.)
mcp-hangar --config config.yaml

# HTTP mode (LM Studio, web clients)
mcp-hangar --config config.yaml --http

Architecture Overview

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                        MCP Hangar                               โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚                    FastMCP Server                         โ”‚  โ”‚
โ”‚  โ”‚              (Stdio or HTTP transport)                    โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                             โ”‚                                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚                  Provider Manager                         โ”‚  โ”‚
โ”‚  โ”‚    โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”                 โ”‚  โ”‚
โ”‚  โ”‚    โ”‚ State   โ”‚  โ”‚ Health  โ”‚  โ”‚ Circuit โ”‚                 โ”‚  โ”‚
โ”‚  โ”‚    โ”‚ Machine โ”‚  โ”‚ Tracker โ”‚  โ”‚ Breaker โ”‚                 โ”‚  โ”‚
โ”‚  โ”‚    โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜                 โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                             โ”‚                                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ–ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”‚
โ”‚  โ”‚                    Providers                              โ”‚  โ”‚
โ”‚  โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”             โ”‚  โ”‚
โ”‚  โ”‚  โ”‚ Subprocessโ”‚  โ”‚  Docker   โ”‚  โ”‚  Remote   โ”‚             โ”‚  โ”‚
โ”‚  โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜             โ”‚  โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜  โ”‚
โ”‚                                                                 โ”‚
โ”‚  Background: [GC Worker] [Health Worker] [Discovery Worker]    โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

Registry Tools

Tool Description
registry_list List all providers with state, health status, and available tools
registry_start Explicitly start a provider
registry_stop Stop a running provider
registry_invoke Invoke a tool on a provider (auto-starts if needed)
registry_invoke_ex Invoke with retry, correlation ID, and metadata
registry_invoke_stream Invoke with real-time progress notifications
registry_tools Get tool schemas for a provider
registry_health Get health status and metrics
registry_status Dashboard view of all providers
registry_discover Trigger discovery cycle
registry_sources List discovery sources with status
registry_warm Pre-start providers to avoid cold start latency

Configuration Reference

Option Description Default
mode Provider mode: subprocess, container, docker, remote, group required
command Command for subprocess providers โ€”
image Container image for container providers โ€”
idle_ttl_s Seconds before idle provider shutdown 300
health_check_interval_s Health check frequency in seconds 60
max_consecutive_failures Failures before transition to DEGRADED 3
tools Predefined tool schemas (visible before start) โ€”
volumes Container volume mounts โ€”
network Container network mode none
read_only Container read-only filesystem true

Observability Setup

observability:
  langfuse:
    enabled: true
    public_key: ${LANGFUSE_PUBLIC_KEY}
    secret_key: ${LANGFUSE_SECRET_KEY}
    host: https://cloud.langfuse.com
    
  tracing:
    enabled: true
    otlp_endpoint: http://localhost:4317
    
  metrics:
    enabled: true
    endpoint: /metrics

Environment Variables:

Variable Description
LANGFUSE_PUBLIC_KEY Langfuse public key
LANGFUSE_SECRET_KEY Langfuse secret key
OTEL_EXPORTER_OTLP_ENDPOINT OpenTelemetry collector endpoint
MCP_TRACING_ENABLED Enable/disable tracing (true/false)

Endpoints:

  • /metrics โ€” Prometheus metrics
  • /health โ€” Liveness probe
  • /ready โ€” Readiness probe

Documentation

๐Ÿ“– Full Documentation

Contributing

See Contributing Guide for development setup, testing requirements, and code style.

git clone https://github.com/mapyr/mcp-hangar.git
cd mcp-hangar
uv sync --extra dev
uv run pytest tests/ -v

License

MIT License โ€” see LICENSE for details.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_hangar-0.1.3.tar.gz (521.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_hangar-0.1.3-py3-none-any.whl (289.7 kB view details)

Uploaded Python 3

File details

Details for the file mcp_hangar-0.1.3.tar.gz.

File metadata

  • Download URL: mcp_hangar-0.1.3.tar.gz
  • Upload date:
  • Size: 521.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_hangar-0.1.3.tar.gz
Algorithm Hash digest
SHA256 d8a0b97ac3748008fd6465c71929913367c4a24962f22ae790c52599e20af345
MD5 106c922d5e54f7c531ea1bf06a246c1e
BLAKE2b-256 5d3009e6551f873cf7766e71bf1a724f72aa276dc4fc4a95451e29c564876bac

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_hangar-0.1.3.tar.gz:

Publisher: release.yml on mapyr/mcp-hangar

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_hangar-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: mcp_hangar-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 289.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_hangar-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 88b3157808bac4470dd84d7078f90e17a5ecb5a4b8aa21e5ba939224756fc884
MD5 75d2107b57f4dd486fc538c26fc1facc
BLAKE2b-256 c914123174b25232290a2fab5da8c7f35d4f8fb2f15d5262800a60a0792acf4c

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_hangar-0.1.3-py3-none-any.whl:

Publisher: release.yml on mapyr/mcp-hangar

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page