Skip to main content
Routers let you organize your MCP server into modular, reusable components. Similar to FastAPI’s APIRouter, you can define tools, resources, and prompts in separate files and include them in your server with optional prefixes.

Basic Usage

Create a router and define your tools:
Include it in your server:
With the prefix="math", your tools become math_add and math_subtract.

Router Options

The MCPRouter constructor accepts optional metadata:

Defining Resources

Use @router.resource() to define resources:

Defining Prompts

Use @router.prompt() to define prompts:

Multiple Routers

Organize different domains into separate routers:
This creates:
  • Tools: math_add, math_multiply, weather_get_weather
  • Resources: weather_weather://forecast

Nested Routers

Routers can include other routers:
This creates tools: math_arithmetic_add, math_factorial

Without Prefix

You can include routers without a prefix:

Enabling/Disabling Routers

Use the enabled flag to conditionally include routers:
This is useful for:
  • Feature flags
  • Environment-specific routes (dev vs production)
  • Temporarily disabling functionality

Complete Example

Here’s a full example with multiple routers:
Output:

API Reference

MCPRouter

Decorators

Methods

MCPServer Methods

include_router Parameters