Skip to main content
Glama

generate_video

Create AI-generated videos from text descriptions using Kling AI models. Specify prompts, aspect ratios, durations, and camera movements to produce custom video content.

Instructions

Generate a video from text prompt using Kling AI

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
promptYesText prompt describing the video to generate (max 2500 characters)
negative_promptNoText describing what to avoid in the video (optional, max 2500 characters)
model_nameNoModel version to use (default: kling-v2-master)
aspect_ratioNoVideo aspect ratio (default: 16:9)
durationNoVideo duration in seconds (default: 5)
modeNoVideo generation mode (default: standard)
cfg_scaleNoCreative freedom scale 0-1 (0=more creative, 1=more adherent to prompt, default: 0.5)
camera_controlNoCamera movement settings for V2 models

Implementation Reference

  • MCP CallToolRequest handler case for 'generate_video': constructs VideoGenerationRequest from tool arguments and delegates to klingClient.generateVideo()
    case 'generate_video': {
      const videoRequest: VideoGenerationRequest = {
        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') || '16:9',
        duration: (args.duration as '5' | '10') || '5',
        mode: (args.mode as 'standard' | 'professional') || 'standard',
        cfg_scale: (args.cfg_scale as number) ?? 0.5,
        camera_control: args.camera_control as any,
      };
    
      const result = await klingClient.generateVideo(videoRequest);
      
      return {
        content: [
          {
            type: 'text',
            text: `Video generation started successfully!\nTask ID: ${result.task_id}\n\nUse the check_video_status tool with this task ID to check the progress.`,
          },
        ],
      };
    }
  • Core KlingClient.generateVideo method: processes optional image URLs, builds request body with defaults, POSTs to Kling AI text2video endpoint, returns task_id
    async generateVideo(request: VideoGenerationRequest): Promise<{ task_id: string }> {
      const path = '/v1/videos/text2video';
      
      // Process any image URLs
      const ref_image_url = await this.processImageUrl(request.ref_image_url);
      
      const body: any = {
        prompt: request.prompt,
        negative_prompt: request.negative_prompt || '',
        cfg_scale: request.cfg_scale || 0.8,
        aspect_ratio: request.aspect_ratio || '16:9',
        duration: request.duration || '5',
        model_name: request.model_name || 'kling-v2-master', // V2-master is default
        ...(request.image_url && { image_url: request.image_url }),
        ...(request.image_tail_url && { image_tail_url: request.image_tail_url }),
        ...(ref_image_url && { ref_image_url }),
        ...(request.ref_image_weight && { ref_image_weight: request.ref_image_weight }),
        ...(request.camera_control && { camera_control: request.camera_control }),
        ...(request.callback_url && { callback_url: request.callback_url }),
        ...(request.external_task_id && { external_task_id: request.external_task_id }),
      };
    
      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;
      }
    }
  • Tool schema definition in TOOLS array: inputSchema for generate_video with properties, enums, descriptions matching VideoGenerationRequest
    {
      name: 'generate_video',
      description: 'Generate a video from text prompt using Kling AI',
      inputSchema: {
        type: 'object',
        properties: {
          prompt: {
            type: 'string',
            description: 'Text prompt describing the video to generate (max 2500 characters)',
          },
          negative_prompt: {
            type: 'string',
            description: 'Text describing what to avoid in the video (optional, max 2500 characters)',
          },
          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'],
            description: 'Video aspect ratio (default: 16:9)',
          },
          duration: {
            type: 'string',
            enum: ['5', '10'],
            description: 'Video duration in seconds (default: 5)',
          },
          mode: {
            type: 'string',
            enum: ['standard', 'professional'],
            description: 'Video generation mode (default: standard)',
          },
          cfg_scale: {
            type: 'number',
            description: 'Creative freedom scale 0-1 (0=more creative, 1=more adherent to prompt, default: 0.5)',
            minimum: 0,
            maximum: 1,
          },
          camera_control: {
            type: 'object',
            description: 'Camera movement settings for V2 models',
            properties: {
              type: {
                type: 'string',
                enum: ['simple', 'down_back', 'forward_up', 'right_turn_forward', 'left_turn_forward'],
                description: 'Camera movement type',
              },
              config: {
                type: 'object',
                description: 'Camera movement configuration (only for "simple" type)',
                properties: {
                  horizontal: {
                    type: 'number',
                    description: 'Horizontal movement [-10, 10]',
                    minimum: -10,
                    maximum: 10,
                  },
                  vertical: {
                    type: 'number',
                    description: 'Vertical movement [-10, 10]',
                    minimum: -10,
                    maximum: 10,
                  },
                  pan: {
                    type: 'number',
                    description: 'Pan rotation [-10, 10]',
                    minimum: -10,
                    maximum: 10,
                  },
                  tilt: {
                    type: 'number',
                    description: 'Tilt rotation [-10, 10]',
                    minimum: -10,
                    maximum: 10,
                  },
                  roll: {
                    type: 'number',
                    description: 'Roll rotation [-10, 10]',
                    minimum: -10,
                    maximum: 10,
                  },
                  zoom: {
                    type: 'number',
                    description: 'Zoom [-10, 10]',
                    minimum: -10,
                    maximum: 10,
                  },
                },
              },
            },
          },
        },
        required: ['prompt'],
      },
    },
  • src/index.ts:467-469 (registration)
    Registration of all tools list handler, exposing the generate_video tool via ListToolsRequestSchema
    server.setRequestHandler(ListToolsRequestSchema, async () => ({
      tools: TOOLS,
    }));
  • TypeScript interface VideoGenerationRequest defining typed inputs used by both tool handler and API client method.
    export interface VideoGenerationRequest {
      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';
      duration?: '5' | '10';
      mode?: 'standard' | 'professional';
      cfg_scale?: number;
      image_url?: string;
      image_tail_url?: string;
      ref_image_url?: string;
      ref_image_weight?: number;
      camera_control?: CameraControl;
      callback_url?: string;
      external_task_id?: string;
    }

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