Skip to main content
Glama
jhanglim

Mattermost MCP Server

by jhanglim

get_channel_messages

Retrieve recent messages from a Mattermost channel with author details. Specify channel ID to fetch messages with user names and usernames included.

Instructions

특정 채널의 최근 메시지들을 가져옵니다. 결과에는 자동으로 작성자의 이름(user_name)과 username이 포함됩니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channel_idYes채널 ID
pageNo페이지 번호 (기본값: 0)
per_pageNo페이지당 메시지 수 (기본값: 60)

Implementation Reference

  • Main handler for the 'get_channel_messages' tool within the CallToolRequestSchema switch statement. Extracts parameters, fetches messages from Mattermost API via client, enriches with user details, formats output, and returns JSON response.
    case "get_channel_messages": {
      const channelId = args.channel_id as string;
      const page = (args.page as number) || 0;
      const perPage = (args.per_page as number) || 60;
      
      const messages = await client.getChannelMessages(channelId, page, perPage);
    
      // 고유한 user_id 추출 및 사용자 정보 조회
      const uniqueUserIds = [...new Set(messages.order?.map((postId: string) => messages.posts[postId].user_id) || [])];
      const userMap = await client.getUsersInfo(uniqueUserIds);
    
      const posts = messages.order?.map((postId: string) => {
        const post = messages.posts[postId];
        const createTime = formatTimestamp(post.create_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",
          create_at: createTime,
        };
      }) || [];
    
      return {
        content: [
          {
            type: "text",
            text: JSON.stringify({
              channel_id: channelId,
              posts: posts,
            }, null, 2),
          },
        ],
      };
    }
  • src/index.ts:279-302 (registration)
    Tool registration in the ListToolsRequestSchema handler's tools array, defining name, description, and input schema for 'get_channel_messages'.
    {
      name: "get_channel_messages",
      description: "특정 채널의 최근 메시지들을 가져옵니다. 결과에는 자동으로 작성자의 이름(user_name)과 username이 포함됩니다.",
      inputSchema: {
        type: "object",
        properties: {
          channel_id: {
            type: "string",
            description: "채널 ID",
          },
          page: {
            type: "number",
            description: "페이지 번호 (기본값: 0)",
            default: 0,
          },
          per_page: {
            type: "number",
            description: "페이지당 메시지 수 (기본값: 60)",
            default: 60,
          },
        },
        required: ["channel_id"],
      },
    },
  • MattermostClient helper method that makes the API request to fetch channel messages, used by the main tool handler.
    async getChannelMessages(channelId: string, page: number = 0, perPage: number = 60): Promise<MattermostPostsResult> {
      return await this.request(`/channels/${channelId}/posts?page=${page}&per_page=${perPage}`) as MattermostPostsResult;
    }

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