OpenRouter Model Router MCP Server
Enables ChatGPT to delegate tasks to various AI models (e.g., Gemini, Claude, Qwen) via OpenRouter, acting as an orchestrator that returns results with confirmed model usage.
README
Connect GPT to All Models with OpenRouter
فارسی · Agent instructions · Remote deployment · Security
Use ChatGPT as an orchestrator for other AI models. A user can say “ask
Gemini,” “review this with GLM,” “send this task to Kimi,” or “compare Claude
and Qwen.” ChatGPT calls an MCP tool, this project routes the request through
OpenRouter, and the answer returns to the same conversation with the actual
model_used value.
Supported friendly aliases include Gemini, Gemini Flash, GLM, Kimi, Claude, DeepSeek, and Qwen. Exact OpenRouter model slugs work too, and other short names can be resolved against OpenRouter's live model catalog.
This project does not turn one model into another. ChatGPT remains the host and orchestrator; OpenRouter provides access to external models that produce delegated answers. Every delegated request may incur OpenRouter charges.
Architecture
flowchart LR
U["User in ChatGPT"] --> O["ChatGPT orchestrator"]
O --> T["ngrok HTTPS tunnel"]
T --> M["OAuth-protected MCP model router"]
I["Auth0"] -->|"signed access token / JWKS"| M
M --> G["Private OpenRouter gateway"]
G --> R["OpenRouter API"]
R --> A["Gemini / GLM / Kimi / Claude / Qwen / others"]
A --> O
The project keeps the credential boundary explicit:
server.py— a credential-holding HTTP gateway. It binds to127.0.0.1:3188by default and talks to OpenRouter.mcp-server.mjs— a stdio MCP server with three tools. It calls the private gateway and never needs to expose the OpenRouter key to ChatGPT.remote-mcp-server.mjs— the optional ChatGPT-web transport. It binds only to loopback, validates Auth0 OAuth access tokens, and exposes/mcpfor an HTTPS tunnel such as ngrok.
Features
- Delegate one task to any OpenRouter model.
- Compare two to four models in parallel.
- Resolve aliases from the live catalog, with optional pinned model overrides.
- Return
model_requested,model_resolved, and confirmedmodel_used. - Keep the OpenRouter key outside ChatGPT and MCP tool responses.
- Use locally through stdio, through an existing local Mac MCP bridge, or from ChatGPT web through a protected HTTPS MCP endpoint.
- Zero third-party Python dependencies; Node is used only for MCP.
Requirements
- Python 3.10 or newer
- Node.js 20 or newer
- An OpenRouter API key with suitable limits
- For ChatGPT web: an HTTPS endpoint and a supported ChatGPT plan/workspace configuration for custom apps/MCP
Quick start
git clone https://github.com/Erfouni/connect-gpt-to-all-models-with-openrouter.git
cd connect-gpt-to-all-models-with-openrouter
cp .env.example .env
npm install
Edit .env and add your own key:
OPENROUTER_API_KEY=
Never paste that key into ChatGPT, a GPT instruction, an MCP configuration, a tunnel command, a screenshot, or a Git commit.
Start the private gateway:
python3 server.py
In another terminal:
curl http://127.0.0.1:3188/health
npm test
An optional paid API smoke test:
curl -X POST http://127.0.0.1:3188/run \
-H 'Content-Type: application/json' \
-d '{"model":"gemini","prompt":"Reply with exactly: ROUTER_OK","max_tokens":64}'
Operating modes
1. Local stdio MCP
Use this with an MCP client running on the same computer. Copy
examples/mcp-client-config.json, replace the absolute path, and add it to your
client's MCP configuration. Keep the gateway running, then the client starts
mcp-server.mjs over stdio.
npm run start:mcp
See Local setup.
2. Existing Mac MCP bridge
If ChatGPT already has access to a trusted Mac MCP that includes an HTTP-fetch tool, it can call the loopback gateway directly from that Mac:
POST http://127.0.0.1:3188/run
This keeps both the key and gateway private. Use the bridge-mode instructions in Agent instructions. Do not expose a general filesystem or shell MCP publicly just to reach this gateway.
3. Protected server / ChatGPT web
For ChatGPT web, configure the Auth0 and public URL fields in .env, then start
the authenticated Streamable HTTP server:
npm run start:mcp:http
It listens only on loopback by default; the MCP path is:
http://127.0.0.1:3200/mcp
The server validates the token signature through Auth0 JWKS, plus issuer,
audience, expiration, required scopes, and an optional client-ID allowlist. It
also publishes OAuth protected-resource metadata for ChatGPT discovery. Tunnel
only port 3200; never tunnel the private gateway on 3188.
After configuring your own ngrok reserved domain and local ngrok authtoken, run:
./scripts/start-secure-ngrok.sh
The URL registered in ChatGPT must be the same HTTPS resource URL configured as
PUBLIC_MCP_URL and AUTH0_AUDIENCE, for example:
https://mcp.example.com/mcp
It is not a local path such as /Users/name/project/start.sh. No ngrok
domain, authtoken, MCP token, API key, or personal path is included in this
repository. Create your own Auth0 application/API, ngrok tunnel, and
credentials. See Remote deployment before exposing
anything. A static API key or ngrok browser login is not a substitute for the
MCP OAuth flow expected by ChatGPT.
ChatGPT / Custom GPT setup
- Get the local or protected remote MCP mode working first.
- In ChatGPT, connect the custom app/MCP endpoint allowed by your plan or
workspace. For server mode, enter
https://YOUR_DOMAIN/mcpand select OAuth authentication. - Create a Custom GPT and enable the connected app, if that option is available for your account/workspace.
- Paste the provided instructions into the GPT instructions field.
- Save it privately and test: “Ask Gemini to reply with
MODEL_OK.” - Confirm that the response includes a real
model_usedvalue.
On ChatGPT web, a saved GPT can also be brought into an existing conversation
with @GPT_NAME, subject to current ChatGPT availability and workspace policy.
MCP tools
| Tool | Purpose |
|---|---|
openrouter_list_models |
Search the current OpenRouter catalog |
openrouter_run_model |
Delegate one prompt to a requested model |
openrouter_compare_models |
Run the same prompt with 2–4 models |
Gateway API
| Endpoint | Purpose |
|---|---|
GET /health |
Readiness and key-configuration status |
GET /models?search=... |
Search models |
POST /run |
Run one model |
POST /compare |
Compare models in parallel |
POST /refresh-models |
Refresh the cached catalog |
Example request:
{
"model": "kimi",
"prompt": "Review the relevant conversation and list the three biggest risks.",
"reasoning_effort": "high",
"max_tokens": 4096
}
Exact slugs such as provider/model-name are passed through unchanged. Alias
defaults can be pinned in .env; otherwise the newest matching live catalog
entry is selected.
Security essentials
.envis ignored by Git. Only.env.examplebelongs in the repository.- The gateway refuses a non-loopback bind unless
OPENROUTER_AGENT_TOKENis set. - The authenticated remote MCP also refuses a non-loopback bind. ngrok connects locally to it and provides public TLS.
- Do not expose port
3188to the internet. Expose only port3200through the tunnel after OAuth has been configured. - Do not publish a broad shell/filesystem MCP alongside this model router.
- Send external models only the context required for the delegated task.
- Set OpenRouter budget/rate limits and remember that
/comparecreates several independent billed requests. - Rotate any credential that has ever appeared in chat, logs, screenshots, or Git history.
Read the full security policy and deployment checklist.
Automatic startup on macOS
After creating .env, install the generated LaunchAgent for the private Python
gateway:
chmod +x scripts/*.sh
./scripts/install-macos-launchagent.sh
The installer computes paths locally. No username or personal path is stored in the repository.
Tests
npm test
python3 -m unittest discover -s tests -p 'test_*.py'
python3 -m py_compile server.py
These tests do not call a paid model.
License
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.