UNPKG

gemini-imagen-mcp-server

Version:

Claude Code MCP server for Google Gemini Imagen API - Generate images directly in your project's imagen folder

335 lines (261 loc) โ€ข 9.02 kB
# Gemini Imagen MCP Server for Claude Code [![npm version](https://badge.fury.io/js/gemini-imagen-mcp-server.svg)](https://badge.fury.io/js/gemini-imagen-mcp-server) [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) [![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/) ๐ŸŽจ **Perfect Claude Code MCP server** for AI-powered image generation with Google's Gemini Imagen API. Generate images directly in your project's `imagen/` folder while coding! ## โœจ Why This MCP Server? - **๐Ÿ”ฅ Claude Code Optimized**: Designed specifically for Claude Code workflow - **๐Ÿ“ Project Integration**: Images saved directly in your project's `imagen/` folder - **๐ŸŽฏ Zero Setup**: Just add API key and start generating images - **โšก Multiple Models**: Support for Imagen 3, Imagen 4, and Imagen 4 Ultra - **๐Ÿ“ฆ Batch Processing**: Generate multiple images efficiently - **๐ŸŽ›๏ธ Advanced Controls**: Aspect ratios, negative prompts, seeds, and more ## ๐Ÿš€ Quick Start ### 1. Get Your API Key Get a free Gemini API key from [Google AI Studio](https://makersuite.google.com/app/apikey) ### 2. Install & Configure **Zero Installation Required** - Use with npx: Add to your Claude Code MCP settings: ```json { "mcpServers": { "gemini-imagen": { "command": "npx", "args": ["-y", "gemini-imagen-mcp-server"], "env": { "GEMINI_API_KEY": "your-api-key-here" } } } } ``` ### 3. Start Generating Images! ``` Generate an image of "a futuristic robot coding in a modern office" ``` Images will be saved to `imagen/` folder in your current project! ๐ŸŽฏ ## ๐Ÿ“ How It Works When you generate images, they're automatically saved with descriptive filenames: ``` your-project/ โ”œโ”€โ”€ imagen/ โ”‚ โ”œโ”€โ”€ imagen-4-ultra_2024-01-15T10-30-45_futuristic_robot_coding_1.png โ”‚ โ”œโ”€โ”€ imagen-4_2024-01-15T10-32-12_sunset_landscape_1.png โ”‚ โ””โ”€โ”€ imagen-3_2024-01-15T10-35-01_abstract_art_design_1.png โ”œโ”€โ”€ src/ โ””โ”€โ”€ README.md ``` ## ๐ŸŽจ Available Models | Model | Quality | Speed | Best For | |-------|---------|-------|----------| | **imagen-4-ultra** | ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ | โšกโšกโšก | Premium quality, detailed images | | **imagen-4** | ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ | โšกโšกโšกโšก | Great quality, faster generation | | **imagen-3** | ๐ŸŒŸ๐ŸŒŸ๐ŸŒŸ | โšกโšกโšกโšกโšก | Good quality, fastest generation | ## ๐Ÿ’ก Usage Examples ### Basic Image Generation ``` Generate an image of "a cat wearing a space helmet" ``` ### Advanced Parameters ``` Generate an image with these settings: - Prompt: "minimalist website mockup for a coffee shop" - Model: imagen-4-ultra - Aspect ratio: 16:9 - Negative prompt: "cluttered, busy, complex" ``` ### Batch Generation ``` Generate images for these prompts: 1. "logo design for a tech startup" 2. "mobile app interface wireframe" 3. "modern dashboard UI design" ``` ### Design Assets for Projects ``` Create a collection of images: - "app icon design, minimalist, blue and white" - "hero banner for landing page, technology theme" - "user avatar placeholder, professional style" ``` ## ๐ŸŽ›๏ธ Advanced Features ### Aspect Ratios - `1:1` - Perfect squares (logos, avatars) - `16:9` - Widescreen (banners, headers) - `9:16` - Portrait (mobile screens) - `4:3` - Standard (presentations) - `3:4` - Portrait (posters) ### Control Parameters - **Negative Prompts**: Specify what to avoid - **Seeds**: Get reproducible results - **Person Generation**: Control person appearance - **Output Format**: JPEG or PNG ### Batch Processing Generate multiple images efficiently with shared settings: ``` Generate a batch of logo variations with these prompts: ["minimalist coffee logo", "geometric coffee logo", "vintage coffee logo"] using imagen-4-ultra with 1:1 aspect ratio ``` ## โš™๏ธ Configuration Options ### Command Line Arguments ```bash # Use different default model npx gemini-imagen-mcp-server --model imagen-4-ultra # Enable batch processing npx gemini-imagen-mcp-server --batch --max-batch-size 8 # Custom output directory npx gemini-imagen-mcp-server --output-dir assets/images ``` ### Available Options | Option | Description | Default | |--------|-------------|---------| | `--model` | Default model (imagen-3, imagen-4, imagen-4-ultra) | imagen-4-ultra | | `--batch` | Enable batch processing | disabled | | `--max-batch-size` | Max batch size (1-8) | 4 | | `--output-dir` | Output directory | imagen | ## ๐Ÿ› ๏ธ Installation Methods ### Option 1: NPX (Recommended) No installation needed! Just configure and use: ```json { "mcpServers": { "gemini-imagen": { "command": "npx", "args": ["-y", "gemini-imagen-mcp-server"], "env": {"GEMINI_API_KEY": "your-key"} } } } ``` ### Option 2: Global Install ```bash npm install -g gemini-imagen-mcp-server ``` Then configure: ```json { "mcpServers": { "gemini-imagen": { "command": "gemini-imagen-claude-code", "env": {"GEMINI_API_KEY": "your-key"} } } } ``` ### Option 3: Local Development ```bash git clone https://github.com/serkanhaslak/gemini-imagen-mcp-server.git cd gemini-imagen-mcp-server npm install npm run build ``` ## ๐Ÿงช Development & Testing ### Build & Test ```bash # Build the project npm run build # Run comprehensive tests npm run test # Development with auto-rebuild npm run watch # Interactive testing with MCP Inspector npm run dev ``` ### Project Structure ``` src/ โ”œโ”€โ”€ index.ts # Main MCP server implementation build/ # Compiled JavaScript test_server.js # Comprehensive test suite tsconfig.json # TypeScript configuration ``` ## ๐Ÿ”ง Available Tools ### `generate_image` Generate single or multiple images with full parameter control. ### `batch_generate` Process multiple prompts efficiently with shared settings. ### `list_models` Show all available Imagen models and their capabilities. ### `health_check` Check server status, API connectivity, and configuration. ## ๐Ÿ“š Resources ### `generation_history` Access recent image generation history with full parameters. ### `api_documentation` Comprehensive API documentation with examples. ## ๐Ÿ› Troubleshooting ### Common Issues **"GEMINI_API_KEY not found"** - Ensure API key is set in MCP configuration - Verify the key is valid and has billing enabled **"No images generated"** - Check if prompt violates content policies - Try a simpler prompt first - Verify API quota hasn't been exceeded **"Permission denied"** - Ensure Claude Code has write access to project directory - Check that `imagen/` folder can be created ### Debug Mode Run with debug logging: ```bash DEBUG=* npx gemini-imagen-mcp-server ``` ## ๐ŸŽฏ Perfect for Claude Code Projects This MCP server is specifically designed for developers using Claude Code: - **Project-Centric**: Images go directly in your project - **Developer-Friendly**: Descriptive filenames with timestamps - **Workflow Integration**: Generate assets while coding - **Version Control Ready**: Images in dedicated folder - **Batch Operations**: Generate multiple assets efficiently ## ๐Ÿ”’ Security & Best Practices - โœ… API keys handled securely through environment variables - โœ… Input validation with Zod schemas - โœ… Comprehensive error handling - โœ… Rate limiting and quota management - โœ… No sensitive data logged or stored ## ๐Ÿ“ˆ Use Cases ### Web Development - Hero images and banners - UI/UX mockups and wireframes - Logo and branding assets - Placeholder images ### App Development - App icons and splash screens - User interface elements - Marketing assets - Documentation images ### Content Creation - Blog post illustrations - Social media graphics - Presentation visuals - Product mockups ## ๐Ÿค Contributing 1. Fork the repository 2. Create feature branch: `git checkout -b feature/amazing-feature` 3. Make changes and add tests 4. Run tests: `npm test` 5. Commit: `git commit -m 'Add amazing feature'` 6. Push: `git push origin feature/amazing-feature` 7. Open Pull Request ## ๐Ÿ“Š API Limits & Pricing - **Free Tier**: Generous monthly quota - **Rate Limits**: Automatically handled - **Batch Processing**: Optimized for efficiency - **Cost Control**: Monitor usage with health checks ## ๐Ÿ“œ License MIT License - see [LICENSE](LICENSE) file for details. ## ๐ŸŒŸ Why Choose This MCP Server? - **๐ŸŽฏ Purpose-Built**: Specifically for Claude Code workflows - **โšก Zero Config**: Works out of the box with just API key - **๐Ÿ“ Smart Organization**: Images organized in project folders - **๐Ÿ”„ Active Development**: Regular updates and improvements - **๐Ÿ“– Great Documentation**: Comprehensive guides and examples - **๐Ÿ› ๏ธ Developer-Friendly**: Built by developers, for developers --- **Ready to supercharge your Claude Code projects with AI-generated images?** Install now and start creating! ๐Ÿš€ ```bash # Just add to your MCP config and go! npx -y gemini-imagen-mcp-server --help ```