RouterMCP
SDKsPython

Framework Integrations

Use RouterMCP with LangChain and Google ADK.

Framework Integrations

The Python SDK provides adapters for LangChain and Google ADK, allowing you to use RouterMCP tools with your existing code.

LangChain

Install with LangChain support:

pip install routermcp[langchain]

Convert RouterMCP tools to LangChain StructuredTool format.

from routermcp import RouterMCPClient
from routermcp.framework import to_langchain_tools
from langchain_openai import ChatOpenAI
from langchain.agents import AgentExecutor, create_openai_functions_agent
from langchain_core.prompts import ChatPromptTemplate

async with RouterMCPClient(
    url='https://gateway.routermcp.com/v1/mcp/my-project',
    api_key='rmc_...',
) as client:
    # Convert to LangChain tools
    tools = await to_langchain_tools(client)
    
    # Create agent
    llm = ChatOpenAI(model='gpt-4o')
    prompt = ChatPromptTemplate.from_messages([
        ('system', 'You are a helpful assistant with access to various tools.'),
        ('human', '{input}'),
        ('placeholder', '{agent_scratchpad}'),
    ])
    
    agent = create_openai_functions_agent(llm, tools, prompt)
    executor = AgentExecutor(agent=agent, tools=tools)
    
    # Run agent
    result = await executor.ainvoke({
        'input': 'Find all open issues labeled "bug" and create a summary',
    })
    
    print(result['output'])

With Chat Models

from langchain_openai import ChatOpenAI
from routermcp import RouterMCPClient
from routermcp.framework import to_langchain_tools

async with RouterMCPClient(url='...') as client:
    tools = await to_langchain_tools(client)
    llm = ChatOpenAI(model='gpt-4o').bind(tools=tools)
    
    response = await llm.ainvoke('List my GitHub repositories')
    print(response)

Tool Schema Conversion

The adapter automatically converts RouterMCP tool schemas to LangChain format:

RouterMCP TypeLangChain Type
stringstr
integerint
numberfloat
booleanbool
arraylist
objectdict

Google ADK

Install with Google ADK support:

pip install routermcp[google-adk]

Convert RouterMCP tools to Google Generative AI function declarations.

from routermcp import RouterMCPClient
from routermcp.framework import to_google_adk_tools
from google import genai

async with RouterMCPClient(
    url='https://gateway.routermcp.com/v1/mcp/my-project',
    api_key='rmc_...',
) as client:
    # Get declarations and executor
    adk_tools = await to_google_adk_tools(client)
    
    # Create Gemini model with tools
    genai_client = genai.Client(api_key='...')
    
    # Start chat with function declarations
    chat = genai_client.chats.create(
        model='gemini-2.0-flash',
        config={
            'tools': [{'function_declarations': adk_tools.declarations}],
        },
    )
    
    # Send message
    response = chat.send_message('Create a new issue for the performance bug')
    
    # Handle function calls
    for part in response.candidates[0].content.parts:
        if hasattr(part, 'function_call'):
            func_call = part.function_call
            
            # Execute via RouterMCP
            tool_result = await adk_tools.executor(func_call.name, func_call.args)
            
            # Send result back
            follow_up = chat.send_message(
                genai.types.Content(
                    parts=[
                        genai.types.Part(
                            function_response=genai.types.FunctionResponse(
                                name=func_call.name,
                                response={'result': tool_result},
                            )
                        )
                    ]
                )
            )
            
            print(follow_up.text)

GoogleADKTools Structure

class GoogleADKTools:
    declarations: list[dict]  # Function declarations for Gemini
    executor: Callable[[str, dict], Awaitable[str]]  # Async tool executor

Framework Comparison

FeatureLangChainGoogle ADK
Async SupportYesYes
AgentsFull supportVia chat
MemoryBuilt-inVia chat
StreamingYesLimited

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

Using Multiple Frameworks

You can use multiple framework adapters with the same client:

from routermcp import RouterMCPClient
from routermcp.framework import to_langchain_tools, to_google_adk_tools

async with RouterMCPClient(url='...') as client:
    # Same client, different frameworks
    langchain_tools = await to_langchain_tools(client)
    google_tools = await to_google_adk_tools(client)
    
    # Use whichever framework fits your use case

Error Handling

Framework adapters propagate errors from RouterMCP:

from routermcp.types import MCPError, TransportError

try:
    tools = await to_langchain_tools(client)
    # Use tools...
except TransportError as e:
    print(f'Network error: {e}')
except MCPError as e:
    print(f'MCP error: {e}')

On this page