Skip to main content

MCP server providing access to 300+ AI models via OpenRouter

Project description

mcp-openrouter

mcp-openrouter

Python License

🚀 Access 300+ AI models through a single MCP server — text, images, embeddings, and model discovery at your fingertips 🤖

Overview

CI

mcp-openrouter is an MCP (Model Context Protocol) server that provides seamless access to OpenRouter's extensive catalog of AI models. Use Claude, GPT, Gemini, Llama, and 300+ other models through a unified interface.

Features

  • Text Completion — Chat with any OpenRouter model (Claude, GPT, Gemini, Mistral, etc.)
  • 🎨 Image Generation — Create images with DALL-E, Gemini, and other image models
  • 📐 Embeddings — Generate vector embeddings with Mistral, OpenAI, Gemini, and other embedding models
  • 🔍 Model Discovery — List and search 300+ models by capability
  • Persistent Connection — No repeated setup or permission prompts
  • 🔧 Zero Config — Just set your API key and go

Quick Start

Installation

uvx mcp-openrouter install

The installer auto-detects codex, claude, and opencode on your PATH, verifies that each detected CLI actually supports MCP management, asks which eligible clients should get the openrouter MCP server, stores your OPENROUTER_API_KEY in each selected client config, and registers the production runtime command uvx mcp-openrouter.

Requirements:

If OPENROUTER_API_KEY is already set in your shell, the installer reuses it. Otherwise it prompts securely.

Non-interactive install

Install into all detected clients:

uvx mcp-openrouter install --yes

Install only specific clients:

uvx mcp-openrouter install --yes --clients codex,claude

Replace existing openrouter configs automatically:

uvx mcp-openrouter install --yes --force
uvx mcp-openrouter install --yes --api-key sk-or-v1-...

What gets installed

  • Codex: codex mcp add openrouter --env OPENROUTER_API_KEY=... -- uvx mcp-openrouter
  • Claude Code: claude mcp add -s user openrouter -e OPENROUTER_API_KEY=... -- uvx mcp-openrouter
  • opencode: writes openrouter under ~/.opencode/settings.json in the mcp object

If an existing openrouter config already matches, the installer skips it. If it differs, the interactive installer asks before replacing it, and --force replaces it automatically.

Uninstall

uvx mcp-openrouter uninstall

Remove only specific clients:

uvx mcp-openrouter uninstall --yes --clients claude,opencode

Equivalent manual commands:

codex mcp remove openrouter
claude mcp remove -s user openrouter

For opencode, the uninstaller removes the openrouter entry from ~/.opencode/settings.json under mcp.

Running the server directly

uvx mcp-openrouter serve

mcp-openrouter with no arguments also starts the stdio MCP server.

Default Models

Configure default models for different use cases. When set, the model parameter becomes optional in tool calls:

# Add to your .env file
DEFAULT_TEXT_MODEL=anthropic/claude-sonnet-4
DEFAULT_IMAGE_MODEL=google/gemini-3-pro-image-preview
DEFAULT_CODE_MODEL=anthropic/claude-sonnet-4
DEFAULT_VISION_MODEL=anthropic/claude-sonnet-4
DEFAULT_EMBEDDING_MODEL=mistralai/mistral-embed-2312

These are included in .env.example — copy it to .env and adjust as needed.

Tools

Tool Description
chat Send chat completion requests to any model
generate_image Generate images with image models
embed Generate vector embeddings for text
list_models List available models, filter by capability
find_models Search for models by name

Examples

Chat with any model:

Use openrouter chat with anthropic/claude-sonnet-4 to explain quantum computing

Generate an image:

Use openrouter generate_image with google/gemini-3-pro-image-preview to create a logo for my app

Find models:

Use openrouter find_models to search for "claude"

Generate embeddings:

Use openrouter embed with mistralai/mistral-embed-2312 to embed "Hello world"

List image generation models:

Use openrouter list_models with capability "image_gen"

API Reference

chat

Send a chat completion request to any OpenRouter model.

Parameter Type Required Description
prompt string Yes User message to send
model string No* Model identifier (e.g., anthropic/claude-sonnet-4)
system string No System prompt for context
max_tokens int No Maximum tokens in response
temperature float No Sampling temperature (0-2)
json_mode bool No Request JSON-formatted response

*Required unless DEFAULT_TEXT_MODEL is set.

generate_image

