• Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
dcm31

dcm31

mcp-router

Model-agnostic MCP router: OpenAI, Claude, Gemini + MCP
Public
Like
mcp-router
Home
Code
5
api
2
providers
5
ui
3
README.md
H
index.tsx
Connections
Environment variables
Branches
1
Pull requests
Remixes
History
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
README.md

⚡ MCP Router

Model-agnostic MCP router for the Big Three: OpenAI, Claude, and Gemini.

One API, one UI — point any MCP server at any frontier model. Switch between GPT-5, Claude Opus 4, and Gemini 2.5 Pro without changing your tool integrations.

How It Works

Architecture

┌─────────────┐     ┌──────────────────────┐     ┌───────────────┐
│   Chat UI   │────▶│   POST /api/chat     │────▶│  MCP Servers  │
│  (browser)  │◀────│   Model Router       │◀────│  (any remote) │
└─────────────┘     └──────────────────────┘     └───────────────┘
                           │
                    ┌──────┼──────┐
                    ▼      ▼      ▼
               ┌────────┐ ┌─────┐ ┌────────┐
               │ OpenAI │ │Claude│ │ Gemini │
               │Response│ │ Msg │ │ GenAI  │
               │  API   │ │ API │ │  SDK   │
               └────────┘ └─────┘ └────────┘

Provider Adapters

ProviderAPIMCP StrategyHow It Works
OpenAIResponses APIServer-sidePass type: "mcp" + server URL → OpenAI handles everything
AnthropicMessages APIClient-sideConnect to MCP, discover tools, agentic loop (tool_use → callTool → tool_result)
GoogleGenAI SDKClient-sideConnect to MCP, discover tools, agentic loop (functionCall → callTool → functionResponse)

Model Auto-Detection

The router detects the provider from the model string:

  • gpt-*, o3*, o4* → OpenAI
  • claude-* → Anthropic
  • gemini-* → Google

Or use explicit prefixes: openai/gpt-4.1, anthropic/claude-sonnet-4-5, google/gemini-2.5-flash

Setup

1. Set API Keys

Add environment variables for the providers you want to use:

KeyProviderGet it from
OPENAI_API_KEYOpenAIplatform.openai.com
ANTHROPIC_API_KEYAnthropicconsole.anthropic.com
GOOGLE_API_KEYGoogleaistudio.google.com

You only need keys for providers you plan to use. The UI shows which are configured.

2. Add MCP Servers

In the sidebar, add any remote MCP server URL. Examples:

  • Val Town MCP: https://www.val.town/mcp
  • Notion MCP: https://mcp.notion.com/mcp
  • Any Streamable HTTP or SSE MCP server

3. Chat

Pick a model, type a message. The router handles the rest.

API

POST /api/chat

{ "model": "gpt-4.1-mini", "messages": [ { "role": "user", "content": "What tools do you have?" } ], "mcpServers": [ { "url": "https://mcp.example.com/sse", "label": "my-server" } ], "system": "You are a helpful assistant." }

Response (same shape for all providers):

{ "content": "I have access to the following tools...", "toolCalls": [ { "name": "list_tools", "serverLabel": "my-server", "arguments": "{}", "output": "..." } ], "provider": "openai", "model": "gpt-4.1-mini", "usage": { "inputTokens": 150, "outputTokens": 89 } }

GET /api/models

Returns available models and which API keys are configured.

Available Models

OpenAI (Responses API — server-side MCP)

  • gpt-5 — GPT-5 flagship
  • gpt-4.1 / gpt-4.1-mini / gpt-4.1-nano — GPT-4.1 family
  • o3 / o4-mini — Reasoning models

Anthropic (Messages API — client-side MCP)

  • claude-opus-4-6 — Claude Opus 4
  • claude-sonnet-4-5-20250929 — Claude Sonnet 4.5
  • claude-haiku-3-5-20241022 — Claude Haiku 3.5

Google (GenAI SDK — client-side MCP)

  • gemini-2.5-pro — Gemini 2.5 Pro
  • gemini-2.5-flash — Gemini 2.5 Flash
  • gemini-2.0-flash — Gemini 2.0 Flash

Key Differences Between Providers

OpenAI is the simplest: their Responses API handles MCP server-side. You pass a URL, they call the MCP server, execute tools, and return results. Zero orchestration code needed.

Anthropic and Google require client-side MCP orchestration. The router connects to MCP servers, discovers tools, converts schemas to each provider's format, then runs an agentic loop — sending messages, catching tool calls, executing them against MCP servers, and feeding results back until the model is done.

Tech Stack

  • Runtime: Val Town (Deno)
  • Framework: Hono
  • OpenAI: openai npm package — Responses API
  • Anthropic: @anthropic-ai/sdk — Messages API
  • Google: @google/genai — GenAI SDK
  • MCP: @modelcontextprotocol/sdk — Streamable HTTP client

Built on Val Town. March 2026.

Code
apiprovidersuiREADME.md
H
index.tsx
FeaturesVersion controlCode intelligenceCLIMCP
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
AboutAlternativesPricingBlogNewsletterCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Open Source Pledge
Terms of usePrivacy policyAbuse contact
© 2026 Val Town, Inc.