wanx-t2v-video-generation
Generate videos from text prompts using Alibaba Cloud's Tongyi Wanxiang API. Initiate the process and use the result-fetching tool to retrieve the output once complete.
Instructions
使用阿里云万相文生视频大模型的文生视频能力,由于视频生成耗时比较久,需要调用 wanx-t2v-video-generation-result 工具获取结果
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes |
Implementation Reference
- src/index.ts:52-62 (registration)Registers the MCP tool 'wanx-t2v-video-generation' with description, input schema {prompt: z.string()}, and handler that calls generateVideo and returns task info.server.tool( "wanx-t2v-video-generation", "使用阿里云万相文生视频大模型的文生视频能力,由于视频生成耗时比较久,需要调用 wanx-t2v-video-generation-result 工具获取结果", { prompt: z.string() }, async ({ prompt }) => { const result = await generateVideo(prompt); return { content: [{ type: "text", text: JSON.stringify(result) }], }; } );
- src/index.ts:55-55 (schema)Input schema using Zod for the tool parameters.{ prompt: z.string() },
- src/wanx-t2v.ts:9-37 (handler)Core handler function 'generateVideo' that makes async API call to Aliyun Dashscope to initiate video generation task and returns the task_id.export async function generateVideo(prompt: string) { const apiKey = config.api.apiKey; const url = 'https://dashscope.aliyuncs.com/api/v1/services/aigc/video-generation/video-synthesis'; const headers = { 'X-DashScope-Async': 'enable', 'Authorization': `Bearer ${apiKey}`, 'Content-Type': 'application/json' }; const payload = { model: 'wanx2.1-t2v-turbo', input: { prompt }, parameters: { size: '832*480', duration: 5, prompt_extend: true, }, }; try { const res = await axios.post(url, payload, { headers }); const taskId = res.data?.output?.task_id; if (taskId) return taskId; // 如果响应里没有task_id,说明有错误 throw res.data; } catch (err: any) { // err.response?.data 可能含详细错误 throw err.response?.data || err.message; } }