Skip to main content
Glama

parse_srt

Extract structured data from SRT subtitle files to enable translation while preserving timing and formatting information.

Instructions

Parse SRT file content and return structured data

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
contentYesSRT file content to parse

Implementation Reference

  • Registration of the parse_srt tool in the MCP server's listTools response, 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'], }, },
  • Handler function for the parse_srt MCP tool that invokes parseSRTFile, handles errors, and returns the parsed SRT structure as JSON.
    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), }, ], }; }
  • Input schema definition for the parse_srt tool requiring SRT content string.
    inputSchema: { type: 'object', properties: { content: { type: 'string', description: 'SRT file content to parse', }, }, required: ['content'], },
  • Core implementation of SRT parsing: splits into blocks, parses each subtitle, validates timings and styles, handles errors and metadata extraction.
    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