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
| Name | Required | Description | Default |
|---|---|---|---|
| bvid | Yes | Bilibili video ID (BVID) |
Implementation Reference
- src/tools/video.ts:17-67 (handler)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)}`, }, ], } } } )
- src/tools/video.ts:14-16 (schema)Input schema for the tool using Zod: requires 'bvid' as string (Bilibili Video ID).{ bvid: z.string().describe("Bilibili video ID (BVID)"), },
- src/tools/video.ts:10-68 (registration)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)
- src/common/utils.ts:52-59 (helper)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 } }