Skip to main content

mcp-capability-router

PyPI Python CI Documentation License

Give every agent the right MCP tools, resources, and prompts, from any number of servers, through one resilient runtime.

mcp-capability-router is an asyncio-first Python library that sits between your agents and your MCP servers, whatever framework the agents use. It discovers what each server offers, keeps that catalog current, ranks it against each request, and runs every server operation through concurrency limits, circuit breakers, retries, rate limits, and timeouts. An agent sees only the few tools that matter for the current turn, however many servers and tools you register.

Applications and agents use the MCPRuntime, which discovers, ranks, and calls the capabilities of MCP servers through a resilience pipeline

Features

  • Only the relevant tools. Retrieval selects the capabilities that match each request, so models stay fast, inexpensive, and accurate with thousands of tools. Qdrant ranks with BM25 out of the box, with no model and no service, and fuses BM25 with any embedding model for hybrid ranking.
  • Every MCP server. Streamable HTTP, SSE, stdio, MCP configurations, and in-process servers through FastMCP, with lazy connections and automatic reconnection.
  • Always current. Discovery runs on registration, on a schedule, on list_changed notifications, or when a query finds nothing, and writes only what changed, through refresh-engine.
  • Resilient by default. Concurrency limits, interceptors, circuit breakers per server and operation, retries, rate limits, and timeouts, built on purgatory, tenacity, and aiolimiter. Failures are classified, so a rejected tool call is never repeated and never opens a circuit.
  • Any agent framework. route_tools returns ready-to-call tools with a name, a description, and a JSON schema, for the OpenAI SDK, Agno, CrewAI, or any other framework. The langchain extra adds routing middleware for create_agent, Deep Agents, and multi-agent systems, and LangChain tools for LangGraph.
  • An MCP gateway. as_mcp_server serves every registered server as one MCP server, with tool search, a full catalog, or an experimental code mode, so any MCP client gets routing and resilience.
  • Isolated and observable. One runtime per tenant shares nothing with others. Health states, metrics for every operation, and standard logging.
  • Typed and extensible. Fully type-annotated ABCs for registries, retrievers, adapters, and interceptors, with reusable conformance tests.
  • Application-owned infrastructure. Supply refresh StateStores, event publishers, fingerprints, FastMCP clients, Qdrant clients, embedders, or result-cache stores. Share the index in a Qdrant server, share circuits in Redis, and export OpenTelemetry spans.

Installation

mcp-capability-router requires Python 3.12 or newer.

pip install mcp-capability-router

Extras add optional integrations: langchain for LangChain, LangGraph, and Deep Agents, codemode for the gateway's code mode, otel for OpenTelemetry, redis for Redis circuit storage, and all for every one of them, such as pip install "mcp-capability-router[langchain,otel]". Configure resilience with MCPRuntime(resilience=ResiliencePolicy(...)); individual registrations can supply their own policy.

Quick start

Register a server, let the runtime discover its capabilities, and route a request to the right tool:

import asyncio

from fastmcp import FastMCP

from mcp_capability_router import MCPRuntime, RefreshPolicy

weather = FastMCP("weather")


@weather.tool
def get_forecast(city: str) -> str:
    """Get the weather forecast for a city."""
    return f"Sunny and 24 degrees in {city}"


@weather.tool
def list_alerts(region: str) -> list[str]:
    """List the active severe-weather alerts of a region."""
    return []


async def main() -> None:
    async with MCPRuntime() as runtime:
        await runtime.register_mcp("weather", weather, refresh=RefreshPolicy(on_register=True))
        [tool] = await runtime.route_tools("What is the forecast for Paris?", limit=1)
        print(tool.capability_id)

        result = await tool({"city": "Paris"})
        print(result.data)


asyncio.run(main())
weather:tool:get_forecast
Sunny and 24 degrees in Paris

The server here runs in process; a URL, a script path, or an MCP configuration works the same way.

Route tools for an agent

route_tools gives any framework the tools that match a request: each has a name, a description, and an input_schema, and awaiting it runs the MCP tool through the runtime. With the langchain extra, add the middleware to a LangChain agent, and every model call receives the tools that match the latest user message:

from langchain.agents import create_agent

from mcp_capability_router.integrations.langchain import CapabilityRoutingMiddleware

agent = create_agent(
    "openai:gpt-5.4-mini",
    tools=[],
    middleware=[CapabilityRoutingMiddleware(runtime, limit=5)],
)
result = await agent.ainvoke(
    {"messages": [{"role": "user", "content": "What is the forecast for Paris?"}]}
)

To serve the router to any MCP client, such as an IDE or a desktop assistant, run runtime.as_mcp_server("gateway") over Streamable HTTP. Continue with the getting started guide to add resilience, refresh policies, and observability.

Performance

The router's overhead is small next to real MCP calls: in-process BM25 ranks 1,000 capabilities in a few milliseconds, and an operation passes through the whole resilience pipeline in a few microseconds. See Performance for the measurements and tuning advice.

Documentation

The documentation covers:

Agent Skills

Coding agents such as Claude Code, Codex, Cursor, and GitHub Copilot can use the mcp-capability-router Agent Skill to integrate the library correctly:

npx skills add https://github.com/smuniharish/mcp-capabilty-router/tree/master/mcp-capability-router-skills/skills/mcp-capability-router

Contributing

Contributions are welcome. Read the contributing guide, and report vulnerabilities as described in the security policy. Notable changes are listed in the changelog.

License

mcp-capability-router is licensed under the Apache License 2.0.

Metadata

Release files for mcp-capability-router 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mcp-capability-router 1.0.0
File Size Uploaded Provenance Actions
mcp_capability_router-1.0.0.tar.gz 118.0 kB Without provenance Details for mcp_capability_router-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mcp-capability-router 1.0.0
File Interpreter ABI Platform Actions
mcp_capability_router-1.0.0-py3-none-any.whl Python 3 none any Details for mcp_capability_router-1.0.0-py3-none-any.whl

Total release size: 197.1 kB

Release files / mcp_capability_router-1.0.0.tar.gz

Download URL mcp_capability_router-1.0.0.tar.gz
Size 118.0 kB
Tags Source
SHA-256 checksum
How to use checksums
39e14e43be17404dcd96ef365bc15fde12da5303c7f7bb7cfe6cd17e53d82f36
BLAKE2b-256 checksum
How to use checksums
d42882488a3f0f1567e6af59c8b432cf7a6fccd5358ba00db8fe6627ab59f776
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Release files / mcp_capability_router-1.0.0-py3-none-any.whl

Download URL mcp_capability_router-1.0.0-py3-none-any.whl
Size 79.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1bbeaac7c3961e4c3bb6aeacf2fb4a3332e82981821039a668ac457f6c6f1e62
BLAKE2b-256 checksum
How to use checksums
67a575066783ba62f1534cf7d20d35e8396a6a51fc4c44f1ce2607e87c153a00
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.6 {"installer":{"name":"uv","version":"0.13.6","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":null,"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

Security for mcp-capability-router 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page