图像生成服务器

Gemini Image MCP Server是一个基于Google Gemini API的图像生成服务器,支持背景去除和批量生成功能。

  • by Jang-myoung-gyoon
  • Python
  • 本地部署
  • 更新于
在 GitHub 查看 Jang-myoung-gyoon/gemini-image-mcp

使用说明

Gemini映像MCP服务器

一个模型上下文协议(MCP)服务器,用于使用谷歌的Gemini API生成图像,并可选择删除背景。

特性

  • 生成背景图像:从文本提示生成单个图像
  • 生成透明图像:生成具有自动背景去除功能的图像(使用rembg/birefnet)
  • 批次生成背景图片:在一次调用中生成多个图像
  • 批生成透明图像:在一次调用中生成多个透明图像
  • 可选的本地参考图像输入,用于保留字符、样式或 应用快速更改时的构图

需求

  • Python 3.10+
  • Google Gemini API密钥

安装

  1. 克隆此存储库:
git clone https://github.com/yourusername/gemini-image-mcp.git
cd gemini-image-mcp
  1. 创建并激活虚拟环境:
python -m venv .venv
source .venv/bin/activate  # On Windows: .venv\Scripts\activate
  1. 安装依赖项:
pip install -r requirements.txt
  1. 创建一个 .env 使用Gemini API密钥文件:
cp .env.example .env
# Edit .env and add your API key

配置

创建一个 .env 项目根目录中的文件:

GEMINI_API_KEY=your_api_key_here

从获取API密钥 谷歌AI工作室.

使用Claude代码

添加到您的 .mcp.json 配置:

{
  "mcpServers": {
    "gemini-image": {
      "command": "/path/to/gemini-image-mcp/.venv/bin/python",
      "args": ["/path/to/gemini-image-mcp/server.py"]
    }
  }
}

工具示例

生成背景图像

Generate a fantasy castle on a mountain at sunset
Output: /path/to/castle.png

参考图像:

generate_background_image(
    prompt="Keep the same manager character, but change the expression to a big smile.",
    output_path="/path/to/manager_smile.png",
    reference_image_path="/path/to/manager_base.png",
)

生成透明图像

A warrior in golden armor holding a sword
Output: /path/to/warrior.png (with transparent background)

参考图像:

generate_transparent_image(
    prompt="Use the same character and pose, but make the expression neutral.",
    output_path="/path/to/manager_neutral.png",
    reference_image_path="/path/to/manager_base.png",
)

批次生成背景图片

[
  {"prompt": "a forest at dawn", "output_path": "/tmp/forest.png"},
  {"prompt": "a desert oasis", "output_path": "/tmp/desert.png"},
  {
    "prompt": "Keep the same fighter portrait, but add sunglasses",
    "output_path": "/tmp/fighter_sunglasses.png",
    "reference_image_path": "/tmp/fighter_base.png"
  }
]

备注

  • 每次API调用都要花钱。这些工具会提醒您在生成之前进行确认。
  • reference_image_path 在单图像工具和每个批次上都是可选的 项目。
  • 生成现有角色的变体时,如果存在原始源,则始终将角色的原始基础图像作为reference_image_path传递。在这种情况下,不要使用裁剪或已处理的衍生工具作为参考。
  • 透明图像生成使用birefnet通用模型进行背景去除。
  • 原始Gemini输出与透明图像一起保存(如 *_raw.png).

许可证

MIT许可证