Skip to main content
Glama
jikime

YouTube Toolbox

get_video_comments

Retrieve and analyze YouTube video comments to understand audience feedback and engagement. Specify video ID, result limits, sorting order, and reply inclusion for targeted insights.

Instructions

Get comments for a YouTube video

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
video_idYes
max_resultsNo
orderNorelevance
include_repliesNo
page_tokenNo

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

Implementation Reference

  • Primary MCP tool handler for get_video_comments. Processes parameters, calls YouTubeService.get_video_comments, formats top-level comments and optional replies into structured JSON response with pagination info.
    @mcp.tool(
        name="get_video_comments",
        description="Get comments for a YouTube video",
    )
    async def get_video_comments(
        video_id: str, 
        max_results: Optional[int] = 20, 
        order: Optional[str] = "relevance", 
        include_replies: bool = False,
        page_token: Optional[str] = None
    ) -> Dict[str, Any]:
        """
        Get comments for a YouTube video
        
        Args:
            video_id (str): YouTube video ID
            max_results (int): Maximum number of comments to return (default: 20)
            order (str): Order by 'relevance' (default) or 'time'
            include_replies (bool): Whether to include replies to comments
            page_token (str, optional): Token for paginated results
        
        Returns:
            Dict[str, Any]: Comments data
        """
        try:
            options = {
                'order': order,
                'includeReplies': include_replies,
            }
            
            if page_token:
                options['pageToken'] = page_token
                
            comments_data = youtube_service.get_video_comments(video_id, max_results, **options)
            
            # Format the response
            formatted_comments = []
            for item in comments_data.get('items', []):
                comment = item.get('snippet', {}).get('topLevelComment', {}).get('snippet', {})
                
                formatted_comment = {
                    'id': item.get('id'),
                    'text': comment.get('textDisplay'),
                    'author': comment.get('authorDisplayName'),
                    'authorProfileImageUrl': comment.get('authorProfileImageUrl'),
                    'likeCount': comment.get('likeCount'),
                    'publishedAt': comment.get('publishedAt'),
                    'updatedAt': comment.get('updatedAt'),
                    'replyCount': item.get('snippet', {}).get('totalReplyCount', 0)
                }
                
                # Include replies if requested and available
                if include_replies and 'replies' in item:
                    reply_comments = []
                    for reply in item.get('replies', {}).get('comments', []):
                        reply_snippet = reply.get('snippet', {})
                        reply_comments.append({
                            'id': reply.get('id'),
                            'text': reply_snippet.get('textDisplay'),
                            'author': reply_snippet.get('authorDisplayName'),
                            'authorProfileImageUrl': reply_snippet.get('authorProfileImageUrl'),
                            'likeCount': reply_snippet.get('likeCount'),
                            'publishedAt': reply_snippet.get('publishedAt'),
                            'updatedAt': reply_snippet.get('updatedAt')
                        })
                    
                    formatted_comment['replies'] = reply_comments
                    
                formatted_comments.append(formatted_comment)
                
            return {
                'comments': formatted_comments,
                'nextPageToken': comments_data.get('nextPageToken'),
                'totalResults': comments_data.get('pageInfo', {}).get('totalResults', 0)
            }
        except Exception as e:
            logger.exception(f"Error in get_video_comments: {e}")
            return {'error': str(e)}
  • Core helper method in YouTubeService class that constructs and executes the YouTube Data API v3 commentThreads.list request, handling URL parsing, parameters like order/pageToken/includeReplies, and error handling.
    def get_video_comments(self, video_id: str, max_results: int = 20, **options) -> Dict[str, Any]:
        """
        Get comments for a specific YouTube video
        """
        video_id = self.parse_url(video_id)
        
        try:
            params = {
                'part': 'snippet',
                'videoId': video_id,
                'maxResults': max_results
            }
            
            if 'order' in options:
                params['order'] = options['order']
                
            if 'pageToken' in options:
                params['pageToken'] = options['pageToken']
                
            if options.get('includeReplies'):
                params['part'] = 'snippet,replies'
                
            response = self.youtube.commentThreads().list(**params).execute()
            return response
        except HttpError as e:
            logger.error(f"Error getting comments: {e}")
            raise e
  • server.py:1053-1056 (registration)
    MCP tool registration decorator specifying the tool name and description.
    @mcp.tool(
        name="get_video_comments",
        description="Get comments for a YouTube video",
    )
  • Input schema inferred from function parameters: video_id (required str), max_results (opt int=20), order (opt str="relevance"), include_replies (opt bool=False), page_token (opt str). Output: Dict with comments list, nextPageToken, totalResults.
    async def get_video_comments(
        video_id: str, 
        max_results: Optional[int] = 20, 
        order: Optional[str] = "relevance", 
        include_replies: bool = False,
        page_token: Optional[str] = None
    ) -> Dict[str, Any]:
Behavior2/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 states 'Get comments' but doesn't clarify if this is a read-only operation, whether it requires API keys or permissions, if there are rate limits, or what the output format looks like. The description is too minimal to provide adequate behavioral context for a tool with 5 parameters.

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

Conciseness5/5

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

The description is a single, efficient sentence that gets straight to the point with no wasted words. It's appropriately sized for a simple tool name and is front-loaded with the core purpose.

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?

Given the tool has 5 parameters, 0% schema description coverage, no annotations, but does have an output schema, the description is incomplete. It covers the basic purpose but misses parameter explanations, usage context, and behavioral details. The output schema helps with return values, but the description alone doesn't provide enough context for effective tool selection and invocation.

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

Parameters2/5

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

The schema description coverage is 0%, meaning none of the 5 parameters have descriptions in the schema. The tool description only mentions 'video_id' implicitly ('for a YouTube video'), leaving the other 4 parameters (max_results, order, include_replies, page_token) completely undocumented. This fails to compensate for the schema's lack of coverage.

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

Purpose4/5

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

The description clearly states the verb ('Get') and resource ('comments for a YouTube video'), making the purpose immediately understandable. It doesn't explicitly distinguish from sibling tools like 'get_video_details' or 'get_video_transcript', but the focus on comments is specific enough to imply differentiation.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'get_video_details' (which might include comments) or 'search_videos' (which might find videos with certain comments). It also lacks context about prerequisites, such as needing a valid video ID or authentication requirements.

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/jikime/py-mcp-youtube-toolbox'

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