Skip to main content
Glama
zencoderai

Slack

by zencoderai

slack_get_channel_history

Retrieve recent messages from a Slack channel by specifying the channel ID and optional message limit for reviewing conversation history.

Instructions

Get recent messages from a channel

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
channel_idYesThe ID of the channel
limitNoNumber of messages to retrieve (default 10)

Implementation Reference

  • index.ts:304-320 (registration)
    Registers the 'slack_get_channel_history' tool with the MCP server, including title, description, input schema, and handler function.
    server.registerTool(
      "slack_get_channel_history",
      {
        title: "Get Slack Channel History",
        description: "Get recent messages from a channel",
        inputSchema: {
          channel_id: z.string().describe("The ID of the channel"),
          limit: z.number().optional().default(10).describe("Number of messages to retrieve (default 10)"),
        },
      },
      async ({ channel_id, limit }) => {
        const response = await slackClient.getChannelHistory(channel_id, limit);
        return {
          content: [{ type: "text", text: JSON.stringify(response) }],
        };
      }
    );
  • The MCP tool handler function that invokes the SlackClient's getChannelHistory method and formats the response as MCP content.
    async ({ channel_id, limit }) => {
      const response = await slackClient.getChannelHistory(channel_id, limit);
      return {
        content: [{ type: "text", text: JSON.stringify(response) }],
      };
    }
  • Core implementation in SlackClient that makes the API call to Slack's conversations.history endpoint to retrieve channel message history.
    async getChannelHistory(
      channel_id: string,
      limit: number = 10,
    ): Promise<any> {
      const params = new URLSearchParams({
        channel: channel_id,
        limit: limit.toString(),
      });
    
      const response = await fetch(
        `https://slack.com/api/conversations.history?${params}`,
        { headers: this.botHeaders },
      );
    
      return response.json();
    }
  • Zod input schema defining parameters for the tool: channel_id (required string) and limit (optional number, default 10).
    inputSchema: {
      channel_id: z.string().describe("The ID of the channel"),
      limit: z.number().optional().default(10).describe("Number of messages to retrieve (default 10)"),
    },
  • TypeScript interface defining the argument types for getChannelHistory.
    interface GetChannelHistoryArgs {
      channel_id: string;
      limit?: number;
    }

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/zencoderai/slack-mcp-server'

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