Skip to main content
Glama

parse_srt

Extract structured data from SRT subtitle files to process timing, text content, and subtitle sequences for translation workflows.

Instructions

Parse SRT file content and return structured data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesSRT file content to parse

Implementation Reference

  • The main handler function for the 'parse_srt' MCP tool. It extracts SRT content from input, calls parseSRTFile utility, validates success, and returns the structured SRT file data as JSON text content.
    private async handleParseSRT(args: any) { const { content } = args; const parseResult = parseSRTFile(content); if (!parseResult.success || !parseResult.file) { const errorDetails = parseResult.errors?.map(e => `${e.type}: ${e.message}`).join(', ') || 'Unknown parsing error'; throw new Error(`Failed to parse SRT file: ${errorDetails}`); } return { content: [ { type: 'text', text: JSON.stringify(parseResult.file, null, 2), }, ], }; }
  • Registration of the 'parse_srt' tool in the MCP server's ListToolsRequestSchema handler, including name, description, and input schema.
    name: 'parse_srt', description: 'Parse SRT file content and return structured data', inputSchema: { type: 'object', properties: { content: { type: 'string', description: 'SRT file content to parse', }, }, required: ['content'], },
  • Input schema definition for the 'parse_srt' tool requiring a 'content' string parameter.
    inputSchema: { type: 'object', properties: { content: { type: 'string', description: 'SRT file content to parse', }, }, required: ['content'], },
  • The core helper function 'parseSRTFile' that implements SRT parsing logic, called by the MCP tool handler. Handles block parsing, validation, error collection, and returns SRTProcessingResult.
    export function parseSRTFile(content: string): SRTProcessingResult { const errors: SRTValidationError[] = []; const warnings: string[] = []; const subtitles: SRTSubtitle[] = []; try { const blocks = content.trim().split(/\n\s*\n/); let lineNumber = 1; for (const block of blocks) { if (!block.trim()) continue; const lines = block.split('\n'); const subtitle = parseSubtitleBlock(lines, lineNumber); if (subtitle) { subtitles.push(subtitle); } else { errors.push({ line: lineNumber, message: 'Failed to parse subtitle block', type: 'format' }); } lineNumber += lines.length + 1; // +1 for empty line separator } // Validate timing sequences validateTimingSequences(subtitles, errors); // Validate style tags validateAllStyleTags(subtitles, errors, warnings); return { success: errors.length === 0, file: { subtitles, metadata: extractMetadata(content) }, errors: errors.length > 0 ? errors : undefined, warnings: warnings.length > 0 ? warnings : undefined }; } catch (error) { return { success: false, errors: [{ line: 1, message: `Parse error: ${error instanceof Error ? error.message : 'Unknown error'}`, type: 'format' }] }; } }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/omd0/srt-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server