Skip to main content
Glama
comeonzhj

即梦AI图片生成 MCP

by comeonzhj

generate-image

Create AI-generated images by specifying text content, illustration elements, background colors, and aspect ratios for visual content needs.

Instructions

当用户需要生成图片时使用的工具

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
textYes用户需要在图片上显示的文字
illustrationYes根据用户要显示的文字,提取3-5个可以作为图片配饰的插画元素关键词
colorYes图片的背景主色调
ratioYes图片比例。支持: 4:3 (512*384), 3:4 (384*512), 16:9 (512*288), 9:16 (288*512)

Implementation Reference

  • The handler function that implements the core logic of the 'generate-image' tool. It validates the ratio, checks API credentials, generates a prompt using helper functions, calls the external Jimeng AI API to generate the image, and returns either the image URL in a formatted text response or an error message.
    async ({ text, illustration, color, ratio }: { text: string; illustration: string; color: string; ratio: string }) => {
      const imageSize = RATIO_MAPPING[ratio];
      
      if (!imageSize) {
        return {
          content: [
            {
              type: "text",
              text: `错误:不支持的图片比例 ${ratio}。支持的比例: 4:3, 3:4, 16:9, 9:16`
            }
          ]
        };
      }
    
      // 检查API密钥是否配置
      if (!JIMENG_ACCESS_KEY || !JIMENG_SECRET_KEY) {
        return {
          content: [
            {
              type: "text",
              text: "错误:未设置环境变量 JIMENG_ACCESS_KEY 和 JIMENG_SECRET_KEY,无法调用API。"
            }
          ]
        };
      }
    
      // 生成组合后的prompt
      const prompt = generatePrompt(text, illustration, color);
    
      const imageUrl = await callJimengAPI(prompt, imageSize);
    
      if (!imageUrl) {
        return {
          content: [
            {
              type: "text",
              text: "生成图片失败,请检查网络连接和API密钥配置。"
            }
          ]
        };
      }
    
      return {
        content: [
          {
            type: "text",
            text: `图片生成成功!\n\n显示文字: ${text}\n配饰元素: ${illustration}\n背景色调: ${color}\n图片比例: ${ratio} (${imageSize.width}×${imageSize.height})\n生成提示词: ${prompt}\n图片URL: ${imageUrl}`
          }
        ]
      };
    }
  • Zod input schema for the 'generate-image' tool defining parameters: text (string), illustration (string), color (string), ratio (enum: '4:3', '3:4', '16:9', '9:16').
    {
      text: z.string().describe("用户需要在图片上显示的文字"),
      illustration: z.string().describe("根据用户要显示的文字,提取3-5个可以作为图片配饰的插画元素关键词"),
      color: z.string().describe("图片的背景主色调"),
      ratio: z.enum(["4:3", "3:4", "16:9", "9:16"]).describe("图片比例。支持: 4:3 (512*384), 3:4 (384*512), 16:9 (512*288), 9:16 (288*512)")
    },
  • src/index.ts:180-240 (registration)
    Registers the 'generate-image' tool on the MCP server, providing name, description, input schema, and handler function.
    server.tool(
      "generate-image",
      "当用户需要生成图片时使用的工具",
      {
        text: z.string().describe("用户需要在图片上显示的文字"),
        illustration: z.string().describe("根据用户要显示的文字,提取3-5个可以作为图片配饰的插画元素关键词"),
        color: z.string().describe("图片的背景主色调"),
        ratio: z.enum(["4:3", "3:4", "16:9", "9:16"]).describe("图片比例。支持: 4:3 (512*384), 3:4 (384*512), 16:9 (512*288), 9:16 (288*512)")
      },
      async ({ text, illustration, color, ratio }: { text: string; illustration: string; color: string; ratio: string }) => {
        const imageSize = RATIO_MAPPING[ratio];
        
        if (!imageSize) {
          return {
            content: [
              {
                type: "text",
                text: `错误:不支持的图片比例 ${ratio}。支持的比例: 4:3, 3:4, 16:9, 9:16`
              }
            ]
          };
        }
    
        // 检查API密钥是否配置
        if (!JIMENG_ACCESS_KEY || !JIMENG_SECRET_KEY) {
          return {
            content: [
              {
                type: "text",
                text: "错误:未设置环境变量 JIMENG_ACCESS_KEY 和 JIMENG_SECRET_KEY,无法调用API。"
              }
            ]
          };
        }
    
        // 生成组合后的prompt
        const prompt = generatePrompt(text, illustration, color);
    
        const imageUrl = await callJimengAPI(prompt, imageSize);
    
        if (!imageUrl) {
          return {
            content: [
              {
                type: "text",
                text: "生成图片失败,请检查网络连接和API密钥配置。"
              }
            ]
          };
        }
    
        return {
          content: [
            {
              type: "text",
              text: `图片生成成功!\n\n显示文字: ${text}\n配饰元素: ${illustration}\n背景色调: ${color}\n图片比例: ${ratio} (${imageSize.width}×${imageSize.height})\n生成提示词: ${prompt}\n图片URL: ${imageUrl}`
            }
          ]
        };
      }
    );
  • Core helper function that calls the Jimeng AI (Volcengine) API to generate the image based on prompt and dimensions, handling authentication signing and returning the generated image URL.
    async function callJimengAPI(prompt: string, ratio: { width: number; height: number }): Promise<string | null> {
      // 查询参数
      const queryParams = {
        'Action': 'CVProcess',
        'Version': '2022-08-31'
      };
      const formattedQuery = formatQuery(queryParams);
    
      // 请求体参数
      const bodyParams = {
        req_key: "jimeng_high_aes_general_v21_L",
        prompt: prompt,
        return_url: true,
        width: ratio.width,
        height: ratio.height
      };
      const formattedBody = JSON.stringify(bodyParams);
    
      try {
        // 生成签名和请求头
        const { headers, requestUrl } = signV4Request(
          JIMENG_ACCESS_KEY!,
          JIMENG_SECRET_KEY!,
          SERVICE,
          formattedQuery,
          formattedBody
        );
    
        const response = await fetch(requestUrl, {
          method: 'POST',
          headers: headers,
          body: formattedBody
        });
    
        if (!response.ok) {
          throw new Error(`HTTP error! status: ${response.status}`);
        }
    
        const responseText = await response.text();
        // 替换转义字符,与Python示例保持一致
        const cleanedResponse = responseText.replace(/\\u0026/g, "&");
        const result = JSON.parse(cleanedResponse);
        
        // 根据火山引擎即梦AI API响应格式解析结果
        if (result.ResponseMetadata && result.ResponseMetadata.Error) {
          throw new Error(`API error: ${result.ResponseMetadata.Error.Message || 'Unknown error'}`);
        }
    
        // 返回生成的图片URL - 根据搜索结果,即梦AI返回的是data.image_urls数组
        if (result.data && result.data.image_urls && result.data.image_urls.length > 0) {
          return result.data.image_urls[0];
        }
        
        return null;
      } catch (error) {
        console.error("调用即梦AI API时出错:", error);
        return null;
      }
    }
  • Helper function that constructs the prompt string for the image generation API using the provided text, illustration keywords, and color.
    function generatePrompt(text: string, illustration: string, color: string): string {
      return `字体设计:"${text}",黑色字体,斜体,带阴影。干净的背景,白色到${color}渐变。点缀浅灰色、半透明${illustration}等元素插图做配饰插画。`;
    }
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It only states the tool is used for image generation, without details on output format, quality, limitations (e.g., rate limits, costs), or error handling. This leaves significant gaps in understanding how the tool behaves beyond its basic function.

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 a single, concise sentence in Chinese ('当用户需要生成图片时使用的工具'), which is efficient and front-loaded. However, it could be more structured by including key details upfront, but given its brevity and lack of redundancy, it earns a high score for conciseness.

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

Completeness2/5

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

Given the tool's complexity (4 required parameters, no output schema, and no annotations), the description is incomplete. It doesn't explain what the generated image looks like, how parameters interact, or any behavioral traits. Without annotations or output schema, the description should provide more context to compensate, but it falls short.

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?

The input schema has 100% description coverage, with clear parameter details (e.g., 'text' for displayed text, 'illustration' for accessory elements, 'color' for background, 'ratio' with enum values). The description adds no parameter semantics beyond what the schema provides, so it meets the baseline of 3 for high schema coverage without compensating value.

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

Purpose3/5

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

The description states the tool's purpose as '当用户需要生成图片时使用的工具' (used when users need to generate images), which is clear but vague. It specifies the general function (generate images) but lacks specificity about what kind of images or how it differs from other image generation tools (though no siblings exist). It's not tautological but doesn't provide detailed verb+resource context beyond the basic action.

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

Usage Guidelines2/5

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

The description provides minimal guidance: it only states when to use the tool ('当用户需要生成图片时' - when users need to generate images), with no context on when not to use it, prerequisites, or alternatives. Since there are no sibling tools, this is less critical, but it still lacks depth in usage scenarios or constraints.

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/comeonzhj/jimengpic-mcp'

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