Skip to main content

MCP Orchestration Gateway - Aggregates and searches tools from multiple MCP servers with deferred loading

Project description

MCP Orchestration Gateway

PyPI Version Python Version License: MIT Tests Contributions Welcome

A central hub that connects to multiple downstream MCP servers, aggregates their tools, and provides unified access with powerful tool search capabilities.

Built around deferred tool loading — search across all your servers without blowing Claude's context window.

Features

  • Config-based Server Registration: Add downstream MCP servers via JSON config file
  • Tool Namespacing: Automatic server_name__tool_name format
  • Tool Search: Unified BM25/regex search with deferred loading support
  • Flexible Authentication: Static saved headers or token forwarding
  • Multiple Transports: stdio or HTTP
  • Tool Definition Caching: Cached definitions, raw result passthrough
  • Storage Backends: In-memory (development) or Redis (production)

Quick Start

Installation

pip install -e .

Running the MCP Server

First, activate the virtual environment:

source .venv/bin/activate

Then run the server:

# Run as stdio MCP server (for Claude Desktop, Cursor, etc.)
mcp-orchestration-gateway

# Or run with Python directly
python -m mcp_gateway.main

HTTP Transport:

GATEWAY_TRANSPORT=http GATEWAY_PORT=8080 python -m mcp_gateway.main

This starts the server on http://localhost:8080/mcp with CORS enabled.

Configuring Servers

Add downstream MCP servers in server_config.json:

{
  "servers": [
    {
      "name": "my-server",
      "url": "http://localhost:8080/mcp",
      "transport": "http",
      "auth_type": "static",
      "auth_headers": {
        "Authorization": "Bearer my-token"
      }
    },
    {
      "name": "my-stdio-server",
      "url": "server.py",
      "transport": "stdio",
      "command": "uv",
      "args": ["run", "python", "server.py"]
    }
  ]
}

Searching for Tools

The gateway provides unified tool search (BM25 by default, regex optional):

# BM25 search (default - natural language)
results = await mcp_client.call_tool("tool_search", {
    "query": "get weather information",
    "max_results": 3
})

# Regex search (set use_regex=true)
results = await mcp_client.call_tool("tool_search", {
    "query": "weather|forecast",
    "use_regex": true,
    "max_results": 3
})

Architecture

┌─────────────────────────────────────────────────────┐
│              MCP Orchestration Gateway               │
│                                                      │
│  ┌──────────────────────────────────────────────┐   │
│  │              FastMCP Server                   │   │
│  │  ┌─────────────┐  ┌──────────────────┐   │   │
│  │  │ tool_search │  │ call_remote_tool  │   │   │
│  │  └─────────────┘  └──────────────────┘   │   │
│  └──────────────────────────────────────────────┘   │
│                                                      │
│  ┌──────────┐  ┌──────────┐  ┌──────────────┐      │
│  │  Server  │  │   Tool   │  │   Storage    │      │
│  │ Registry │  │  Search  │  │(Memory/Redis)│      │
│  └──────────┘  └──────────┘  └──────────────┘      │
└─────────────────────────────────────────────────────┘
                           │
        ┌───────────────────┼───────────────────┐
        ▼                   ▼                   ▼
   ┌─────────┐        ┌─────────┐        ┌─────────┐
   │ MCP Svr │        │ MCP Svr │        │ MCP Svr │
   │   #1    │        │   #2    │        │   #N    │
   └─────────┘        └─────────┘        └─────────┘

Configuration

Environment Variables

Variable Default Description
STORAGE_BACKEND memory Storage backend (memory or redis)
REDIS_URL redis://localhost:6379/0 Redis connection URL
MCP_GATEWAY_TOOL_CACHE_TTL 300 Tool schema cache TTL in seconds
MCP_GATEWAY_DEFAULT_CONNECTION_MODE stateless Default connection mode
MCP_GATEWAY_CONNECTION_TIMEOUT 30.0 Connection timeout in seconds
MCP_GATEWAY_MAX_RETRIES 3 Maximum retry attempts
GATEWAY_TRANSPORT stdio MCP transport (stdio or http)
GATEWAY_PORT 8080 Port for HTTP transport
GATEWAY_HOST 0.0.0.0 Host for HTTP transport
GATEWAY_LOG_LEVEL INFO Logging level
SERVER_CONFIG_PATH server_config.json Path to server configuration file

