wanx-t2v-video-generation-result
Retrieve text-to-video generation results using Alibaba Cloud's Tongyi Wanxiang API by providing a task ID for tracking and accessing the output.
Instructions
获取阿里云万相文生视频大模型的文生视频结果
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| task_id | Yes |
Implementation Reference
- src/index.ts:64-74 (registration)Registration of the 'wanx-t2v-video-generation-result' MCP tool, including description, input schema {task_id: string}, and a thin handler that calls the queryVideoTaskStatus helper.server.tool( "wanx-t2v-video-generation-result", "获取阿里云万相文生视频大模型的文生视频结果", { task_id: z.string() }, async ({ task_id }) => { const result = await queryVideoTaskStatus(task_id); return { content: [{ type: "text", text: JSON.stringify(result) }], }; } );
- src/index.ts:68-73 (handler)The handler function passed to server.tool, which executes the tool logic by querying the task status and returning the result in MCP format.async ({ task_id }) => { const result = await queryVideoTaskStatus(task_id); return { content: [{ type: "text", text: JSON.stringify(result) }], }; }
- src/index.ts:67-67 (schema)Zod input schema validating the task_id parameter.{ task_id: z.string() },
- src/wanx-t2v.ts:45-80 (helper)Core helper function that polls the DashScope API for video task status until 'SUCCEEDED', then returns the video_url, or throws on failure/timeout.export async function queryVideoTaskStatus(taskId: string) { const apiKey = config.api.apiKey; const url = `https://dashscope.aliyuncs.com/api/v1/tasks/${taskId}`; const headers = { 'Authorization': `Bearer ${apiKey}` }; let videoUrl = null; let retries = 0; const maxRetries = config.maxRetries; // 从配置文件中获取最大重试次数 const pollingInterval = config.pollingInterval; // 从配置文件中获取轮询间隔 while (retries < maxRetries) { try { const res = await axios.get(url, { headers }); // res.data.output.task_status 可能为 INITIAL, RUNNING, SUCCEEDED, FAILED, CANCELLED // res.data.output.video_url 只有在 SUCCEEDED 时有值 if (res.data.output.task_status === 'SUCCEEDED') { videoUrl = res.data.output.video_url; break; // 如果状态为 SUCCEEDED,则跳出循环 } else if (res.data.output.task_status === 'FAILED' || res.data.output.task_status === 'CANCELLED') { throw res.data.output.task_status; // 如果状态为 FAILED 或 CANCELLED,则抛出错误 } // 如果状态不是 SUCCEEDED,则等待一段时间后继续轮询 await new Promise(resolve => setTimeout(resolve, pollingInterval)); retries++; } catch (err: any) { throw err.response?.data || err.message; } } if (!videoUrl) { throw new Error('视频生成任务超时或失败'); } return videoUrl; }