OpenRouter Image MCP Server
Enables generating and editing images using OpenRouter's API with Gemini 2.5 Flash Image model. Supports custom aspect ratios, iterative editing, and reference images for style transfer.
README
OpenRouter Image MCP Server 🖼️
🤖 A Model Context Protocol (MCP) server for generating and editing images using OpenRouter's API with Gemini 2.5 Flash Image model.
一个用于通过 OpenRouter API 生成和编辑图像的 Model Context Protocol (MCP) 服务器,支持自定义图像尺寸比例。
✨ 特性
- 🎨 生成图像: 从文本描述创建全新的图像
- ✏️ 编辑图像: 使用文本提示修改现有图像
- 🔄 迭代编辑: 持续编辑上次生成/编辑的图像
- 📐 自定义尺寸: 支持多种图像宽高比(1:1, 16:9, 9:16, 等)
- 🖼️ 多参考图像: 使用参考图像进行风格迁移和引导
- 🌍 跨平台: 支持 Windows、macOS 和 Linux 的智能文件路径
- 🔧 简单配置: 使用 API 密钥轻松配置
- 📁 自动文件管理: 自动保存图像并组织命名
🔑 获取 API 密钥
- 访问 OpenRouter Settings - Keys
- 创建一个新的 API 密钥
- 复制密钥用于配置
💻 使用方法
在 Claude Desktop 中使用
配置方法:
在 Claude Desktop 的 MCP 配置中添加:
方法 A:使用环境变量(推荐 - 最安全)
{
"mcpServers": {
"openrouter-image": {
"command": "npx",
"args": ["openrouter-image-mcp"],
"env": {
"OPENROUTER_API_KEY": "your-openrouter-api-key-here"
}
}
}
}
方法 B:不使用环境变量
{
"mcpServers": {
"openrouter-image": {
"command": "npx",
"args": ["openrouter-image-mcp"]
}
}
}
使用示例:
生成一张日落山景图像
将这张图像编辑成添加一些飞鸟
继续编辑,让它更加戏剧化
生成一张 16:9 比例的未来城市图像
🎯 在 Cursor 中使用
配置方法:
在 Cursor 的 MCP 配置中添加:
方法 A:使用环境变量(推荐)
{
"openrouter-image": {
"command": "node",
"args": ["E:\\Study\\赚钱\\工具\\Openrouter-Image-MCP\\dist\\index.js"],
"env": {
"OPENROUTER_API_KEY": "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"
}
}
}
方法 B:不使用环境变量
{
"openrouter-image": {
"command": "npx",
"args": ["openrouter-image-mcp"]
}
}
使用示例:
- 让 Cursor 为你的应用生成图像
- 创建模型和原型
- 为项目生成资源
🔧 在其他 MCP 客户端中使用
如果你使用其他 MCP 客户端,可以使用以下任一配置方法:
配置方法
方法 A:MCP 配置中的环境变量(推荐)
{
"openrouter-image": {
"command": "npx",
"args": ["openrouter-image-mcp"],
"env": {
"OPENROUTER_API_KEY": "your-openrouter-api-key-here"
}
}
}
方法 B:系统环境变量
export OPENROUTER_API_KEY="your-openrouter-api-key-here"
npx openrouter-image-mcp
方法 C:使用配置工具
npx openrouter-image-mcp
# 服务器会在首次使用时提示你配置
# 这会在当前目录创建 .openrouter-image-config.json 文件
🛠️ 可用命令
generate_image
从文本提示创建新图像。
generate_image({
prompt: "A futuristic city at night with neon lights",
aspectRatio: "16:9" // 可选
})
支持的宽高比:
1:1→ 1024×1024(默认)16:9→ 1344×7689:16→ 768×13443:4→ 864×11844:3→ 1184×8642:3→ 832×12483:2→ 1248×8324:5→ 896×11525:4→ 1152×89621:9→ 1536×672
edit_image
编辑特定的图像文件。
edit_image({
imagePath: "/path/to/image.png",
prompt: "Add a rainbow in the sky",
referenceImages: ["/path/to/reference.jpg"], // 可选
aspectRatio: "16:9" // 可选
})
continue_editing
继续编辑上次生成/编辑的图像。
continue_editing({
prompt: "Make it more colorful",
referenceImages: ["/path/to/style.jpg"], // 可选
aspectRatio: "1:1" // 可选
})
get_last_image_info
获取上次生成的图像信息。
get_last_image_info()
configure_openrouter_token
配置你的 OpenRouter API 密钥。
configure_openrouter_token({
apiKey: "your-openrouter-api-key"
})
get_configuration_status
检查 API 密钥是否已配置。
get_configuration_status()
⚙️ 配置优先级
MCP 服务器按以下优先级顺序加载你的 API 密钥:
-
🥇 MCP 配置环境变量(最高优先级)
- 在 MCP 客户端配置中设置
- 最安全,因为包含在 MCP 配置中
- 示例:
"env": { "OPENROUTER_API_KEY": "your-key" }
-
🥈 系统环境变量
- 在 shell/系统环境中设置
- 示例:
export OPENROUTER_API_KEY="your-key"
-
🥉 本地配置文件(最低优先级)
- 使用
configure_openrouter_token工具时创建 - 作为
.openrouter-image-config.json存储在当前目录 - 自动被 Git 和 NPM 忽略
- 使用
💡 推荐: 使用方法 1(MCP 配置环境变量)以获得最佳安全性和便利性。
📁 文件存储
图像自动保存到适合平台的位置:
- Windows:
%USERPROFILE%\\Documents\\openrouter-images\\ - macOS/Linux:
./generated_imgs/(在当前目录) - 系统目录:
~/openrouter-images/(从系统路径运行时)
文件命名规范:
- 生成的图像:
generated-[timestamp]-[id].png - 编辑的图像:
edited-[timestamp]-[id].png
🎨 示例工作流程
基本图像生成
generate_image- 创建你的基础图像continue_editing- 优化和改进continue_editing- 添加最后的润色
风格迁移
generate_image- 创建基础内容edit_image- 使用参考图像应用风格continue_editing- 微调结果
迭代设计
generate_image- 从概念开始get_last_image_info- 检查当前状态continue_editing- 进行调整- 重复直到满意
自定义尺寸
generate_image- 使用 aspectRatio: "16:9" 创建宽屏图像continue_editing- 使用 aspectRatio: "9:16" 调整为竖屏edit_image- 使用不同比例创建变体
🔧 开发
本地开发
# 克隆仓库
git clone https://github.com/yourusername/openrouter-image-mcp.git
cd openrouter-image-mcp
# 安装依赖
npm install
# 开发模式运行
npm run dev
# 生产构建
npm run build
# 运行测试
npm test
技术栈
- TypeScript - 类型安全开发
- Node.js - 运行时环境
- Zod - 模式验证
- OpenAI SDK - OpenRouter API 客户端
- MCP SDK - Model Context Protocol
📋 要求
- Node.js 18.0.0 或更高版本
- 来自 OpenRouter 的 API 密钥
- 兼容 Claude Desktop、Cursor 和其他 MCP 客户端
🤝 贡献
欢迎贡献!请随时:
- 报告 bug
- 建议新功能
- 提交 pull request
- 改进文档
📄 许可证
MIT 许可证 - 详见 LICENSE 文件。
🙏 致谢
- OpenRouter - 提供强大的 API 平台
- Google AI - Gemini 2.5 Flash Image 模型
- Anthropic - Model Context Protocol
- Claude Code - 用于生成此项目
- 开源社区 - 提供精彩的工具和库
📞 支持
- 🐛 问题: GitHub Issues
- 📖 文档: 本 README 和内联代码注释
- 💬 讨论: GitHub Discussions
🔗 链接
✨ 通过 OpenRouter 和 MCP 协议实现强大的 AI 图像生成功能!
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。