generate_image
Create custom images from text descriptions using DALL-E 3 within Cursor IDE. Specify size, quality, and quantity to generate visual content for your projects.
Instructions
Generate an image using DALL-E 3
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | The description of the image you want to generate | |
| size | No | Image size (1024x1024, 1024x1792, or 1792x1024) | 1024x1024 |
| quality | No | Image quality (standard or hd) | standard |
| n | No | Number of images to generate |
Implementation Reference
- mcp_simple_tool/server.py:141-173 (handler)The core handler function that implements the generate_image tool logic using OpenAI DALL-E 3 API to generate and return an image URL.async def generate_image( prompt: str, size: str = "1024x1024", quality: str = "standard", n: int = 1, ) -> list[types.TextContent | types.ImageContent | types.EmbeddedResource]: """Generate an image using DALL-E 3.""" try: api_key = os.getenv("OPENAI_API_KEY") if not api_key: return [types.TextContent( type="text", text="Error: OPENAI_API_KEY environment variable is not set" )] client = OpenAI(api_key=api_key) response = client.images.generate( model="dall-e-3", prompt=prompt, size=size, quality=quality, n=n, ) return [types.TextContent( type="text", text=response.data[0].url )] except Exception as e: return [types.TextContent( type="text", text=f"Error: Failed to generate image: {str(e)}" )]
- mcp_simple_tool/server.py:279-307 (schema)The input schema definition for the generate_image tool, specifying parameters like prompt, size, quality, and n.inputSchema={ "type": "object", "required": ["prompt"], "properties": { "prompt": { "type": "string", "description": "The description of the image you want to generate", }, "size": { "type": "string", "description": "Image size (1024x1024, 1024x1792, or 1792x1024)", "default": "1024x1024", "enum": ["1024x1024", "1024x1792", "1792x1024"], }, "quality": { "type": "string", "description": "Image quality (standard or hd)", "default": "standard", "enum": ["standard", "hd"], }, "n": { "type": "integer", "description": "Number of images to generate", "default": 1, "minimum": 1, "maximum": 1, }, }, },
- mcp_simple_tool/server.py:276-308 (registration)The tool registration in list_tools(), defining name, description, and schema for generate_image.types.Tool( name="generate_image", description="Generate an image using DALL-E 3", inputSchema={ "type": "object", "required": ["prompt"], "properties": { "prompt": { "type": "string", "description": "The description of the image you want to generate", }, "size": { "type": "string", "description": "Image size (1024x1024, 1024x1792, or 1792x1024)", "default": "1024x1024", "enum": ["1024x1024", "1024x1792", "1792x1024"], }, "quality": { "type": "string", "description": "Image quality (standard or hd)", "default": "standard", "enum": ["standard", "hd"], }, "n": { "type": "integer", "description": "Number of images to generate", "default": 1, "minimum": 1, "maximum": 1, }, }, }, ),
- mcp_simple_tool/server.py:222-231 (registration)Dispatch logic in the call_tool handler that validates arguments and invokes the generate_image handler.elif name == "generate_image": if "prompt" not in arguments: return [types.TextContent( type="text", text="Error: Missing required argument 'prompt'" )] size = arguments.get("size", "1024x1024") quality = arguments.get("quality", "standard") n = arguments.get("n", 1) return await generate_image(arguments["prompt"], size, quality, n)