This MCP server provides an interface to OpenAI's image generation capabilities through the Model Context Protocol, allowing AI assistants to generate and edit images using the GPT-4 Vision model via the official OpenAI Python SDK.
Clone the repository:
git clone https://github.com/IncomeStreamSurfer/chatgpt-native-image-gen-mcp.git
cd chatgpt-native-image-gen-mcp
Create and activate a virtual environment:
python -m venv venv
source venv/bin/activate # On Windows use: venv\Scripts\activate
Install required dependencies:
pip install -r requirements.txt
Set up your OpenAI API key:
It's recommended to set this as an environment variable:
export OPENAI_API_KEY="your-api-key-here"
set OPENAI_API_KEY=your-api-key-here
$env:OPENAI_API_KEY="your-api-key-here"
Add the server configuration to your MCP settings file (typically cline_mcp_settings.json
):
{
"mcpServers": {
"openai-image-gen-mcp": {
"autoApprove": [
"generate_image",
"edit_image"
],
"disabled": false,
"timeout": 180,
"command": "python",
"args": [
"/absolute/path/to/chatgpt-native-image-gen-mcp/openai_image_mcp.py"
],
"transportType": "stdio"
}
}
}
Be sure to replace /absolute/path/to/
with the actual path to your cloned repository.
The MCP server provides two primary tools for image generation and editing:
Creates images from text prompts using OpenAI's GPT-4 Vision model.
Parameters:
prompt
(required): Text description of the desired imagemodel
: The model to use (default: "gpt-image-1")n
: Number of images to generate (default: 1)size
: Image dimensions - "1024x1024", "1536x1024", "1024x1536", or "auto" (default: "auto")quality
: Rendering quality - "low", "medium", "high", or "auto" (default: "auto")user
: Optional unique identifier for your end-usersave_filename
: Optional custom filename without extensionExample usage:
result = generate_image(
prompt="A serene mountain landscape at sunset with a lake reflecting the sky",
size="1536x1024",
quality="high"
)
# Returns: {"status": "success", "saved_path": "path/to/image.png"}
Edits existing images or creates variations based on input images. Can use multiple reference images or perform inpainting with a mask.
Parameters:
prompt
(required): Text description of the desired final imageimage_paths
(required): List of file paths to input image(s) (PNG format, < 25MB)mask_path
: Optional file path to mask image for inpaintingmodel
: The model to use (default: "gpt-image-1")n
: Number of images to generate (default: 1)size
: Image dimensions - "1024x1024", "1536x1024", "1024x1536", or "auto" (default: "auto")quality
: Rendering quality - "low", "medium", "high", or "auto" (default: "auto")user
: Optional unique identifier for your end-usersave_filename
: Optional custom filename without extensionExample usage:
result = edit_image(
prompt="Change the sunset to a bright day with blue sky",
image_paths=["/path/to/original/image.png"],
quality="high"
)
# Returns: {"status": "success", "saved_path": "path/to/edited-image.png"}
Generated and edited images are saved in an ai-images
subdirectory where the MCP server script is located. The server returns the absolute path to the saved image.
There are two ways to add an MCP server to Cursor. The most common way is to add the server globally in the ~/.cursor/mcp.json
file so that it is available in all of your projects.
If you only need the server in a single project, you can add it to the project instead by creating or adding it to the .cursor/mcp.json
file.
To add a global MCP server go to Cursor Settings > MCP and click "Add new global MCP server".
When you click that button the ~/.cursor/mcp.json
file will be opened and you can add your server like this:
{
"mcpServers": {
"cursor-rules-mcp": {
"command": "npx",
"args": [
"-y",
"cursor-rules-mcp"
]
}
}
}
To add an MCP server to a project you can create a new .cursor/mcp.json
file or add it to the existing one. This will look exactly the same as the global MCP server example above.
Once the server is installed, you might need to head back to Settings > MCP and click the refresh button.
The Cursor agent will then be able to see the available tools the added MCP server has available and will call them when it needs to.
You can also explictly ask the agent to use the tool by mentioning the tool name and describing what the function does.