search_users
Find Weibo users by entering keywords and specify the number of results to retrieve. This tool simplifies user searches by returning a list of matched profiles directly from the Weibo MCP Server.
Instructions
根据关键词搜索微博用户并返回匹配的用户列表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| keyword | Yes | 查找用户的搜索词 | |
| limit | Yes | 返回的最大用户数量 |
Implementation Reference
- src/weibo.ts:69-95 (handler)Core handler logic for searching Weibo users: builds query params for Weibo mobile API search endpoint, fetches with axios using DEFAULT_HEADERS, parses cards[1].card_group, maps users via toSearchResult helper, returns up to 'limit' SearchResult items or [] on error.async searchWeiboUsers(keyword: string, limit: number): Promise<SearchResult[]> { try { const params = { 'containerid': `100103type=3&q=${keyword}&t=`, 'page_type': 'searchall' }; const searchParams = new URLSearchParams(); for (const [key, value] of Object.entries(params)) { searchParams.append(key, value); } const queryString = searchParams.toString(); const response = await axios.get(`https://m.weibo.cn/api/container/getIndex?${queryString}`, { headers: DEFAULT_HEADERS }); const result = response.data; const cards = result.data.cards; if (cards.length < 2) { return []; } else { const cardGroup = cards[1]['card_group']; return cardGroup.map((item: any) => this.toSearchResult(item.user)).slice(0, limit); } } catch (error) { console.error(`无法搜索关键词为'${keyword}'的用户`, error); return []; } }
- src/server.ts:20-23 (schema)Zod input validation schema for 'search_users' tool parameters: keyword (string search term), limit (number max results).{ keyword: z.string().describe("查找用户的搜索词"), limit: z.number().describe("返回的最大用户数量") },
- src/types.ts:17-40 (schema)TypeScript interface defining output structure SearchResult[] for search_users: id (number), nickName (string), avatarHD (string), description (string).* 微博用户搜索结果数据模型 */ export interface SearchResult { /** * 用户的唯一标识符 */ id: number; /** * 用户的显示名称 */ nickName: string; /** * 用户高分辨率头像图片的URL */ avatarHD: string; /** * 用户的个人简介 */ description: string; }
- src/server.ts:18-30 (registration)MCP server registration of 'search_users' tool: sets name, Chinese description, input schema, thin async handler wrapping crawler.searchWeiboUsers and formatting as MCP content response.server.tool("search_users", "根据关键词搜索微博用户并返回匹配的用户列表", { keyword: z.string().describe("查找用户的搜索词"), limit: z.number().describe("返回的最大用户数量") }, async ({ keyword, limit }) => { const users = await crawler.searchWeiboUsers(keyword, limit); return { content: [{ type: "text", text: JSON.stringify(users) }] }; } );
- src/weibo.ts:103-110 (helper)Private helper mapping raw Weibo API user object to standardized SearchResult interface used in searchWeiboUsers.private toSearchResult(user: any): SearchResult { return { id: user.id, nickName: user.screen_name, avatarHD: user.avatar_hd, description: user.description }; }