Skip to main content

mcp-capability-router

mcp-capability-router logo

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. RetrievalLoom ranks with BM25 out of the box, with no model and no service, fuses BM25 with any embedding model for hybrid ranking, and reorders the matches with an optional cross-encoder reranker.
  • 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, RetrievalLoom stores, embedders, rerankers, or result-cache stores. Keep the index across restarts or in a Qdrant server, share circuits in Redis, and export OpenTelemetry spans, recorded by default with no duplicates.

Installation

mcp-capability-router supports Python 3.12 through 3.14.

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 the OpenTelemetry SDK and metrics, 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.

Router tool spans include arguments and results by default when tracing is configured. These may contain sensitive data; set MCPRuntime(capture_tool_content=False) to omit them from router spans.

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 2.0.1

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 2.0.1
File Size Uploaded Provenance Actions
mcp_capability_router-2.0.1.tar.gz 123.8 kB Without provenance Details for mcp_capability_router-2.0.1.tar.gz

Built distribution (wheel)

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

Total release size: 205.3 kB

Release files / mcp_capability_router-2.0.1.tar.gz

Download URL mcp_capability_router-2.0.1.tar.gz
Size 123.8 kB
Tags Source
SHA-256 checksum
How to use checksums
4a0ebaf65f20bc40ddee21871c284548b14af4c0dea449e7e86a473aa48758c9
BLAKE2b-256 checksum
How to use checksums
7eeee9926aeb923bd81812493c6b843abcf39b728e8ace82d7cec2ba0efc90a6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","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-2.0.1-py3-none-any.whl

Download URL mcp_capability_router-2.0.1-py3-none-any.whl
Size 81.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
51c2ea373f0ce5bb1929840ca739a11714e6b0c22b6df84fedc11cb09481afc8
BLAKE2b-256 checksum
How to use checksums
074c92d8b47154fb61ce94c6147575123ae212a273ef8ff9751f9fd61404e2dd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.12.15 {"installer":{"name":"uv","version":"0.12.15","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 2.0.1

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