Logo OpenRouter

OpenRouter

Cộng đồng
th3nolo

Mcp compatible with claude code cli tool to use open router models

Nhà phát hànhth3nolo
Kho mãopenrouter-mcp
Ngôn ngữTypeScript
Bản fork
9
Sao
13
Công cụ có sẵn
0
Phương thức truyền tảistdio
Danh mục
Liên kết
  • Kết nối công cụ với quy trình làm việc AI

    OpenRouter cung cấp các khả năng MCP mà ứng dụng khách và tác nhân AI tương thích có thể sử dụng.

  • 0 công cụ có sẵn

    Xem các thao tác có thể gọi bên dưới, kèm tên và mô tả nếu máy chủ cung cấp.

  • Cấu hình sẵn để sao chép

    Dùng các đoạn cấu hình cài đặt mẫu để thiết lập máy chủ này trong ứng dụng khách MCP bạn muốn dùng.

  • Chỉ số quan tâm đến mã nguồn mở

    13 sao và 9 bản fork từ kho mã được liên kết.

OpenRouter MCP server

This project connects agents to OpenRouter through two front doors: an agent-first command-line interface and a strict stateless MCP server. Both use the same operation layer and stable response shapes. The MCP server exposes thirteen focused tools and one API-key usage resource.

Version 3.0 targets MCP 2026-07-28 only. Each HTTP POST is independent. The server does not accept initialize, create Mcp-Session-Id sessions, expose a GET event stream, or run a legacy fallback.

Design notes and the reasoning behind the stateless 2026-07-28 surface are in the engineering note Building a strict stateless MCP 2026-07-28 server for OpenRouter. More notes and case studies: th3nolo.com. Author: Manuel Parra.

What changed in 3.0

  • list_models sends pagination, filters, and sorting to OpenRouter instead of downloading the full catalog.
  • get_model calls OpenRouter's direct model endpoint. It replaces get_model_info; there is no alias.
  • list_model_endpoints returns provider price, context, uptime, latency, throughput, and supported parameters.
  • list_providers exposes provider geography, policy links, and service-status metadata without a browser.
  • list_model_rankings and list_app_rankings expose bounded versions of OpenRouter's public rankings pages.
  • get_credits and list_activity expose account data with a separate management-key boundary.
  • get_analytics_schema and query_analytics expose the current Activity Explore analytics contract with explicit time ranges and bounded results.
  • chat_with_model and compare_models return a generation_id and the resolved model.
  • get_generation uses that ID to fetch exact provider, token, latency, and cost metadata.
  • The openrouter-mcp CLI exposes the same operations directly, emits JSON automatically when piped, and never prompts.
  • Browser inspection informed the surface contract, but no browser, cookie, HAR file, or browser session is required at runtime.
  • openrouter://models and openrouter://pricing were removed. Their unbounded catalog payloads are not retained as fallbacks.
  • Unknown fields added by OpenRouter are stripped at the API boundary. The MCP output schemas remain stable.
  • Static discovery responses declare a one-hour public cache hint. API-key usage remains private with a five-second hint.
  • Model comparisons run at most three OpenRouter calls at once. Paid calls are never retried automatically.
  • Custom OpenRouter base URLs must use HTTPS. Plain HTTP is accepted only for loopback development.

See docs/API.md for the complete tool contract, docs/CLI.md for direct CLI use, and docs/MCP-2026-07-28.md for wire-level behavior.

Requirements

  • Node.js 24 LTS
  • pnpm 12.0.0, exactly as pinned in package.json
  • An OpenRouter API key for rankings, inference, generation metadata, and key-usage data
  • An OpenRouter management key for credit totals, account activity, and analytics

OpenRouter currently serves public model and provider discovery without a key. That anonymous behavior may be rate-limited or changed upstream.

Install

bash
git clone https://github.com/th3nolo/openrouter-mcp.git
cd openrouter-mcp
pnpm install
pnpm run check

pnpm-workspace.yaml waits 72 hours before resolving a release. It also blocks exotic transitive sources and trust downgrades. Only esbuild@0.28.2 may run a dependency lifecycle script.

On Windows, pnpm@12.0.0 does not carry an Authenticode signature. Windows may label it "Unknown publisher." Install it with a method from pnpm's installation guide, and do not weaken Defender or PowerShell execution policy to suppress the warning.

