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
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。