Skip to main content
Glama
wangshunnn

bilibili MCP Server

by wangshunnn

search_videos

Search for videos on Bilibili using keywords, specify page numbers, and control the number of results returned for focused content discovery.

Instructions

Search for videos on Bilibili

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of results to return, default 10, maximum 20
keywordYesKeyword to search for
pageNoPage number, defaults to 1

Implementation Reference

  • The main execution handler for the search_videos tool. It calls searchVideos helper, filters video results, formats them into a readable text output, handles pagination and count limits, and returns MCP-formatted content blocks.
    async ({ keyword, page, count }) => {
      try {
        const searchResult = await searchVideos(keyword, page) || {}
    
        if (!searchResult.result || searchResult.result.length === 0) {
          return {
            content: [
              {
                type: "text",
                text: `No videos found related to "${keyword}".`,
              },
            ],
          }
        }
    
        // 过滤出视频结果并限制数量
        const videoResults = searchResult.result
          .filter((item) => item.result_type === "video")?.[0]
          ?.data?.slice(0, count) as VideoSearchItem[]
    
        const formattedResults = videoResults
          .map((video, index) => {
            return [
              `${index + 1}. "${video.title}" - ${video.author}`,
              ` BV ID: ${video.bvid}`,
              ` Views: ${video.play?.toLocaleString()}`,
              ` Danmaku: ${video.danmaku?.toLocaleString()}`,
              ` Likes: ${video.like?.toLocaleString()}`,
              ` Duration: ${video.duration}`,
              ` Published: ${formatTimestamp(video.pubdate)}`,
              ` Description: ${video.description?.substring(0, 100)}${video.description?.length > 100 ? "..." : ""}`,
            ].join("\n")
          })
          .join("\n\n")
    
        return {
          content: [
            {
              type: "text",
              text: [
                `Search results for "${keyword}":`,
                formattedResults,
                `Found ${searchResult.numResults} related videos in total, currently showing ${videoResults.length} results from page ${page}.`,
              ].join("\n"),
            },
          ],
        }
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `Failed to search videos: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        }
      }
    }
  • Input validation schema using Zod for the search_videos tool parameters: keyword (required string), page (optional int >=1, default 1), count (optional int 1-20, default 10).
    {
      keyword: z.string().describe("Keyword to search for"),
      page: z
        .number()
        .int()
        .min(1)
        .default(1)
        .describe("Page number, defaults to 1"),
      count: z
        .number()
        .int()
        .min(1)
        .max(20)
        .default(10)
        .describe("Number of results to return, default 10, maximum 20"),
    },
  • Registration function for the search_videos tool on the MCP server, specifying name, description, input schema, and handler.
    export function registerSearchTools(server: McpServer): void {
      server.tool(
        "search_videos",
        "Search for videos on Bilibili",
        {
          keyword: z.string().describe("Keyword to search for"),
          page: z
            .number()
            .int()
            .min(1)
            .default(1)
            .describe("Page number, defaults to 1"),
          count: z
            .number()
            .int()
            .min(1)
            .max(20)
            .default(10)
            .describe("Number of results to return, default 10, maximum 20"),
        },
        async ({ keyword, page, count }) => {
          try {
            const searchResult = await searchVideos(keyword, page) || {}
    
            if (!searchResult.result || searchResult.result.length === 0) {
              return {
                content: [
                  {
                    type: "text",
                    text: `No videos found related to "${keyword}".`,
                  },
                ],
              }
            }
    
            // 过滤出视频结果并限制数量
            const videoResults = searchResult.result
              .filter((item) => item.result_type === "video")?.[0]
              ?.data?.slice(0, count) as VideoSearchItem[]
    
            const formattedResults = videoResults
              .map((video, index) => {
                return [
                  `${index + 1}. "${video.title}" - ${video.author}`,
                  ` BV ID: ${video.bvid}`,
                  ` Views: ${video.play?.toLocaleString()}`,
                  ` Danmaku: ${video.danmaku?.toLocaleString()}`,
                  ` Likes: ${video.like?.toLocaleString()}`,
                  ` Duration: ${video.duration}`,
                  ` Published: ${formatTimestamp(video.pubdate)}`,
                  ` Description: ${video.description?.substring(0, 100)}${video.description?.length > 100 ? "..." : ""}`,
                ].join("\n")
              })
              .join("\n\n")
    
            return {
              content: [
                {
                  type: "text",
                  text: [
                    `Search results for "${keyword}":`,
                    formattedResults,
                    `Found ${searchResult.numResults} related videos in total, currently showing ${videoResults.length} results from page ${page}.`,
                  ].join("\n"),
                },
              ],
            }
          } catch (error) {
            return {
              content: [
                {
                  type: "text",
                  text: `Failed to search videos: ${error instanceof Error ? error.message : String(error)}`,
                },
              ],
            }
          }
        }
      )
    }
  • src/index.ts:16-16 (registration)
    Top-level call to register the search tools (including search_videos) on the main MCP server instance.
    registerSearchTools(server)
  • Utility helper function that invokes the Bilibili search API via searchAPI and handles errors, used by the search_videos handler.
    export async function searchVideos(
      keyword: string,
      page: number = 1
    ): Promise<SearchResult> {
      try {
        return await searchAPI.searchVideos(keyword, page) || {}
      } catch (error) {
        console.error("Error searching videos:", error)
        throw error
      }
    }
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. The description only states the basic purpose without mentioning any behavioral traits such as rate limits, authentication requirements, pagination behavior, or what the search results include (e.g., metadata fields). This leaves significant gaps for an AI agent to understand how to use it effectively.

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, efficient sentence with zero waste. It's appropriately sized and front-loaded, directly stating the tool's purpose without unnecessary elaboration.

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?

Given the lack of annotations and output schema, the description is incomplete. It doesn't address key contextual aspects like what the search returns (e.g., list of video objects, error handling), behavioral constraints, or how it differs from sibling tools. For a search tool with no structured output information, more detail is needed.

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 has 100% description coverage, with clear documentation for all three parameters (keyword, count, page). The description adds no additional meaning beyond what the schema provides, such as explaining search semantics (e.g., partial matches, relevance scoring) or parameter interactions. Baseline 3 is appropriate when the schema does the heavy lifting.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Search for') and resource ('videos on Bilibili'), providing a specific verb+resource combination. However, it doesn't explicitly distinguish this tool from its sibling tools (get_user_info, get_video_info), which are likely for retrieving specific user or video details rather than performing searches.

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 provides no guidance on when to use this tool versus alternatives. It doesn't mention the sibling tools (get_user_info, get_video_info) or explain scenarios where searching for videos is appropriate compared to directly fetching known video or user information.

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

Related 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/wangshunnn/bilibili-mcp-server'

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