OpenRouter MCP Server
OpenRouter MCP 服务器
模型上下文协议 (MCP) 服务器,可与 OpenRouter.ai 丰富的模型生态系统无缝集成。通过统一、类型安全的接口访问各种 AI 模型,该接口内置缓存、速率限制和错误处理功能。
特征
模型访问
直接访问所有 OpenRouter.ai 模型
自动模型验证和能力检查
默认模型配置支持
性能优化
智能模型信息缓存(1小时有效)
自动速率限制管理
失败请求的指数退避
统一响应格式
所有响应的
ToolResult结构一致使用
isError标志清除错误标识带有上下文的结构化错误消息
Related MCP server: OpenRouter MCP Multimodal Server
安装
pnpm install @mcpservers/openrouterai配置
先决条件
从OpenRouter Keys获取您的 OpenRouter API 密钥
选择默认模型(可选)
环境变量
OPENROUTER_API_KEY=your-api-key-here
OPENROUTER_DEFAULT_MODEL=optional-default-model设置
添加到您的 MCP 设置配置文件( cline_mcp_settings.json或claude_desktop_config.json ):
{
"mcpServers": {
"openrouterai": {
"command": "npx",
"args": ["@mcpservers/openrouterai"],
"env": {
"OPENROUTER_API_KEY": "your-api-key-here",
"OPENROUTER_DEFAULT_MODEL": "optional-default-model"
}
}
}
}响应格式
所有工具都以标准化结构返回响应:
interface ToolResult {
isError: boolean;
content: Array<{
type: "text";
text: string; // JSON string or error message
}>;
}成功案例:
{
"isError": false,
"content": [{
"type": "text",
"text": "{\"id\": \"gen-123\", ...}"
}]
}错误示例:
{
"isError": true,
"content": [{
"type": "text",
"text": "Error: Model validation failed - 'invalid-model' not found"
}]
}可用工具
聊天完成
向 OpenRouter.ai 模型发送消息:
interface ChatCompletionRequest {
model?: string;
messages: Array<{role: "user"|"system"|"assistant", content: string}>;
temperature?: number; // 0-2
}
// Response: ToolResult with chat completion data or error搜索模型
搜索并过滤可用型号:
interface ModelSearchRequest {
query?: string;
provider?: string;
minContextLength?: number;
capabilities?: {
functions?: boolean;
vision?: boolean;
};
}
// Response: ToolResult with model list or error获取模型信息
获取特定型号的详细信息:
{
model: string; // Model identifier
}验证模型
检查模型 ID 是否有效:
interface ModelValidationRequest {
model: string;
}
// Response:
// Success: { isError: false, valid: true }
// Error: { isError: true, error: "Model not found" }错误处理
服务器提供带有上下文信息的结构化错误:
// Error response structure
{
isError: true,
content: [{
type: "text",
text: "Error: [Category] - Detailed message"
}]
}常见错误类别:
Validation Error:输入参数无效API Error:OpenRouter API 通信问题Rate Limit:请求节流检测Internal Error:服务器端处理失败
处理响应:
async function handleResponse(result: ToolResult) {
if (result.isError) {
const errorMessage = result.content[0].text;
if (errorMessage.startsWith('Error: Rate Limit')) {
// Handle rate limiting
}
// Other error handling
} else {
const data = JSON.parse(result.content[0].text);
// Process successful response
}
}发展
有关以下方面的详细信息,请参阅CONTRIBUTING.md :
开发设置
项目结构
功能实现
错误处理指南
工具使用示例
# Install dependencies
pnpm install
# Build project
pnpm run build
# Run tests
pnpm test变更日志
查看CHANGELOG.md了解最新更新,包括:
统一响应格式实现
增强的错误处理系统
类型安全接口改进
执照
该项目根据 Apache License 2.0 获得许可 - 有关详细信息,请参阅LICENSE文件。
Available Tools
4 toolschat_completionA
Sends conversational context (messages) to OpenRouter.ai for completion using a specified model. Use this for dialogue, text generation, or instruction-following tasks. Supports advanced provider routing and parameter overrides. Returns the generated text response.
Inputs: messages (required), model, provider, max_tokens, +1 more.
get_model_infoA
Retrieves the complete metadata for a single OpenRouter.ai model specified by its unique ID. Use this when you know the model ID and need its full details (pricing, context limits, capabilities, etc.). Returns a model information object.
Inputs: model (required).
search_modelsA
Queries the OpenRouter.ai model registry, filtering by various criteria like capabilities, pricing, or provider. Use this to discover models suitable for specific needs. Returns a list of matching model metadata objects.
Inputs: limit, query, provider, capabilities, +4 more.
validate_modelA
Verifies if a given model ID exists within the OpenRouter.ai registry. Use this for a quick check of model ID validity before making other API calls. Returns a boolean value (true if valid, false otherwise).
Inputs: model (required).
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
TDQS
Scored across 4 tools
All four tools serve clearly distinct purposes: chat_completion generates text, get_model_info retrieves details for a specific model, search_models filters models by criteria, and validate_model checks model existence. No overlap or ambiguity.
All tool names follow a consistent verb_noun pattern (chat_completion, get_model_info, search_models, validate_model) using snake_case. This makes the API predictable and easy to use.
With 4 tools, the set is well-scoped for OpenRouter's purpose: one core action (chat), two for model discovery (get and search), and one for validation. No bloat or deficiency.
The tool set covers the essential workflows: chatting, retrieving model metadata, searching for models, and verifying model existence. No critical missing functionality for typical use.
Maintenance
Related MCP Connectors
AI model routing on your own vendor keys: pick the best model per prompt, or route and run it.
The OpenRouter MCP server plugs OpenRouter into the AI tools you already use. Once connected, your assistant can pull live OpenRouter data (models, prices, your credits, rankings, and docs) and send quick test messages, all without leaving your editor.
Open AI models through one OpenAI-compatible API: chat, live model list, prices and cost estimates.
Related MCP Servers
- AlicenseBqualityBmaintenanceProvides chat and image analysis capabilities through OpenRouter.ai's diverse model ecosystem, enabling both text conversations and powerful multimodal image processing with various AI models.11407 npm104Apache 2.0
- FlicenseBqualityDmaintenanceProvides access to OpenRouter.ai's diverse model ecosystem for text chat and image analysis capabilities, with support for multimodal conversations and automatic image optimization.712 npm-
- AlicenseNot gradedqualityDmaintenanceProvides seamless access to 200+ AI models through OpenRouter's unified API, featuring multi-model collaboration, vision support, intelligent benchmarking, and collective intelligence capabilities for enhanced decision-making.10MIT
- AlicenseAqualityBmaintenanceProvides access to 400+ AI models from OpenRouter, enabling users to chat with models like GPT-4, Claude, Gemini, and Llama, compare responses across multiple models, and retrieve model information with pricing details.414MIT