Provides image generation and editing capabilities using Google's Gemini 2.5 Flash Image model through OpenRouter's API platform
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 密钥
创建一个新的 API 密钥
复制密钥用于配置
💻 使用方法
在 Claude Desktop 中使用
配置方法:
在 Claude Desktop 的 MCP 配置中添加:
方法 A:使用环境变量(推荐 - 最安全)
方法 B:不使用环境变量
使用示例:
🎯 在 Cursor 中使用
配置方法:
在 Cursor 的 MCP 配置中添加:
方法 A:使用环境变量(推荐)
方法 B:不使用环境变量
使用示例:
让 Cursor 为你的应用生成图像
创建模型和原型
为项目生成资源
🔧 在其他 MCP 客户端中使用
如果你使用其他 MCP 客户端,可以使用以下任一配置方法:
配置方法
方法 A:MCP 配置中的环境变量(推荐)
方法 B:系统环境变量
方法 C:使用配置工具
🛠️ 可用命令
generate_image
从文本提示创建新图像。
支持的宽高比:
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
编辑特定的图像文件。
continue_editing
继续编辑上次生成/编辑的图像。
get_last_image_info
获取上次生成的图像信息。
configure_openrouter_token
配置你的 OpenRouter API 密钥。
get_configuration_status
检查 API 密钥是否已配置。
⚙️ 配置优先级
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
- 使用不同比例创建变体
🔧 开发
本地开发
技术栈
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 图像生成功能!
remote-capable server
The server can be hosted and run remotely because it primarily relies on remote services or has no dependency on the local environment.
Tools
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.