Skip to main content
Glama
lesir831

Bilibili Video Info MCP

by lesir831

get_subtitles

Read-only

Extract subtitles with timestamps from Bilibili videos. Input a video URL to receive organized subtitle content by language for accessibility and analysis.

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

  • Primary implementation of the 'get_subtitles' MCP tool: async handler registered via @mcp.tool decorator, with input schema (url: str), docstring description, and logic to extract video info and fetch subtitles.
    @mcp.tool(
        annotations={
            "title": "获取视频字幕",
            "readOnlyHint": True,
            "openWorldHint": False
        }
    )
    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
  • Helper function implementing the core API logic for fetching and parsing Bilibili subtitles using aid and cid parameters.
    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 provide readOnlyHint=true and openWorldHint=false, indicating a safe read operation with limited scope. The description adds valuable behavioral context beyond annotations by specifying the return format ('List of subtitles grouped by language' with 'subtitle content with timestamps'), which helps the agent understand output structure without contradicting 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 efficiently structured with three focused sentences: purpose statement, parameter explanation with example, and return format specification. Every sentence adds value without redundancy, and information is front-loaded appropriately for quick comprehension.

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 (single parameter, read-only operation) and lack of output schema, the description provides good completeness: it covers purpose, parameter semantics, and return format. However, it doesn't address potential edge cases like error conditions or authentication needs, leaving minor gaps in full contextual understanding.

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?

With 0% schema description coverage for the single parameter 'url', the description fully compensates by providing clear semantics: it defines 'url' as a 'Bilibili video URL' and gives a concrete example (https://www.bilibili.com/video/BV1x341177NN). This adds essential meaning beyond the bare schema, though it could further clarify URL format constraints.

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 specific action ('Get subtitles') and resource ('from a Bilibili video'), distinguishing it from sibling tools like get_comments and get_danmaku which handle different video content aspects. The verb+resource combination is precise and unambiguous.

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

Usage Guidelines3/5

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

The description implies usage context by specifying 'Bilibili video URL' and providing an example, but it doesn't explicitly state when to use this tool versus alternatives like get_comments or get_danmaku. There's no guidance on prerequisites or exclusions, leaving usage context partially implied rather than fully articulated.

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