RouterMCP
SDKsTypeScript

Framework Integrations

Use RouterMCP with Vercel AI SDK, LangChain, Google ADK, and Mastra.

Framework Integrations

The TypeScript SDK provides adapters for popular AI frameworks, allowing you to use RouterMCP tools with your existing code.

Vercel AI SDK

Convert RouterMCP tools to Vercel AI SDK tool format for use with generateText and streamText.

import { RouterMCPClient, toAISDKTools } from '@routermcp/sdk';
import { generateText } from 'ai';
import { openai } from '@ai-sdk/openai';

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

await client.connect();

// Convert to AI SDK tools
const tools = await toAISDKTools(client);

// Use with generateText
const { text, toolCalls } = await generateText({
  model: openai('gpt-4o'),
  tools,
  prompt: 'Create a GitHub issue for the login bug',
});

console.log(text);
console.log('Tool calls:', toolCalls);

await client.disconnect();

Streaming

import { streamText } from 'ai';

const tools = await toAISDKTools(client);

const result = streamText({
  model: openai('gpt-4o'),
  tools,
  prompt: 'Search for recent issues and summarize them',
});

for await (const chunk of result.textStream) {
  process.stdout.write(chunk);
}

LangChain

Convert RouterMCP tools to LangChain StructuredTool format.

import { RouterMCPClient, toLangChainTools } from '@routermcp/sdk';
import { ChatOpenAI } from '@langchain/openai';
import { AgentExecutor, createOpenAIFunctionsAgent } from 'langchain/agents';
import { ChatPromptTemplate } from '@langchain/core/prompts';

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

await client.connect();

// Convert to LangChain tools
const tools = await toLangChainTools(client);

// Create agent
const llm = new ChatOpenAI({ model: 'gpt-4o' });
const prompt = ChatPromptTemplate.fromMessages([
  ['system', 'You are a helpful assistant with access to various tools.'],
  ['human', '{input}'],
  ['placeholder', '{agent_scratchpad}'],
]);

const agent = await createOpenAIFunctionsAgent({ llm, tools, prompt });
const executor = new AgentExecutor({ agent, tools });

// Run agent
const result = await executor.invoke({
  input: 'Find all open issues labeled "bug" and create a summary',
});

console.log(result.output);

await client.disconnect();

With Chat Models

import { ChatOpenAI } from '@langchain/openai';

const tools = await toLangChainTools(client);
const llm = new ChatOpenAI({ model: 'gpt-4o' }).bind({ tools });

const response = await llm.invoke('List my GitHub repositories');

Google ADK

Convert RouterMCP tools to Google Generative AI function declarations.

import { RouterMCPClient, toGoogleADKTools } from '@routermcp/sdk';
import { GoogleGenerativeAI } from '@google/generative-ai';

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

await client.connect();

// Get declarations and executor
const { declarations, executor } = await toGoogleADKTools(client);

// Create Gemini model with tools
const genAI = new GoogleGenerativeAI(process.env.GOOGLE_API_KEY!);
const model = genAI.getGenerativeModel({
  model: 'gemini-1.5-pro',
  tools: [{ functionDeclarations: declarations }],
});

// Start chat
const chat = model.startChat();
const result = await chat.sendMessage('Create a new issue for the performance bug');

// Handle function calls
const response = result.response;
const functionCall = response.functionCalls()?.[0];

if (functionCall) {
  const toolResult = await executor(functionCall.name, functionCall.args);
  
  // Send result back to model
  const followUp = await chat.sendMessage([
    { functionResponse: { name: functionCall.name, response: { result: toolResult } } },
  ]);
  
  console.log(followUp.response.text());
}

await client.disconnect();

Mastra

Convert RouterMCP tools to Mastra tool definitions.

import { RouterMCPClient, toMastraTools } from '@routermcp/sdk';
import { Agent } from '@mastra/core';

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

await client.connect();

// Convert to Mastra tools
const tools = await toMastraTools(client);

// Create Mastra agent
const agent = new Agent({
  name: 'helper',
  instructions: 'You are a helpful assistant with access to various tools.',
  model: {
    provider: 'OPEN_AI',
    name: 'gpt-4o',
  },
  tools,
});

// Run agent
const response = await agent.generate('Create a GitHub issue for the login bug');
console.log(response.text);

await client.disconnect();

Framework Comparison

FeatureAI SDKLangChainGoogle ADKMastra
StreamingYesYesLimitedYes
AgentsVia toolsFull supportVia chatFull support
MemoryVia contextBuilt-inVia chatBuilt-in
Parallel callsYesYesYesYes

All framework adapters automatically handle tool input schema conversion and result parsing. You don't need to manually transform the data.

Combining Frameworks

You can use multiple framework adapters with the same client:

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

await client.connect();

// Same client, different frameworks
const aiSdkTools = await toAISDKTools(client);
const langchainTools = await toLangChainTools(client);
const googleTools = await toGoogleADKTools(client);
const mastraTools = await toMastraTools(client);

// Use whichever framework fits your use case

On this page