Generate an image using an OpenRouter image model.

Parameter Type Required Description
prompt string Yes Image description
output_path string Yes Absolute path to save the image
model string No* Image model (e.g., google/gemini-3-pro-image-preview)
aspect_ratio string No 1:1, 16:9, 9:16, 4:3, 3:4, 21:9
size string No 1K, 2K, or 4K
background string No Background setting (e.g., transparent)

*Required unless DEFAULT_IMAGE_MODEL is set.

embed

Generate vector embeddings for text input.

Parameter Type Required Description
input string or list Yes Text string or list of strings to embed
model string No* Embedding model (e.g., mistralai/mistral-embed-2312)
encoding_format string No Output format: float or base64
dimensions int No Custom embedding dimensions (model-dependent)

*Required unless DEFAULT_EMBEDDING_MODEL is set.

list_models

List available models, optionally filtered by capability.

Parameter Type Required Description
capability string No Filter: vision, image_gen, embedding, tools, long_context

find_models

Search for models by name or slug.

Parameter Type Required Description
search_term string Yes Text to search in model names

Development

# Clone the repository
git clone https://github.com/tsilva/mcp-openrouter.git
cd mcp-openrouter

# Install dependencies
uv sync --dev

# Run the server
OPENROUTER_API_KEY=your-key uv run mcp-openrouter

# Run tests
OPENROUTER_API_KEY=your-key uv run pytest tests/

# Lint
uv run ruff check src/
uv run ruff format src/

Manual development install

If you want your MCP client to run directly from a local checkout instead of the published PyPI package, register the repo path manually.

Claude Code:

claude mcp add openrouter --scope user -- uv run --directory /path/to/mcp-openrouter mcp-openrouter

Codex:

codex mcp add openrouter --env OPENROUTER_API_KEY=your-key -- uv run --directory /path/to/mcp-openrouter mcp-openrouter

opencode:

Add this openrouter entry under mcp in ~/.opencode/settings.json:

{
  "type": "local",
  "command": ["uv", "run", "--directory", "/path/to/mcp-openrouter", "mcp-openrouter"],
  "environment": {
    "OPENROUTER_API_KEY": "your-key"
  },
  "enabled": true
}

Applying Code Changes

When you modify the MCP server code, Claude won't automatically pick up the changes. The server runs as a long-lived process that persists across tool calls within a session.

To apply your changes:

  1. Start a new Claude Code session — Close your current terminal/conversation and open a new one. The MCP server process restarts when a new session begins.

  2. Or use the /mcp command — Check server status and restart options within Claude Code.

Why this works: The installation uses uv run --directory /path/to/mcp-openrouter which executes code directly from your source directory. There's no separate "install" step needed — just restart the server process to load your changes.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mcp_openrouter-1.1.4.tar.gz (5.9 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mcp_openrouter-1.1.4-py3-none-any.whl (18.6 kB view details)

Uploaded Python 3

File details

Details for the file mcp_openrouter-1.1.4.tar.gz.

File metadata

  • Download URL: mcp_openrouter-1.1.4.tar.gz
  • Upload date:
  • Size: 5.9 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_openrouter-1.1.4.tar.gz
Algorithm Hash digest
SHA256 d41dbf07852d1abdcfd55d28d99ba7c134148f01e8135432fe1426606b1ae238
MD5 c907e9bbf1dc0c203ab3579e0fdfbf9c
BLAKE2b-256 7121e4da25f40d971c427b5699162a7295de56aa102c0c8006f74380b7b5a21a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_openrouter-1.1.4.tar.gz:

Publisher: release.yml on tsilva/mcp-openrouter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file mcp_openrouter-1.1.4-py3-none-any.whl.

File metadata

  • Download URL: mcp_openrouter-1.1.4-py3-none-any.whl
  • Upload date:
  • Size: 18.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for mcp_openrouter-1.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 1cbe1719a32455cd780ab4ad297df5000e752b11c13743f57a305aa292ddf45a
MD5 f2107611f339344f6724b8743bf36e79
BLAKE2b-256 7af99b7f6923b3a0354cda5fd5188325357ba6b60d4fd39c2cebe417bbc1af1a

See more details on using hashes here.

Provenance

The following attestation bundles were made for mcp_openrouter-1.1.4-py3-none-any.whl:

Publisher: release.yml on tsilva/mcp-openrouter

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page