Skip to main content
Glama
wangshunnn

bilibili MCP Server

by wangshunnn

get_user_info

Retrieve detailed information about a Bilibili user by providing their numeric ID for analysis or integration in workflows.

Instructions

Get information about a Bilibili user

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
midYesUser's numeric ID

Implementation Reference

  • The tool handler function that executes the logic for 'get_user_info': fetches user data using helper, formats it, and returns as text content block, with error handling.
    async ({ mid }) => {
      try {
        const userInfo = await getUserInfo(mid) || {}
        const formattedInfo = formatUserInfo(userInfo)
    
        return {
          content: [
            {
              type: "text",
              text: formattedInfo,
            },
          ],
        }
      } catch (error) {
        return {
          content: [
            {
              type: "text",
              text: `get user info failed: ${error instanceof Error ? error.message : String(error)}`,
            },
          ],
        }
      }
    }
  • Input schema using Zod for the 'mid' parameter (user numeric ID).
    {
      mid: z.number().int().positive().describe("User's numeric ID"),
    },
  • src/tools/user.ts:6-36 (registration)
    Registration of the 'get_user_info' tool on the MCP server, specifying name, description, input schema, and handler.
    server.tool(
      "get_user_info",
      "Get information about a Bilibili user",
      {
        mid: z.number().int().positive().describe("User's numeric ID"),
      },
      async ({ mid }) => {
        try {
          const userInfo = await getUserInfo(mid) || {}
          const formattedInfo = formatUserInfo(userInfo)
    
          return {
            content: [
              {
                type: "text",
                text: formattedInfo,
              },
            ],
          }
        } catch (error) {
          return {
            content: [
              {
                type: "text",
                text: `get user info failed: ${error instanceof Error ? error.message : String(error)}`,
              },
            ],
          }
        }
      }
    )
  • Helper function that retrieves and merges Bilibili user information (basic info + follow stats) from API.
    export async function getUserInfo(mid: number): Promise<UserInfo> {
      try {
        // 获取用户基本信息
        const userInfo = (await userAPI.getInfo(mid)) || {}
    
        // 获取用户粉丝和关注数
        const followData = (await userAPI.getRelationStat(mid)) || {}
    
        // 合并数据
        userInfo.followInfo = {
          follower: followData.follower,
          following: followData.following,
        }
    
        return userInfo
      } catch (error) {
        console.error("Error fetching user info:", error)
        throw error
      }
    }
  • Helper function that formats UserInfo into a readable multi-line string using internationalization.
    export function formatUserInfo(user: UserInfo): string {
      const t = i18n.user
      const baseInfo = {
        [t.profile]: `https://space.bilibili.com/${user.mid}`,
        [t.uid]: user.mid,
      }
      const optionalInfo: Record<string, string | undefined> = {
        [t.nickname]: user.name,
        [t.followers]: user.followInfo?.follower?.toLocaleString(),
        [t.following]: user.followInfo?.following?.toLocaleString(),
        [t.level]: user.level?.toString(),
        [t.avatar]: user.face,
        [t.bio]: user.sign,
        [t.birthday]: user.birthday,
        [t.tags]: user.tags?.length > 0 ? user.tags.join(", ") : undefined,
        [t.verification]: user.official?.title,
        [t.verificationDesc]: user.official?.title
          ? user.official?.desc
          : undefined,
        [t.liveRoomUrl]: user.live_room?.url,
        [t.liveStatus]: user.live_room?.url
          ? user.live_room.liveStatus
            ? t.liveOn
            : t.liveOff
          : undefined,
      }
    
      let info =
        Object.entries(baseInfo)
          .map(([key, value]) => `${key}: ${value}`)
          .join("\n") + "\n"
      info += Object.entries(optionalInfo)
        .filter(([_, value]) => value !== undefined && value !== "")
        .map(([key, value]) => `${key}: ${value}`)
        .join("\n")
    
      return info
    }

Schema Changelog

Changes observed during successful MCP inspections.

  1. First observedv1.0.0

TDQS

A4/5.0
Behavior3/5

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

With no annotations provided, the description must carry the burden of behavioral disclosure. It indicates a read-only operation through the verb 'Get', but does not disclose additional behavioral traits such as error handling, rate limits, or return format. This is a neutral score because it is not misleading, but it adds minimal behavioral context.

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, concise sentence with no unnecessary words. It front-loads the action and resource, making it easy to parse and understand quickly.

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 simplicity of the tool (one parameter, no output schema, no annotations), the description is adequately complete. It states the core purpose clearly, and while it could mention what specific information is returned, this is not critical for a basic user-info lookup.

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?

Schema description coverage is 100%, so the parameter 'mid' is fully documented in the schema as 'User's numeric ID'. The description does not add any additional semantic context beyond the schema, which is acceptable given the high coverage.

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 uses a specific verb ('Get') with a clear resource ('information about a Bilibili user'). It clearly distinguishes itself from siblings like get_video_info and search_videos, which target different resource types.

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

Usage Guidelines4/5

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

The description clearly implies when to use the tool: whenever you need information about a specific user. It provides clear context for usage, though it does not explicitly mention alternatives or exclusions. For a simple lookup tool, this is sufficient.

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