Skip to content

factspark23-hash/mcp-handler

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”Œ MCP Hub

One server to rule all your MCP tools.

Python 3.10+ MCP SDK License: MIT Tests

A meta-MCP server that aggregates multiple backend MCP servers into one unified interface.

Your host agent (Claude, Codex, OpenClaw) sees only one MCP server, but gets tools from all of them.

Quick Start β€’ What It Does β€’ Config β€’ Tools Reference β€’ Contributing


Quick Start

git clone https://github.com/factspark23-hash/mcp-handler.git
cd mcp-handler
pip install -e .
cp config.example.yaml mcp_hub.yaml
# Edit mcp_hub.yaml with your servers

Add to your host agent config (Claude Desktop example):

{
  "mcpServers": {
    "mcp-hub": {
      "command": "python3",
      "args": ["-m", "src.server"],
      "cwd": "/path/to/mcp-hub"
    }
  }
}

Restart your host agent. All tools from all servers are available. βœ…


What It Does

🧠 Smart Management

  • 34 management tools for complete control
  • Smart namespacing β€” auto-prefixes only when tool names conflict
  • Tool aliases β€” fs_read instead of filesystem__read_file
  • Quiet mode β€” temporarily disable tools/servers
  • Config hot-reload β€” edit config without restart

πŸ”— Cross-Server Power

  • Cross-server composition β€” chain tools from different servers
  • Stateful sessions β€” multi-step workflows with context
  • Cost estimation β€” check costs before calling
  • Auto-restart β€” crashed servers restart automatically
  • Call replay β€” replay past calls for debugging

πŸ“Š Analytics & Tracking

  • Usage tracking β€” SQLite-backed per-call logging
  • Per-session stats β€” track success rates, durations
  • Error summaries β€” grouped error analysis
  • Slow tool detection β€” find bottlenecks
  • Export stats β€” JSON export for analysis

πŸ›‘οΈ Zero Hassle

  • Zero extra infrastructure β€” just Python + SQLite
  • Auto health checks β€” periodic server pings
  • Dependency ordering β€” servers start in correct order
  • Graceful failures β€” individual tool errors don't crash hub
  • Environment variable support β€” ${VAR} in config

Config

hub:
  name: "My MCP Hub"
  database: "data/hub.db"
  health_check_interval: 30    # seconds between health pings
  auto_restart: true
  max_restart_attempts: 3
  restart_delay: 5             # seconds between restart attempts

servers:
  filesystem:
    transport: "stdio"
    command: "npx"
    args: ["-y", "@modelcontextprotocol/server-filesystem", "/tmp"]
    enabled: true
    aliases:
      read_file: "fs_read"
      write_file: "fs_write"
      list_directory: "fs_ls"
    depends_on: []

  sqlite:
    transport: "stdio"
    command: "uvx"
    args: ["mcp-server-sqlite", "--db", "/tmp/app.db"]
    enabled: true
    aliases:
      query: "db_query"
    depends_on: [filesystem]

namespacing:
  mode: "auto"                 # auto | always | never

tracking:
  enabled: true
  max_records: 100000
  track_params: false          # privacy: don't log params by default
  session_tracking: true

hotreload:
  enabled: true
  watch_interval: 5

Environment Variables

servers:
  github:
    env:
      GITHUB_TOKEN: "${GITHUB_TOKEN}"

Tools Reference

Status & Discovery (5 tools)
Tool Description
hub_status Hub and all servers status
hub_tools List all tools. Optional: server, search
hub_tool_info Detailed info: schema, server, alias, cost
hub_search_tools Search tools by name or description
hub_refresh Re-discover tools from all servers
Usage Analytics (6 tools)
Tool Description
hub_stats Aggregated stats. Optional: since_hours
hub_stats_detailed Filtered call history
hub_top_tools Most used tools
hub_error_summary Recent errors grouped by message
hub_session_stats Current session stats
hub_slow_tools Slowest tools by average duration
Server Management (5 tools)
Tool Description
hub_server_info Server details: connected, transport, tool count
hub_enable_server Enable and connect a disabled server
hub_disable_server Disconnect a server
hub_restart_server Restart a server
hub_server_logs Server health history
Tool Control (6 tools)
Tool Description
hub_quiet_on Temporarily disable tools/servers
hub_quiet_off Re-enable
hub_quiet_status Show currently quieted items
hub_alias_set Set alias for a tool
hub_alias_remove Remove alias
hub_alias_list List all aliases
Cross-Server Composition (2 tools)
Tool Description
hub_compose Chain tools from different servers
hub_compose_template Save/load/run composition templates

