Skip to main content
Glama

OpenRouter MCP Server

OpenRouter MCP 服务器

模型上下文协议 (MCP) 服务器,可与 OpenRouter.ai 丰富的模型生态系统无缝集成。通过统一、类型安全的接口访问各种 AI 模型,该接口内置缓存、速率限制和错误处理功能。

特征

  • 模型访问
    • 直接访问所有 OpenRouter.ai 模型
    • 自动模型验证和能力检查
    • 默认模型配置支持
  • 性能优化
    • 智能模型信息缓存(1小时有效)
    • 自动速率限制管理
    • 失败请求的指数退避
  • 统一响应格式
    • 所有响应的ToolResult结构一致
    • 使用isError标志清除错误标识
    • 带有上下文的结构化错误消息

安装

pnpm install @mcpservers/openrouterai

配置

先决条件

  1. OpenRouter Keys获取您的 OpenRouter API 密钥
  2. 选择默认模型(可选)

环境变量

OPENROUTER_API_KEY=your-api-key-here OPENROUTER_DEFAULT_MODEL=optional-default-model

设置

添加到您的 MCP 设置配置文件( cline_mcp_settings.jsonclaude_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文件。

You must be authenticated.

A
security – no known vulnerabilities
A
license - permissive license
A
quality - confirmed to work

remote-capable server

The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.

提供与OpenRouter.ai的集成,允许通过统一的界面访问各种AI模型。

  1. 特征
    1. 安装
      1. 配置
        1. 先决条件
        2. 环境变量
        3. 设置
      2. 响应格式
        1. 可用工具
          1. 聊天完成
          2. 搜索模型
          3. 获取模型信息
          4. 验证模型
        2. 错误处理
          1. 发展
            1. 变更日志
              1. 执照

                Related MCP Servers

                • -
                  security
                  A
                  license
                  -
                  quality
                  This server facilitates the invocation of AI models from providers like Anthropic, OpenAI, and Groq, enabling users to manage and configure large language model interactions seamlessly.
                  Last updated -
                  9
                  Python
                  MIT License
                • -
                  security
                  A
                  license
                  -
                  quality
                  A proxy server that bridges AI agents and external APIs by dynamically translating OpenAPI specifications into standardized MCP tools, enabling seamless interaction without custom integration code.
                  Last updated -
                  39
                  Python
                  MIT License
                  • Linux
                  • Apple
                • -
                  security
                  A
                  license
                  -
                  quality
                  Enables AI agents to interact with multiple LLM providers (OpenAI, Anthropic, Google, DeepSeek) through a standardized interface, making it easy to switch between models or use multiple models in the same application.
                  Last updated -
                  3
                  Python
                  MIT License
                  • Linux
                  • Apple
                • A
                  security
                  A
                  license
                  A
                  quality
                  An AI router that connects applications to multiple LLM providers (OpenAI, Anthropic, Google, DeepSeek, Ollama, etc.) with smart model orchestration capabilities, enabling dynamic switching between models for different reasoning tasks.
                  Last updated -
                  3
                  8
                  11
                  TypeScript
                  MIT License
                  • Linux
                  • Apple

                View all related MCP servers

                MCP directory API

                We provide all the information about MCP servers via our MCP API.

                curl -X GET 'https://glama.ai/api/mcp/v1/servers/heltonteixeira/openrouterai'

                If you have feedback or need assistance with the MCP directory API, please join our Discord server