Skip to main content
Glama

get_video_comments

Extract and organize comments from any YouTube video using video ID. Specify order, max results, and include replies for tailored analysis or engagement tracking.

Instructions

Get comments for a YouTube video

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
include_repliesNo
max_resultsNo
orderNorelevance
page_tokenNo
video_idYes

Implementation Reference

  • MCP tool handler for get_video_comments. This is the main entrypoint for the tool, decorated with @mcp.tool. It processes input parameters, calls the YouTubeService helper method, formats the response including comments and optional replies, handles pagination, and returns structured JSON data.
    @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)}
  • Supporting utility method in YouTubeService class that makes the actual YouTube Data API v3 call to retrieve comment threads using commentThreads.list(). Handles URL parsing, parameter construction including order, pagination, and replies, and returns the raw API response.
    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)
    The @mcp.tool decorator registers the get_video_comments function as an MCP tool with the specified name and description.
    @mcp.tool( name="get_video_comments", description="Get comments for a YouTube video", )

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