get_hot_search
Fetch trending topics from the Weibo hot search list. Specify a limit to retrieve the desired number of top trending entries for analysis or monitoring.
Instructions
获取当前微博热搜榜的热门话题列表
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| limit | Yes | 返回的最大热搜条目数量 |
Implementation Reference
- src/server.ts:68-79 (registration)MCP server tool registration for 'get_hot_search', including description, input schema, and execution handler that delegates to WeiboCrawlerserver.tool("get_hot_search", "获取当前微博热搜榜的热门话题列表", { limit: z.number().describe("返回的最大热搜条目数量") }, async ({ limit }) => { const hotSearchList = await crawler.getHotSearchList(limit); return { content: [{ type: "text", text: JSON.stringify(hotSearchList) }] }; } );
- src/server.ts:73-78 (handler)Inline handler function for the get_hot_search tool that invokes the crawler's getHotSearchList method and formats the responseasync ({ limit }) => { const hotSearchList = await crawler.getHotSearchList(limit); return { content: [{ type: "text", text: JSON.stringify(hotSearchList) }] }; }
- src/server.ts:70-72 (schema)Zod input schema defining the 'limit' parameter as a number{ limit: z.number().describe("返回的最大热搜条目数量") },
- src/weibo.ts:177-227 (helper)Core helper method in WeiboCrawler class that fetches the hot search list from Weibo API, parses the response cards, and returns formatted HotSearchItem array limited by inputasync getHotSearchList(limit: number): Promise<HotSearchItem[]> { try { const response = await axios.get(HOT_SEARCH_URL, { headers: DEFAULT_HEADERS }); const data = response.data; const cards = data?.data?.cards || []; if (cards.length === 0) { return []; } // 查找包含热搜数据的card let hotSearchCard = null; for (const card of cards) { if (card.card_group && Array.isArray(card.card_group)) { hotSearchCard = card; break; } } if (!hotSearchCard || !hotSearchCard.card_group) { return []; } // 转换热搜数据为HotSearchItem格式 const hotSearchItems: HotSearchItem[] = []; let rank = 1; for (const item of hotSearchCard.card_group) { if (item.desc && rank <= limit) { const hotSearchItem: HotSearchItem = { keyword: item.desc, rank: rank, hotValue: parseInt(item.desc_extr || '0', 10), tag: item.icon ? item.icon.slice(item.icon.lastIndexOf('/') + 1).replace('.png', '') : undefined, url: item.scheme }; hotSearchItems.push(hotSearchItem); rank++; } } return hotSearchItems; } catch (error) { console.error('无法获取微博热搜榜', error); return []; } }
- src/types.ts:44-69 (schema)TypeScript interface defining the structure of each HotSearchItem in the tool's outputexport interface HotSearchItem { /** * 热搜关键词 */ keyword: string; /** * 热搜排名 */ rank: number; /** * 热搜热度 */ hotValue: number; /** * 标签类型(如新、热、爆等) */ tag?: string; /** * 搜索链接 */ url?: string; }