LLM Router MCP

LLM Router MCP

Route prompts intelligently across Claude, Gemini, and GPT-4o, automatically picking the best model for every task while minimizing token cost.

Category
访问服务器

README

LLM Router MCP

Route prompts intelligently across Claude, Gemini, and GPT-4o — automatically picking the best model for every task while minimising token cost.

npm TypeScript MCP Node.js License


✨ What is this?

llm-router-mcp is a Model Context Protocol (MCP) server that acts as an intelligent dispatcher for your AI workloads. Instead of hardcoding a single LLM into your workflow, the router analyses the intent of each prompt and automatically selects the most cost-effective and capable model for that specific task type.

Your prompt ──► LLM Router ──► PLANNING      → Gemini
                            ├── SCAFFOLDING  → Gemini
                            ├── CODEGEN      → Claude
                            ├── REFACTOR     → Claude
                            ├── REVIEW       → Claude
                            ├── TESTING      → GPT-4o
                            └── IMPLEMENT    → GPT-4o

🚀 Features

  • Smart intent-based routing — classifies prompts into 8 task categories and dispatches to the optimal model
  • Three frontier models — integrates Claude (Anthropic), Gemini (Google), and GPT-4o (OpenAI) out of the box
  • Zero-config mock mode — works out of the box with no API keys; auto-enables mock mode when keys are absent
  • Session-aware context caching — maintains conversation context across turns within the same session
  • Explicit tool shortcuts — bypass auto-routing with dedicated plan_workflow, generate_code, and implement_feature tools
  • MCP-native — drop it into any MCP-compatible host (Claude Desktop, Cursor, VS Code Continue, etc.)

📦 Quick Start

Option A — npx (no install needed)

npx llm-router-mcp

Option B — Global install

npm install -g llm-router-mcp
llm-router-mcp

Option C — From source

git clone https://github.com/Devatva24/LLM-Router-MCP.git
cd LLM-Router-MCP
npm install
npm run build
node dist/index.js

No API keys? No problem. The server automatically falls back to mock mode and logs a helpful message. You only need keys when you want real model responses.


🗺️ Routing Logic

Task Category Trigger Keywords Routed To
Planning architecture, design, system design, strategy, workflow ✦ Gemini
Scaffolding scaffold, boilerplate, setup, folder structure ✦ Gemini
Code Generation write a function, implement, create a class, algorithm ✦ Claude
Refactor refactor, clean up, improve, rewrite, restructure ✦ Claude
Code Review review, debug, explain, what's wrong, critique ✦ Claude
Testing unit tests, Jest, Vitest, test suite, test cases ✦ GPT-4o
Implementation implement, add endpoint, build the, create the API ✦ GPT-4o
General anything else ✦ Claude (fallback)

⚙️ Configuration

Set your API keys as environment variables to use real models:

# Mac / Linux
export ANTHROPIC_API_KEY=sk-ant-...
export GOOGLE_API_KEY=AIza...
export OPENAI_API_KEY=sk-...

# Windows (PowerShell)
$env:ANTHROPIC_API_KEY="sk-ant-..."
$env:GOOGLE_API_KEY="AIza..."
$env:OPENAI_API_KEY="sk-..."

If any keys are missing the server auto-enables mock mode — no crash, no config needed.


🖥️ Editor Integration

Claude Desktop

Edit ~/Library/Application Support/Claude/claude_desktop_config.json (Mac) or %APPDATA%\Claude\claude_desktop_config.json (Windows):

{
  "mcpServers": {
    "llm-router": {
      "command": "npx",
      "args": ["llm-router-mcp"]
    }
  }
}

Cursor

Add to your Cursor MCP settings:

{
  "mcpServers": {
    "llm-router": {
      "command": "npx",
      "args": ["llm-router-mcp"]
    }
  }
}

VS Code (Continue extension)

Add to ~/.continue/config.json:

{
  "mcpServers": {
    "llm-router": {
      "command": "npx",
      "args": ["llm-router-mcp"]
    }
  }
}

Ready-made config files for Cursor and Continue are included in the cursor-config/ and %USERPROFILE%/.continue/ directories of this repo.


🧰 Available MCP Tools

route_prompt

Automatically classifies and routes a prompt to the best model.

{
  "prompt": "Write a recursive function to flatten deeply nested objects",
  "session_id": "my-session"
}

plan_workflow

Explicitly routes to Gemini for high-level planning and architecture tasks.

{
  "prompt": "Design a checkout flow for an e-commerce app",
  "session_id": "my-session"
}

generate_code

Explicitly routes to Claude for complex logic, algorithms, and refactoring.

{
  "prompt": "Write a binary search tree with insert and delete",
  "session_id": "my-session"
}

implement_feature

Explicitly routes to GPT-4o for feature implementation and test generation.

{
  "prompt": "Implement the /api/products CRUD endpoints",
  "session_id": "my-session"
}

clear_context

Clears the cached conversation context for a given session.

{
  "session_id": "my-session"
}

🧪 Running Tests

The test suite validates all routing decisions in mock mode — no API keys needed:

npm test

Expected output:

🧪 LLM Router — mock test suite

  ✅ planning → Gemini
  ✅ codegen → Claude
  ✅ testing → GPT-4o
  ✅ review → Claude
  ✅ explicit plan_workflow
  ✅ explicit implement_feature
  ✅ context cache — 2nd turn
  ✅ clear_context

──────────────────────────────────────────
  8 passed  0 failed (8 total)

📁 Project Structure

LLM-Router-MCP/
├── src/
│   ├── index.ts          # MCP server entrypoint & routing logic
│   ├── classifier.ts     # Prompt intent classifier
│   ├── context-cache.ts  # Session-aware context management
│   ├── mock.ts           # Mock responses for zero-cost testing
│   └── logger.ts         # Lightweight logger
├── dist/                 # Compiled JavaScript (after npm run build)
├── cursor-config/        # Ready-made Cursor MCP config
├── test-router.cjs       # End-to-end test suite (mock mode)
├── tsconfig.json
└── package.json

🤝 Contributing

Contributions are welcome! Feel free to open an issue or submit a pull request for:

  • Adding support for additional LLM providers
  • Improving routing classification accuracy
  • Adding streaming response support
  • Writing more test coverage

📄 License

MIT — see LICENSE for details.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选