slack_get_channel_history
Retrieve recent messages from a Slack channel using channel ID and optional limit to view 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:458-471 (handler)Executes the slack_get_channel_history tool by parsing arguments, validating channel_id, calling SlackClient.getChannelHistory, and returning the API response as JSON.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) }], }; }
- index.ts:139-157 (schema)Defines the Tool metadata including name, description, and input schema (channel_id required, limit optional) for slack_get_channel_history.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:296-311 (helper)SlackClient method that performs the actual 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.headers }, ); return response.json(); }
- index.ts:532-546 (registration)Registers slack_get_channel_history by including getChannelHistoryTool in the tools list returned for ListToolsRequest.server.setRequestHandler(ListToolsRequestSchema, async () => { console.error("Received ListToolsRequest"); return { tools: [ listChannelsTool, postMessageTool, replyToThreadTool, addReactionTool, getChannelHistoryTool, getThreadRepliesTool, getUsersTool, getUserProfileTool, ], }; });