Skip to main content
Glama

image2-mcp

MCP Server for the company image2 text-to-image API. Allows Claude Code, Codex, and other MCP-compatible AI tools to generate images directly.

🚀 Quick Start

自动安装(推荐)

git clone <repo-url>
cd image2-mcp
bash scripts/setup.sh

脚本会自动完成:

  1. 检查/安装 uv

  2. 安装 Python 依赖(uv sync

  3. 引导你输入 API Key(或从 ~/.claude/.env 复用已有 key)

  4. 写入 ~/.claude/.env 环境配置

  5. image2 注册到 ~/.claude.json(Claude Code 的 MCP 配置)

  6. 运行健康检查验证一切正常

完成后重启 Claude Code,说「帮我生成一张图片」即可。

手动安装

# 1. 安装依赖
uv sync

# 2. 配置环境变量
cp .env.example ~/.claude/.env
# 编辑 ~/.claude/.env,将 MAGENE_API_KEY 改为你的真实 key:
#   MAGENE_API_KEY=user_xxxxxxxx

# 3. 健康检查
uv run python -m image2_mcp --health-check

MCP 配置需要手动添加到 ~/.claude.json 的顶层 mcpServers 字段:

{
  "mcpServers": {
    "image2": {
      "command": "bash",
      "args": [
        "-c",
        "set -a; [ -f ~/.claude/.env ] && . ~/.claude/.env; [ -f .env ] && . ./.env; set +a; exec /Users/你的用户名/.local/bin/uv run --directory /path/to/image2-mcp python -m image2_mcp"
      ],
      "env": {
        "PATH": "/Users/你的用户名/.local/bin:/usr/local/bin:/usr/bin:/bin",
        "HOME": "/Users/你的用户名"
      },
      "description": "文生图 — 调用公司统一 API 平台 image2 模型生成图片",
      "type": "stdio"
    }
  }
}

⚠️ 注意将 /Users/你的用户名/ 替换为实际路径。uv 的路径可通过 which uv 获取。


Related MCP server: universal-image-mcp

⚙️ 环境变量

变量

必填

默认值

说明

MAGENE_API_KEY

公司 API 平台的 key

MAGENE_API_BASE_URL

http://tops.magene.cn:11636/api/v1/images/generations

API 地址

IMAGE2_OUTPUT_DIR

自动检测(项目 /output

图片保存路径

IMAGE2_MODEL

openai/gpt-image-2

模型名称

图片输出目录的优先级

  1. 显式参数

  2. IMAGE2_OUTPUT_DIR 环境变量

  3. CLAUDE_PROJECT_DIR<项目>/output/(Claude Code 自动设)

  4. IMAGE2_PROJECT_DIR<项目>/output/(legacy)

  5. 当前工作目录 /output

  6. 系统临时目录 /image2-output

💡 通常无需手动设置任何目录变量——如果你在某个项目中用 Claude Code 打开,图片会自动存到那个项目的 output/ 文件夹。


📐 工具参数

参数

类型

必填

默认值

说明

prompt

string

图片描述(最长 32000 字符)

size

string

尺寸,见下方

quality

string

auto

low / medium / high / auto

filename

string

自动生成

自定义文件名(不含 .png

可用尺寸

分辨率

1024x1024

1K 方形

1536x1024

1.5K 横版

1024x1536

1.5K 竖版

2048x2048

2K 方形

2048x1152

2K 横版

3840x2160

4K 横版

2160x3840

4K 竖版

auto

自动

自定义尺寸:WxH 格式,每边 ≤ 3840px,16 的倍数,宽高比 ≤ 3:1,总像素 655,360–8,294,400。


🧪 开发

uv sync --group dev
uv run pytest --cov=src --cov-report=term-missing

🔧 工作原理

AI: generate_image(prompt="a cat in a garden", size="1024x1024")
    → 服务端校验参数
    → POST 到公司 API
    → 解码 Base64 响应
    → 写入 PNG 到磁盘
    → 返回图片 + 路径 + 用量统计

生成是异步的——AI 调用后立即返回,图片就绪后会通过日志通知。多张图片可并行生成。

Available Tools

2 tools
generate_imageA

Generate an image from a text prompt using the company image2 model. Use async_mode=true (default) for fire-and-forget — returns immediately, image saves to disk in the background. Use async_mode=false to wait for the image and see it in the response. Size: Presets: 1024x1024, 1024x1536, 1536x1024, 2048x1152, 2048x2048, 2160x3840, 3840x2160, auto. Custom: WxH (max 3840px per side, multiples of 16, ratio ≤ 3.0:1, pixels 655,360–8,294,400)

ParametersJSON Schema
NameRequiredDescriptionDefault
sizeYes
promptYes
qualityNoauto
filenameNo
async_modeNo
output_dirNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A4.1/5.0
Behavior4/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description discloses key behaviors: async mode behavior, size limits and ratio rules. Does not mention failure handling or auth, but covers the main behavioral traits.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

Two sentences, front-loaded with purpose. Second sentence packs size details efficiently. No superfluous text.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With an output schema present, description focuses on behavioral aspects. Covers async vs sync and size constraints, which are critical. Missing details on quality and error handling, but adequate for generation tool.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 0%, so description must compensate. Explains async_mode and size in detail, but does not cover 'quality,' 'filename,' or 'output_dir' parameters. Adds partial value but leaves gaps.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

Clearly states 'Generate an image from a text prompt using the company image2 model,' specifying the action and model. Distinguishes from sibling 'list_images' which lists existing images.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

Provides clear context for async mode usage (fire-and-forget vs wait) and size constraints. No explicit when-not or alternatives beyond the sibling, but sufficient for the tool's domain.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

list_imagesA

List recently generated images in the output directory. Useful after async/fire-and-forget generation to see what's been created.

ParametersJSON Schema
NameRequiredDescriptionDefault
limitNo
output_dirNo

Output Schema

ParametersJSON Schema
NameRequiredDescription
resultYes

TDQS

A3.8/5.0
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden. It states the tool lists recent images but does not disclose details like sorting order, recency definition, or whether it returns metadata. The behavior is minimally described but not fully transparent.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely concise—two short sentences with no extraneous information. Every word serves a purpose: stating the action and providing usage context.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Despite having an output schema, the description lacks parameter explanations and a definition of 'recently.' For a simple listing tool, it is adequate but not comprehensive; agents may need to infer or experiment.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters2/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 0%, yet the description offers no explanation for the two parameters ('limit' and 'output_dir'). Agents receive no guidance on how to use these parameters, which is a significant gap.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'List recently generated images in the output directory.' The verb 'List' and resource 'recently generated images' are specific, and the sibling tool 'generate_image' contrasts as a creation tool, making the distinction clear.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description explicitly mentions usefulness 'after async/fire-and-forget generation to see what's been created,' providing clear context for when to use this tool. However, it lacks explicit when-not-to-use or alternative suggestions beyond the implied sibling.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

TDQS

A4/5.0
Disambiguation5/5

The two tools have clearly distinct purposes: generating images and listing generated images. There is no overlap or ambiguity.

Naming Consistency5/5

Both tools follow a consistent verb_noun pattern: 'generate_image' and 'list_images'. The convention is uniform and predictable.

Tool Count3/5

With only 2 tools, the server feels thin for its domain, but it covers the essential generation and listing operations. It is borderline reasonable but lacks additional supporting tools.

Completeness4/5

The server covers core image generation and listing. However, it lacks individual image retrieval, deletion, or progress tracking for async operations, which are minor but notable gaps.

Maintenance

ActivitySlowing
ResponsivenessSyncing

Resources

Unclaimed servers have limited discoverability.

Looking for Admin?

If you are the server author, to access and configure the admin panel.

Related MCP Connectors

Related MCP Servers

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/Paipai112/image2-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server