RouterMCP
SDKsTypeScript

TypeScript SDK

Official TypeScript SDK for RouterMCP with framework adapters for Vercel AI SDK, LangChain, Google ADK, and Mastra.

TypeScript SDK

The @routermcp/sdk package provides a fully-typed client for connecting to RouterMCP from Node.js, Bun, Deno, and Edge runtimes.

Installation

npm install @routermcp/sdk
bun add @routermcp/sdk
yarn add @routermcp/sdk
pnpm add @routermcp/sdk

Quick Start

import { RouterMCPClient } from '@routermcp/sdk';

const client = new RouterMCPClient({
  url: 'https://gateway.routermcp.com/v1/mcp/my-project',
  apiKey: 'rmc_...',
});

// Connect and initialize
await client.connect();

// List available tools
const tools = await client.listTools();
console.log(`Found ${tools.length} tools`);

// Call a tool
const result = await client.callTool('github_create_issue', {
  title: 'Bug report',
  body: 'Found an issue...',
});

// Disconnect when done
await client.disconnect();

Configuration Options

const client = new RouterMCPClient({
  // Required
  url: 'https://gateway.routermcp.com/v1/mcp/my-project',
  
  // Authentication
  apiKey: 'rmc_...', // or set ROUTERMCP_API_KEY env var
  
  // Multi-user
  userId: '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: {
    adapter: memoryAdapter(), // Token storage adapter
    autoRefresh: true, // Auto-refresh expired tokens
  },
});

Environment Variables

The SDK automatically reads configuration from environment variables:

VariableDescription
ROUTERMCP_URLServer URL
ROUTERMCP_API_KEYAPI key
ROUTERMCP_USER_IDDefault user ID
ROUTERMCP_TIMEOUTTimeout in milliseconds
ROUTERMCP_DEBUGEnable debug logging (true/false)
// Uses ROUTERMCP_URL and ROUTERMCP_API_KEY from env
const client = new RouterMCPClient();

Typed Results

Use callToolTyped with Zod schemas for type-safe results:

import { z } from 'zod';

const IssueSchema = z.object({
  id: z.number(),
  url: z.string(),
  title: z.string(),
});

const issue = await client.callToolTyped(
  'github_create_issue',
  { title: 'Bug report' },
  IssueSchema
);

// issue is typed as { id: number, url: string, title: string }
console.log(issue.url);

Documentation

On this page