Skip to main content
Glama
lesir831

Bilibili Video Info MCP

by lesir831

get_comments

Read-only

Retrieve popular comments from any Bilibili video by providing its URL. Get comment content, user info, and like counts for analysis or display.

Instructions

Get popular comments from a Bilibili video

Args:
    url: Bilibili video URL, e.g., https://www.bilibili.com/video/BV1x341177NN
    
Returns:
    List of popular comments including comment content, user information, and metadata such as like counts

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • The MCP tool handler for 'get_comments'. Extracts BV ID from URL, gets basic video info (aid), then calls bilibili_api.get_comments(aid) to fetch popular comments.
    async def get_comments(url: str) -> list:
        """Get popular comments from a Bilibili video
        
        Args:
            url: Bilibili video URL, e.g., https://www.bilibili.com/video/BV1x341177NN
            
        Returns:
            List of popular comments including comment content, user information, and metadata such as like counts
        """
        bvid = bilibili_api.extract_bvid(url)
        if not bvid:
            return [f"错误: 无法从 URL 提取 BV 号: {url}"]
        
        aid, cid, error = bilibili_api.get_video_basic_info(bvid)
        if error:
            return [f"获取视频信息失败: {error['error']}"]
        
        comments, error = bilibili_api.get_comments(aid)
        if error:
            return [f"获取评论失败: {error['error']}"]
        
        if not comments:
            return ["该视频没有热门评论"]
        
        return comments
  • Registration decorator @mcp.tool with annotations (title='获取视频评论', readOnlyHint=True) that registers get_comments as an MCP tool.
    @mcp.tool(
        annotations={
            "title": "获取视频评论",
            "readOnlyHint": True,
            "openWorldHint": False
        }
    )
  • Helper function get_comments(aid) that calls the Bilibili API (x/v2/reply) with type=1, oid=aid, sort=2 to fetch hot comments, returning a list of comments with user, content, and likes.
    def get_comments(aid):
        """Fetches comments for a given aid."""
        headers = _get_headers()
        comments_list = []
        try:
            params_comments = {'type': 1, 'oid': aid, 'sort': 2}  # sort=2 fetches hot comments
            response_comments = requests.get(API_GET_COMMENTS, params=params_comments, headers=headers)
            response_comments.raise_for_status()
            comments_data = response_comments.json()
            
            if comments_data.get('code') == 0 and comments_data.get('data', {}).get('replies'):
                for comment in comments_data['data']['replies']:
                    if comment.get('content', {}).get('message'):
                        comments_list.append({
                            'user': comment.get('member', {}).get('uname', 'Unknown User'),
                            'content': comment['content']['message'],
                            'likes': comment.get('like', 0)
                        })
            return comments_list, None
        except requests.RequestException as e:
            return [], {'error': f'Failed to get comments: {e}'}
  • Response parsing schema: extracts 'user' (from member.uname), 'content' (from content.message), and 'likes' (from like) from each reply in the API response.
        if comments_data.get('code') == 0 and comments_data.get('data', {}).get('replies'):
            for comment in comments_data['data']['replies']:
                if comment.get('content', {}).get('message'):
                    comments_list.append({
                        'user': comment.get('member', {}).get('uname', 'Unknown User'),
                        'content': comment['content']['message'],
                        'likes': comment.get('like', 0)
                    })
        return comments_list, None
    except requests.RequestException as e:
        return [], {'error': f'Failed to get comments: {e}'}
Behavior3/5

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

Annotations already declare readOnlyHint=true. The description adds that the tool returns comment content, user info, and metadata, which is useful but does not cover potential rate limits or pagination behavior. No contradiction with annotations.

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 concise (3 sentences), well-structured with clear purpose, Args, and Returns sections. Every sentence adds value with no waste.

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?

For a simple read-only tool with one parameter and no output schema, the description adequately covers purpose, parameter format, and return content. Missing error handling or rate limits but acceptable given simplicity.

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?

Schema coverage is 0%, but the description provides a detailed explanation of the 'url' parameter with an example URL, adding meaningful context beyond the schema's 'Url' title.

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 verb 'Get', the resource 'popular comments', and the source 'Bilibili video'. It distinguishes from sibling tools (get_danmaku for danmaku, get_subtitles for subtitles).

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 does not provide guidance on when to use this tool vs alternatives like get_danmaku. It only describes what it does, without context on selection criteria.

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/lesir831/bilibili-video-info-mcp'

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