Copy .env.example to .env, then set:

dotenv
OPENROUTER_API_KEY=your_openrouter_api_key_here
# Optional; required only for get_credits and list_activity
OPENROUTER_MANAGEMENT_KEY=your_openrouter_management_key_here

Keep .env out of Git.

Use the CLI

Build once, then call the same operations without starting an MCP client:

bash
pnpm run build
node dist/cli.js schema
node dist/cli.js models list --q claude --limit 5
node dist/cli.js providers list --datacenter DE
node dist/cli.js rankings models --limit 10
node dist/cli.js account credits
node dist/cli.js analytics schema

Interactive terminals receive compact text or tables. Redirected output is JSON automatically; --json makes that behavior explicit. Diagnostics use stderr, usage failures exit with status 2, operation failures exit with status 1, and commands never prompt. Run the strict stateless server through the same binary with node dist/cli.js serve --transport stdio.

Use with Claude over stdio

stdio is the default transport for local Claude integrations.

bash
pnpm run build
claude mcp add --transport stdio --scope user \
  --env OPENROUTER_API_KEY=your_openrouter_api_key_here \
  openrouter -- node /absolute/path/to/openrouter-mcp/dist/server.js

The equivalent Claude Desktop configuration is in examples/claude-config.json.

Use with Claude over local HTTP

Start the loopback-only server:

bash
pnpm run build
OPENROUTER_API_KEY=your_openrouter_api_key_here pnpm run start:http

On PowerShell:

powershell
$env:OPENROUTER_API_KEY = "your_openrouter_api_key_here"
pnpm run start:http

Then register its URL:

bash
claude mcp add --transport http --scope user openrouter http://127.0.0.1:3000/mcp

HTTP mode listens only on 127.0.0.1 and validates the Host and Origin headers. It does not implement a bearer-token shortcut.

Do not expose this listener directly to the internet. Put an HTTPS gateway that implements the MCP OAuth 2.1 resource-server flow in front of it.

Tools

ToolPurposeExternal effect
list_modelsSearch, filter, sort, and page the live model catalogRead-only OpenRouter request
get_modelRead one exact model, variant, or aliasRead-only OpenRouter request
list_model_endpointsCompare the providers serving one modelRead-only OpenRouter request
list_providersFilter providers by name, headquarters, or datacenterRead-only public request
list_model_rankingsRead one completed UTC day of model rankingsRead-only API-key request
list_app_rankingsRead popular or trending public appsRead-only API-key request
get_creditsRead purchased, used, and remaining creditsRead-only management request
list_activityRead endpoint-level daily account activityRead-only management request
get_analytics_schemaDiscover current analytics metrics, dimensions, operators, and granularitiesRead-only management request
query_analyticsQuery bounded Activity Explore aggregates over an explicit time rangeRead-only management request
chat_with_modelGenerate one response and return its generation IDCan consume API credits
compare_modelsGenerate with two to eight models, three calls at a timeCan consume API credits per model
get_generationRead provider, tokens, latency, and cost for one generation IDRead-only authenticated request

Each tool returns a text block and structuredContent. Zod rejects invalid input before the handler runs. The SDK converts upstream failures into MCP tool errors.

Resource

URIDataCache hint
openrouter://usageUsage and limits for the configured API keyPrivate, five seconds

Model and pricing catalogs are tools rather than resources so every response can be filtered and bounded.

Verify the live API

bash
pnpm run test:live

The command always checks live model pagination, direct model lookup, model endpoints, and provider discovery. If OPENROUTER_API_KEY is configured, it also checks both ranking datasets, sends one short request through openrouter/free, and resolves the returned generation metadata. If OPENROUTER_MANAGEMENT_KEY is configured, it checks credits, bounded activity, analytics schema discovery, and a small seven-day analytics query. The report never prints a credential or generation ID.

Environment

VariableDefaultMeaning
OPENROUTER_API_KEYnoneOpenRouter key for rankings, inference, generation metadata, and openrouter://usage
OPENROUTER_MANAGEMENT_KEYOPENROUTER_API_KEYOpenRouter management key for credits, account activity, and analytics
OPENROUTER_BASE_URLhttps://openrouter.ai/api/v1HTTPS OpenRouter API base URL; HTTP is loopback-only
OPENROUTER_SITE_URLnoneOptional HTTP-Referer app attribution
OPENROUTER_APP_NAMEOpenRouter MCP ServerX-OpenRouter-Title attribution
OPENROUTER_TIMEOUT_MS60000Per-request timeout
MCP_TRANSPORTstdiostdio or http
MCP_HTTP_PORT3000Local HTTP port

