SDKsPython
Python SDK
Official Python SDK for RouterMCP with async/sync clients and framework adapters for LangChain and Google ADK.
Python SDK
The routermcp package provides async and sync clients for connecting to RouterMCP from Python 3.10+.
Installation
pip install routermcp# With LangChain support
pip install routermcp[langchain]
# With Google ADK support
pip install routermcp[google-adk]
# All framework integrations
pip install routermcp[all]Quick Start
Async Client
from routermcp import RouterMCPClient
async with RouterMCPClient(
url='https://gateway.routermcp.com/v1/mcp/my-project',
api_key='rmc_...',
) as client:
# List available tools
tools = await client.list_tools()
print(f'Found {len(tools)} tools')
# Call a tool
result = await client.call_tool('github_create_issue', {
'title': 'Bug report',
'body': 'Found an issue...',
})
print(result.content)Sync Client
from routermcp import SyncRouterMCPClient
with SyncRouterMCPClient(
url='https://gateway.routermcp.com/v1/mcp/my-project',
api_key='rmc_...',
) as client:
tools = client.list_tools()
result = client.call_tool('github_create_issue', {'title': 'Bug report'})Use RouterMCPClient (async) for web applications and high-concurrency scenarios. Use SyncRouterMCPClient for scripts and CLI tools.
Configuration Options
from routermcp import RouterMCPClient
from routermcp.oauth import memory_adapter
from routermcp.types import OAuthConfig
client = RouterMCPClient(
# Required
url='https://gateway.routermcp.com/v1/mcp/my-project',
# Authentication
api_key='rmc_...', # or set ROUTERMCP_API_KEY env var
# Multi-user
user_id='user-123', # Default user for OAuth token storage
# Options
timeout=30000, # Request timeout in ms (default: 30000)
debug=False, # Enable debug logging
# Custom headers
headers={
'X-Custom-Header': 'value',
},
# OAuth configuration
oauth=OAuthConfig(
adapter=memory_adapter(),
auto_refresh=True,
),
)Environment Variables
The SDK automatically reads configuration from environment variables:
| Variable | Description |
|---|---|
ROUTERMCP_URL | Server URL |
ROUTERMCP_API_KEY | API key |
ROUTERMCP_USER_ID | Default user ID |
ROUTERMCP_TIMEOUT | Timeout in milliseconds |
ROUTERMCP_DEBUG | Enable debug logging (true/false) |
# Uses ROUTERMCP_URL and ROUTERMCP_API_KEY from env
client = RouterMCPClient()Typed Results with Pydantic
Use call_tool_typed with Pydantic models for type-safe results:
from pydantic import BaseModel
from routermcp import RouterMCPClient
class Issue(BaseModel):
id: int
url: str
title: str
async with RouterMCPClient(url='...') as client:
issue = await client.call_tool_typed(
'github_create_issue',
{'title': 'Bug report'},
Issue,
)
# issue is typed as Issue
print(issue.url)