Skip to main content
Glama

Slack MCP Server

by MNizarSall
MIT License

Slack MCP 服务器

一个模型上下文协议 (MCP) 服务器,使 AI 助手能够与 Slack 工作区交互。该服务器通过 Slack API 提供阅读消息、发布消息、管理频道等功能。

特征

  • 频道管理:列出频道、获取频道信息、创建频道
  • 消息操作:发送消息、阅读消息历史记录、回复帖子
  • 用户管理:获取用户信息,列出工作区成员
  • 文件操作:上传文件、在频道中分享文件
  • 搜索:在工作区中搜索消息和文件
  • 反应:添加和删除对消息的表情符号反应

先决条件

  • Python 3.8 或更高版本
  • 具有管理员权限的 Slack 工作区
  • 具有适当范围的 Slack Bot Token

安装

  1. 克隆此存储库:
git clone <repository-url> cd slack-mcp-server
  1. 安装依赖项:
pip install -r requirements.txt
  1. 设置您的 Slack Bot Token(请参阅下面的配置部分)

配置

设置 Slack Bot 令牌

  1. 转到Slack API并创建一个新应用程序
  2. 导航至侧边栏中的“OAuth 和权限”
  3. 添加以下机器人令牌范围:
    • channels:read - 查看公共频道的基本信息
    • channels:write - 管理公共频道
    • chat:write - 以机器人身份发送消息
    • chat:write.public - 向机器人不属于的频道发送消息
    • files:read - 查看在频道和对话中共享的文件
    • files:write上传、编辑和删除文件
    • groups:read - 查看私人频道的基本信息
    • im:read - 查看直接消息的基本信息
    • mpim:read - 查看群组直接消息的基本信息
    • reactions:read - 查看表情符号反应及其相关内容
    • reactions:write - 添加和编辑表情符号反应
    • search:read搜索消息和文件
    • users:read - 查看工作区中的人员
    • channels:history - 查看公共频道中的消息和其他内容
    • groups:history - 查看私人频道中的消息和其他内容
    • im:history - 查看直接消息中的消息和其他内容
    • mpim:history - 查看群组直接消息中的消息和其他内容
  4. 将应用程序安装到您的工作区
  5. 复制“Bot User OAuth Token”(以xoxb-开头)

环境变量

将您的 Slack Bot Token 设置为环境变量:

export SLACK_BOT_TOKEN="xoxb-your-bot-token-here"

或者在项目根目录中创建一个.env文件:

SLACK_BOT_TOKEN=xoxb-your-bot-token-here

用法

运行服务器

python slack_mcp_server.py

服务器将启动并通过 stdio 监听 MCP 连接。

与 Claude Desktop 一起使用

将以下配置添加到您的 Claude Desktop 配置文件:

{ "mcpServers": { "slack": { "command": "python", "args": ["/path/to/slack_mcp_server.py"], "env": { "SLACK_BOT_TOKEN": "xoxb-your-bot-token-here" } } } }

可用工具

该服务器提供以下工具:

渠道运营
  • list_channels() - 列出工作区中的所有频道
  • get_channel_info(channel_id) - 获取有关频道的详细信息
  • create_channel(name, is_private=False) -创建新频道
消息操作
  • send_message(channel, text, thread_ts=None) - 向频道发送消息
  • get_channel_history(channel, limit=10) - 获取频道的最新消息
  • search_messages(query, count=20) - 在工作区中搜索消息
用户操作
  • get_user_info(user_id) - 获取有关用户的信息
  • list_users() - 列出工作区中的所有用户
文件操作
  • upload_file(channels, content, filename, title=None) - 将文件上传到频道
  • search_files(query, count=20) - 在工作区中搜索文件
反应操作
  • add_reaction(channel, timestamp, name) - 在消息中添加表情符号反应
  • remove_reaction(channel, timestamp, name) - 从消息中删除表情符号反应

示例

发送消息

# Through Claude Desktop or other MCP client "Send a message to #general saying 'Hello from the MCP server!'"

获取频道历史记录

# Get the last 5 messages from a channel "Get the last 5 messages from the #development channel"

搜索消息

# Search for messages containing specific keywords "Search for messages containing 'deployment' in the last week"

创建频道

# Create a new public channel "Create a new channel called 'mcp-testing' for testing the MCP integration"

错误处理

该服务器包括针对以下方面的全面错误处理:

  • 无效的 Slack 令牌
  • 速率限制
  • 网络连接问题
  • 无效的频道/用户 ID
  • 权限错误

安全注意事项

  • 安全存储您的 Slack Bot Token,切勿将其提交到版本控制
  • 使用环境变量或安全秘密管理
  • 定期轮换你的机器人代币
  • 监控 Slack 工作区中的机器人活动
  • 仅授予所需的最低权限

贡献

  1. 分叉存储库
  2. 创建功能分支
  3. 进行更改
  4. 如果适用,添加测试
  5. 提交拉取请求

执照

该项目根据 MIT 许可证获得许可 - 有关详细信息,请参阅 LICENSE 文件。

支持

对于问题和疑问:

  1. 查看Slack API 文档
  2. 查看MCP 规范
  3. 在此存储库中打开一个问题
-
security - not tested
A
license - permissive license
-
quality - not tested

使 AI 助手能够通过模型上下文协议与 Slack 工作区进行交互,提供读取/发送消息、管理频道和访问 Slack API 功能的工具。

  1. 特征
    1. 先决条件
      1. 安装
        1. 配置
          1. 设置 Slack Bot 令牌
          2. 环境变量
        2. 用法
          1. 运行服务器
          2. 与 Claude Desktop 一起使用
          3. 可用工具
        3. 示例
          1. 发送消息
          2. 获取频道历史记录
          3. 搜索消息
          4. 创建频道
        4. 错误处理
          1. 安全注意事项
            1. 贡献
              1. 执照
                1. 支持

                  Related MCP Servers

                  • A
                    security
                    A
                    license
                    A
                    quality
                    Enables interaction with Slack workspaces as a user, supporting channel listing, message posting, threading, reactions, and user management via the Slack API.
                    Last updated -
                    8
                    3
                    JavaScript
                    MIT License
                  • A
                    security
                    A
                    license
                    A
                    quality
                    Enables AI models to interact with messages from various messaging platforms (Mobile, Mail, WhatsApp, LinkedIn, Slack, Twitter, Telegram, Instagram, Messenger) through a standardized interface.
                    Last updated -
                    3
                    3
                    Python
                    MIT License
                    • Linux
                  • A
                    security
                    A
                    license
                    A
                    quality
                    A Model Context Protocol server that enables AI assistants to interact with the HackMD API for managing notes, including creating, reading, updating, and deleting notes.
                    Last updated -
                    12
                    122
                    21
                    TypeScript
                    MIT License
                  • -
                    security
                    A
                    license
                    -
                    quality
                    A Model Context Protocol server implementation that enables AI assistants to interact with Slack workspaces, allowing them to browse channels, send messages, reply to threads, add reactions, and retrieve user information.
                    Last updated -
                    18
                    JavaScript
                    Apache 2.0

                  View all related MCP servers

                  MCP directory API

                  We provide all the information about MCP servers via our MCP API.

                  curl -X GET 'https://glama.ai/api/mcp/v1/servers/MNizarSall/Slack-MCP'

                  If you have feedback or need assistance with the MCP directory API, please join our Discord server