mrn-gemini-imagen-mcp

mrn-gemini-imagen-mcp

MCP server for generating and editing images using Google Gemini API, with support for multi-turn iterative refinement.

Category
访问服务器

README

mrn-gemini-imagen-mcp

npm version License: MIT

MCP (Model Context Protocol) server for generating and editing images using Google Gemini API.

Quick Start

  1. Get your API key from Google AI Studio
  2. Add to Claude Desktop config:
{
  "mcpServers": {
    "gemini-imagen": {
      "command": "npx",
      "args": ["-y", "mrn-gemini-imagen-mcp"],
      "env": { "GEMINI_API_KEY": "your-api-key-here" }
    }
  }
}
  1. Restart Claude Desktop and start generating images!

Features

  • Text-to-Image Generation: Generate images from text descriptions
  • Image Editing: Modify existing images based on text prompts
  • Multi-turn Iteration: Refine images through conversational editing sessions
  • Configurable Aspect Ratios: Support for 10 different aspect ratios
  • Flexible Model Selection: Use any Gemini image model via configuration

Prerequisites

Installation

Option 1: Using npx (Recommended)

No installation needed! Just configure Claude Desktop or Claude Code to use it directly via npx.

Option 2: Global Install

npm install -g mrn-gemini-imagen-mcp

Option 3: From Source

git clone https://github.com/mernorthzide/mrn-gemini-imagen-mcp.git
cd mrn-gemini-imagen-mcp
npm install
npm run build

Configuration

Set the following environment variables:

Variable Required Default Description
GEMINI_API_KEY Yes - Your Google Gemini API key
GEMINI_MODEL No gemini-3-pro-image-preview Gemini model to use
GEMINI_OUTPUT_DIR No ./generated_images Output directory for images

Supported Models

  • gemini-3-pro-image-preview (default, latest)
  • gemini-2.5-flash-image (stable, faster)

Supported Aspect Ratios

1:1, 2:3, 3:2, 3:4, 4:3, 4:5, 5:4, 9:16, 16:9, 21:9

Note: Aspect ratio is optional. If not specified, Gemini will automatically select the best aspect ratio based on your prompt.

Usage with Claude Desktop

Add to your Claude Desktop configuration (~/Library/Application Support/Claude/claude_desktop_config.json on macOS):

Using npx (Recommended)

{
  "mcpServers": {
    "gemini-imagen": {
      "command": "npx",
      "args": ["-y", "mrn-gemini-imagen-mcp"],
      "env": {
        "GEMINI_API_KEY": "your-api-key-here"
      }
    }
  }
}

Using Global Install

{
  "mcpServers": {
    "gemini-imagen": {
      "command": "mrn-gemini-imagen-mcp",
      "env": {
        "GEMINI_API_KEY": "your-api-key-here"
      }
    }
  }
}

Usage with Claude Code

Add to your Claude Code settings file (~/.claude.json):

{
  "mcpServers": {
    "gemini-imagen": {
      "type": "stdio",
      "command": "npx",
      "args": ["-y", "mrn-gemini-imagen-mcp"],
      "env": {
        "GEMINI_API_KEY": "your-api-key-here"
      }
    }
  }
}

Tip: Set GEMINI_MODEL to gemini-2.5-flash-image for faster generation.

Tools

1. generate_image

Generate an image from a text description.

Parameters:

Parameter Type Required Description
prompt string Yes Description of the image to generate
aspectRatio string No Aspect ratio (auto-selected by Gemini if not provided)
outputPath string No Custom output file path

Example:

{
  "prompt": "A serene Japanese garden with a koi pond and cherry blossoms",
  "aspectRatio": "16:9"
}

Response:

{
  "success": true,
  "filePath": "/path/to/a_serene_japanese_garden_1705123456789.png",
  "message": "Image generated successfully"
}

2. edit_image

Edit an existing image based on a text prompt.

Parameters:

Parameter Type Required Description
imagePath string Yes Path to the image to edit
prompt string Yes Instructions for editing
aspectRatio string No Aspect ratio for output
outputPath string No Custom output file path

Example:

{
  "imagePath": "/path/to/original.png",
  "prompt": "Change the sky to a beautiful sunset with orange and pink colors"
}

3. iterate_image

Iteratively refine an image through multi-turn conversation.

Parameters:

Parameter Type Required Description
prompt string Yes Instructions for this iteration
sessionId string No Session ID from previous iteration
imagePath string Conditional Required when starting new session
aspectRatio string No Aspect ratio for output

Starting a new session:

{
  "imagePath": "/path/to/original.png",
  "prompt": "Add a rainbow in the background"
}

Response:

{
  "success": true,
  "filePath": "/path/to/add_a_rainbow_1705123456789.png",
  "sessionId": "550e8400-e29b-41d4-a716-446655440000",
  "message": "Image iteration completed. Use the same sessionId to continue editing."
}

Continuing the session:

{
  "sessionId": "550e8400-e29b-41d4-a716-446655440000",
  "prompt": "Make the rainbow more vibrant and add some birds"
}

Error Handling

All tools return structured error responses when something goes wrong:

{
  "success": false,
  "error": {
    "code": "SAFETY_BLOCKED",
    "message": "Content was blocked by safety filters",
    "reason": "HARM_CATEGORY_DANGEROUS_CONTENT"
  }
}

Error Codes:

Code Description
SAFETY_BLOCKED Content blocked by safety filters
API_ERROR Error from Gemini API
INVALID_INPUT Invalid input parameters
FILE_ERROR File read/write error

Development

# Watch mode for development
npm run dev

# Build for production
npm run build

# Run the server directly
npm start

File Structure

mrn-gemini-imagen-mcp/
├── src/
│   ├── index.ts              # MCP server entry point
│   ├── types.ts              # TypeScript types and constants
│   ├── services/
│   │   └── geminiClient.ts   # Gemini API wrapper
│   ├── tools/
│   │   ├── generateImage.ts  # Text-to-image tool
│   │   ├── editImage.ts      # Image editing tool
│   │   └── iterateImage.ts   # Multi-turn iteration tool
│   └── utils/
│       ├── fileManager.ts    # File operations
│       └── sessionManager.ts # Session management
├── dist/                     # Compiled JavaScript
├── package.json
├── tsconfig.json
└── README.md

License

MIT

Acknowledgments

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选