Skip to main content
Glama
williamvd4
by williamvd4

get_transcript

Extract YouTube video transcripts by providing a URL or video ID with optional language support. Ideal for accessing and analyzing video content in specific languages.

Instructions

Extract transcript from a YouTube video URL or ID

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
langYesLanguage code for transcript (e.g., 'ko', 'en')en
urlYesYouTube video URL or ID

Implementation Reference

  • Main execution handler for the 'get_transcript' tool within the MCP call tool request handler. Handles argument validation, video ID extraction, transcript retrieval, error handling, and formats the MCP-compliant tool result.
    case "get_transcript": { const { url: input, lang = "en" } = args; if (!input || typeof input !== 'string') { throw new McpError( ErrorCode.InvalidParams, 'URL parameter is required and must be a string' ); } if (lang && typeof lang !== 'string') { throw new McpError( ErrorCode.InvalidParams, 'Language code must be a string' ); } try { const videoId = this.extractor.extractYoutubeId(input); console.error(`Processing transcript for video: ${videoId}`); const transcript = await this.extractor.getTranscript(videoId, lang); console.error(`Successfully extracted transcript (${transcript.length} chars)`); return { toolResult: { content: [{ type: "text", text: transcript, metadata: { videoId, language: lang, timestamp: new Date().toISOString(), charCount: transcript.length } }], isError: false } }; } catch (error) { console.error('Transcript extraction failed:', error); if (error instanceof McpError) { throw error; } throw new McpError( ErrorCode.InternalError, `Failed to process transcript: ${(error as Error).message}` ); } }
  • Tool schema definition for 'get_transcript', including name, description, and input schema specifying 'url' and 'lang' parameters.
    { name: "get_transcript", description: "Extract transcript from a YouTube video URL or ID", inputSchema: { type: "object", properties: { url: { type: "string", description: "YouTube video URL or ID" }, lang: { type: "string", description: "Language code for transcript (e.g., 'ko', 'en')", default: "en" } }, required: ["url", "lang"] } }
  • src/index.ts:153-163 (registration)
    Registers the MCP request handlers for listing tools (exposes get_transcript schema) and calling tools (dispatches to handleToolCall based on name).
    private setupHandlers(): void { // List available tools this.server.setRequestHandler(ListToolsRequestSchema, async () => ({ tools: TOOLS })); // Handle tool calls this.server.setRequestHandler(CallToolRequestSchema, async (request) => this.handleToolCall(request.params.name, request.params.arguments ?? {}) ); }
  • Core helper function in YouTubeTranscriptExtractor that fetches subtitles using 'youtube-captions-scraper' library and formats them into a single string.
    async getTranscript(videoId: string, lang: string): Promise<string> { try { const transcript = await getSubtitles({ videoID: videoId, lang: lang, }); return this.formatTranscript(transcript); } catch (error) { console.error('Failed to fetch transcript:', error); throw new McpError( ErrorCode.InternalError, `Failed to retrieve transcript: ${(error as Error).message}` ); } }
  • Helper function to parse YouTube video ID from various URL formats or direct ID input, with validation.
    extractYoutubeId(input: string): string { if (!input) { throw new McpError( ErrorCode.InvalidParams, 'YouTube URL or ID is required' ); } // Handle URL formats try { const url = new URL(input); if (url.hostname === 'youtu.be') { return url.pathname.slice(1); } else if (url.hostname.includes('youtube.com')) { const videoId = url.searchParams.get('v'); if (!videoId) { throw new McpError( ErrorCode.InvalidParams, `Invalid YouTube URL: ${input}` ); } return videoId; } } catch (error) { // Not a URL, check if it's a direct video ID if (!/^[a-zA-Z0-9_-]{11}$/.test(input)) { throw new McpError( ErrorCode.InvalidParams, `Invalid YouTube video ID: ${input}` ); } return input; } throw new McpError( ErrorCode.InvalidParams, `Could not extract video ID from: ${input}` ); }

Other Tools

Related Tools

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/williamvd4/mcp-server-youtube-transcript'

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