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
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | Yes | The ID of the channel | |
| limit | No | Number 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) }], }; } );
- index.ts:314-319 (handler)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) }], }; }
- index.ts:160-175 (helper)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(); }
- index.ts:309-312 (schema)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)"), },
- index.ts:34-37 (schema)TypeScript interface defining the argument types for getChannelHistory.interface GetChannelHistoryArgs { channel_id: string; limit?: number; }