Skip to main content
Glama
jhanglim

Mattermost MCP Server

by jhanglim

search_messages

Search for messages in Mattermost using keywords, usernames (with @ or from:), or dates to find specific conversations and information.

Instructions

Mattermost에서 메시지를 검색합니다. 키워드, 사용자명(@username 또는 from:username), 날짜 등으로 검색할 수 있습니다. 검색 결과에는 자동으로 작성자의 이름(user_name)과 username이 포함됩니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYes검색할 키워드 또는 검색어. 사용자명으로 검색하려면 'from:username' 또는 '@username' 형식 사용
is_or_searchNotrue인 경우 OR 검색, false인 경우 AND 검색 (기본값: false)

Implementation Reference

  • The handler for the 'search_messages' tool. It takes a query and optional is_or_search flag, searches Mattermost posts via client.searchPosts, retrieves user info for all posters, formats timestamps to KST, and returns a JSON object with total_count and detailed posts including usernames and names.
    case "search_messages": {
      const query = args.query as string;
      const isOrSearch = (args.is_or_search as boolean) || false;
      
      const result = await client.searchPosts(query, isOrSearch);
    
      // 고유한 user_id 추출
      const uniqueUserIds = [...new Set(result.order?.map((postId: string) => result.posts[postId].user_id) || [])];
      
      // 사용자 정보 일괄 조회
      const userMap = await client.getUsersInfo(uniqueUserIds);
    
      // 검색 결과 포맷팅
      const posts = result.order?.map((postId: string) => {
        const post = result.posts[postId];
        const createTime = formatTimestamp(post.create_at);
        const updateTime = formatTimestamp(post.update_at);
        const userInfo = userMap.get(post.user_id);
        
        return {
          id: post.id,
          message: post.message,
          user_id: post.user_id,
          username: userInfo?.username || "unknown",
          user_name: userInfo?.name || "Unknown User",
          channel_id: post.channel_id,
          create_at: createTime,
          update_at: updateTime,
        };
      }) || [];
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              total_count: posts.length,
              posts: posts,
            }, null, 2),
          },
        ],
      };
    }
  • src/index.ts:206-224 (registration)
    Registration of the 'search_messages' tool in the list of tools returned by ListToolsRequestSchema, including its name, description, and input schema definition.
    {
      name: "search_messages",
      description: "Mattermost에서 메시지를 검색합니다. 키워드, 사용자명(@username 또는 from:username), 날짜 등으로 검색할 수 있습니다. 검색 결과에는 자동으로 작성자의 이름(user_name)과 username이 포함됩니다.",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "검색할 키워드 또는 검색어. 사용자명으로 검색하려면 'from:username' 또는 '@username' 형식 사용",
          },
          is_or_search: {
            type: "boolean",
            description: "true인 경우 OR 검색, false인 경우 AND 검색 (기본값: false)",
            default: false,
          },
        },
        required: ["query"],
      },
    },
  • Helper method in MattermostClient class that performs the actual Mattermost API search for posts, used by the search_messages handler.
    async searchPosts(terms: string, isOrSearch: boolean = false): Promise<MattermostSearchResult> {
      return await this.request("/posts/search", {
        method: "POST",
        body: JSON.stringify({
          terms,
          is_or_search: isOrSearch,
        }),
      }) as MattermostSearchResult;
    }

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/jhanglim/mattermost-mcp-server'

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