OpenAI 图像生成 MCP 服务器
该项目实现了一个 MCP(模型上下文协议)服务器,该服务器通过官方 Python SDK 提供使用 OpenAI 的gpt-image-1
模型生成和编辑图像的工具。
特征
该 MCP 服务器提供以下工具:
generate_image
:根据文本提示,使用 OpenAI 的gpt-image-1
模型生成图像并保存。- 输入模式:
- 输出:
{"status": "success", "saved_path": "path/to/image.png"}
或错误字典。
- 输入模式:
edit_image
:使用 OpenAI 的gpt-image-1
模型编辑图像或创建变体并保存。可以使用多张输入图像作为参考,或使用遮罩进行修复。- 输入模式:
- 输出:
{"status": "success", "saved_path": "path/to/image.png"}
或错误字典。
- 输入模式:
先决条件
- Python(建议使用 3.8 或更高版本)
- pip(Python 包安装程序)
- OpenAI API 密钥(直接在脚本中设置或通过
OPENAI_API_KEY
环境变量设置 -强烈建议使用环境变量以确保安全)。 - MCP 客户端环境(如 Cline 使用的环境)能够管理和启动 MCP 服务器。
安装
- 克隆存储库:
- 设置虚拟环境(推荐):
- 安装依赖项:
- **(可选但推荐)设置环境变量:**使用您的 OpenAI 密钥设置
OPENAI_API_KEY
环境变量,而不是将其硬编码在脚本中。如何设置取决于您的操作系统。
配置(适用于 Cline MCP 客户端)
为了使您的 AI 助手(如 Cline)可以使用此服务器,请将其配置添加到您的 MCP 设置文件(例如, cline_mcp_settings.json
)。
在您的设置文件中找到mcpServers
对象并添加以下条目:
**重要提示:**请将C:/path/to/your/cloned/repo/
替换为您在计算机上克隆此仓库的正确绝对路径。请确保路径分隔符与您的操作系统匹配(例如,在 Windows 上使用反斜杠\
)。如果您通过环境变量设置了 API 密钥,则可以将其从脚本中移除,并在您的 MCP 客户端支持的情况下将其添加到此处的env
部分。
运行服务器
通常情况下,您无需手动运行服务器。MCP 客户端(例如 Cline)会在首次调用其工具时,使用配置文件中指定的command
和args
自动启动服务器。
如果您想手动测试它(确保依赖项已安装并且 API 密钥可用):
用法
AI 助手使用generate_image
和edit_image
工具与服务器交互。图像保存在openai_image_mcp.py
脚本所在位置的ai-images
子目录中。成功后,这两个工具会返回已保存图像的绝对路径。
This server cannot be installed
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.
通过 MCP 接口提供使用 OpenAI 的 gpt-image-1 模型生成和编辑图像的工具,使 AI 助手能够根据文本提示创建和修改图像。
Related MCP Servers
- AsecurityAlicenseAqualityAllows AI assistants to generate and transform high-quality images from text prompts using Google's Gemini model via the MCP protocol.Last updated -316PythonMIT License
- -securityAlicense-qualityAn MCP tool server that enables generating and editing images through OpenAI's image models, supporting text-to-image generation and advanced image editing (inpainting, outpainting) across various MCP-compatible clients.Last updated -60TypeScriptMIT License
- AsecurityFlicenseAqualityAn MCP (Model Context Protocol) server that allows generating, editing, and creating variations of images using OpenAI's DALL-E APIs.Last updated -1TypeScript
- AsecurityAlicenseAqualityAn MCP server that allows Claude to use OpenAI's image generation capabilities (gpt-image-1) to create image assets for users, which is particularly useful for game and web development projects.Last updated -112JavaScriptMIT License