video_generate
Create short videos from text prompts using AI video generation for content creation and visual storytelling.
Instructions
Generate a short video from a prompt using Kling AI ($0.05)
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| prompt | Yes | ||
| duration | No |
Implementation Reference
- index.js:23-23 (registration)The 'video_generate' tool is defined in the TOOLS array, specifying its input schema and associated API endpoint.
{ name: 'video_generate', description: 'Generate a short video from a prompt using Kling AI', inputSchema: { type: 'object', properties: { prompt: { type: 'string' }, duration: { type: 'number', default: 5 } }, required: ['prompt'] }, endpoint: '/video/generate', price: '$0.05' }, - index.js:94-115 (handler)The tool handler dispatches the call to the generic `callTool` function, which performs an HTTP request to the configured endpoint.
server.setRequestHandler(CallToolRequestSchema, async (request) => { const { name, arguments: args } = request.params; if (!API_KEY) { return { content: [{ type: 'text', text: 'Error: ITERATOOLS_API_KEY environment variable not set. Get a key at https://iteratools.com' }], isError: true, }; } const tool = TOOLS.find(t => t.name === name); if (!tool) { return { content: [{ type: 'text', text: `Unknown tool: ${name}` }], isError: true }; } try { const result = await callTool(tool.endpoint, args); return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; } catch (err) { return { content: [{ type: 'text', text: `Error: ${err.message}` }], isError: true }; } }); - index.js:50-79 (helper)The `callTool` helper function executes the API request for any tool by calling the specified endpoint with the provided parameters.
async function callTool(endpoint, params) { const fetch = (await import('node-fetch')).default; const isGet = ['GET'].includes((TOOLS.find(t => t.endpoint === endpoint) || {}).method); const url = isGet ? `${BASE_URL}${endpoint}?${new URLSearchParams(params)}` : `${BASE_URL}${endpoint}`; const res = await fetch(url, { method: isGet ? 'GET' : 'POST', headers: { 'Content-Type': 'application/json', 'Authorization': `Bearer ${API_KEY}`, }, body: isGet ? undefined : JSON.stringify(params), }); const text = await res.text(); let data; try { data = JSON.parse(text); } catch { data = { raw: text }; } if (!res.ok) { if (res.status === 402) { throw new Error(`Insufficient credits. Add credits at https://iteratools.com. Cost: ${TOOLS.find(t=>t.endpoint===endpoint)?.price || 'see docs'}`); } throw new Error(`API error ${res.status}: ${text.substring(0, 200)}`); } return data; }