OpenRouter MCP Server
OpenRouter MCP サーバー
OpenRouter.aiの多様なモデルエコシステムとのシームレスな統合を実現するモデルコンテキストプロトコル(MCP)サーバー。キャッシュ、レート制限、エラー処理を内蔵した統合型セーフインターフェースを通じて、様々な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