Skip to main content
Glama

get-key-moments

Extract timestamped key moments from video transcripts to quickly navigate and summarize important segments. Analyze YouTube videos by providing the video ID and optional max moments count for structured output.

Instructions

Extract key moments with timestamps from a video transcript for easier navigation and summarization. This tool analyzes the video transcript to identify important segments based on content density and creates a structured output with timestamped key moments. Useful for quickly navigating to important parts of longer videos. Parameters: videoId (required) - The YouTube video ID; maxMoments (optional) - Number of key moments to extract (default: 5, max: 10). Returns a formatted text with key moments and their timestamps, plus the full transcript.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
maxMomentsNo
videoIdYes

Implementation Reference

  • src/index.ts:727-757 (registration)
    Registers the MCP tool 'get-key-moments' with description, input schema using Zod, and handler function that parses parameters and calls YouTubeService.getKeyMomentsTranscript to execute the tool logic.
    server.tool(
      'get-key-moments',
      'Extract key moments with timestamps from a video transcript for easier navigation and summarization. This tool analyzes the video transcript to identify important segments based on content density and creates a structured output with timestamped key moments. Useful for quickly navigating to important parts of longer videos. Parameters: videoId (required) - The YouTube video ID; maxMoments (optional) - Number of key moments to extract (default: 5, max: 10). Returns a formatted text with key moments and their timestamps, plus the full transcript.',
      {
        videoId: z.string().min(1),
        maxMoments: z.string().optional()
      },
      async ({ videoId, maxMoments }) => {
        try {
          // 문자열 maxMoments를 숫자로 변환
          const maxMomentsNum = maxMoments ? parseInt(maxMoments, 10) : 5;
    
          const keyMomentsTranscript = await youtubeService.getKeyMomentsTranscript(videoId, maxMomentsNum);
    
          return {
            content: [{
              type: 'text',
              text: keyMomentsTranscript.text || 'No key moments found'
            }]
          };
        } catch (error) {
          return {
            content: [{
              type: 'text',
              text: `Error extracting key moments: ${error instanceof Error ? error.message : String(error)}`
            }],
            isError: true
          };
        }
      }
    );
  • Main handler implementation in YouTubeService class that fetches the video transcript and details, groups transcript into paragraphs, identifies key moments by selecting longest paragraphs, formats markdown output with timestamps for key moments followed by full transcript.
    async getKeyMomentsTranscript(
      videoId: string,
      maxMoments: number = 5
    ): Promise<FormattedTranscript> {
      try {
        // Get full transcript
        const transcriptData = await this.getTranscript(videoId);
    
        // Get video details for title and other metadata
        const videoData = await this.getVideoDetails(videoId);
        const video = videoData.items?.[0];
    
        if (!transcriptData.length) {
          throw new Error('No transcript available for this video');
        }
    
        // Convert to paragraph chunks to better identify key moments
        const paragraphs: { text: string; startTime: number; endTime: number }[] = [];
        let currentParagraph = '';
        let startTime = 0;
    
        // Group segments into logical paragraphs (simple approach: group 5-8 segments together)
        const paragraphSize = Math.max(5, Math.min(8, Math.floor(transcriptData.length / 15)));
    
        for (let i = 0; i < transcriptData.length; i++) {
          const segment = transcriptData[i];
    
          if (i % paragraphSize === 0) {
            if (currentParagraph) {
              paragraphs.push({
                text: currentParagraph.trim(),
                startTime,
                endTime: segment.offset / 1000
              });
            }
            currentParagraph = segment.text;
            startTime = segment.offset / 1000;
          } else {
            currentParagraph += ' ' + segment.text;
          }
        }
    
        // Add the last paragraph
        if (currentParagraph) {
          const lastSegment = transcriptData[transcriptData.length - 1];
          paragraphs.push({
            text: currentParagraph.trim(),
            startTime,
            endTime: (lastSegment.offset + lastSegment.duration) / 1000
          });
        }
    
        // Identify key moments (simple approach: paragraphs with the most content)
        // In a real implementation, this would use NLP to identify important moments
        const keyMoments = paragraphs
          .filter(p => p.text.length > 100) // Filter out short paragraphs
          .sort((a, b) => b.text.length - a.text.length) // Sort by length (simple heuristic)
          .slice(0, maxMoments); // Take only the top N moments
    
        // Create formatted output
        const title = video?.snippet?.title || 'Video Transcript';
        let formattedText = `# Key Moments in: ${title}\n\n`;
    
        keyMoments.forEach((moment, index) => {
          const timeFormatted = this.formatTimestamp(moment.startTime * 1000);
          formattedText += `## Key Moment ${index + 1} [${timeFormatted}]\n${moment.text}\n\n`;
        });
    
        // Add full transcript at the end
        formattedText += `\n# Full Transcript\n\n`;
        formattedText += transcriptData.map(segment =>
          `[${this.formatTimestamp(segment.offset)}] ${segment.text}`
        ).join('\n');
    
        return {
          segments: transcriptData,
          totalSegments: transcriptData.length,
          duration: (transcriptData[transcriptData.length - 1].offset +
                   transcriptData[transcriptData.length - 1].duration) / 1000,
          format: 'timestamped',
          text: formattedText,
          metadata: video ? [{
            id: video.id,
            title: video.snippet?.title,
            channelId: video.snippet?.channelId,
            channelTitle: video.snippet?.channelTitle,
            publishedAt: video.snippet?.publishedAt,
            duration: video.contentDetails?.duration,
            viewCount: video.statistics?.viewCount,
            likeCount: video.statistics?.likeCount
          }] : undefined
        };
      } catch (error) {
        console.error('Error getting key moments transcript:', error);
        throw error;
      }
    }
  • Utility function to format milliseconds into MM:SS timestamp string, used for displaying timestamps in key moments output.
    private formatTimestamp(milliseconds: number): string {
      const totalSeconds = Math.floor(milliseconds / 1000);
      const minutes = Math.floor(totalSeconds / 60);
      const seconds = totalSeconds % 60;
      return `${minutes}:${seconds.toString().padStart(2, '0')}`;
    }
  • Zod schema defining input parameters for the tool: videoId (required string) and maxMoments (optional string).
    {
      videoId: z.string().min(1),
      maxMoments: z.string().optional()
    },
