AI图像生成服务器

基于MCP协议和OpenRouter API的AI图像生成服务器,支持文本到图像和图像到图像的转换,并自动保存生成的文件。

  • by sftinc
  • TypeScript
  • 本地部署
  • 更新于
在 GitHub 查看 sftinc/openrouter-image-mcp

使用说明

MCP图像生成服务器

用于通过OpenRouter API生成AI图像的MCP(模型上下文协议)服务器。

特性

  • 文本到图像生成:根据文本描述生成图像
  • 图像到图像生成:根据提示转换现有图像
  • 自动文件保存:生成的图像保存在本地
  • 灵活输入:支持本地文件、URL、base64和数据URL

先决条件

验证您的Node.js安装:

node --version
npm --version

如果未安装Node.js,请从以下网址下载 nodejs.org.

安装

npm install
npm run build

配置

更改模型

图像生成模型在中配置 src/openrouter.ts:

const GEMINI_MODEL = 'google/gemini-3.1-flash-image-preview'

要使用其他型号,请将此值更改为上可用的任何支持图像的型号 开放路由.更改后,用重建 npm run build.

克劳德代码全局配置

将MCP服务器添加到您的全局Claude配置中 ~/.claude.json:

{
	"mcpServers": {
		"image": {
			"command": "node",
			"args": ["/path/to/image-mcp/dist/index.js"],
			"env": {
				"OPENROUTER_API_KEY": "sk-or-your-api-key"
			}
		}
	}
}

Claude代码项目级配置

添加一个 .mcp.json 将文件保存到项目根目录:

{
	"mcpServers": {
		"image": {
			"command": "node",
			"args": ["/path/to/image-mcp/dist/index.js"],
			"env": {
				"OPENROUTER_API_KEY": "sk-or-your-api-key"
			}
		}
	}
}

确保 .mcp.json 已添加到您的 .gitignore 以避免提交API密钥。

克劳德桌面版

将以下内容添加到您的配置文件中:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json 视窗: %APPDATA%\Claude\claude_desktop_config.json

{
	"mcpServers": {
		"image": {
			"command": "node",
			"args": ["/path/to/image-mcp/dist/index.js"],
			"env": {
				"OPENROUTER_API_KEY": "sk-or-your-api-key"
			}
		}
	}
}

用法

可用工具

generate

根据文本提示生成图像或转换现有图像。

参数:

  • prompt (必填):要生成的图像的文本描述
  • filename (必需):保存图像的基本文件名(不带扩展名)
  • input_images (可选):用于图像到图像生成、编辑或组合多个图像的输入图像数组。每个元素都可以是文件路径、URL、base64或数据URL。
  • show_full_response (默认值:false):在响应中包含base64数据

示例:

Generate a photorealistic mountain landscape at sunset
Create a watercolor painting of a cat, square format

对于图像到图像(单幅图像):

input_images: ["/path/to/photo.jpg"]
prompt: "Transform this image into an oil painting style"

对于多图像操作:

input_images: ["/path/to/style-reference.jpg", "/path/to/content.jpg"]
prompt: "Apply the artistic style from the first image to the scene in the second image"

提示提示

通过提示文本控制图像输出:

  • 宽高比:“方形图像”、“横向”、“16:9纵横比”、“肖像9:16”
  • 风格:“写实主义”、“油画”、“水彩”、“数字艺术”、“铅笔素描”
  • 质量:“超高清”、“4K”、“高度细节”
  • 多张图片:“生成…的3个变体”(模型可能并不总是遵循精确计数)

输出

生成的图像保存到 ./generated_images/ 文件名格式为的目录:

{sort_code}_{filename}_{index}.{ext}

排序代码是base36编码的时间戳,其确保文件在按字母顺序排序时按时间顺序列出(例如。, jzk5m1kv_my_logo_1.png).

许可证

麻省理工学院