RouterMCP
SDKs

Examples

Runnable code examples for TypeScript and Python SDKs

Examples

Complete, runnable examples demonstrating common use cases for both SDKs.

Repository

All examples are available on GitHub:

github.com/aistack/routermcp-sdks/tree/main/examples

TypeScript Examples

ExampleDescription
01-basic-connectionConnect, list tools, call a tool
02-typed-resultsType-safe results with Zod schemas
03-error-handlingHandle all error types gracefully
04-multi-user-sessionsIsolated sessions per user
05-oauth-flowOAuth adapters and authorization
06-vercel-aiVercel AI SDK integration
07-langchainLangChain agent with MCP tools
08-google-adkGoogle ADK function calling
09-mastraMastra agent integration

Quick Start

cd examples/typescript
cp .env.example .env
npm install
npm run example:01

Python Examples

ExampleDescription
01_basic_connectionAsync client with context manager
02_typed_resultsPydantic model validation
03_error_handlingComprehensive error handling
04_multi_user_sessionsRouterMCPSession for multiple users
05_oauth_flowOAuth adapter configuration
06_sync_clientSynchronous client for scripts
07_langchainLangChain agent integration
08_google_adkGoogle ADK tools

Quick Start

cd examples/python
cp .env.example .env
pip install -r requirements.txt
python examples/01_basic_connection.py

Environment Variables

Both example sets use the same environment variables:

VariableRequiredDescription
ROUTERMCP_API_KEYYesYour RouterMCP API key
ROUTERMCP_USER_IDNoUser ID for OAuth token storage
OPENAI_API_KEYFor AI examplesOpenAI API key
GOOGLE_API_KEYFor ADK examplesGoogle API key

The SDK defaults to https://routermcp.com as the base URL.

Framework Dependencies

Framework integrations require additional dependencies:

TypeScript

npm install ai @ai-sdk/openai          # Vercel AI SDK
npm install langchain @langchain/openai # LangChain
npm install @google/generative-ai       # Google ADK
npm install @mastra/core                # Mastra

Python

pip install langchain langchain-openai  # LangChain
pip install google-generativeai         # Google ADK

On this page