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
    }
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 states the action ('Get information') but doesn't describe what information is returned, any rate limits, authentication needs, or error conditions. For a tool with no annotations, this leaves significant behavioral gaps, though it doesn't contradict any 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 a single, efficient sentence that directly states the tool's purpose without unnecessary words. It's front-loaded with the core action and resource, making it easy to understand at a glance. Every part of the sentence earns its place by conveying essential information.

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 tool's simplicity (1 parameter, no output schema, no annotations), the description is minimal. It lacks details on what user information is returned, any usage constraints, or output format, which are important for a tool with no structured output documentation. This makes it incomplete for effective agent use beyond basic invocation.

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 the 'mid' parameter clearly documented as 'User's numeric ID' with type and constraints. The description doesn't add any parameter-specific details beyond what the schema provides, such as examples or format explanations. With high schema coverage, the baseline score of 3 is appropriate as the schema handles 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 verb ('Get') and resource ('information about a Bilibili user'), making the purpose understandable. It doesn't explicitly differentiate from sibling tools like 'get_video_info' or 'search_videos', which operate on different resources, but the distinction is implicit through the resource type. This is clear but lacks explicit sibling differentiation.

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 any prerequisites, context for usage, or comparisons to sibling tools like 'get_video_info' for video-related queries. Without such guidance, users must infer usage based on the tool name alone.

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