使用说明
OpenRouter MCP网桥
一个轻量级的MCP(模型上下文协议)服务器,使AI编码助手能够与OpenRouter API交互。适用于Claude Code、Cursor、VS Code和其他MCP兼容客户端。
✨ 特性
- 直接OpenRouter API集成:使用httpx异步HTTP调用
- 简单的MCP工具:查询、文件分析和批处理的三个核心功能
- 无状态操作:没有会话、缓存或复杂的状态管理
- 生产就绪:具有可配置超时的强大错误处理(默认值:90秒)
- 最小依赖性:httpx、python dotenv和mcp>=1.0.0
- 异步/等待:对并发操作的完全异步支持
- 模型灵活性:支持任何OpenRouter兼容型号
🚀 快速开始
先决条件
-
获取OpenRouter API密钥:
# Visit https://openrouter.ai/keys # Sign up and get your API key -
设置环境变量:
export OPENROUTER_API_KEY="your-api-key-here"
安装
来自PyPI:
pip install openrouter-mcp-bridge
使用uvx(建议用于MCP服务器):
uvx openrouter-mcp-bridge
地方发展:
# Clone the repository
git clone https://github.com/htooayelwinict/open-bridge.git
cd open-bridge
# Create virtual environment
python3 -m venv .venv
source .venv/bin/activate
# Install in development mode
pip install -e .
# Run directly
python -m src
⚙️ 配置
环境变量
| 变量 | 必填 | 默认 | 描述 |
|---|---|---|---|
OPENROUTER_API_KEY |
✅ 是 | - | 您的OpenRouter API密钥 |
OPENROUTER_MODEL |
没有 | openai/gpt-4o |
要使用的模型 |
OPENROUTER_TIMEOUT |
没有 | 90 |
请求超时(秒) |
Claude代码配置
# Add to Claude Code with uvx (recommended)
claude mcp add openrouter-mcp-bridge -s user \
--env OPENROUTER_API_KEY=sk-or-... \
--env OPENROUTER_MODEL=anthropic/claude-3.5-sonnet \
-- uvx openrouter-mcp-bridge
或添加到 ~/.claude.json:
{
"mcpServers": {
"openrouter-mcp-bridge": {
"type": "stdio",
"command": "uvx",
"args": ["openrouter-mcp-bridge"],
"env": {
"OPENROUTER_API_KEY": "sk-or-...",
"OPENROUTER_MODEL": "anthropic/claude-3.5-sonnet"
}
}
}
}
🛠️ 可用工具
| 工具 | 说明 |
|---|---|
consult_openrouter |
具有结构化输出的直接API查询 |
consult_openrouter_with_stdin |
用于分析的管道文件内容 |
consult_openrouter_batch |
多个并发查询 |
📋 使用示例
# Basic query
consult_openrouter(
query="What authentication patterns are used in this project?",
directory="/path/to/project",
format="json"
)
# File analysis
consult_openrouter_with_stdin(
stdin_content=open("src/auth.py").read(),
prompt="Review this file for security issues",
directory="/path/to/project"
)
# Batch processing
consult_openrouter_batch(
queries=[
{"query": "Analyze authentication patterns"},
{"query": "Review database implementations"}
],
directory="/path/to/project"
)
🏗️ 建筑
- API-第一个:对OpenRouter API的直接异步HTTP调用
- 无状态:每个工具调用都是独立的,没有会话状态
- 异步/等待:对并发操作的完全异步支持
- 错误处理:全面的HTTP和超时错误处理
📄 许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
🙏 学分
最初分叉自 shelakh/codex大桥.
聚焦:Claude Code和OpenRouter API之间简单可靠的桥梁。