Slack MCP Server
Integrates AI assistants with Slack workspaces using OAuth 2.0 authenticated user tokens for secure, multi-functional interaction. It enables comprehensive operations including channel management, message searching, file handling, and reaction management through natural language.
README
Slack MCP Server
A Model Context Protocol (MCP) server for Slack API integration. This server allows AI assistants to interact with Slack workspaces through OAuth 2.0 authenticated user tokens.
Features
- Channel Operations: List channels, get channel info, get channel members
- Message Operations: Read messages, send messages, reply to threads, search messages
- User Operations: List users, get user info, get user profiles
- File Operations: List files, get file info, upload files
- Reaction Operations: Add/remove reactions, get message reactions
Prerequisites
- Node.js 18+
- A Slack App with OAuth 2.0 configured
- User token (xoxp-...) with appropriate scopes
Installation
npm install
npm run build
Slack App Setup
1. Create a Slack App
- Go to api.slack.com/apps
- Click "Create New App" → "From scratch"
- Enter app name and select workspace
2. Configure OAuth Scopes
Add these User Token Scopes under "OAuth & Permissions":
channels:read # List channels
channels:history # Read channel messages
groups:read # List private channels
groups:history # Read private channel messages
im:read # List direct messages
im:history # Read direct messages
mpim:read # List group DMs
mpim:history # Read group DMs
chat:write # Send messages
users:read # List users
users.profile:read # Read user profiles
files:read # List files
files:write # Upload files
reactions:read # Read reactions
reactions:write # Add/remove reactions
search:read # Search messages
3. Configure Redirect URI
Add your platform's callback URL under "OAuth & Permissions" → "Redirect URLs":
https://your-platform.com/oauth/slack/callback
4. Get Client Credentials
Note down your:
- Client ID
- Client Secret
Environment Variables
The MCP server reads credentials from environment variables:
# Required
SLACK_ACCESS_TOKEN=xoxp-your-user-token
# Optional
SLACK_TEAM_ID=T0123456789
OAuth 2.0 Flow (Platform Implementation)
Step 1: Redirect User to Slack Authorization
const SLACK_CLIENT_ID = 'your-client-id';
const REDIRECT_URI = 'https://your-platform.com/oauth/slack/callback';
const SCOPES = 'channels:read,channels:history,chat:write,users:read,files:read,files:write,reactions:read,reactions:write,search:read,groups:read,groups:history,im:read,im:history,mpim:read,mpim:history,users.profile:read';
const authUrl = `https://slack.com/oauth/v2/authorize?client_id=${SLACK_CLIENT_ID}&user_scope=${SCOPES}&redirect_uri=${encodeURIComponent(REDIRECT_URI)}&state=${generateRandomState()}`;
// Redirect user to authUrl
Step 2: Handle OAuth Callback
// In your callback handler
app.get('/oauth/slack/callback', async (req, res) => {
const { code, state } = req.query;
// Verify state to prevent CSRF
if (!verifyState(state)) {
return res.status(400).send('Invalid state');
}
// Exchange code for token
const response = await fetch('https://slack.com/api/oauth.v2.access', {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
body: new URLSearchParams({
client_id: SLACK_CLIENT_ID,
client_secret: SLACK_CLIENT_SECRET,
code,
redirect_uri: REDIRECT_URI,
}),
});
const data = await response.json();
if (data.ok) {
// Save user token to your database
const userToken = data.authed_user.access_token; // xoxp-...
const userId = data.authed_user.id;
const teamId = data.team.id;
await db.saveSlackToken(currentUserId, {
token: userToken,
slackUserId: userId,
teamId: teamId,
});
res.redirect('/success');
} else {
res.status(400).send(`OAuth error: ${data.error}`);
}
});
Step 3: Start MCP Server with User Token
// When starting the MCP server for a user, inject their token as env var
const userSlackToken = await db.getSlackToken(currentUserId);
const mcpProcess = spawn('node', ['/path/to/slack-mcp/dist/index.js'], {
env: {
...process.env,
SLACK_ACCESS_TOKEN: userSlackToken,
},
});
MCP Configuration
Add to your Claude Code configuration (~/.claude/claude_desktop_config.json):
{
"mcpServers": {
"slack": {
"command": "node",
"args": ["/path/to/slack-mcp/dist/index.js"],
"env": {
"SLACK_ACCESS_TOKEN": "xoxp-your-token"
}
}
}
}
Available Tools
Channel Tools
| Tool | Description |
|---|---|
slack_list_channels |
List all accessible channels |
slack_get_channel_info |
Get channel details |
slack_get_channel_members |
Get channel member list |
Message Tools
| Tool | Description |
|---|---|
slack_get_messages |
Get messages from a channel |
slack_get_thread_replies |
Get replies in a thread |
slack_send_message |
Send a message to a channel |
slack_reply_to_thread |
Reply to a thread |
slack_search_messages |
Search messages (requires user token) |
User Tools
| Tool | Description |
|---|---|
slack_list_users |
List workspace users |
slack_get_user_info |
Get user details |
slack_get_user_profile |
Get user profile |
File Tools
| Tool | Description |
|---|---|
slack_list_files |
List shared files |
slack_get_file_info |
Get file details |
slack_upload_file |
Upload a file |
Reaction Tools
| Tool | Description |
|---|---|
slack_add_reaction |
Add emoji reaction |
slack_remove_reaction |
Remove emoji reaction |
slack_get_reactions |
Get message reactions |
Example Usage
List Channels
{
"tool": "slack_list_channels",
"arguments": {
"types": "public_channel,private_channel",
"limit": 50
}
}
Send Message
{
"tool": "slack_send_message",
"arguments": {
"channel_id": "C1234567890",
"text": "Hello from MCP!"
}
}
Search Messages
{
"tool": "slack_search_messages",
"arguments": {
"query": "from:@user in:#channel important",
"count": 20
}
}
Error Handling
The server returns structured error responses:
{
"error": "Slack API Error (invalid_auth): Invalid authentication token."
}
Common error codes:
invalid_auth: Token is invalidtoken_revoked: Token has been revokedmissing_scope: Token lacks required scopechannel_not_found: Channel doesn't existratelimited: Rate limit exceeded
Security Considerations
- Never expose user tokens in client-side code
- Store tokens securely in your database (encrypted)
- Use HTTPS for all OAuth redirects
- Validate state parameter to prevent CSRF
- Rotate tokens periodically using refresh tokens
- Request only necessary scopes
License
MIT
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。