Skip to main content
Glama

getTranscripts

Read-onlyIdempotent

Retrieve key segments or full text of YouTube video transcripts to analyze messaging.

Instructions

Retrieves specific, meaningful segments of a video's transcript. By default, it returns the intro 'hook' and the final 'outro' or call to action. It can also return the full transcript text. Use this to efficiently analyze a video's key messaging.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
videoIdsYesArray of YouTube video IDs to get transcripts for
langNoLanguage code for transcripts (e.g., 'en', 'ko', 'es'). Defaults to environment setting or 'en'en
formatNoThe desired transcript format. 'full_text': Returns the entire transcript as a single string. 'key_segments': (Default) Returns only the video's intro hook and final call to action.key_segments

Implementation Reference

  • The GetTranscriptsTool class - the handler that executes the 'getTranscripts' tool logic. It maps over videoIds, calls transcriptService.getTranscriptSegments for each, then formats results via formatVideoMap.
    export class GetTranscriptsTool extends BaseTool<typeof getTranscriptsSchema> {
      name = "getTranscripts";
      description =
        "Retrieves specific, meaningful segments of a video's transcript. By default, it returns the intro 'hook' and the final 'outro' or call to action. It can also return the full transcript text. Use this to efficiently analyze a video's key messaging.";
      schema = getTranscriptsSchema;
    
      protected async executeImpl(
        params: z.infer<typeof getTranscriptsSchema>
      ): Promise<CallToolResult> {
        const { videoIds, lang, format } = params;
    
        const transcriptPromises = videoIds.map((videoId) =>
          this.container.transcriptService.getTranscriptSegments(
            videoId,
            lang,
            format
          )
        );
        const transcripts = await Promise.all(transcriptPromises);
        const result = formatVideoMap(videoIds, transcripts);
    
        return formatSuccess(result);
      }
    }
  • The Zod schema for getTranscripts: accepts videoIds (array of video IDs), lang (default 'en'), and format ('full_text' or 'key_segments', default 'key_segments').
    export const getTranscriptsSchema = z.object({
      videoIds: z
        .array(videoIdSchema)
        .describe("Array of YouTube video IDs to get transcripts for"),
      lang: languageSchema
        .default("en")
        .describe(
          "Language code for transcripts (e.g., 'en', 'ko', 'es'). Defaults to environment setting or 'en'"
        ),
      format: z
        .enum(["full_text", "key_segments"])
        .default("key_segments")
        .describe(
          "The desired transcript format. " +
            "'full_text': Returns the entire transcript as a single string. " +
            "'key_segments': (Default) Returns only the video's intro hook and final call to action."
        ),
    });
  • GetTranscriptsTool is imported and included in TOOL_CLASSES array (line 31) and also conditionally registered as a standalone tool when no YouTube API key is present (line 53). The actual MCP registration via server.registerTool happens in the loop (lines 65-87).
    import { GetTranscriptsTool } from "./video/getTranscripts.js";
    import { GetVideoCommentsTool } from "./video/getVideoComments.js";
    import { GetChannelStatisticsTool } from "./channel/getChannelStatistics.js";
    import { GetChannelTopVideosTool } from "./channel/getChannelTopVideos.js";
    import { GetTrendingVideosTool } from "./general/getTrendingVideos.js";
    import { GetVideoCategoriesTool } from "./general/getVideoCategories.js";
    import { FindConsistentOutlierChannelsTool } from "./general/findConsistentOutlierChannels.js";
    
    interface ITool {
      readonly name: string;
      readonly description: string;
      readonly schema: z.ZodObject<z.ZodRawShape>;
      execute(args: z.infer<this["schema"]>): Promise<CallToolResult>;
    }
    
    type ToolConstructor = new (container: IServiceContainer) => ITool;
    
    // 1. Maintain a list of Constructors
    const TOOL_CLASSES = [
      GetVideoDetailsTool,
      SearchVideosTool,
      GetTranscriptsTool,
      GetVideoCommentsTool,
      GetChannelStatisticsTool,
      GetChannelTopVideosTool,
      GetTrendingVideosTool,
      GetVideoCategoriesTool,
    ];
    
    export function registerTools(server: McpServer, container: IServiceContainer) {
      const hasYoutubeKey = !!process.env.YOUTUBE_API_KEY;
      const toolsToRegister: ToolConstructor[] = [];
    
      if (hasYoutubeKey) {
        // Register all standard YouTube tools
        toolsToRegister.push(...(TOOL_CLASSES as ToolConstructor[]));
    
        // Register analytics tools if connection string is present
        if (process.env.MDB_MCP_CONNECTION_STRING) {
          toolsToRegister.push(FindConsistentOutlierChannelsTool);
        }
      } else {
        // Only register tools that don't require the API key
        toolsToRegister.push(GetTranscriptsTool);
      }
  • TranscriptService.getTranscriptSegments - the core helper service that fetches and processes transcript data. Fetches via youtube-transcript-plus, caches results, and returns either full_text (joined string) or key_segments (extracted hook and outro).
      public async getTranscriptSegments(
        videoId: string,
        lang: string = "en",
        format: "full_text" | "key_segments" = "key_segments"
      ): Promise<object | null> {
        const rawSubtitles = await this.fetchAndCacheRawTranscript(videoId, lang);
    
        if (!rawSubtitles || rawSubtitles.length === 0) {
          return null;
        }
    
        if (format === "full_text") {
          return {
            transcript: rawSubtitles.map((sub) => sub.text).join(" "),
          };
        }
    
        const hook = this.extractHook(rawSubtitles);
        const outro = this.extractOutro(rawSubtitles);
        return { hook, outro };
      }
    
      private async fetchAndCacheRawTranscript(
        videoId: string,
        lang: string = "en"
      ): Promise<Subtitle[]> {
        const cacheKey = this.cacheService.createOperationKey("getTranscript", {
          videoId,
          lang,
        });
    
        const operation = async (): Promise<Subtitle[]> => {
          try {
            const transcript = (await fetchTranscript(videoId, {
              lang,
            })) as TranscriptResult[];
    
            // Map youtube-transcript-plus format to the Subtitle shape used internally
            return transcript.map(
              (item: { offset: number; duration: number; text: string }) => ({
                start: String(item.offset),
                dur: String(item.duration),
                text: item.text,
              })
            );
          } catch (error) {
            console.error(
              `[TranscriptService] Failed to fetch transcript for ${videoId} (lang: ${lang}):`,
              error instanceof Error ? error.message : error
            );
            return [];
          }
        };
    
        return this.cacheService.getOrSet<Subtitle[]>(
          cacheKey,
          operation,
          CACHE_TTLS.STATIC,
          CACHE_COLLECTIONS.TRANSCRIPTS,
          { videoId, lang }
        );
      }
    
      private extractHook(subtitles: Subtitle[]): string {
        const HOOK_DURATION_SECONDS = 40;
        let hookText = "";
        for (const sub of subtitles) {
          const startTime = parseFloat(sub.start);
          if (startTime < HOOK_DURATION_SECONDS) {
            hookText += sub.text + " ";
          } else {
            break;
          }
        }
        return hookText.trim();
      }
    
      private extractOutro(subtitles: Subtitle[]): string {
        if (subtitles.length === 0) return "";
    
        const OUTRO_DURATION_SECONDS = 30;
        const lastTimestamp = parseFloat(subtitles[subtitles.length - 1].start);
        const outroStartTime = Math.max(0, lastTimestamp - OUTRO_DURATION_SECONDS);
    
        const startIndex = subtitles.findIndex(
          (sub) => parseFloat(sub.start) >= outroStartTime
        );
    
        if (startIndex === -1) {
          return subtitles
            .map((s) => s.text)
            .join(" ")
            .trim();
        }
    
        return subtitles
          .slice(startIndex)
          .map((s) => s.text)
          .join(" ")
          .trim();
      }
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

Annotations already declare readOnlyHint and idempotentHint. The description adds behavior about default segments and full text option, but fails to mention prerequisites (e.g., captions must exist) or limitations.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness4/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is four sentences, packing essential information concisely with no waste. It could be slightly tighter but is well-structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness3/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

With no output schema, the description should clarify the return format (e.g., string vs array) and structure. It only mentions what is returned but not how it is presented, leaving some ambiguity.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100% and includes clear parameter details. The description adds minimal value beyond repeating the format options with slightly different wording (e.g., 'hook', 'outro').

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description uses the specific verb 'retrieves' and clearly identifies the resource as 'transcript' with detail on what segments are returned (intro hook, outro). It also implicitly distinguishes from siblings by being the only transcript tool.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

It states when to use ('to efficiently analyze a video's key messaging') but does not explicitly mention when not to use or provide alternatives. Since siblings are all different, no direct comparison is made.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/kirbah/mcp-youtube'

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