Slack MCP Server
Provides complete Slack Web API integration with 9 tools for reading messages, managing channels, searching content, and interacting with Slack workspaces.
README
Slack MCP Server
A comprehensive Model Context Protocol (MCP) server providing complete Slack Web API integration with 9 tools for reading messages, managing channels, searching content, and interacting with Slack workspaces.
Features
Channel Operations (5 tools)
- List all channels you're a member of
- Get message history from channels
- Get detailed channel information
- Search messages across all channels
- Post messages to channels and threads
User Operations (4 tools)
- Get user profile information
- List all workspace users
- Get thread replies
- Get messages where you were mentioned
Prerequisites
- Python 3.12 or higher
- Slack workspace with user token access
- Slack User OAuth Token with appropriate scopes
Installation
- Install dependencies using uv:
cd /Users/dimay/mcp/slack_mcp
uv sync
Configuration
Getting a Slack User Token
You have two options:
Option 1: Create a Slack App (Recommended)
-
Go to https://api.slack.com/apps and create a new app
-
Under OAuth & Permissions, add these User Token Scopes:
channels:history- View messages in public channelschannels:read- View basic public channel infogroups:history- View messages in private channelsgroups:read- View basic private channel infoim:history- View direct messagesmpim:history- View group direct messagesusers:read- View users in workspacesearch:read- Search workspace contentchat:write- Send messages (optional, for posting)
-
Install the app to your workspace and authorize it
-
Copy the User OAuth Token (starts with
xoxp-)
Option 2: Extract Token from Browser (Quick but Less Secure)
- Open Slack in your web browser (https://app.slack.com)
- Open Developer Tools (F12)
- Go to Console tab
- Run:
TS.boot_data.api_token - Copy the token (starts with
xoxc-)
Note: Browser tokens may expire and are less secure. Use OAuth method for production.
Set Environment Variables
The server supports two authentication methods:
Method 1: Browser Token + Cookie (Quick)
- Open Slack in your browser (https://app.slack.com)
- Open Developer Tools (F12) → Console
- Run:
TS.boot_data.api_tokento get your token (starts withxoxc-) - Go to Application/Storage tab → Cookies → https://app.slack.com
- Find cookie named
dand copy its value (starts withxoxd-) - Add both to your shell profile (~/.zshrc):
export SLACK_USER_TOKEN="xoxc-your-token-here"
export SLACK_USER_COOKIE="xoxd-your-cookie-here"
Then run: source ~/.zshrc
Note: Browser tokens may expire with your browser session.
Method 2: OAuth Token (Recommended for Production)
export SLACK_USER_TOKEN="xoxp-your-oauth-token-here"
OAuth tokens (from creating a Slack App) don't require a cookie and are more reliable.
Usage
Running the MCP Server
cd /Users/dimay/mcp/slack_mcp
uv run slack_mcp_server.py
Configuring with Claude Code
Add to your Claude Code MCP settings:
For Browser Token (xoxc-):
{
"mcpServers": {
"slack": {
"command": "uv",
"args": ["run", "slack_mcp_server.py"],
"cwd": "/Users/dimay/mcp/slack_mcp",
"env": {
"SLACK_USER_TOKEN": "xoxc-your-token-here",
"SLACK_USER_COOKIE": "xoxd-your-cookie-here"
}
}
}
}
For OAuth Token (xoxp-):
{
"mcpServers": {
"slack": {
"command": "uv",
"args": ["run", "slack_mcp_server.py"],
"cwd": "/Users/dimay/mcp/slack_mcp",
"env": {
"SLACK_USER_TOKEN": "xoxp-your-token-here"
}
}
}
}
Alternatively, if you've set the environment variables in your shell profile, you can omit the env section entirely.
Available Tools (9 Total)
Channel Operations
slack_list_channels
List all channels you're a member of.
Parameters:
types(optional): Comma-separated types (default: "public_channel,private_channel")- Options:
public_channel,private_channel,mpim,im
- Options:
exclude_archived(optional): Exclude archived channels (default: true)limit(optional): Maximum channels to return (default: 1000)
Returns: List of channels with ID, name, member count, topic, and purpose
Example:
{
"types": "public_channel,private_channel",
"exclude_archived": true
}
slack_get_channel_history
Get messages from a specific channel.
Parameters:
channel_id(required): Channel ID (e.g., "C1234567890")limit(optional): Number of messages (max 1000, default: 100)oldest(optional): Unix timestamp - only messages after this timelatest(optional): Unix timestamp - only messages before this time
Returns: List of messages with user, text, and timestamp
Example:
{
"channel_id": "C1234567890",
"limit": 50
}
slack_get_channel_info
Get detailed information about a channel.
Parameters:
channel_id(required): Channel ID
Returns: Channel details including name, topic, purpose, creator, member count
slack_search_messages
Search for messages across all channels.
Parameters:
query(required): Search query (supports Slack search syntax)count(optional): Number of results (max 100, default: 20)sort(optional): Sort by "timestamp" or "score" (default: "timestamp")sort_dir(optional): "asc" or "desc" (default: "desc")
Returns: Matching messages with channel context and permalinks
Search Examples:
from:@username- Messages from specific userin:#channel-name- Messages in specific channelduring:2024-01- Messages during January 2024has:link- Messages containing links"exact phrase"- Exact phrase match
slack_post_message
Post a message to a channel.
Parameters:
channel_id(required): Channel IDtext(required): Message text (supports Slack markdown)thread_ts(optional): Thread timestamp to reply to
Returns: Posted message confirmation with timestamp
Note: Requires chat:write scope
User Operations
slack_get_user_info
Get information about a specific user.
Parameters:
user_id(required): User ID (e.g., "U1234567890")
Returns: User profile with name, email, title, status, and admin flags
slack_list_users
List all users in the workspace.
Parameters:
limit(optional): Maximum users to return (default: 1000)
Returns: List of active users with profile information
slack_get_thread_replies
Get all replies in a thread.
Parameters:
channel_id(required): Channel IDthread_ts(required): Thread timestamp (parent message ts)limit(optional): Maximum replies (default: 100)
Returns: All messages in the thread
slack_get_mentions
Get messages where you were mentioned.
Parameters:
hours(optional): Look back this many hours (default: 24)count(optional): Number of results to return (max 100, default: 20)
Returns: Messages mentioning you with channel context and permalinks
Example:
{
"hours": 24,
"count": 10
}
Use Cases:
- "What did I miss while I was away?"
- "Where was I mentioned today?"
- "Show me all mentions from the last week"
Common Workflows
Reading Channel Messages
1. List your channels:
Tool: slack_list_channels
2. Find the channel you want (note the channel ID)
3. Get messages from that channel:
Tool: slack_get_channel_history
channel_id: "C1234567890"
limit: 100
Searching for Information
1. Search across all channels:
Tool: slack_search_messages
query: "bug report from:@john"
count: 20
2. Get user details if needed:
Tool: slack_get_user_info
user_id: "U1234567890"
Reading Thread Conversations
1. Get channel history to find a thread:
Tool: slack_get_channel_history
channel_id: "C1234567890"
2. Get all replies in a specific thread:
Tool: slack_get_thread_replies
channel_id: "C1234567890"
thread_ts: "1234567890.123456"
Posting Messages
1. List channels to find where to post:
Tool: slack_list_channels
2. Post a message:
Tool: slack_post_message
channel_id: "C1234567890"
text: "Hello from MCP!"
3. Reply to a thread:
Tool: slack_post_message
channel_id: "C1234567890"
text: "Reply message"
thread_ts: "1234567890.123456"
Catching Up on Mentions
1. Check mentions from the last 24 hours:
Tool: slack_get_mentions
hours: 24
count: 20
2. Check mentions from the last week:
Tool: slack_get_mentions
hours: 168
count: 50
Understanding Slack IDs
Slack uses unique IDs for different objects:
- Channel IDs: Start with
C(e.g.,C1234567890) - User IDs: Start with
U(e.g.,U1234567890) - Direct Message IDs: Start with
D(e.g.,D1234567890) - Group DM IDs: Start with
G(e.g.,G1234567890) - Message Timestamps: Unix timestamps (e.g.,
1234567890.123456)
Slack Search Syntax
The slack_search_messages tool supports advanced search operators:
from:@username- Messages from specific userin:#channel- Messages in specific channelto:@username- Direct messages to useron:YYYY-MM-DD- Messages on specific datebefore:YYYY-MM-DD- Messages before dateafter:YYYY-MM-DD- Messages after dateduring:YYYY-MM- Messages during monthhas:link- Messages with linkshas:pin- Pinned messageshas::emoji:- Messages with specific reaction"exact phrase"- Exact phrase match-word- Exclude messages with word
Troubleshooting
Authentication Issues
Error: "SLACK_USER_TOKEN environment variable not set"
- Set the environment variable:
export SLACK_USER_TOKEN="xoxp-..." - Check your shell profile if it's not persisting
Error: "invalid_auth"
- Your token may be expired or invalid
- Create a new token using the OAuth method
- Ensure you copied the full token (they're quite long)
Permission Errors
Error: "missing_scope"
- Your token doesn't have required permissions
- Add the necessary scopes to your Slack App
- Reinstall the app to your workspace to apply new scopes
Error: "channel_not_found"
- The channel ID is incorrect
- You're not a member of that channel
- Use
slack_list_channelsto find valid channel IDs
Rate Limiting
Slack has rate limits:
- Tier 3 methods (reading): 50+ requests per minute
- Tier 2 methods (posting): 20+ requests per minute
If you hit rate limits, wait a minute before retrying.
Development
Project Structure
slack_mcp/
├── slack_mcp_server.py # Main MCP server (8 tools)
├── pyproject.toml # Project dependencies
├── .gitignore # Git ignore rules
├── .python-version # Python version specification
└── README.md # This file
Architecture
The server is organized into sections:
- Shared Utilities: Slack client, error handling, message formatting
- Channel Operations: Channel listing, history, search, posting
- User Operations: User info, workspace members, threads
- MCP Handlers: Tool registration and execution
Error Handling
All tools provide consistent error responses with:
- Clear error messages from Slack API
- Detailed error information
- Helpful suggestions for resolution
Security Best Practices
- Never commit tokens - Use environment variables
- Use OAuth tokens - More secure than browser tokens
- Minimum scopes - Only request permissions you need
- Rotate tokens - Regenerate tokens periodically
- Monitor usage - Check Slack App dashboard for suspicious activity
Version History
v0.1.0 (Current)
- Initial release with 8 tools
- Channel operations (list, history, info, search, post)
- User operations (info, list, threads)
- Complete Slack Web API integration
- Support for public/private channels and DMs
License
MIT
Related Resources
Recommended Servers
playwright-mcp
A Model Context Protocol server that enables LLMs to interact with web pages through structured accessibility snapshots without requiring vision models or screenshots.
Magic Component Platform (MCP)
An AI-powered tool that generates modern UI components from natural language descriptions, integrating with popular IDEs to streamline UI development workflow.
Audiense Insights MCP Server
Enables interaction with Audiense Insights accounts via the Model Context Protocol, facilitating the extraction and analysis of marketing insights and audience data including demographics, behavior, and influencer engagement.
VeyraX MCP
Single MCP tool to connect all your favorite tools: Gmail, Calendar and 40 more.
graphlit-mcp-server
The Model Context Protocol (MCP) Server enables integration between MCP clients and the Graphlit service. Ingest anything from Slack to Gmail to podcast feeds, in addition to web crawling, into a Graphlit project - and then retrieve relevant contents from the MCP client.
Kagi MCP Server
An MCP server that integrates Kagi search capabilities with Claude AI, enabling Claude to perform real-time web searches when answering questions that require up-to-date information.
E2B
Using MCP to run code via e2b.
Neon Database
MCP server for interacting with Neon Management API and databases
Exa Search
A Model Context Protocol (MCP) server lets AI assistants like Claude use the Exa AI Search API for web searches. This setup allows AI models to get real-time web information in a safe and controlled way.
Qdrant Server
This repository is an example of how to create a MCP server for Qdrant, a vector search engine.