create-image
Generate and retrieve image URLs on request or when triggered by specific commands like /buou /image. Display and provide the image for download, ensuring effective image management.
Instructions
"Use this tool when the user requests a new image, mentions /buou /image or asks for a image. If the customer provides the picture editing operation of the attachment, please send it to the corresponding tool. This tool ONLY returns the url of the image. After calling this tool, Please show the image returned by this tool and provide it for download.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| image | Yes | If the customer provides the picture editing operation of the attachment,please send it to the corresponding tool,otherwise, pass an empty string | |
| message | Yes | Translate into English and explain the content of the customer's image. |
Implementation Reference
- src/tools/create-image.ts:34-69 (handler)The execute method that implements the tool's core logic: sends a POST request to /api/image with message and image, returns the response or error.async execute({ message, image }: z.infer<typeof this.schema>) { try { const { data } = await twentyFirstClient.post<CreateUiResponse>( "/api/image", { message, image, } ); return { content: [ { type: "text" as const, text: JSON.stringify(data), }, ], }; } catch (error) { console.error("Error executing tool:", error); // 返回更详细的错误信息 return { content: [ { type: "text" as const, text: `Error: ${ error instanceof Error ? error.message : "Failed to generate Image" }. Please try again.`, }, ], }; } }
- src/tools/create-image.ts:21-32 (schema)Zod input schema for the tool defining 'message' and 'image' string parameters.schema = z.object({ message: z .string() .describe( "Translate into English and explain the content of the customer's image." ), image: z .string() .describe( "If the customer provides the picture editing operation of the attachment,please send it to the corresponding tool,otherwise, pass an empty string" ), });
- src/index.ts:15-15 (registration)Registers the CreateImageTool with the MCP server.new CreateImageTool().register(server);
- src/index.ts:6-6 (registration)Imports the CreateImageTool class.import { CreateImageTool } from "./tools/create-image";
- src/utils/base-tool.ts:9-16 (helper)BaseTool's register method that wires the tool name, description, schema, and execute handler to the MCP server.register(server: McpServer) { server.tool( this.name, this.description, this.schema.shape, this.execute.bind(this) ); }