Behavior3/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the tool's function (extracting key moments based on content density) and output format (structured text with timestamps and full transcript), which is helpful. However, it lacks details about potential limitations (e.g., accuracy of moment identification, processing time, or error conditions like invalid video IDs), which would be valuable for an agent to understand behavioral traits beyond basic functionality.

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 appropriately sized and front-loaded, starting with the core purpose in the first sentence. Each sentence adds value: the first defines the tool, the second explains the analysis method, and the third provides usage context and parameter details. However, the last sentence about return values could be slightly more concise, and the structure might benefit from separating parameter explanations into a distinct section.

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

Completeness4/5

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

Given the tool's moderate complexity (2 parameters, no annotations, no output schema), the description is fairly complete. It covers purpose, usage, parameters, and output format. However, without annotations or an output schema, it could improve by detailing error handling, performance characteristics, or more specifics on the 'structured output' format (e.g., JSON structure or text layout), which would help an agent invoke it correctly in edge cases.

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

Parameters4/5

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

The schema description coverage is 0%, so the description must compensate. It effectively explains both parameters: 'videoId' as the required YouTube video ID and 'maxMoments' as the optional number to extract with default (5) and maximum (10) values. This adds crucial meaning beyond the bare schema, though it doesn't specify format details for 'videoId' (e.g., length or pattern) or clarify that 'maxMoments' is a string type in the schema.

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 clearly states the tool's purpose with specific verbs ('extract', 'analyzes', 'identify', 'creates') and resources ('key moments with timestamps from a video transcript'). It distinguishes itself from sibling tools like 'get-video-transcript' (which likely retrieves raw transcript) and 'enhanced-transcript' (which might process transcript differently) by focusing on extracting structured key moments for navigation and summarization.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('for easier navigation and summarization', 'useful for quickly navigating to important parts of longer videos'). However, it doesn't explicitly state when NOT to use it or mention specific alternatives among the sibling tools, such as when a user might prefer 'get-video-transcript' for raw data or 'enhanced-transcript' for different processing.

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

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

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