extract_audio
Extract audio from video files into specified formats like mp3 or aac. Input the video path and desired output path to convert videos into standalone audio files.
Instructions
Extract audio from a video file
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| format | Yes | Audio format (mp3, aac, etc.) | |
| inputPath | Yes | Path to the input video file | |
| outputPath | Yes | Path for the output audio file |
Implementation Reference
- src/tools/handlers.ts:39-54 (handler)Core handler function for 'extract_audio' tool: validates inputs, ensures output directory, runs FFmpeg command to extract audio from video (-vn -acodec), and returns completion message with result.case "extract_audio": { const inputPath = validatePath(String(args?.inputPath), true); const outputPath = validatePath(String(args?.outputPath)); const format = String(args?.format || "mp3"); await ensureDirectoryExists(outputPath); const command = `-i "${inputPath}" -vn -acodec ${format} "${outputPath}" -y`; const result = await runFFmpegCommand(command); return { content: [{ type: "text", text: `Audio extraction completed: ${inputPath} → ${outputPath}\n\n${result}` }] }; }
- src/tools/definitions.ts:43-62 (schema)Tool schema definition for 'extract_audio' including name, description, and input validation schema.name: "extract_audio", description: "Extract audio from a video file", inputSchema: { type: "object", properties: { inputPath: { type: "string", description: "Path to the input video file" }, outputPath: { type: "string", description: "Path for the output audio file" }, format: { type: "string", description: "Audio format (mp3, aac, etc.)" } }, required: ["inputPath", "outputPath", "format"] }
- src/index.ts:46-50 (registration)Registers all tools (including 'extract_audio') for listing via MCP ListToolsRequest by providing the toolDefinitions array.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: toolDefinitions }; });
- src/index.ts:56-68 (registration)Registers the generic tool call handler in MCP server that dispatches to handleToolCall switch based on tool name, thus executing 'extract_audio'.server.setRequestHandler(CallToolRequestSchema, async (request) => { try { return await handleToolCall(request.params.name, request.params.arguments); } catch (error: any) { console.error("Tool execution error:", error.message); return { content: [{ type: "text", text: `Error: ${error.message}` }] }; } });