Command-line --transport and --port values override their environment variables.

Development

bash
pnpm run typecheck
pnpm run lint
pnpm run test
pnpm run build

# Complete offline source gate
pnpm run check

# Build first, then verify the packed distribution
pnpm pack --out contract-package.tgz
pnpm run test:smoke

The deterministic tests cover modern HTTP without initialize, strict legacy rejection, real stdio negotiation, CLI schema output, cache hints, credential separation, upstream and local pagination, direct API routes, generation handles, comparison concurrency, cancellation, schema drift, bounded errors, and HTTPS enforcement. The live contract tests are separate because they depend on current network and OpenRouter availability. pnpm run test:live:public runs the public catalog regression; pnpm run test:live runs the broader live contract described above. Missing credentials remain reported as skipped by the live report, never as passed. Neither live command runs in application CI.

.github/workflows/application.yml runs pnpm run check and the packed-distribution smoke test on pushes and pull requests with Node 24.19.0, pnpm 12.0.0, immutable action references, and a frozen lockfile. GitHub default-setup CodeQL remains a separate security check. The repository has no configured formatter; CI checks whitespace and the existing ESLint rules.

The offline runner refuses a checkout containing .env, removes inherited OpenRouter settings, and preloads a network-denial guard in the tests and their stdio children. Setting OPENROUTER_LIVE_TEST no longer enables live requests in pnpm test. The packed smoke suite extracts the actual tarball and uses its declared CLI/server entrypoints with the real SDK client; it checks modern discovery, strict legacy rejection, invalid tool/CLI input, stdout framing, EOF and process shutdown. Dependencies resolve from the frozen checkout, so this is packaged-entrypoint evidence, not a clean consumer install or live OpenRouter acceptance. TAP output reports test/pass/fail/skip counts separately for each offline suite.

Sources

License

MIT

Dùng MCP OpenRouter với nhiều mô hình AI

TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên sau khi kết nối OpenRouter, bạn có thể dùng với nhiều mô hình AI khác nhau trong TypingMind thay vì phải thiết lập riêng cho từng mô hình. MCP này chạy cục bộ thông qua trình kết nối MCP của TypingMind trên thiết bị của bạn.

Hướng dẫn thiết lập để dùng trình kết nối cục bộ

Dùng cách này khi máy chủ MCP cần truy cập các tệp, ứng dụng hoặc tài nguyên riêng tư trên máy tính của bạn.

1

Mở cài đặt MCP

Trong TypingMind, vào Cài đặt, Cài đặt nâng cao, rồi đến Giao thức ngữ cảnh mô hình và chọn Cài trình kết nối.

  1. Mở TypingMind trong trình duyệt của bạn.
  2. Nhấp vào biểu tượng Cài đặt.
  3. Vào Cài đặt nâng cao.
  4. Mở mục Giao thức ngữ cảnh mô hình.
  5. Nhấp vào Cài trình kết nối rồi chọn Thiết bị này.
Màn hình thiết lập trình kết nối MCP của TypingMind với tùy chọn Thiết bị này được chọn
2

Chạy lệnh trình kết nối

Chọn Thiết bị này, sao chép lệnh từ TypingMind và chạy trong Terminal. Giữ tiến trình chạy trong khi bạn dùng MCP.

  1. Sao chép lệnh thiết lập hiển thị trong TypingMind.
  2. Mở Terminal trên macOS hoặc Windows Terminal trên Windows.
  3. Dán và chạy lệnh.
  4. Xác nhận cài đặt gói nếu Terminal hỏi bạn có muốn tiếp tục không.
  5. Giữ tiến trình trong cửa sổ Terminal chạy trong khi dùng các công cụ MCP.
3

Thêm OpenRouter làm máy chủ

