GPT Image 1
Generate high-quality AI images with OpenAI's GPT-Image-1 model and save them directly to your local machine.
GPT-Image-1 MCP Server
A Model Context Protocol (MCP) server that provides access to OpenAI's GPT-Image-1 model. This server enables high-quality image generation using OpenAI's latest image generation model with enhanced detail, richer lighting, and fewer artifacts.
š Repository: https://github.com/PierrunoYT/gpt-image-1-mcp-server
š Ready to use! Pre-built executable included - no compilation required.
ā Enhanced Reliability: Server handles missing API keys gracefully without crashes and includes robust error handling.
Features
- High-Quality Image Generation: Uses OpenAI's GPT-Image-1 model
- Automatic Image Download: Generated images are automatically saved to local
imagesdirectory as PNG files - Multiple Sizes: Support for 1024x1024, 1024x1536, and 1536x1024 resolutions
- Batch Generation: Generate up to 4 images at once
- Style Variations: Enhanced tool with style guidance support
- Quality Control: Standard and HD quality options
- Base64 Processing: Handles OpenAI's base64 image format automatically
- Detailed Responses: Returns local file paths with generation metadata
- Robust Error Handling: Graceful handling of missing API keys without server crashes
- Universal Portability: Works anywhere with npx - no local installation required
- Enhanced Reliability: Graceful shutdown handlers and comprehensive error reporting
Prerequisites
- Node.js 18 or higher
- OpenAI API key with access to GPT-Image-1 model
Installation
1. Get your OpenAI API Key
- Visit OpenAI Platform
- Sign up for an account or log in
- Navigate to API Keys section
- Generate an API key
- Ensure you have access to the GPT-Image-1 model
2. Clone or Download
git clone https://github.com/PierrunoYT/gpt-image-1-mcp-server.git
cd gpt-image-1-mcp-server
3. Install Dependencies (Optional)
The server is pre-built, but if you want to modify it:
npm install
npm run build
Configuration
š Recommended: Universal npx Configuration (Works Everywhere)
Best option for portability - works on any machine with Node.js:
{
"mcpServers": {
"gpt-image-1": {
"command": "npx",
"args": [
"-y",
"https://github.com/PierrunoYT/gpt-image-1-mcp-server.git"
],
"env": {
"OPENAI_API_KEY": "your-openai-api-key-here"
}
}
}
}
Benefits:
- ā Universal Access: Works on any machine with Node.js
- ā No Local Installation: npx downloads and runs automatically
- ā Always Latest Version: Pulls from GitHub repository
- ā Cross-Platform: Windows, macOS, Linux compatible
- ā Settings Sync: Works everywhere you use your MCP client
Alternative: Local Installation
If you prefer to install locally, use the path helper:
npm run get-path
This will output the complete MCP configuration with the correct absolute path.
For Claude Desktop
Add to ~/Library/Application Support/Claude/claude_desktop_config.json (macOS) or %APPDATA%\Claude\claude_desktop_config.json (Windows):
{
"mcpServers": {
"gpt-image-1": {
"command": "node",
"args": ["path/to/gpt-image-1-mcp-server/build/index.js"],
"env": {
"OPENAI_API_KEY": "your-openai-api-key-here"
}
}
}
}
For Kilo Code MCP Settings
Add to your MCP settings file at:
C:\Users\[username]\AppData\Roaming\Kilo-Code\MCP\settings\mcp_settings.json
{
"mcpServers": {
"gpt-image-1": {
"command": "node",
"args": ["path/to/gpt-image-1-mcp-server/build/index.js"],
"env": {
"OPENAI_API_KEY": "your-openai-api-key-here"
},
"disabled": false,
"alwaysAllow": []
}
}
}
Available Tools
gpt_image_1_generate
Generate images using OpenAI's GPT-Image-1 model with standard processing.
Parameters:
prompt(required): Text description of the image to generatesize(optional): "1024x1024", "1024x1536", or "1536x1024" (default: "1024x1024")n(optional): Number of images to generate, 1-4 (default: 1)
Response includes:
- Local file paths for saved PNG images
- Generation metadata (revised prompts if applicable)
- File information and save status
gpt_image_1_generate_with_variations
Generate images using GPT-Image-1 with enhanced style control and quality options.
Parameters:
prompt(required): Text description of the image to generatesize(optional): "1024x1024", "1024x1536", or "1536x1024" (default: "1024x1024")n(optional): Number of images to generate, 1-4 (default: 1)style(optional): Style guidance for the image generationquality(optional): "standard" or "hd" (default: "standard")
Use this tool when:
- You want to specify a particular artistic style
- You need higher quality (HD) images
- You want enhanced control over the generation process
- Creating variations of a concept with different styles
Features:
- Style-enhanced prompts for better artistic control
- HD quality option for higher resolution details
- Enhanced metadata in responses
š„ How Image Download Works
The GPT-Image-1 MCP server automatically processes and saves generated images to your local machine. Here's the complete process:
1. Image Generation Flow
- API Call: Server calls OpenAI's GPT-Image-1 API
- Response: OpenAI returns base64-encoded image data
- Auto-Save: Server immediately converts and saves images as PNG files
- Response: Returns local file paths and generation metadata
2. Base64 Processing Implementation
Save Function (saveBase64Image):
async function saveBase64Image(b64Data: string, filename: string): Promise<string> {
// 1. Create 'images' directory if it doesn't exist
const imagesDir = path.join(process.cwd(), 'images');
if (!fs.existsSync(imagesDir)) {
fs.mkdirSync(imagesDir, { recursive: true });
}
// 2. Convert base64 to buffer and save as PNG
const filePath = path.join(imagesDir, filename);
const buffer = Buffer.from(b64Data, 'base64');
fs.writeFileSync(filePath, buffer);
return filePath;
}
Filename Generation (generateImageFilename):
function generateImageFilename(prompt: string, index: number): string {
// Creates safe filename: gpt_image_1_prompt_index_timestamp.png
const safePrompt = prompt
.toLowerCase()
.replace(/[^a-z0-9\s]/g, '') // Remove special characters
.replace(/\s+/g, '_') // Replace spaces with underscores
.substring(0, 50); // Limit length
const timestamp = new Date().toISOString().replace(/[:.]/g, '-');
return `gpt_image_1_${safePrompt}_${index}_${timestamp}.png`;
}
3. File Storage Details
Directory Structure:
your-project/
āāā images/ # Auto-created directory
ā āāā gpt_image_1_mountain_landscape_1_2025-06-24T18-30-45-123Z.png
ā āāā gpt_image_1_cute_robot_1_2025-06-24T18-31-20-456Z.png
ā āāā ...
Filename Format:
- Prefix:
gpt_image_1_ - Prompt: First 50 chars, sanitized (alphanumeric + underscores)
- Index: Image number (for multiple images)
- Timestamp: ISO timestamp for uniqueness
- Extension:
.png
4. Response Format
The server returns detailed information about saved images:
Successfully generated 1 image(s) using GPT-Image-1:
Prompt: "a serene mountain landscape"
Size: 1024x1024
Number of Images: 1
Generated Images:
Image 1:
Local Path: /path/to/project/images/gpt_image_1_a_serene_mountain_landscape_1_2025-06-24T18-30-45-123Z.png
Revised Prompt: A serene mountain landscape with snow-capped peaks...
Images have been saved to the local 'images' directory.
5. Benefits of Local Processing
ā
Persistent Storage: Images saved locally as standard PNG files
ā
Offline Access: View images without internet connection
ā
Organized Storage: All images in dedicated images directory
ā
Unique Naming: No filename conflicts with timestamp system
ā
Standard Format: PNG files compatible with all image viewers
ā
No URL Expiration: Local files never expire unlike temporary URLs
Example Usage
Basic Image Generation
Generate a photorealistic image of a golden retriever playing in a field of sunflowers
With Specific Parameters
Generate an image with:
- Prompt: "A minimalist logo design for a tech startup, clean lines"
- Size: 1536x1024
- Number of images: 2
Advanced Usage with Style
Generate an image of "A futuristic cityscape at night with neon lights and flying cars"
with style "cyberpunk art" and HD quality
Technical Details
Architecture
- Language: TypeScript with ES2022 target
- Runtime: Node.js 18+ with ES modules
- Protocol: Model Context Protocol (MCP) SDK v1.0.0
- API Client: OpenAI JavaScript SDK v4.0.0
- Validation: Zod schema validation
API Model Used
- Model:
gpt-image-1(OpenAI's latest image generation model) - Response Format:
b64_json(base64-encoded PNG data) - Supported Sizes: 1024x1024, 1024x1536, 1536x1024
Error Handling
- Graceful API key handling: Server continues running even without OPENAI_API_KEY set
- No crash failures: Removed
process.exit()calls that caused connection drops - Null safety checks: All tools validate API client availability before execution
- Graceful shutdown: Proper SIGINT and SIGTERM signal handling
- API error catching: Comprehensive error reporting with detailed context
- File save error handling: Graceful fallback with detailed error messages
- User-friendly messages: Clear error descriptions instead of technical crashes
Development
Project Structure
āāā src/
ā āāā index.ts # Main MCP server implementation
āāā build/ # Compiled JavaScript (ready to use)
āāā test-server.js # Server testing utility
āāā get-path.js # Configuration path helper
āāā example-mcp-config.json # Example configuration
āāā package.json # Project metadata and dependencies
āāā tsconfig.json # TypeScript configuration
Scripts
npm run build- Compile TypeScript to JavaScriptnpm run dev- Watch mode for developmentnpm run start- Start the server directlynpm run test- Test server startup and basic functionalitynpm run get-path- Get configuration path for your system
Making Changes
- Edit files in the
src/directory - Run
npm run buildto compile - Restart your MCP client to use the updated server
Testing
npm run test
This runs an OpenAI API connectivity test that verifies:
- OpenAI API key is configured correctly
- API connection is working
- Available image generation models
- GPT-Image-1 model access
API Costs
This server uses OpenAI's API, which charges per image generation. Check OpenAI pricing for current rates.
Typical costs (as of 2024):
- GPT-Image-1: ~$0.04-0.08 per image depending on size and quality
- HD quality images cost more than standard quality
- Costs vary by resolution (1024x1024 vs 1536x1024)
Troubleshooting
Server not appearing in MCP client
- Recommended: Use the npx configuration for universal compatibility
- If using local installation, verify the path to
build/index.jsis correct and absolute - Ensure Node.js 18+ is installed:
node --version - Test server startup:
npm run test - Restart your MCP client (Claude Desktop, Kilo Code, etc.)
- Note: Server will start successfully even without OPENAI_API_KEY - check tool responses for API key errors
Image generation failing
- Verify your OpenAI API key is valid and has sufficient credits
- Ensure you have access to the GPT-Image-1 model (may require specific API tier)
- Check that your prompt follows OpenAI's content policy
- Try reducing the number of images or simplifying the prompt
- Check the server logs for detailed error messages
- Verify your account has image generation capabilities enabled
Build issues
If you need to rebuild the server:
npm install
npm run build
Configuration issues
Use the helper script to get the correct path:
npm run get-path
Support
For issues with:
- This MCP server: Create an issue in this repository
- OpenAI API: Check OpenAI documentation
- MCP Protocol: See MCP documentation
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Test with
npm run test - Submit a pull request
Changelog
v1.0.0 (Latest)
- šØ Initial release with GPT-Image-1: Complete rewrite to use OpenAI's GPT-Image-1 model
- š„ Automatic base64 processing: Generated images automatically converted and saved as PNG files
- šļø Smart filename generation: Images saved with descriptive names including prompt and timestamp
- š Enhanced tools: Two generation tools with different feature sets (basic and with variations)
- š Auto-directory creation: Creates
imagesfolder automatically if it doesn't exist - š”ļø Robust error handling: Graceful handling of API errors and file save failures
- šØ Style support: Enhanced tool with style guidance and quality control
- š Universal portability: Updated for npx usage - works universally without local installation
- ā Production ready: Comprehensive error handling and user-friendly messages
Migration from FAL Imagen 4
If you're migrating from the previous FAL Imagen 4 MCP server:
- Update your configuration to use
OPENAI_API_KEYinstead ofFAL_KEY - Tool names changed:
imagen4_generateāgpt_image_1_generateimagen4_generate_asyncāgpt_image_1_generate_with_variations
- Parameter changes:
aspect_ratioāsize(with specific resolution options)negative_promptā removed (not supported by GPT-Image-1)- Added
qualityandstyleparameters for enhanced control
- Response format: Now includes revised prompts and local PNG file paths
- Image format: All images saved as PNG files instead of various formats
Related Servers
Scout Monitoring MCP
sponsorPut performance and error data directly in the hands of your AI assistant.
Alpha Vantage MCP Server
sponsorAccess financial market data: realtime & historical stock, ETF, options, forex, crypto, commodities, fundamentals, technical indicators, & more
Guardian MCP
Engineering discipline and persistent memory for AI coding assistants
Apktool
A server for Android APK analysis and reverse engineering using Apktool.
ID Generator MCP
Generate unique IDs using various algorithms like UUID, CUID2, Nanoid, and ULID.
Core Lightning MCP Server
A Rust-based gRPC server that provides a standardized MCP interface for Core Lightning nodes.
Paraview_MCP
An autonomous agent that integrates large language models with ParaView for creating and manipulating scientific visualizations using natural language and visual inputs.
chuk-mcp
A Python client for the Model Context Protocol (MCP), an open standard for connecting AI assistants to external data and tools.
Scorecard
Access Scorecard's AI model evaluation and testing tools via a Cloudflare Workers deployment.
MCP Server Starter
A TypeScript starter template for building Model Context Protocol (MCP) servers.
Starwind UI
Provides tools to help developers work with Starwind UI components.
FAL Imagen 4
Generate high-quality images using Google's Imagen 4 Ultra model via the FAL AI platform.