Skip to main content
Glama
zxkane

Amazon Bedrock MCP Server

by zxkane

generate_image

Create custom images from text prompts using Amazon Bedrock's Nova Canvas model. Specify dimensions, quality, and optional parameters like negative prompts for precise results. Outputs Base64-encoded image data.

Instructions

Generate image(s) using Amazon Nova Canvas model. The returned data is Base64-encoded string that represent each image that was generated.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cfg_scaleNoHow closely to follow the prompt (1.1-10, default: 6.5)
heightNoHeight of the generated image (default: 1024)
negativePromptNoOptional text description of what to avoid in the image (1-1024 characters)
numberOfImagesNoNumber of images to generate (1-5, default: 1)
promptYesText description of the image to generate (1-1024 characters)
qualityNoQuality of the generated image (default: standard)
seedNoSeed for reproducible generation (0-858993459, default: 12)
widthNoWidth of the generated image (default: 1024)

Implementation Reference

  • Handler for the generate_image tool. Validates input using GenerateImageSchema, invokes AWS Bedrock Nova model via InvokeModelCommand, processes the response to extract base64 images, and returns MCP-formatted content with images.
    server.setRequestHandler(CallToolRequestSchema, async (request) => {
      if (request.params.name !== "generate_image") {
        throw new McpError(
          ErrorCode.MethodNotFound,
          `Unknown tool: ${request.params.name}`
        );
      }
    
      try {
        // Validate and parse input
        const args = GenerateImageSchema.parse(request.params.arguments);
        
        server.sendLoggingMessage({
          level: "info",
          data: `Configuration: ${JSON.stringify({
            width: args.width,
            height: args.height,
            quality: args.quality,
            numberOfImages: args.numberOfImages,
            cfgScale: args.cfg_scale,
            seed: args.seed
          })}`,
        });
    
        const progressToken = request.params._meta?.progressToken;
    
        server.sendLoggingMessage({
          level: "info",
          data: "Sending request to Bedrock API...",
        });
    
        const response = await bedrock.send(new InvokeModelCommand({
          modelId: NOVA_MODEL_ID,
          contentType: "application/json",
          accept: "application/json",
          body: JSON.stringify({
            taskType: GENERATION_TYPES.TEXT_TO_IMAGE,
            textToImageParams: {
              text: args.prompt,
              negativeText: args.negativePrompt || undefined,
            },
            imageGenerationConfig: {
              numberOfImages: args.numberOfImages,
              height: args.height,
              width: args.width,
              quality: args.quality,
              cfgScale: args.cfg_scale,
              seed: args.seed
            },
          }),
        }));
    
        server.sendLoggingMessage({
          level: "info",
          data: "Received response from Bedrock API",
        });
    
        if (!response.body) {
          server.sendLoggingMessage({
            level: "error",
            data: "No response body received from Bedrock",
          });
          throw new McpError(
            ErrorCode.InternalError,
            "No response body received from Bedrock"
          );
        }
    
        const responseBody = JSON.parse(new TextDecoder().decode(response.body)) as BedrockResponse;
    
        if (!responseBody.images || responseBody.images.length === 0) {
          server.sendLoggingMessage({
            level: "error",
            data: "No image data in response",
          });
          throw new McpError(
            ErrorCode.InternalError,
            `No image data in response due to ${responseBody.error}.`
          );
        }
    
        server.sendLoggingMessage({
          level: "info",
          data: "Successfully generated image",
        });
    
        // Return the response in the correct MCP format
        return {
          content: [
            {
              type: "text",
              text: `This is the image generated for your request '${args.prompt}'.`,
            },
            ...responseBody.images.map(image => ({
              type: "image",
              data: image as string,
              mimeType: "image/png",
            })),
            {
              type: "text",
              text: "This is the end of the image generation.",
            }
          ],
        };
      } catch (error) {
        console.error('Error:', error);
    
        // Handle Zod validation errors
        if (error instanceof z.ZodError) {
          throw new McpError(
            ErrorCode.InvalidParams,
            `Invalid parameters: ${error.errors.map(e => e.message).join(", ")}`
          );
        }
    
        // Handle AWS Bedrock errors
        if (error instanceof Error) {
          throw new McpError(
            ErrorCode.InternalError,
            `Failed to generate image: ${error.message}`
          );
        }
    
        // Handle unknown errors
        throw new McpError(
          ErrorCode.InternalError,
          "An unexpected error occurred"
        );
      }
    });
  • Zod schema for validating input parameters to the generate_image tool, including prompt, dimensions, quality, etc., with refinements for aspect ratio and pixel count.
    const GenerateImageSchema = z.object({
      prompt: z.string().min(1).max(1024, "Prompt must be 1-1024 characters"),
      negativePrompt: z.string().min(1).max(1024, "Negative prompt must be 1-1024 characters").optional(),
      width: z.number().int()
        .min(320, "Width must be at least 320 pixels")
        .max(4096, "Width must be at most 4096 pixels")
        .refine(val => val % 16 === 0, "Width must be divisible by 16")
        .default(1024),
      height: z.number().int()
        .min(320, "Height must be at least 320 pixels")
        .max(4096, "Height must be at most 4096 pixels")
        .refine(val => val % 16 === 0, "Height must be divisible by 16")
        .default(1024),
      quality: z.enum(["standard", "premium"]).default("standard"),
      cfg_scale: z.number().min(1.1).max(10).default(6.5),
      seed: z.number().int().min(0).max(858993459).default(12),
      numberOfImages: z.number().int().min(1).max(5).default(1)
    }).refine(
      (data) => {
        // Check aspect ratio between 1:4 and 4:1
        const ratio = data.width / data.height;
        return ratio >= 0.25 && ratio <= 4;
      },
      "Aspect ratio must be between 1:4 and 4:1"
    ).refine(
      (data) => {
        // Check total pixel count
        return data.width * data.height < 4194304;
      },
      "Total pixel count must be less than 4,194,304"
    );
    
    type GenerateImageInput = z.infer<typeof GenerateImageSchema>;
  • src/index.ts:124-172 (registration)
    Registration of the generate_image tool in the ListToolsRequestSchema handler, providing name, description, and JSON input schema.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          {
            name: "generate_image",
            description: "Generate image(s) using Amazon Nova Canvas model. The returned data is Base64-encoded string that represent each image that was generated.",
            inputSchema: {
              type: "object",
              properties: {
                prompt: {
                  type: "string",
                  description: "Text description of the image to generate (1-1024 characters)",
                },
                negativePrompt: {
                  type: "string",
                  description: "Optional text description of what to avoid in the image (1-1024 characters)",
                },
                width: {
                  type: "number",
                  description: "Width of the generated image (default: 1024)",
                },
                height: {
                  type: "number",
                  description: "Height of the generated image (default: 1024)",
                },
                quality: {
                  type: "string",
                  enum: ["standard", "premium"],
                  description: "Quality of the generated image (default: standard)",
                },
                cfg_scale: {
                  type: "number",
                  description: "How closely to follow the prompt (1.1-10, default: 6.5)",
                },
                seed: {
                  type: "number",
                  description: "Seed for reproducible generation (0-858993459, default: 12)",
                },
                numberOfImages: {
                  type: "number",
                  description: "Number of images to generate (1-5, default: 1)",
                },
              },
              required: ["prompt"],
            },
          },
        ],
      };
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the return format (Base64-encoded string) but lacks critical details such as rate limits, authentication requirements, error handling, or whether this is a read/write operation. For a complex image generation tool, this is insufficient.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is concise and front-loaded, consisting of two clear sentences. However, it could be slightly more efficient by combining ideas, but it avoids unnecessary verbosity.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/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 8 parameters and no output schema or annotations, the description is incomplete. It covers the basic purpose and return format but misses behavioral context, usage guidelines, and output details, leaving significant gaps for an AI agent.

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?

Schema description coverage is 100%, so the schema fully documents all 8 parameters. The description adds no parameter-specific information beyond what's in the schema, resulting in a baseline score of 3.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: 'Generate image(s) using Amazon Nova Canvas model.' It specifies the verb ('generate') and resource ('image(s)'), and identifies the specific model. However, without sibling tools, we cannot assess differentiation, so it cannot achieve a perfect 5.

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?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or typical use cases. It simply states what the tool does without context for selection.

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

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/zxkane/mcp-server-amazon-bedrock'

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