Khi trạng thái trình kết nối là Sẵn sàng, nhấp vào Sửa máy chủ và dán cấu hình máy chủ MCP.

  1. Đợi đến khi trạng thái trình kết nối hiển thị Sẵn sàng.
  2. Nhấp vào Sửa máy chủ.
  3. Dán cấu hình máy chủ MCP của OpenRouter.
  4. Lưu danh sách máy chủ.
  5. Làm mới nếu bạn muốn xác nhận trình kết nối vẫn sẵn sàng.
Cài đặt MCP của TypingMind hiển thị máy chủ đang hoạt động và nút Sửa máy chủ
{
  "mcpServers": {
    "openrouter-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "<mcp-server-package>"
      ]
    }
  }
}
4

Dùng kết nối với nhiều mô hình

Lưu danh sách máy chủ, mở Plugin, bật các công cụ MCP của OpenRouter, sau đó chọn bất kỳ mô hình AI nào được hỗ trợ trong TypingMind và dùng các công cụ trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.

  1. Mở trang Plugin trong TypingMind.
  2. Bật các công cụ MCP của OpenRouter.
  3. Bắt đầu cuộc trò chuyện và chọn mô hình AI bạn muốn dùng.
  4. Dùng các công cụ MCP trong cuộc trò chuyện hoặc gán chúng cho một tác nhân AI.
  5. Chuyển sang mô hình AI khác bất cứ khi nào cần mà không phải kết nối lại MCP.
Cuộc trò chuyện TypingMind dùng các công cụ MCP đã bật với một mô hình AI được chọn
Bạn có thể dùng OpenRouter giúp tôi làm việc này không?
OpenRouter
Được. Tôi đã đọc.
Đây là kết quả tôi tìm được bằng OpenRouter.

Câu hỏi thường gặp

Máy chủ MCP OpenRouter dùng để làm gì?

OpenRouter là máy chủ MCP cho phép các ứng dụng AI tương thích kết nối với công cụ và ngữ cảnh bên ngoài. Trong TypingMind, bạn chỉ cần thêm máy chủ MCP này một lần để các công cụ của nó có sẵn trong không gian làm việc AI của bạn.

Bạn có thể dùng MCP OpenRouter với nhiều mô hình AI trong TypingMind không?

Có. TypingMind kết nối các công cụ MCP ở cấp không gian làm việc, nên bạn có thể dùng OpenRouter với nhiều mô hình AI như Claude, ChatGPT, Gemini hoặc các mô hình khác đã cấu hình trong TypingMind mà không cần thiết lập máy chủ MCP riêng cho từng mô hình.

Vì sao nên dùng MCP OpenRouter với TypingMind?

TypingMind là một trong những giao diện trò chuyện với LLM tốt nhất vì tập hợp nhiều mô hình AI, prompt, plugin, tác nhân AI, khóa API và công cụ MCP vào một không gian làm việc. Khi kết nối OpenRouter, bạn có thể dùng các công cụ MCP của dịch vụ này với những mô hình ưa thích, đồng thời giữ quy trình trò chuyện gọn gàng trong TypingMind.

Làm cách nào để kết nối MCP OpenRouter với TypingMind?

OpenRouter hoạt động thông qua trình kết nối MCP cục bộ của TypingMind. Đây là lựa chọn phù hợp nhất khi máy chủ MCP cần truy cập tệp cục bộ, ứng dụng máy tính, công cụ dòng lệnh hoặc tài nguyên riêng trên máy tính của bạn.

MCP OpenRouter cung cấp những công cụ nào trong TypingMind?

OpenRouter cung cấp các chức năng MCP mà bạn có thể bật từ trang Plugin của TypingMind để dùng trong trò chuyện hoặc gán cho tác nhân AI.

Bạn có cần chia sẻ khóa API với TypingMind để dùng MCP OpenRouter không?

Không. TypingMind ưu tiên xử lý cục bộ và cho phép bạn kiểm soát nhà cung cấp mô hình, khóa API, prompt và cấu hình MCP. Nếu OpenRouter yêu cầu xác thực, hãy thêm các header, cài đặt OAuth hoặc cấu hình cục bộ cần thiết cho máy chủ MCP đó khi tạo kết nối.

Máy chủ MCP liên quan

Xem tất cả

Tạo ngay không gian làm việc AI riêng

Đăng ký bản tin của chúng tôi để nhận thông báo về tính năng mới và các đợt tặng quà sắp tới 👇