Skip to main content
Glama

generate_image

Create AI-generated images from text descriptions using Kling AI models. Customize aspect ratios, exclude unwanted elements, and maintain character consistency with reference images.

Instructions

Generate images from text prompts using Kling AI. Create high-quality images with multiple aspect ratios and optional character reference support. Supports models v1, v1.5, and v2 with customizable parameters for creative control.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText prompt describing the image to generate
negative_promptNoText describing what to avoid in the image (optional)
model_nameNoModel version to use (default: kling-v2-master)
aspect_ratioNoImage aspect ratio (default: 1:1)
num_imagesNoNumber of images to generate (default: 1)
ref_image_urlNoOptional reference image URL for character consistency
ref_image_weightNoWeight of reference image influence (0-1, default: 0.5)

Implementation Reference

  • Core handler function in KlingClient that makes the API call to Kling AI's image generation endpoint, processes reference images if provided, and handles the request/response.
    async generateImage(request: ImageGenerationRequest): Promise<{ task_id: string }> {
      const path = '/v1/images/generation';
      
      // Process reference image URL if provided
      const ref_image_url = await this.processImageUrl(request.ref_image_url);
      
      const body: any = {
        prompt: request.prompt,
        negative_prompt: request.negative_prompt || '',
        aspect_ratio: request.aspect_ratio || '1:1',
        num_images: request.num_images || 1,
        ...(ref_image_url && { ref_image_url }),
        ...(request.ref_image_weight && { ref_image_weight: request.ref_image_weight }),
      };
      
      // Always add model_name
      body.model_name = request.model_name || 'kling-v2-master';
    
      try {
        const response = await this.axiosInstance.post(path, body);
        return response.data.data;
      } catch (error) {
        if (axios.isAxiosError(error)) {
          throw new Error(`Kling API error: ${error.response?.data?.message || error.message}`);
        }
        throw error;
      }
    }
  • MCP server tool handler for 'generate_image' that validates and maps input arguments to ImageGenerationRequest, invokes KlingClient.generateImage, and formats the response with task ID.
    case 'generate_image': {
      const imageRequest: ImageGenerationRequest = {
        prompt: args.prompt as string,
        negative_prompt: args.negative_prompt as string | undefined,
        model_name: (args.model_name as 'kling-v1' | 'kling-v1.5' | 'kling-v1.6' | 'kling-v2-master' | undefined) || 'kling-v2-master',
        aspect_ratio: (args.aspect_ratio as '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | '2:3' | '3:2') || '1:1',
        num_images: (args.num_images as number) || 1,
        ref_image_url: args.ref_image_url as string | undefined,
        ref_image_weight: (args.ref_image_weight as number) ?? 0.5,
      };
    
      const result = await klingClient.generateImage(imageRequest);
      
      return {
        content: [
          {
            type: 'text',
            text: `Image generation started successfully!\nTask ID: ${result.task_id}\n\nGenerating ${imageRequest.num_images} image(s) with aspect ratio ${imageRequest.aspect_ratio}.\nUse the check_image_status tool with this task ID to check the progress.`,
          },
        ],
      };
    }
  • src/index.ts:328-370 (registration)
    Tool registration in the TOOLS array, defining name, description, and detailed inputSchema for the generate_image tool.
      name: 'generate_image',
      description: 'Generate images from text prompts using Kling AI. Create high-quality images with multiple aspect ratios and optional character reference support. Supports models v1, v1.5, and v2 with customizable parameters for creative control.',
      inputSchema: {
        type: 'object',
        properties: {
          prompt: {
            type: 'string',
            description: 'Text prompt describing the image to generate',
          },
          negative_prompt: {
            type: 'string',
            description: 'Text describing what to avoid in the image (optional)',
          },
          model_name: {
            type: 'string',
            enum: ['kling-v1', 'kling-v1.5', 'kling-v1.6', 'kling-v2-master'],
            description: 'Model version to use (default: kling-v2-master)',
          },
          aspect_ratio: {
            type: 'string',
            enum: ['16:9', '9:16', '1:1', '4:3', '3:4', '2:3', '3:2'],
            description: 'Image aspect ratio (default: 1:1)',
          },
          num_images: {
            type: 'number',
            description: 'Number of images to generate (default: 1)',
            minimum: 1,
            maximum: 4,
          },
          ref_image_url: {
            type: 'string',
            description: 'Optional reference image URL for character consistency',
          },
          ref_image_weight: {
            type: 'number',
            description: 'Weight of reference image influence (0-1, default: 0.5)',
            minimum: 0,
            maximum: 1,
          },
        },
        required: ['prompt'],
      },
    },
  • TypeScript interface defining the structure of ImageGenerationRequest used by the generateImage handler.
    export interface ImageGenerationRequest {
      prompt: string;
      negative_prompt?: string;
      model_name?: 'kling-v1' | 'kling-v1.5' | 'kling-v1.6' | 'kling-v2-master';
      aspect_ratio?: '16:9' | '9:16' | '1:1' | '4:3' | '3:4' | '2:3' | '3:2';
      num_images?: number;
      ref_image_url?: string;
      ref_image_weight?: number;
    }
Behavior2/5

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

With no annotations provided, the description carries full burden for behavioral disclosure. It mentions 'high-quality images' and 'creative control' but fails to disclose critical behavioral traits such as rate limits, authentication requirements, processing time, cost implications, or what happens on failure. For a complex 7-parameter tool with no annotation coverage, this is a significant gap.

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 appropriately sized with three sentences that efficiently cover purpose, features, and capabilities. It's front-loaded with the core functionality and avoids unnecessary repetition. Every sentence adds value, though it could be slightly more structured with clearer separation of key features.

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

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a complex image generation tool with 7 parameters, no annotations, and no output schema, the description is incomplete. It doesn't explain what the tool returns (image URLs? base64? metadata?), doesn't mention error conditions, rate limits, or authentication requirements, and provides insufficient behavioral context for safe and effective use.

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 already documents all parameters thoroughly. The description adds marginal value by mentioning 'multiple aspect ratios' and 'optional character reference support' which map to aspect_ratio and ref_image_url parameters, but doesn't provide additional semantic context beyond what's in the schema. Baseline 3 is appropriate when schema does the heavy lifting.

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

Purpose5/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 with specific verbs ('generate images from text prompts') and resources ('using Kling AI'), distinguishing it from sibling tools like generate_video or generate_image_to_video. It explicitly mentions the core functionality of text-to-image generation with quality and aspect ratio options.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage for creative image generation with Kling AI, but provides no explicit guidance on when to use this tool versus alternatives like generate_image_to_video or apply_video_effect. It mentions 'creative control' as a general context but lacks specific when/when-not scenarios or comparisons to sibling tools.

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

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/199-mcp/mcp-kling'

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