Skip to main content
Glama

generateImage

Create AI-generated images using text prompts via the Jimeng MCP Server. Customize dimensions, enhance with super-resolution, and add watermarks or return image URLs with a 24-hour validity.

Instructions

调用即梦AI生成图像

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
heightNo图像高度,默认值:512
logo_infoNo水印信息
promptYes生成图像的文本描述
req_keyNo取固定值: jimeng_high_aes_general_v21_Ljimeng_high_aes_general_v21_L
return_urlNo输出是否返回图片链接(链接有效期为24小时)
seedNo随机种子,默认值:-1
use_pre_llmNo开启文本扩写,针对输入prompt进行扩写优化,如果输入prompt较短建议开启,如果输入prompt较长建议关闭
use_srNo文生图+AIGC超分
widthNo图像宽度,默认值:512

Implementation Reference

  • MCP tool handler for 'generateImage'. Invokes the generateImage helper, processes the image URLs into MCP resource format, and handles errors.
    async (params) => { try { const imageUrls = await generateImage(params); // 如果没有返回URL数组,返回错误信息 if (!imageUrls || (Array.isArray(imageUrls) && imageUrls.length === 0)) { return { content: [{ type: "text", text: "图像生成失败:未能获取图像URL" }], isError: true }; } // 定义正确的类型 type ContentItem = { type: "resource"; resource: { uri: string; blob: string; mimeType: string } } // 将返回的图像URL转换为MCP响应格式 const responseContent: ContentItem[] = [] if (typeof imageUrls === 'string') { // 单个URL的情况 responseContent.push({ type: "resource", resource: { uri: imageUrls, blob: '', mimeType: '' } }); } else if (Array.isArray(imageUrls)) { // URL数组的情况 for (const url of imageUrls) { responseContent.push({ type: "resource", resource: { uri: url, mimeType: '', blob: '' } }); } } return { content: responseContent }; } catch (error) { const errorMessage = error instanceof Error ? error.message : String(error); return { content: [{ type: "text", text: `图像生成失败: ${errorMessage}` }], isError: true }; } }
  • Zod input schema for the 'generateImage' tool parameters.
    { prompt: z.string().describe("生成图像的文本描述"), req_key: z.string().default("jimeng_high_aes_general_v21_L").describe("取固定值: jimeng_high_aes_general_v21_L"), width: z.number().optional().default(512).describe("图像宽度,默认值:512"), height: z.number().optional().default(512).describe("图像高度,默认值:512"), seed: z.number().optional().default(-1).describe("随机种子,默认值:-1"), use_sr: z.boolean().optional().default(true).describe("文生图+AIGC超分"), use_pre_llm: z.boolean().optional().default(true).describe("开启文本扩写,针对输入prompt进行扩写优化,如果输入prompt较短建议开启,如果输入prompt较长建议关闭"), return_url: z.boolean().optional().default(true).describe("输出是否返回图片链接(链接有效期为24小时)"), logo_info: z.object({ add_logo: z.boolean().optional().describe("是否添加水印,默认不添加"), position: z.number().optional().describe("水印位置:0-右下角 1-左下角 2-左上角 3-右上角"), language: z.number().optional().describe("水印语言:0-中文(AI生成) 1-英文(Generated by AI)"), opacity: z.number().optional().describe("水印透明度:0-1,默认0.3"), logo_text_content: z.string().optional().describe("水印文字内容") }).optional().describe("水印信息") },
  • src/server.ts:20-22 (registration)
    Registration of the 'generateImage' tool on the MCP server with name and description.
    server.tool( "generateImage", "调用即梦AI生成图像",
  • Core helper function in JimengApiClient that performs the actual image generation by calling the Volcengine (JiMeng AI) API with proper parameters, authentication, and error handling.
    public async generateImage(params: ImageGenerationParams): Promise<any> { // 验证环境变量 const credentialError = this.validateCredentials(); if (credentialError) { throw new Error(credentialError); } const timestamp = new Date().toISOString().replace(/[-:]|\.\d{3}/g, ''); const requestParams = { prompt: params.prompt, req_key: params.req_key || ' jimeng_high_aes_general_v21_L', ...(params.width && { width: params.width.toString() }), ...(params.height && { height: params.height.toString() }), ...(params.seed && { seed: params.seed.toString() }), ...({ use_sr: params.use_sr !== undefined ? Boolean(params.use_sr) : true }), ...({ use_pre_llm: params.use_pre_llm !== undefined ? Boolean(params.use_pre_llm) : true }), ...({ return_url: params.return_url !== undefined ? Boolean(params.return_url) : true }), ...(params.logo_info !== undefined && { logo_info: JSON.stringify({ AddLogo: params.logo_info.add_logo, Position: params.logo_info.position, Language: params.logo_info.language, Opacity: params.logo_info.opacity, LogoTextContent: params.logo_info.logo_text_content }) }), }; try { // 发送API请求 const response = await this.iamService.fetchOpenAPI<ImageResponse>({ Action: this.API_ACTION, Version: this.API_VERSION, data: requestParams, method: 'POST', timeout: 1800000 }, { serviceName: this.API_SERVICE, defaultVersion: this.API_VERSION }) if (response.ResponseMetadata?.Error) { throw new Error(`${response.ResponseMetadata.Error.Code}: ${response.ResponseMetadata.Error.Message}`) } return (response as unknown as ImageResponse).data.image_urls || '' } catch (error) { if (axios.isAxiosError(error) && error.response) { throw new Error(`即梦AI图像生成API错误: ${error.response.data}`) } else { throw new Error('即梦AI图像生成请求失败:' + error) } } }
  • TypeScript interface defining the ImageGenerationParams, matching the tool schema.
    interface ImageGenerationParams { prompt: string; req_key: string; // 取固定值: jimeng_high_aes_general_v21_L width?: number; // 默认值:512 height?: number; // 默认值:512 seed?: number; // 默认值:-1 use_sr?: boolean; // 文生图+AIGC超分 use_pre_llm?: boolean; // 开启文本扩写,会针对输入prompt进行扩写优化,如果输入prompt较短建议开启,如果输入prompt较长建议关闭 return_url?: boolean; // 输出是否返回图片链接 (链接有效期为24小时) logo_info?: LogoInfo; // 水印信息 }

Other Tools

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

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