Example:

{
  "steps": [
    {"tool": "fs_read", "arguments": {"path": "data.csv"}},
    {"tool": "db_query", "arguments": {"sql": "INSERT INTO imports VALUES ('{{step_1.output}}')"}}
  ]
}
Stateful Sessions (2 tools)
Tool Description
hub_session_begin Start session with optional context
hub_session_step Execute step with auto-injected context
Cost Estimation (2 tools)
Tool Description
hub_cost_register Register cost for a tool
hub_cost_estimate Check cost before calling
Advanced (6 tools)
Tool Description
hub_replay Replay last N calls
hub_replay_one Replay specific call by ID
hub_config_reload Reload config file
hub_config_show Show current config as JSON
hub_health_history Health history per server
hub_export_stats Export all stats as JSON

How It Works

User: "read the config file"
  β”‚
  β–Ό
Claude decides: call tool "fs_read" (alias)
  β”‚
  β–Ό
MCP Hub receives call
  β”œβ”€β”€ Check quiet mode β†’ not quieted
  β”œβ”€β”€ Registry: "fs_read" β†’ server="filesystem", original="read_file"
  β”œβ”€β”€ Router: get connector for "filesystem"
  β”œβ”€β”€ connector.call_tool("read_file", {path: "config.yaml"})
  β”œβ”€β”€ Track: log_call(filesystem, fs_read, 45ms, success)
  β”‚
  β–Ό
Return response to Claude β†’ Claude tells user

Project Structure

mcp-hub/
β”œβ”€β”€ pyproject.toml           # Package config + dependencies
β”œβ”€β”€ config.example.yaml      # Example config
β”œβ”€β”€ src/
β”‚   β”œβ”€β”€ server.py            # Main MCP Server (34 hub_* tools)
β”‚   β”œβ”€β”€ router.py            # Routes calls to backends
β”‚   β”œβ”€β”€ registry.py          # Tool discovery + namespacing
β”‚   β”œβ”€β”€ connector.py         # MCP server connections (stdio/HTTP)
β”‚   β”œβ”€β”€ db.py                # SQLite layer (4 tables)
β”‚   β”œβ”€β”€ config.py            # YAML config loader + validation
β”‚   β”œβ”€β”€ aliases.py           # Bidirectional alias mapping
β”‚   β”œβ”€β”€ namespacing.py       # Auto/prefix/never modes
β”‚   β”œβ”€β”€ quiet.py             # Temporary tool/server disabling
β”‚   β”œβ”€β”€ session.py           # Per-session statistics
β”‚   β”œβ”€β”€ health.py            # Health checks + uptime
β”‚   β”œβ”€β”€ autorun.py           # Auto-restart with dependency ordering
β”‚   β”œβ”€β”€ replay.py            # Replay past tool calls
β”‚   └── hotreload.py         # Config file watching
β”œβ”€β”€ data/                    # SQLite database (auto-created)
└── tests/
    β”œβ”€β”€ test_core.py         # 19 unit tests
    └── test_integration.py  # Integration tests

Running Tests

pip install pytest pytest-asyncio
pytest tests/ -v

# 19/19 tests pass βœ…

Tech Stack

Layer Technology
Language Python 3.10+
Protocol MCP SDK 1.6+
Config YAML (PyYAML)
Storage SQLite (aiosqlite)
Async asyncio
HTTP httpx

Contributing

Contributions welcome! Here's how:

  1. Fork this repo
  2. Create a feature branch (git checkout -b feat/amazing-feature)
  3. Commit your changes (git commit -m 'feat: add amazing feature')
  4. Push to the branch (git push origin feat/amazing-feature)
  5. Open a Pull Request

Ideas for contributions:

  • WebSocket transport support
  • Tool usage dashboard (web UI)
  • Rate limiting per tool
  • Authentication layer
  • Docker support
  • More transport types (SSE, gRPC)

License

MIT β€” use it however you want.


Built with ❀️ for the MCP community

⭐ Star this repo if you find it useful!

About

πŸ”Œ Meta-MCP server: aggregate 10+ MCP servers into one β€” smart namespacing, cross-server composition, usage analytics

Topics

Resources

Stars

Watchers

Forks

Packages

 
 
 

Contributors

Languages