feat: Add conversations_unread tool to check for unread messages #163
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
This PR adds a new
conversations_unreadtool that lets users quickly check which channels and DMs have unread messages.The Problem
I wanted to use Claude Code to check if I had any unread Slack messages before diving into work. The existing MCP server has great tools for reading conversations and sending messages, but no way to see which conversations need attention.
What I Tried
My first attempt used the
conversations.infoAPI to get unread counts for each channel individually. This worked but was way too slow - it made N API calls (one per channel), which caused timeouts when you have hundreds of channels.The Solution
I discovered the
client.countsedge API that's already used elsewhere in this codebase. It returns unread status for all channels in a single API call. Much faster!Trade-off: The
client.countsAPI only returnsHasUnreads: true/false, not the actual unread count. So the tool reportsUnreadCount: 1for any channel with unreads. If exact counts are needed, that would require the slower per-channel approach.Changes
pkg/provider/api.go: AddedClientCountsmethod to theSlackAPIinterface andMCPSlackClientpkg/handler/conversations.go: AddedConversationsUnreadHandlerandUnreadChannelstructpkg/server/server.go: Registered the newconversations_unreadtoolUsage
Returns CSV with columns:
ChannelID,ChannelName,UnreadCount,PurposeThe
channel_typesparameter is optional and defaults to all types.Testing
Screenshots
Example response when no unreads:
Example response with unreads: