Skip to main content
Glama
longhz

MiniMax MCP Server

by longhz

generate_image

Generate images from text descriptions, with automatic local saving and customizable aspect ratios, powered by MiniMax's image-01 model.

Instructions

使用 MiniMax image-01 生成图片,默认保存到本地

图片自动保存到配置的输出目录(默认 ~/Pictures/MiniMax)。

Args: prompt: 图片描述文本(英文效果最佳,中文也可) model: 模型名称,默认 image-01 aspect_ratio: 图片比例:1:1 / 16:9 / 9:16 / 3:4 / 4:3,默认 1:1 response_format: 默认 base64(自动存本地),改 url 则仅返回24h临时链接 n: 生成数量 1-3,默认 1 prompt_optimizer: 是否启用提示词优化,默认 true save_to_disk: 是否保存到本地(仅 base64 模式有效),默认 true

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes
modelNoimage-01
aspect_ratioNo1:1
response_formatNobase64
nNo
prompt_optimizerNo
save_to_diskNo

Implementation Reference

  • Core implementation of the generate_image tool. Handles parameter validation, calls the MiniMax API via MiniMaxClient.generate_image(), processes responses (URL or base64), and optionally saves base64 images to disk.
    def generate_image(
        client: MiniMaxClient,
        prompt: str,
        model: str = "image-01",
        aspect_ratio: str = "1:1",
        response_format: str = "url",
        n: int = 1,
        prompt_optimizer: bool = True,
        save_to_disk: bool = True,
    ) -> dict:
        """使用 MiniMax image-01 模型生成图片
    
        Args:
            client: MiniMax API 客户端
            prompt: 图片描述文本(英文效果最佳,中文也可)
            model: 模型名称,默认 image-01
            aspect_ratio: 图片比例:1:1 / 16:9 / 9:16 / 3:4 / 4:3
            response_format: 返回格式:url(24h有效)或 base64
            n: 生成数量 1-3
            prompt_optimizer: 是否启用提示词优化
            save_to_disk: base64 模式下是否自动保存到本地
    
        Returns:
            {
                success: bool,
                images: [{url, saved_path, base64_preview}],
                model: str,
                request_id: str,
            }
        """
        # 参数校验
        if n not in (1, 2, 3):
            return {"success": False, "error": "n 必须为 1、2 或 3"}
        if aspect_ratio not in VALID_ASPECT_RATIOS:
            return {"success": False, "error": f"aspect_ratio 必须是: {', '.join(VALID_ASPECT_RATIOS)}"}
        if response_format not in VALID_FORMATS:
            return {"success": False, "error": f"response_format 必须是 'url' 或 'base64'"}
        if not prompt or not prompt.strip():
            return {"success": False, "error": "prompt 不能为空"}
    
        # 调用 API
        result = client.generate_image(
            prompt=prompt.strip(),
            model=model,
            aspect_ratio=aspect_ratio,
            n=n,
            prompt_optimizer=prompt_optimizer,
            response_format=response_format,
        )
    
        if not result.get("success"):
            return {
                "success": False,
                "error": result.get("error", "Image generation failed"),
                "detail": result.get("detail", ""),
            }
    
        # 解析响应
        data = result.get("data", result)
        images_out = []
    
        # 获取图片列表
        if response_format == "url":
            img_list = data.get("image_urls", []) if isinstance(data, dict) else []
        else:
            img_list = data.get("image_base64", []) if isinstance(data, dict) else []
    
        if isinstance(img_list, str):
            img_list = [img_list]
    
        for img in img_list:
            item = {}
    
            if response_format == "url":
                url = img.get("url", img) if isinstance(img, dict) else str(img)
                item["url"] = url
                item["saved_path"] = ""
            else:
                b64 = img if isinstance(img, str) else (img.get("image_base64", "") or img.get("b64_img", ""))
                item["base64_preview"] = (b64[:40] + "...") if b64 else ""
    
                if save_to_disk and b64:
                    try:
                        raw = base64.b64decode(b64)
                        filename = f"minimax_{uuid.uuid4().hex[:8]}.jpg"
                        out_path = IMAGE_OUTPUT_DIR / filename
                        out_path.write_bytes(raw)
                        item["saved_path"] = str(out_path)
                    except Exception as e:
                        item["saved_path"] = ""
                        item["save_error"] = str(e)
    
            images_out.append(item)
    
        return {
            "success": True,
            "images": images_out,
            "count": len(images_out),
            "model": result.get("model", model),
            "request_id": result.get("request_id", ""),
        }
  • Schema constants: VALID_ASPECT_RATIOS and VALID_FORMATS define the allowed input values for aspect_ratio and response_format parameters.
    # 支持的参数范围
    VALID_ASPECT_RATIOS = ("1:1", "16:9", "9:16", "3:4", "4:3")
    VALID_FORMATS = ("url", "base64")
  • MCP tool registration via @mcp.tool() decorator. The async function 'generate_image' on the server is decorated and delegates to the core handler in tools/image_generate.py.
    @mcp.tool()
    def generate_image(
        prompt: str,
        model: str = "image-01",
        aspect_ratio: str = "1:1",
        response_format: str = "base64",
        n: int = 1,
        prompt_optimizer: bool = True,
        save_to_disk: bool = True,
    ) -> dict:
        """使用 MiniMax image-01 生成图片,默认保存到本地
    
        图片自动保存到配置的输出目录(默认 ~/Pictures/MiniMax)。
    
        Args:
            prompt:           图片描述文本(英文效果最佳,中文也可)
            model:            模型名称,默认 image-01
            aspect_ratio:     图片比例:1:1 / 16:9 / 9:16 / 3:4 / 4:3,默认 1:1
            response_format:  默认 base64(自动存本地),改 url 则仅返回24h临时链接
            n:                生成数量 1-3,默认 1
            prompt_optimizer: 是否启用提示词优化,默认 true
            save_to_disk:     是否保存到本地(仅 base64 模式有效),默认 true
        """
        from minimax_mcp.tools.image_generate import generate_image as _run
        return _run(
            get_client(),
            prompt,
            model=model,
            aspect_ratio=aspect_ratio,
            response_format=response_format,
            n=n,
            prompt_optimizer=prompt_optimizer,
            save_to_disk=save_to_disk,
        )
  • API client method generate_image on MiniMaxClient. Sends a POST request to {host}/v1/image_generation with model, prompt, aspect_ratio, n, prompt_optimizer, and response_format.
    def generate_image(
        self,
        prompt: str,
        model: str = "image-01",
        aspect_ratio: str = "1:1",
        n: int = 1,
        prompt_optimizer: bool = True,
        response_format: str = "url",
    ) -> dict:
        """图片生成
    
        POST {host}/v1/image_generation
        Body: {"model": "image-01", "prompt": "...", ...}
        """
        return self._request(
            "POST",
            "/v1/image_generation",
            body={
                "model": model,
                "prompt": prompt,
                "aspect_ratio": aspect_ratio,
                "n": n,
                "prompt_optimizer": prompt_optimizer,
                "response_format": response_format,
            },
        )
  • Configuration helper: IMAGE_OUTPUT_DIR defines where generated images are saved (default ~/Pictures/MiniMax).
    # 输出目录
    IMAGE_OUTPUT_DIR: Path = Path(_get("MINIMAX_IMAGE_OUTPUT_DIR", str(Path.home() / "Pictures" / "MiniMax"))).expanduser()
    IMAGE_OUTPUT_DIR.mkdir(parents=True, exist_ok=True)
Behavior4/5

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

With no annotations, the description carries the full burden of behavioral disclosure. It details save behavior, response_format, prompt_optimizer, and the dependency of save_to_disk on base64 mode. It omits potential latency and auth requirements, but covers core traits well.

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?

The description is efficiently structured with a head sentence and a list of Args. It front-loads the purpose and avoids fluff, though it repeats default values that are already in the schema. Minor redundancy barely detracts from clarity.

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?

Given 7 parameters, no output schema, and no annotations, the description provides adequate context for prompt, model, aspect_ratio, response_format, n, and optimizer. However, it does not specify the exact output structure or error handling, leaving minor gaps.

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

Parameters5/5

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

Despite 0% schema description coverage, the description compensates fully by explaining all 7 parameters with defaults, constraints (e.g., aspect_ratio options, n range 1-3), and mode interactions (e.g., save_to_disk only for base64). This adds significant value beyond the raw schema.

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 it uses 'MiniMax image-01' to 'generate images' and defaults to local saving. This distinct verb-resource pairing differentiates it from siblings like 'understand_image' and 'web_search'.

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

Usage Guidelines3/5

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

The description explains parameter behavior and defaults but lacks explicit guidance on when to use this tool versus alternatives. It does not mention when not to use it or specify any prerequisites, leaving usage context implicit.

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

Install Server

Other Tools

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/longhz/minimax-mcp'

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