Get Slack Channel History
slack_get_channel_historyRetrieve recent messages from a Slack channel by providing its channel ID. Optionally specify the number of messages to fetch, with a default of 10, for quick access to conversation history.
Instructions
Get recent messages from a channel
Input 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 (handler)The tool registration and handler for 'slack_get_channel_history'. It registers the tool on the MCP server, defines the input schema (channel_id and optional limit), and the handler calls slackClient.getChannelHistory().
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:160-175 (helper)The SlackClient.getChannelHistory() method that executes the actual API call to Slack's conversations.history endpoint.
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:34-37 (schema)TypeScript interface defining the input arguments for GetChannelHistory: channel_id (string) and optional limit (number).
interface GetChannelHistoryArgs { channel_id: string; limit?: number; } - index.ts:304-320 (registration)Registration of the 'slack_get_channel_history' tool via server.registerTool() on the McpServer instance.
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) }], }; } );