A Model Context Protocol (MCP) server that enables Claude Code to generate images using multiple AI models via the OpenRouter API.
π Visit our landing page at imageroutermcp.com for interactive documentation and examples!
Built for Claude Code - The official CLI for Claude by Anthropic
- π¨ Multiple Model Support: OpenAI GPT-5 Image, GPT-5 Image Mini, Google Gemini 2.5 Flash Image
- πΎ Local Saving: Save generated images to your filesystem
- π Flexible Input: Supports various image data formats (URLs, base64, data URLs)
- β‘ Type-Safe: Built with TypeScript for reliability
- π§ͺ Well-Tested: Comprehensive test coverage
| Model | Description | Best For |
|---|---|---|
openai/gpt-5-image |
Highest quality general-purpose | Professional quality images |
openai/gpt-5-image-mini |
Faster, balanced quality | Quick iterations |
google/gemini-2.5-flash-image |
Fast Gemini model | Speed-focused tasks |
google/gemini-2.5-flash-image-preview |
Latest preview (default) | Latest features |
- Node.js 18 or higher
- OpenRouter API key (Get one here)
-
Clone and setup in one command
git clone https://github.com/scotthooker/OpenRouter-ImageGen-MCP.git cd OpenRouter-ImageGen-MCP npm run setup -
Copy the generated configuration
- The
npm run setupcommand will display your custom configuration - Copy the JSON configuration shown in the output
- The
-
Add to Claude Code
- Open
~/.config/claude-code/mcp_settings.json(macOS/Linux) - Or
%APPDATA%\Claude Code\mcp_settings.json(Windows) - Paste the configuration (create the file if it doesn't exist)
- Replace
your-openrouter-api-key-herewith your actual API key
- Open
-
Restart Claude Code
-
Clone the repository
git clone https://github.com/scotthooker/OpenRouter-ImageGen-MCP.git cd OpenRouter-ImageGen-MCP -
Install and build
npm install npm run build
-
Generate configuration
npm run config
This will show you the exact configuration for your setup.
-
Get your OpenRouter API key
- Sign up at OpenRouter
- Generate an API key from your dashboard
The npm run config command generates the exact configuration you need based on where you cloned the repository.
Configuration file locations:
- macOS/Linux:
~/.config/claude-code/mcp_settings.json - Windows:
%APPDATA%\Claude Code\mcp_settings.json
Example configuration:
{
"mcpServers": {
"openrouter-imagegen": {
"command": "node",
"args": [
"/your/path/to/OpenRouter-ImageGen-MCP/dist/index.js"
],
"env": {
"OPENROUTER_API_KEY": "your-api-key-here"
}
}
}
}π‘ Tip: Run
npm run configanytime to see your current configuration
Set the OPENROUTER_API_KEY environment variable:
export OPENROUTER_API_KEY="your-api-key-here"
npm startOnce configured, Claude Code can generate images using natural language commands:
In your Claude Code terminal, simply ask:
"Generate a photorealistic sunset over mountains"
"Create a watercolor painting of a cat in a garden"
"Make a minimalist logo for a tech startup"
"Generate a square image of a futuristic city at night, cyberpunk style, ultra HD"
"Create a landscape orientation image of a serene lake, oil painting style"
"Generate 3 variations of an abstract pattern, digital art style"
"Generate an image of a dragon and save it as 'dragon_art'"
Images are saved to the generated_images folder in your current working directory.
Claude Code automatically detects and uses the MCP server when you request image generation:
# Start Claude Code in your project directory
claude-code
# Then simply ask:
> "Generate a hero image for my landing page, modern gradient style"
> "Create an icon for my app, minimalist design, 512x512"
> "Generate a diagram showing microservices architecture"Generate images using AI models.
Parameters:
prompt(required): Text description of the image to generatemodel(optional): Model ID to use (defaults togoogle/gemini-2.5-flash-image-preview)save_to_file(optional): Boolean, save image locallyfilename(optional): Base filename for saved imageshow_full_response(optional): Boolean, include full response data
Example:
{
"prompt": "A serene mountain landscape at sunset",
"model": "openai/gpt-5-image",
"save_to_file": true,
"filename": "mountain_sunset"
}List all available image generation models with descriptions.
npm run setup # Complete setup: install, build, and show configuration
npm run config # Generate MCP configuration for your installation path
npm install # Install dependencies
npm run build # Build the TypeScript projectnpm start # Start the MCP server
npm run dev # Build and start in development modenpm test # Run all tests
npm run test:watch # Run tests in watch mode
npm run test:coverage # Run tests with coverage report
npm run lint # Lint TypeScript files
npm run lint:fix # Auto-fix linting issues
npm run format # Format code with Prettier
npm run format:check # Check code formatting
npm run typecheck # Run TypeScript type checkingnpm run clean # Clean build artifacts and coverage
npm run website:serve # Serve landing page locally
npm run website:validate # Validate website structureπ See website/README.md for website development and deployment details.
βββ src/
β βββ config/ # Configuration constants
β βββ domain/ # Domain models and errors
β βββ services/ # Business logic services
β βββ validators/ # Input validation
β βββ formatters/ # Response formatting
β βββ utils/ # Utility functions
β βββ __tests__/ # Test suites
β βββ index.ts # Main entry point
βββ website/ # Landing page (imageroutermcp.com)
β βββ index.html # Main landing page
β βββ styles.css # Styling
β βββ script.js # Interactive features
β βββ README.md # Website documentation
βββ dist/ # Compiled JavaScript
βββ generated_images/ # Saved images (created automatically)
Built following SOLID principles with clean architecture:
- Separation of Concerns: Each module has a single responsibility
- Dependency Injection: Services are loosely coupled
- Type Safety: Full TypeScript coverage
- Testability: Comprehensive unit and integration tests
- Ensure
OPENROUTER_API_KEYis set in your environment or configuration file - Verify the key starts with
sk-or-
- Check the model ID matches one of the supported models
- Use
list_modelstool to see available options
- Check write permissions in the current directory
- Verify the
generated_imagesfolder can be created
Contributions are welcome! Please:
- Fork the repository
- Create a feature branch (
git checkout -b feature/amazing-feature) - Commit your changes (
git commit -m 'Add amazing feature') - Push to the branch (
git push origin feature/amazing-feature) - Open a Pull Request
MIT License - see LICENSE file for details.
- Built with the Model Context Protocol SDK
- Powered by OpenRouter
- Supports models from OpenAI and Google
- π Website - Interactive documentation and examples
- π« Report Issues
- π¬ Discussions
Made with β€οΈ for the MCP community