Skip to main content
Glama
Selenium39

Weibo MCP Server

search_users

Find Weibo users by entering keywords to discover relevant profiles and accounts matching your search criteria.

Instructions

根据关键词搜索微博用户并返回匹配的用户列表

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
keywordYes查找用户的搜索词
limitYes返回的最大用户数量

Implementation Reference

  • src/server.ts:18-30 (registration)
    Registers the 'search_users' MCP tool, defining its description, input schema with Zod, and inline handler that delegates to WeiboCrawler.searchWeiboUsers
    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) }]
        };
      }
    );
  • Implements the core logic for searching Weibo users by keyword: constructs API URL for mobile Weibo search, fetches data with axios, parses cards to extract user list, maps to SearchResult using toSearchResult helper, limits results.
    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 [];
      }
    }
  • Zod input schema for 'search_users' tool defining keyword (string) and limit (number) parameters.
    { 
      keyword: z.string().describe("查找用户的搜索词"),
      limit: z.number().describe("返回的最大用户数量")
    },
  • Helper method to transform raw Weibo user data into standardized SearchResult interface.
    private toSearchResult(user: any): SearchResult {
      return {
        id: user.id,
        nickName: user.screen_name,
        avatarHD: user.avatar_hd,
        description: user.description
      };
    }
  • TypeScript interface defining the output structure for search results (SearchResult[]).
    export interface SearchResult {
      /**
       * 用户的唯一标识符
       */
      id: number;
      
      /**
       * 用户的显示名称
       */
      nickName: string;
      
      /**
       * 用户高分辨率头像图片的URL
       */
      avatarHD: string;
      
      /**
       * 用户的个人简介
       */
      description: string;
    }

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/Selenium39/mcp-server-weibo'

If you have feedback or need assistance with the MCP directory API, please join our Discord server