Skip to main content
Glama
ttkkasd

Jimeng MCP Server

by ttkkasd

generateImage

Create AI-generated images from text prompts using the Jimeng MCP Server. Specify prompts, model versions, and parameters to produce custom visual content.

Instructions

调用即梦AI生成图像

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYes生成图像的文本描述
req_keyNo模型版本,默认值: jimeng_high_aes_general_v21_Ljimeng_high_aes_general_v21_L
seedNo随机种子,默认值:-1
negative_promptNo负面提示词,描述不希望在图像中出现的内容

Implementation Reference

  • src/index.ts:33-67 (registration)
    Registers the 'generateImage' tool with the MCP server in the ListToolsRequestHandler, providing name, description, and input schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      // Return tools even without credentials for lazy loading support
      const tools: Tool[] = [
        {
          name: 'generateImage',
          description: '调用即梦AI生成图像',
          inputSchema: {
            type: 'object',
            properties: {
              prompt: {
                type: 'string',
                description: '生成图像的文本描述'
              },
              req_key: {
                type: 'string',
                description: '模型版本,默认值: jimeng_high_aes_general_v21_L',
                default: 'jimeng_high_aes_general_v21_L'
              },
              seed: {
                type: 'number',
                description: '随机种子,默认值:-1',
                default: -1
              },
              negative_prompt: {
                type: 'string',
                description: '负面提示词,描述不希望在图像中出现的内容'
              }
            },
            required: ['prompt']
          }
        }
      ];
    
      return { tools };
    });
  • The MCP CallToolRequest handler specifically for the 'generateImage' tool, which validates parameters, initializes the image generator with credentials, calls generateImage, and formats the response.
    if (name === 'generateImage') {
      try {
        const params = args as unknown as ImageGenerationParams;
        
        if (!params.prompt) {
          return {
            content: [
              {
                type: 'text',
                text: 'Error: prompt parameter is required for image generation.'
              }
            ]
          };
        }
    
        // Get credentials (will be passed via context in HTTP mode)
        const credentials = getCredentials();
        if (!credentials.accessKeyId || !credentials.secretAccessKey) {
          return {
            content: [
              {
                type: 'text',
                text: 'Error: Missing Volcengine credentials. Please configure accessKeyId and secretAccessKey.'
              }
            ]
          };
        }
    
        const imageGenerator = new JimengImageGenerator(credentials);
        console.log('=== MCP 调试 ===');
        console.log('请求参数:', params);
        
        const result = await imageGenerator.generateImage(params);
        
        console.log('返回结果:', JSON.stringify(result, null, 2));
        console.log('Algorithm base resp:', result.algorithm_base_resp);
        console.log('Image URLs:', result.image_urls);
        console.log('Image URLs 长度:', result.image_urls?.length);
        console.log('结果类型:', typeof result);
        console.log('==============');
        
        // 检查结果是否有效
        if (!result || !result.algorithm_base_resp) {
          return {
            content: [
              {
                type: 'text',
                text: `图像生成失败:无效的响应格式\n\n原始响应: ${JSON.stringify(result, null, 2)}`
              }
            ]
          };
        }
        
        return {
          content: [
            {
              type: 'text',
              text: `图像生成成功!\n\n状态: ${result.algorithm_base_resp.status_message || 'Unknown'}\n请求ID: ${result.algorithm_base_resp.request_id || 'Unknown'}\n\n生成的图像链接:\n${result.image_urls.map((url, index) => `${index + 1}. ${url}`).join('\n')}`
            }
          ]
        };
      } catch (error) {
        return {
          content: [
            {
              type: 'text',
              text: `图像生成失败: ${error instanceof Error ? error.message : '未知错误'}`
            }
          ]
        };
      }
    }
  • TypeScript interface defining the input parameters for generateImage (ImageGenerationParams).
    export interface ImageGenerationParams {
      prompt: string;
      req_key?: string;
      seed?: number;
      negative_prompt?: string;
    }
  • Core implementation of the generateImage method in JimengImageGenerator class, which constructs the API request, signs it with auth, calls the Volcengine API, processes the response, and returns image URLs.
    async generateImage(params: ImageGenerationParams): Promise<ImageGenerationResponse> {
      const timestamp = this.getTimestamp();
      const payload = JSON.stringify({
        req_key: params.req_key || 'jimeng_high_aes_general_v21_L',
        prompt: params.prompt,
        seed: params.seed ?? -1,
        return_url: true, // 请求返回图像URL而非base64数据
        ...(params.negative_prompt && { negative_prompt: params.negative_prompt })
      });
    
      const headers: Record<string, string> = {
        'Content-Type': 'application/json',
        'X-Date': timestamp,
        'Host': 'visual.volcengineapi.com'
      };
    
      const authorization = this.auth.signRequest(
        'POST',
        '/',
        'Action=CVProcess&Version=2022-08-31',
        headers,
        payload,
        timestamp
      );
    
      headers['Authorization'] = authorization;
    
      try {
        const response = await axios.post(
          `${this.baseUrl}/?Action=CVProcess&Version=2022-08-31`,
          payload,
          { headers }
        );
    
        // 处理实际的响应格式
        const data = response.data;
        
        console.log('=== 原始API响应 ===');
        console.log('Status:', response.status);
        console.log('Data:', JSON.stringify(data, null, 2));
        console.log('==================');
        
        // 优先处理返回URL的响应格式
        if (data.code === 10000 && data.data) {
          // 如果有image_urls,直接使用
          if (data.data.image_urls && Array.isArray(data.data.image_urls) && data.data.image_urls.length > 0) {
            return {
              algorithm_base_resp: {
                status_code: 0,
                status_message: 'Success',
                request_id: data.request_id || 'unknown'
              },
              image_urls: data.data.image_urls,
              log_id: data.request_id || 'unknown'
            };
          }
          
          // 如果没有URL但有base64数据,转换为data URL(备用方案)
          if (data.data.binary_data_base64 && Array.isArray(data.data.binary_data_base64)) {
            console.warn('收到base64数据而非URL,可能需要设置return_url参数');
            const base64Images = data.data.binary_data_base64.map((base64: string, index: number) => 
              `data:image/png;base64,${base64}`
            );
            return {
              algorithm_base_resp: {
                status_code: 0,
                status_message: 'Success',
                request_id: data.request_id || 'unknown'
              },
              image_urls: base64Images,
              log_id: data.request_id || 'unknown'
            };
          }
        }
        
        // 如果响应格式不同,尝试适配
        if (data.ResponseMetadata || data.Result) {
          return {
            algorithm_base_resp: {
              status_code: data.ResponseMetadata?.Error?.Code || 0,
              status_message: data.ResponseMetadata?.Error?.Message || 'Success',
              request_id: data.ResponseMetadata?.RequestId || 'unknown'
            },
            image_urls: data.Result?.image_urls || [],
            log_id: data.ResponseMetadata?.RequestId || 'unknown'
          };
        }
        
        // 如果都不匹配,返回原始响应但添加默认结构
        return {
          algorithm_base_resp: {
            status_code: 0,
            status_message: 'Response format unknown',
            request_id: 'unknown'
          },
          image_urls: [],
          log_id: 'unknown',
          raw_response: data
        };
      } catch (error) {
        if (axios.isAxiosError(error)) {
          console.error('API Error:', error.response?.data);
          throw new Error(`API request failed: ${error.response?.status} ${error.response?.statusText} - ${JSON.stringify(error.response?.data)}`);
        }
        throw error;
      }
    }
  • TypeScript interface defining the output response format for generateImage (ImageGenerationResponse).
    export interface ImageGenerationResponse {
      algorithm_base_resp: {
        status_code: number;
        status_message: string;
        request_id: string;
      };
      image_urls: string[];
      log_id: string;
      raw_response?: any;
    }
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. It mentions '即梦AI' but doesn't disclose behavioral traits like rate limits, authentication needs, output format, or error handling. This leaves significant gaps for an AI agent to understand tool behavior.

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 a single, efficient sentence with no wasted words. It is appropriately sized and front-loaded, clearly stating the tool's purpose without unnecessary elaboration.

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 complexity of an image generation tool with no annotations and no output schema, the description is incomplete. It lacks details on output format, error cases, or usage constraints, making it inadequate for full contextual understanding.

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 description adds no parameter semantics beyond what the input schema provides. With 100% schema description coverage, the baseline is 3, as the schema adequately documents parameters like 'prompt' and 'req_key'. No additional value is added by the description.

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 '调用即梦AI生成图像' states the action (generate) and resource (image) but is vague about the specific AI service ('即梦AI') without further context. It doesn't distinguish from siblings as there are none, but the purpose is clear though not highly specific.

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?

No guidance on when to use this tool vs alternatives is provided. The description implies usage for image generation but lacks context on prerequisites, limitations, or scenarios. With no sibling tools, this is less critical, but still a gap in usage instructions.

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/ttkkasd/jimeng-mcp'

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