Skip to main content
Glama

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 }

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