Imagen Tools MCP服务器
MCP(模型上下文协议)服务器,用于通过Vertex AI生成Google Gemini图像。
特性
- 图像生成使用Gemini 3 Pro Image创建图像(
gemini-3-pro-image-preview) - 图像编辑使用提示符编辑现有图像
- 分辨率支持:1K、2K、4K
- 宽高比: 1:1, 16:9, 9:16, 4:3, 3:4, 3:2, 2:3, 4:5, 5:4, 21:9
- Base64 解码自动处理 base64 编码的图像数据
前提条件
谷歌云设置
- 创建 Google Cloud 项目
- 创建 Google Cloud 项目或使用现有项目 - 启用 Vertex AI API - 记下你的项目ID
- 安装 Google Cloud SDK
- 下载:https://cloud.google.com/sdk/docs/install
- 设置身份验证
gcloud auth application-default login- GOOGLE_CLOUD_PROJECT 设置环境变量
Windows(PowerShell):
setx GOOGLE_CLOUD_PROJECT "your-project-id"Linux/Mac:
export GOOGLE_CLOUD_PROJECT="your-project-id"
# Dauerhaft in ~/.bashrc oder ~/.zshrc hinzufügen:
echo 'export GOOGLE_CLOUD_PROJECT="your-project-id"' >> ~/.bashrc重要 : 设置环境变量后,必须重新启动终端/shell!
- (可选) 设置配额项目
gcloud auth application-default set-quota-project your-project-idPython依赖关系
pip install -r requirements.txt需要 :
google-genai>= 1.59.0mcpPillow
使用
Als MCP服务器
在 ~/.claude/settings.json (或相应配置):
{
"mcpServers": {
"imagen-tools": {
"command": "python",
"args": ["C:/Users/herbe/mcp/imagen_tools_mcp.py"]
}
}
}工具
create_image_using_gemini
创建新图像 。
参数:
prompt(required):图片说明(应该以“Generate”或“Create”开头)aspect_ratio(可选): 宽高比 (default: “16:9”)image_size(可选): 分辨率 - “1K”, “2K”, “4K”(默认:“2K”)
例如:
create_image_using_gemini(
prompt="Generate an infographic showing AI and human collaboration",
aspect_ratio="16:9",
image_size="4K"
)edit_image_using_gemini
编辑现有图像。
参数:
image_path(required): 源图像路径prompt(required): 加工说明image_size(可选):分辨率 - “1K”,“2K”,“4K”
配置
环境变量
自动加入代码:
GOOGLE_GENAI_USE_VERTEXAI=TrueGOOGLE_CLOUD_PROJECT=gen-lang-client-0300367995GOOGLE_CLOUD_LOCATION=global
调试日志记录
调试日志已启用,并写道: ~/mcp/imagen_tools_debug.log
要停用: DEBUG_ENABLED = False 放在第11行。
分辨率
- 1K:~1376x768(16:9)=110万像素
- 2K:~2752x1536(16:9)=420万像素
- 4K:约5504x3072(16:9)=1690万像素
超时
- 标准:300秒(5分钟)
- 4K图像可能需要2-3分钟
重要提示
提示格式
该模型最适合使用提示符 “生成” 或 “创建” 开始。
❌ 坏 :
Die moderne Softwareentwicklung hat sich verändert...✅ 勇气:
Generate an infographic illustrating modern software development...响应结构
API 总是 文本 和 图像 回去图像数据在 response.parts 作为base64编码 inline_data.
版本
0.5.0
许可证
所有者
