Basic Usage
Create a router and define your tools:prefix="math", your tools become math_add and math_subtract.
Router Options
TheMCPRouter 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:- Tools:
math_add,math_multiply,weather_get_weather - Resources:
weather_weather://forecast
Nested Routers
Routers can include other routers:math_arithmetic_add, math_factorial
Without Prefix
You can include routers without a prefix:Enabling/Disabling Routers
Use theenabled flag to conditionally include routers:
- Feature flags
- Environment-specific routes (dev vs production)
- Temporarily disabling functionality
Complete Example
Here’s a full example with multiple routers:API Reference
MCPRouter
Decorators
| Decorator | Description |
|---|---|
@router.tool() | Register a function as an MCP tool |
@router.resource() | Register a function as an MCP resource |
@router.prompt() | Register a function as an MCP prompt |
Methods
| Method | Description |
|---|---|
router.include_router(router, prefix) | Include another router |
MCPServer Methods
| Method | Description |
|---|---|
server.include_router(router, prefix, enabled) | Include a router in the server |
include_router Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
router | MCPRouter | required | The router to include |
prefix | str | "" | Prefix for tool/prompt names |
enabled | bool | True | Whether to register this router |