Claude Desktop Integration

Add to your Claude Desktop config (~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "mcp-orchestration-gateway": {
      "command": "mcp-orchestration-gateway",
      "env": {
        "STORAGE_BACKEND": "memory",
        "GATEWAY_LOG_LEVEL": "INFO"
      }
    }
  }
}

MCP Tools

tool_search

Search for tools using BM25 relevance ranking or regex pattern matching.

@mcp.tool()
async def tool_search(
    query: str,
    max_results: int = 3,
    use_regex: bool = False,
) -> dict:
    """Search for tools using BM25 or regex.
    
    By default uses BM25 natural language search. Set use_regex=True
    to search using Python regex patterns instead.
    """

discover_tools

Discover tools from a registered downstream server.

@mcp.tool()
async def discover_tools(
    server_name: str,
) -> dict:
    """Discover tools from a registered server and index them for search.
    
    Returns the list of discovered tools with their schemas.
    """

call_remote_tool

Call a tool directly on a downstream MCP server.

@mcp.tool()
async def call_remote_tool(
    tool_name: str,
    arguments: Optional[dict] = None,
    auth_header: Optional[str] = None,
) -> Any:
    """Call a tool on a downstream server.
    
    Args:
        tool_name: Namespaced tool name (server_name__tool_name)
        arguments: Tool arguments
        auth_header: Optional auth header to override server's configured auth
    """

Tool Search Results

The search tools return results in the format expected by Claude's tool search system:

{
  "success": true,
  "tool_references": [
    {
      "type": "tool_reference",
      "tool_name": "server_name__tool_name"
    }
  ],
  "total_matches": 5,
  "query": "weather"
}

Testing

Run the test suite:

uv run pytest

Run with coverage:

uv run pytest --cov=mcp_gateway

Project Structure

mcp-gateway/
├── src/mcp_gateway/
│   ├── __init__.py
│   ├── main.py              # Entry point
│   ├── models.py            # Pydantic models
│   ├── mcp_server.py        # FastMCP server
│   ├── config_loader.py     # Config file loader
│   ├── server/
│   │   └── registry.py      # Server registry
│   ├── tools/
│   │   ├── router.py       # Tool router
│   │   └── search.py       # Tool search service
│   └── storage/
│       ├── base.py          # Storage interface
│       ├── memory.py        # In-memory backend
│       └── redis.py         # Redis backend
├── tests/
│   ├── test_registry.py
│   ├── test_search.py
│   ├── test_storage.py
│   ├── test_models.py
│   └── test_integration.py
├── server_config.json       # Pre-configured downstream servers
├── pyproject.toml
├── README.md
└── .env                    # Environment variables (not committed)

License

MIT License

Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

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_orchestration_gateway-0.1.1.tar.gz (120.0 kB view details)

Uploaded Source

Built Distribution

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

mcp_orchestration_gateway-0.1.1-py3-none-any.whl (29.9 kB view details)

Uploaded Python 3

File details

Details for the file mcp_orchestration_gateway-0.1.1.tar.gz.

File metadata

  • Download URL: mcp_orchestration_gateway-0.1.1.tar.gz
  • Upload date:
  • Size: 120.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_orchestration_gateway-0.1.1.tar.gz
Algorithm Hash digest
SHA256 40b104c9acb1dfcfc1c5bf9c13ff3f1aefcab1f1705fa6374b106982e0064774
MD5 164530c706dcb92c26d5df66d95ec150
BLAKE2b-256 1adf059ebf45b7f106e5afcfeaa07d0e8a211dc177a5126623644aeb4e9adaa8

See more details on using hashes here.

File details

Details for the file mcp_orchestration_gateway-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: mcp_orchestration_gateway-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 29.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.10.4 {"installer":{"name":"uv","version":"0.10.4","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for mcp_orchestration_gateway-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 0a1d0e523aebbfbc3ab49a59a42c78cdba748fc79b0ef5339df345da01653422
MD5 cc7ad2df946f06b8b71abea9910ef225
BLAKE2b-256 b2be2bcc0996f3b4dd1e9c7dc3830ecbfd7938536fe90075b6d54343be7542f2

See more details on using hashes here.

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