Probe Media File
media_probeInspect video, audio, or image files to retrieve technical metadata using ffprobe, enabling informed decisions for further processing in the video automation pipeline.
Instructions
Use ffprobe to inspect a video/audio/image file under VIDEO_FACTORY_ROOT.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| inputPath | Yes |
Implementation Reference
- src/tools/media.ts:6-25 (registration)Registration of the 'media_probe' tool via server.registerTool(), called from src/index.ts line 21.
export function registerMediaTools(server: McpServer) { server.registerTool( 'media_probe', { title: 'Probe Media File', description: 'Use ffprobe to inspect a video/audio/image file under VIDEO_FACTORY_ROOT.', inputSchema: z.object({ inputPath: z.string() }) }, async ({ inputPath }) => { try { const input = safePath(inputPath); const args = ['-v', 'error', '-show_format', '-show_streams', '-of', 'json', input]; const result = await runCommand(config.ffprobeBin, args); if (result.code !== 0) return errorResult('ffprobe failed', result.stderr); return textResult(JSON.parse(result.stdout)); } catch (err) { return errorResult('Failed to probe media', String(err)); } } ); - src/tools/media.ts:14-24 (handler)Handler function that uses ffprobe to inspect a media file under VIDEO_FACTORY_ROOT. Runs ffprobe with -show_format and -show_streams flags, parses JSON output, and returns results or errors.
async ({ inputPath }) => { try { const input = safePath(inputPath); const args = ['-v', 'error', '-show_format', '-show_streams', '-of', 'json', input]; const result = await runCommand(config.ffprobeBin, args); if (result.code !== 0) return errorResult('ffprobe failed', result.stderr); return textResult(JSON.parse(result.stdout)); } catch (err) { return errorResult('Failed to probe media', String(err)); } } - src/tools/media.ts:9-13 (schema)Input schema for media_probe: requires a single string inputPath (path relative to VIDEO_FACTORY_ROOT).
{ title: 'Probe Media File', description: 'Use ffprobe to inspect a video/audio/image file under VIDEO_FACTORY_ROOT.', inputSchema: z.object({ inputPath: z.string() }) }, - src/config.ts:28-35 (helper)safePath helper used by the handler to resolve and validate the input path stays within VIDEO_FACTORY_ROOT.
export function safePath(input: string) { ensureRoot(); const resolved = path.resolve(config.root, input); if (!resolved.startsWith(config.root)) { throw new Error(`Path escapes VIDEO_FACTORY_ROOT: ${input}`); } return resolved; } - src/utils.ts:15-24 (helper)runCommand helper used by the handler to execute ffprobe as a subprocess.
export function runCommand(command: string, args: string[], cwd?: string): Promise<{ code: number; stdout: string; stderr: string }> { return new Promise((resolve) => { const child = spawn(command, args, { cwd, shell: false }); let stdout = ''; let stderr = ''; child.stdout.on('data', (d) => (stdout += d.toString())); child.stderr.on('data', (d) => (stderr += d.toString())); child.on('close', (code) => resolve({ code: code ?? -1, stdout, stderr })); }); }