Skip to main content
Glama
lesir831

Bilibili Video Info MCP

by lesir831

get_subtitles

Read-only

Retrieve subtitles from any Bilibili video by providing its URL. Returns subtitles grouped by language with timestamps for easy access.

Instructions

Get subtitles from a Bilibili video

Args:
    url: Bilibili video URL, e.g., https://www.bilibili.com/video/BV1x341177NN
    
Returns:
    List of subtitles grouped by language. Each entry contains subtitle content with timestamps.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
urlYes

Implementation Reference

  • The 'get_subtitles' tool handler function. Extracts BVID from URL, gets basic video info (aid/cid), then calls bilibili_api.get_subtitles to fetch subtitle data grouped by language.
    async def get_subtitles(url: str) -> list:
        """Get subtitles from a Bilibili video
        
        Args:
            url: Bilibili video URL, e.g., https://www.bilibili.com/video/BV1x341177NN
            
        Returns:
            List of subtitles grouped by language. Each entry contains subtitle content with timestamps.
        """
        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']}"]
        
        subtitles, error = bilibili_api.get_subtitles(aid, cid)
        if error:
            return [f"获取字幕失败: {error['error']}"]
        
        if not subtitles:
            return ["该视频没有字幕"]
        
        return subtitles
  • The tool signature (async def get_subtitles(url: str) -> list) serves as the schema definition, with docstring specifying input URL and output list of subtitles grouped by language.
    async def get_subtitles(url: str) -> list:
        """Get subtitles from a Bilibili video
        
        Args:
            url: Bilibili video URL, e.g., https://www.bilibili.com/video/BV1x341177NN
            
        Returns:
            List of subtitles grouped by language. Each entry contains subtitle content with timestamps.
        """
        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']}"]
        
        subtitles, error = bilibili_api.get_subtitles(aid, cid)
        if error:
            return [f"获取字幕失败: {error['error']}"]
        
        if not subtitles:
            return ["该视频没有字幕"]
        
        return subtitles
  • The decorator @mcp.tool registers get_subtitles as an MCP tool with annotations including title '获取视频字幕', readOnlyHint and openWorldHint.
    @mcp.tool(
        annotations={
            "title": "获取视频字幕",
            "readOnlyHint": True,
            "openWorldHint": False
        }
    )
  • The helper function get_subtitles(aid, cid) that actually calls the Bilibili API (API_GET_SUBTITLE), fetches subtitle JSON data, parses subtitle_body into content lists grouped by language ('lan').
    def get_subtitles(aid, cid):
        """Fetches subtitles for a given aid and cid."""
        headers = _get_headers()
        subtitles = []
        try:
            params_subtitle = {'aid': aid, 'cid': cid}
            response_subtitle = requests.get(API_GET_SUBTITLE, params=params_subtitle, headers=headers)
            response_subtitle.raise_for_status()
            subtitle_data = response_subtitle.json()
            if subtitle_data.get('code') == 0 and subtitle_data.get('data', {}).get('subtitle', {}).get('subtitles'):
                for sub_meta in subtitle_data['data']['subtitle']['subtitles']:
                    if sub_meta.get('subtitle_url'):
                        try:
                            subtitle_json_url = f"https:{sub_meta['subtitle_url']}"
                            response_sub_content = requests.get(subtitle_json_url, headers=headers)
                            response_sub_content.raise_for_status()
                            sub_content = response_sub_content.json()
                            subtitle_body = sub_content.get('body', [])
                            content_list = [item.get('content', '') for item in subtitle_body]
                            subtitles.append({
                                'lan': sub_meta['lan'],
                                'content': content_list
                            })
                        except requests.RequestException as e:
                            print(f"Could not fetch or parse subtitle content from {sub_meta.get('subtitle_url')}: {e}")
            return subtitles, None
        except requests.RequestException as e:
            return [], {'error': f'Could not fetch subtitles: {e}'}
Behavior4/5

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

Annotations already indicate readOnlyHint=true; the description adds value by specifying the return structure (list grouped by language with timestamps) beyond the annotations, but does not disclose other behaviors like rate limits or auth.

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 concise (5 lines) and front-loaded with the purpose, but the Args/Returns formatting could be more streamlined; still efficient.

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 tool with one parameter and no output schema, the description covers input format and output structure adequately, though it omits potential errors or prerequisites.

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%, so the description compensates by explaining the 'url' parameter with an example and format, adding meaning beyond the bare schema definition.

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 explicitly states 'Get subtitles from a Bilibili video' and provides an example URL, making the tool's purpose clear and distinguishing it from sibling tools like get_comments and get_danmaku.

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?

No guidance on when to use this tool versus alternatives; it does not mention context for use or exclusion criteria, leaving agents to infer from the name alone.

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