Skip to main content
Glama
andreasHornqvist

MCP Server Template for Cursor IDE

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
NameRequiredDescriptionDefault
promptYesThe description of the image you want to generate
sizeNoImage size (1024x1024, 1024x1792, or 1792x1024)1024x1024
qualityNoImage quality (standard or hd)standard
nNoNumber of images to generate

Implementation Reference

  • 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)}" )]
  • 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, }, }, },
  • 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, }, }, }, ),
  • 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)

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/andreasHornqvist/MCP'

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