Skip to main content
Glama
z9905080

MCP Server for Slack

by z9905080

slack_get_channel_history

Retrieve recent messages from a Slack channel to review conversation history or analyze discussions.

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

  • The switch case that handles the tool execution: validates arguments, calls SlackClient.getChannelHistory, and returns the JSON response.
    case "slack_get_channel_history": {
      const args = request.params
        .arguments as unknown as GetChannelHistoryArgs;
      if (!args.channel_id) {
        throw new Error("Missing required argument: channel_id");
      }
      const response = await slackClient.getChannelHistory(
        args.channel_id,
        args.limit,
      );
      return {
        content: [{ type: "text", text: JSON.stringify(response) }],
      };
    }
  • Tool schema definition including name, description, and input schema with properties for channel_id (required) and optional limit.
    const getChannelHistoryTool: Tool = {
      name: "slack_get_channel_history",
      description: "Get recent messages from a channel",
      inputSchema: {
        type: "object",
        properties: {
          channel_id: {
            type: "string",
            description: "The ID of the channel",
          },
          limit: {
            type: "number",
            description: "Number of messages to retrieve (default 10)",
            default: 10,
          },
        },
        required: ["channel_id"],
      },
    };
  • index.ts:567-582 (registration)
    The listTools request handler that registers the tool by including it in the returned tools array.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      console.log("Received ListToolsRequest");
      return {
        tools: [
          listChannelsTool,
          postMessageTool,
          replyToThreadTool,
          addReactionTool,
          getChannelHistoryTool,
          getThreadRepliesTool,
          getUsersTool,
          getUserProfileTool,
          lookupUserByEmailTool,
        ],
      };
    });
  • SlackClient method that performs the actual API call to Slack's conversations.history endpoint to fetch channel 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();
    }

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

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