Skip to main content
Glama
wangshunnn

bilibili MCP Server

by wangshunnn

get_video_info

Retrieve detailed metadata for a Bilibili video by specifying its unique BVID, enabling precise access to video information for analysis or integration purposes.

Instructions

Get detailed information about a Bilibili video

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bvidYesBilibili video ID (BVID)

Implementation Reference

  • The main execution logic for the 'get_video_info' tool. Fetches Bilibili video details, formats title, uploader, stats, description, tags into a multi-line text response using i18n translations and utility formatters, returns as MCP content block. Handles fetch errors.
      async ({ bvid }) => {
        try {
          const t = i18n.video
    
          const videoDetail = (await getVideoDetail(bvid)) || {}
          const stats = videoDetail.stat || {}
    
          const detailLines = [
            `${t.title}: ${videoDetail.title}`,
            `${t.url}: https://www.bilibili.com/video/${videoDetail.bvid}`,
            `${t.aid}: ${videoDetail.aid}`,
            `${t.uploader}: ${videoDetail.owner?.name} (${t.uploaderUID}: ${videoDetail.owner?.mid})`,
            `${t.publishDate}: ${formatTimestamp(videoDetail.pubdate)}`,
            `${t.duration}: ${formatDuration(videoDetail.duration)}`,
            "",
            `${t.stats}:`,
            `- ${t.views}: ${stats.view?.toLocaleString()}`,
            `- ${t.danmaku}: ${stats.danmaku?.toLocaleString()}`,
            `- ${t.comments}: ${stats.reply?.toLocaleString()}`,
            `- ${t.likes}: ${stats.like?.toLocaleString()}`,
            `- ${t.coins}: ${stats.coin?.toLocaleString()}`,
            `- ${t.favorites}: ${stats.favorite?.toLocaleString()}`,
            `- ${t.shares}: ${stats.share?.toLocaleString()}`,
            "",
            `${t.description}:`,
            ...videoDetail.desc?.split("\n")?.map?.((line) => line),
            "",
            `${t.tags}: ${videoDetail.tags?.join(", ")}`,
          ]
          const formattedDetail = detailLines.map((line) => line).join("\n")
    
          return {
            content: [
              {
                type: "text",
                text: formattedDetail.trim(),
              },
            ],
          }
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `Failed to fetch video info: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          }
        }
      }
    )
  • Input schema for the tool using Zod: requires 'bvid' as string (Bilibili Video ID).
    {
      bvid: z.string().describe("Bilibili video ID (BVID)"),
    },
  • Registers the 'get_video_info' tool on the MCP server, specifying name, description, input schema, and handler function.
    export function registerVideoTools(server: McpServer): void {
      server.tool(
        "get_video_info",
        "Get detailed information about a Bilibili video",
        {
          bvid: z.string().describe("Bilibili video ID (BVID)"),
        },
        async ({ bvid }) => {
          try {
            const t = i18n.video
    
            const videoDetail = (await getVideoDetail(bvid)) || {}
            const stats = videoDetail.stat || {}
    
            const detailLines = [
              `${t.title}: ${videoDetail.title}`,
              `${t.url}: https://www.bilibili.com/video/${videoDetail.bvid}`,
              `${t.aid}: ${videoDetail.aid}`,
              `${t.uploader}: ${videoDetail.owner?.name} (${t.uploaderUID}: ${videoDetail.owner?.mid})`,
              `${t.publishDate}: ${formatTimestamp(videoDetail.pubdate)}`,
              `${t.duration}: ${formatDuration(videoDetail.duration)}`,
              "",
              `${t.stats}:`,
              `- ${t.views}: ${stats.view?.toLocaleString()}`,
              `- ${t.danmaku}: ${stats.danmaku?.toLocaleString()}`,
              `- ${t.comments}: ${stats.reply?.toLocaleString()}`,
              `- ${t.likes}: ${stats.like?.toLocaleString()}`,
              `- ${t.coins}: ${stats.coin?.toLocaleString()}`,
              `- ${t.favorites}: ${stats.favorite?.toLocaleString()}`,
              `- ${t.shares}: ${stats.share?.toLocaleString()}`,
              "",
              `${t.description}:`,
              ...videoDetail.desc?.split("\n")?.map?.((line) => line),
              "",
              `${t.tags}: ${videoDetail.tags?.join(", ")}`,
            ]
            const formattedDetail = detailLines.map((line) => line).join("\n")
    
            return {
              content: [
                {
                  type: "text",
                  text: formattedDetail.trim(),
                },
              ],
            }
          } catch (error) {
            return {
              content: [
                {
                  type: "text",
                  text: `Failed to fetch video info: ${error instanceof Error ? error.message : String(error)}`,
                },
              ],
            }
          }
        }
      )
    }
  • src/index.ts:15-15 (registration)
    Invocation of registerVideoTools during MCP server startup to enable the tool.
    registerVideoTools(server)
  • Helper function called by the handler to fetch raw video detail data from the API.
    export async function getVideoDetail(bvid: string): Promise<VideoDetail> {
      try {
        return await videoAPI.getDetail(bvid)
      } catch (error) {
        console.error("Error fetching video detail:", error)
        throw error
      }
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

B3.4/5.0
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It fails to mention the return format, what fields constitute 'detailed information,' or any potential side effects (though 'get' implies read-only). It adds minimal behavioral context beyond the verb.

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 sentence with no wasted words. It is appropriately minimal for a simple getter tool.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

This tool has no output schema and no annotations, requiring the description to explain what return values to expect. The description only says 'detailed information' without specifying any fields or structure, leaving the agent with insufficient understanding of the output. Given the availability of sibling tools, it also doesn't clarify how this differs in output or use case.

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

Parameters3/5

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

The input schema already fully documents the only parameter (bvid) with a description, achieving 100% schema coverage. The description adds no additional parameter semantics such as format examples or constraints, so it performs at the baseline.

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 states a specific verb ('Get') and resource ('detailed information about a Bilibili video'). It distinguishes from siblings by the resource type (video vs user/search), making its purpose clear.

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 provides no explicit guidance on when to use this tool versus get_user_info or search_videos. Usage is only implied by the name and description: if you have a known BVID. No exclusions or alternative suggestions are given.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Deploy Server

Other Tools

Related Tools