slack_get_channel_history
Retrieve recent messages from a Slack channel to review conversation history and stay updated on team discussions.
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:322-337 (handler)Core handler function in SlackClient that fetches the recent messages (history) from a Slack channel using the conversations.history API.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:484-497 (handler)Dispatch handler in the CallToolRequest handler that parses arguments and invokes the SlackClient.getChannelHistory method.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)Tool schema definition specifying the name, description, input schema, and required parameters 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:34-37 (schema)TypeScript interface defining the expected arguments for the getChannelHistory tool.interface GetChannelHistoryArgs { channel_id: string; limit?: number; }
- index.ts:567-582 (registration)Tool registration in the ListToolsRequest handler, where getChannelHistoryTool is included in the list of available tools.server.setRequestHandler(ListToolsRequestSchema, async () => { console.log("Received ListToolsRequest"); return { tools: [ listChannelsTool, postMessageTool, replyToThreadTool, addReactionTool, getChannelHistoryTool, getThreadRepliesTool, getUsersTool, getUserProfileTool, lookupUserByEmailTool, ], }; });