generate_video
Create AI-generated videos from text prompts using Kling AI. Specify aspect ratio, duration, creative freedom, and camera controls for precise video customization.
Instructions
Generate a video from text prompt using Kling AI
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| aspect_ratio | No | Video aspect ratio (default: 16:9) | |
| camera_control | No | Camera movement settings for V2 models | |
| cfg_scale | No | Creative freedom scale 0-1 (0=more creative, 1=more adherent to prompt, default: 0.5) | |
| duration | No | Video duration in seconds (default: 5) | |
| mode | No | Video generation mode (default: standard) | |
| model_name | No | Model version to use (default: kling-v2-master) | |
| negative_prompt | No | Text describing what to avoid in the video (optional, max 2500 characters) | |
| prompt | Yes | Text prompt describing the video to generate (max 2500 characters) |
Implementation Reference
- src/kling-client.ts:171-202 (handler)Core implementation of generateVideo: processes request parameters (including optional image uploads via processImageUrl), constructs API payload, and performs POST to Kling AI /v1/videos/text2video endpoint returning 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; } }
- src/index.ts:480-502 (handler)MCP CallToolRequest handler dispatch for 'generate_video': maps tool arguments to VideoGenerationRequest type, calls KlingClient.generateVideo, formats success response with task_id and instructions.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.`, }, ], }; }
- src/kling-client.ts:23-38 (schema)TypeScript interface defining the input parameters for video generation, used by both the MCP handler and Kling API client.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; }
- src/index.ts:66-162 (registration)Tool registration in TOOLS array: defines name, description, and detailed inputSchema for generate_video, returned by ListToolsRequestHandler.{ 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'], }, },