get_channel_messages
Retrieve recent messages from a Slack channel using its ID, with an optional limit up to 100 messages.
Instructions
Read recent messages from a specific Slack channel
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| channel_id | No | Slack channel ID (e.g., C01234567). If not provided, uses the build channel. | |
| limit | No | Number of messages to retrieve (default: 10, max: 100) |
Implementation Reference
- index.js:68-86 (registration)Tool registration for 'get_channel_messages' in the ListToolsRequestSchema handler. Defines name, description, and inputSchema (channel_id and limit parameters).
{ name: "get_channel_messages", description: "Read recent messages from a specific Slack channel", inputSchema: { type: "object", properties: { channel_id: { type: "string", description: "Slack channel ID (e.g., C01234567). If not provided, uses the build channel.", }, limit: { type: "number", description: "Number of messages to retrieve (default: 10, max: 100)", default: 10, }, }, required: [], }, }, - index.js:71-86 (schema)Input schema for get_channel_messages: channel_id (string, optional, defaults to build channel) and limit (number, optional, default 10, max 100).
inputSchema: { type: "object", properties: { channel_id: { type: "string", description: "Slack channel ID (e.g., C01234567). If not provided, uses the build channel.", }, limit: { type: "number", description: "Number of messages to retrieve (default: 10, max: 100)", default: 10, }, }, required: [], }, }, - index.js:302-336 (handler)Handler for 'get_channel_messages' tool. Uses slack.conversations.history() to fetch messages from the specified channel (or build channel if not provided). Returns messages with timestamp, user, text, and bot_id fields.
case "get_channel_messages": { const channelId = args?.channel_id || buildChannelId; if (!channelId) { return { content: [ { type: "text", text: "Error: No channel_id provided and SLACK_BUILD_CHANNEL_ID not configured.", }, ], }; } const limit = Math.min(args?.limit || 10, 100); const result = await slack.conversations.history({ channel: channelId, limit: limit, }); const messages = (result.messages || []).map((msg) => ({ timestamp: new Date(parseFloat(msg.ts) * 1000).toISOString(), user: msg.user, text: msg.text?.substring(0, 500), bot_id: msg.bot_id, })); return { content: [ { type: "text", text: JSON.stringify({ messages }, null, 2), }, ], }; }