virtual_try_on
Visualize how clothing looks on a person by uploading their image and up to 5 clothing items. Use AI to combine items for complete outfit previews and experiment with virtual try-on results.
Instructions
Apply virtual clothing try-on to a person image using AI. Upload a person image and up to 5 clothing items to see how they would look wearing those clothes. Supports both single and multiple clothing combinations for complete outfit visualization.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| cloth_image_urls | Yes | Array of clothing image URLs (1-5 items). Multiple items will be combined into a complete outfit | |
| model_name | No | Model version to use (default: kolors-virtual-try-on-v1.5) | |
| person_image_url | Yes | URL of the person image to try clothes on |
Implementation Reference
- src/index.ts:680-697 (handler)MCP server handler for 'virtual_try_on' tool: parses args, calls klingClient.virtualTryOn(), returns task_id and instructions.case 'virtual_try_on': { const tryOnRequest: VirtualTryOnRequest = { person_image_url: args.person_image_url as string, cloth_image_urls: args.cloth_image_urls as string[], model_name: (args.model_name as 'kolors-virtual-try-on-v1' | 'kolors-virtual-try-on-v1.5') || 'kolors-virtual-try-on-v1.5', }; const result = await klingClient.virtualTryOn(tryOnRequest); return { content: [ { type: 'text', text: `Virtual try-on started successfully!\nTask ID: ${result.task_id}\n\nThe AI is processing your virtual try-on with ${tryOnRequest.cloth_image_urls.length} clothing item(s).\nUse the check_video_status tool with this task ID to check the progress and retrieve the try-on result video.`, }, ], }; }
- src/index.ts:385-412 (registration)Tool registration in TOOLS array: defines name, description, and inputSchema for 'virtual_try_on'.{ name: 'virtual_try_on', description: 'Apply virtual clothing try-on to a person image using AI. Upload a person image and up to 5 clothing items to see how they would look wearing those clothes. Supports both single and multiple clothing combinations for complete outfit visualization.', inputSchema: { type: 'object', properties: { person_image_url: { type: 'string', description: 'URL of the person image to try clothes on', }, cloth_image_urls: { type: 'array', items: { type: 'string', }, description: 'Array of clothing image URLs (1-5 items). Multiple items will be combined into a complete outfit', minItems: 1, maxItems: 5, }, model_name: { type: 'string', enum: ['kolors-virtual-try-on-v1', 'kolors-virtual-try-on-v1.5'], description: 'Model version to use (default: kolors-virtual-try-on-v1.5)', }, }, required: ['person_image_url', 'cloth_image_urls'], }, },
- src/kling-client.ts:90-94 (schema)TypeScript interface defining the request parameters for virtual try-on.export interface VirtualTryOnRequest { person_image_url: string; cloth_image_urls: string[]; model_name?: 'kolors-virtual-try-on-v1' | 'kolors-virtual-try-on-v1.5'; }
- src/kling-client.ts:419-451 (helper)KlingClient method implementing virtual try-on: validates inputs, processes/uploads images, POSTs to Kling AI API /v1/virtual-try-on.async virtualTryOn(request: VirtualTryOnRequest): Promise<{ task_id: string }> { const path = '/v1/virtual-try-on'; if (request.cloth_image_urls.length === 0) { throw new Error('At least one clothing image URL is required'); } if (request.cloth_image_urls.length > 5) { throw new Error('Maximum 5 clothing items allowed per request'); } // Process all image URLs const person_image_url = await this.processImageUrl(request.person_image_url); const cloth_image_urls = await Promise.all( request.cloth_image_urls.map(url => this.processImageUrl(url)) ); const body = { model_name: request.model_name || 'kolors-virtual-try-on-v1.5', person_image_url: person_image_url!, cloth_image_urls: cloth_image_urls.filter(url => url !== undefined), }; 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; } }