slack-mcp-server

repository·master·Indexed 23 days ago

https://github.com/korotovsky/slack-mcp-server

A Model Context Protocol (MCP) server that enables AI agents to interact with Slack workspaces. It supports Stdio, SSE, and HTTP transport protocols and offers multiple authentication modes, including OAuth, bot tokens, and a 'stealth mode' using browser session tokens. Key capabilities include fetching channel and thread history, searching messages, managing unread messages, handling user groups, and accessing workspace metadata via URI resources.

Tokens
10.8K
Snippets
9
Records
47
Agent score
80%

What's inside slack-mcp-server

  1. Overview of Slack MCP Server features

    master

    The Slack MCP Server is a Model Context Protocol (MCP) server designed for Slack Workspaces. It supports multiple transport protocols (Stdio, SSE, and HTTP) and offers advanced features for interacting with Slack data through an AI agent or MCP client.

    Key capabilities include:

    • Stealth and OAuth Modes: Run in 'stealth mode' without requiring additional permissions or bot installations, or use OAuth tokens for secure access.
    • Channel and Thread Interaction: Fetch messages from channels and threads using names (e.g., #general) or IDs.
    • Smart History: Retrieve message history using pagination by date (e.g., d1, 7d, 1m) or by message count.
    • Unread Messages: Efficiently retrieve unread messages with priority sorting (DMs > partner channels > internal) and support for marking messages as read.
    • Search: Search messages across channels, threads, and DMs using filters like date, user, and content.
    • Safe Message Posting: The conversations_add_message tool is disabled by default for safety and must be explicitly enabled.
    • DM and Group DM Support: Full support for retrieving direct messages and group direct messages.
    • Enterprise Support: Compatible with Enterprise Slack setups.
    • Performance: Includes cache support for users and channels to speed up access.
  2. How tool registration and permissions work

    master

    Tools in the Slack MCP Server are controlled by two distinct layers: Registration and Runtime Permissions.

    1. Registration (SLACK_MCP_ENABLED_TOOLS)

    This determines which tools are visible to the MCP client.

    • Usergroups tools are registered by default.
    • Write tools (conversations_add_message, reactions_add, reactions_remove, attachment_get_data) are NOT registered by default to prevent accidental exposure. To enable them, you must either set their specific environment variable (e.g., SLACK_MCP_ADD_MESSAGE_TOOL) or explicitly list them in SLACK_MCP_ENABLED_TOOLS.

    2. Runtime Permissions (Tool-specific env vars)

    Even if a tool is registered, it may have channel restrictions.

    • Using SLACK_MCP_ADD_MESSAGE_TOOL allows you to restrict message posting to specific channels (e.g., C123,C456) or use ! to exclude specific channels.

    Behavior Matrix

    ENABLED_TOOLSTool-specific env varWrite tool registered?Channel restrictions
    empty/not setnot setNoN/A
    empty/not settrueYesNone
    empty/not setC123,C456YesOnly listed channels
    includes toolnot setYesNone
    includes toolC123,C456YesOnly listed channels
    excludes toolanyNoN/A
    # Example 1: Read-only mode (default)
    {
      "env": {
        "SLACK_MCP_XOXP_TOKEN": "xoxp-..."
      }
    }
    
    # Example 2: Enable messaging to specific channels
    {
      "env": {
        "SLACK_MCP_XOXP_TOKEN": "xoxp-...",
        "SLACK_MCP_ADD_MESSAGE_TOOL": "C123456789,C987654321"
      }
    }
    
    # Example 3: Enable messaging without channel restrictions
    {
      "env": {
        "SLACK_MCP_XOXP_TOKEN": "xoxp-...",
        "SLACK_MCP_ENABLED_TOOLS": "conversations_history,conversations_add_message,reactions_add"
      }
    }
  3. Understand Slack MCP Server Cache and Limitations

    master

    The server uses local cache files for users and channels to avoid repeated API calls on startup. The presence or absence of these caches affects functionality:

    • No Caches: channels_list is non-functional. conversations_* tools have limited capabilities; you cannot search or retrieve messages by @userHandle or #channel-name.
    • Users Cache Only: channels_list is non-functional. conversations_* tools have limited capabilities (no @userHandle or #channel-name support).
    • Both Caches Present: Fully functional server with no limitations.

    Default Cache Paths:

    • macOS: ~/Library/Caches/slack-mcp-server/
    • Linux: ~/.cache/slack-mcp-server/
    • Windows: %LocalAppData%/slack-mcp-server/
  4. Debug the Slack MCP Server

    master

    To debug the server, you can use the MCP Inspector with the stdio transport or inspect the logs generated by the environment (e.g., Claude Desktop).

    Run the Inspector:

    npx @modelcontextprotocol/inspector go run mcp/mcp-server.go --transport stdio

    View Logs (macOS example):

    tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
    # Run the inspector with stdio transport
    npx @modelcontextprotocol/inspector go run mcp/mcp-server.go --transport stdio
    
    # View logs
    tail -n 20 -f ~/Library/Logs/Claude/mcp*.log
  5. Configure Slack MCP Server Authentication

    master

    The Slack MCP Server requires authentication to interact with Slack APIs. You must provide at least one of the following sets of credentials via environment variables:

    • User OAuth Token: SLACK_MCP_XOXP_TOKEN (xoxp-...)
    • Bot Token: SLACK_MCP_XOXB_TOKEN (xoxb-...). Note that bots have limited access (invited channels only, no search).
    • Browser Tokens: Both SLACK_MCP_XOXC_TOKEN (xoxc-...) and SLACK_MCP_XOXD_TOKEN (the d cookie) are required if using the browser-based authentication method.
  6. Configure User OAuth Scopes for Slack MCP

    master

    To use a User OAuth token (SLACK_MCP_XOXP_TOKEN), you must create a Slack App at api.slack.com/apps and add the following scopes under OAuth & Permissions > User Token Scopes:

    • channels:history / channels:read / channels:write
    • groups:history / groups:read
    • im:history / im:read / im:write
    • mpim:history / mpim:read / mpim:write
    • users:read
    • chat:write
    • search:read
    • usergroups:read / usergroups:write

    You can use the following App Manifest to preconfigure these permissions automatically.

    {
        "display_information": {
            "name": "Slack MCP"
        },
        "oauth_config": {
            "scopes": {
                "user": [
                    "channels:history",
                    "channels:read",
                    "groups:history",
                    "groups:read",
                    "im:history",
                    "im:read",
                    "im:write",
                    "mpim:history",
                    "mpim:read",
                    "mpim:write",
                    "users:read",
                    "chat:write",
                    "search:read",
                    "usergroups:read",
                    "usergroups:write",
                    "channels:write"
                ]
            }
        },
        "settings": {
            "org_deploy_enabled": false,
            "socket_mode_enabled": false,
            "token_rotation_enabled": false
        }
    }
  7. Configure Slack MCP Authentication

    master

    To use the Slack MCP Server, you must provide authentication tokens via environment variables. You only need one of the following methods, with priority given in this order: xoxp (User OAuth) > xoxb (Bot Token) > xoxc/xoxd (Browser Session).

    Option 1: Browser Session (Quickest, less secure)

    Use this if you want to use your existing browser login. You need to provide two environment variables:

    • SLACK_MCP_XOXC_TOKEN: Found via the browser console.
    • SLACK_MCP_XOXD_TOKEN: Found via browser cookies.

    Provides full user permissions. Requires creating a Slack App and setting specific User Token Scopes.

    • Environment Variable: SLACK_MCP_XOXP_TOKEN (starts with xoxp-).

    Option 3: Bot Token

    Provides bot-level permissions. Note that bots must be manually invited to channels to access them, and they cannot use the conversations_search_messages tool because they lack access to the search.messages API.

    • Environment Variable: SLACK_MCP_XOXB_TOKEN (starts with xoxb-).
  8. Install the Slack MCP Server

    master

    You can install the Slack MCP Server using one of the following methods depending on your environment:

    • DXT Extension: For users utilizing the DXT extension.
    • Cursor Installer: For users using the Cursor IDE.
    • npx: For running the server directly via npm without a permanent local installation.
    • Docker: For running the server in a containerized environment.

    Detailed instructions for each method can be found in the Configuration and Usage guide.

  9. Install Slack MCP Server via DXT for Claude Desktop

    master

    For Claude Desktop users, you can use the DXT extension to install the server without manual JSON editing.

    1. Download the latest .dxt file from the releases page.
    2. In Claude Desktop, go to Settings > Extensions.
    3. Drag and drop the .dxt file into the window and click "Install".
    4. Configure the following fields:
      • Authentication method: Choose xoxc/xoxd, xoxp, or xoxb.
      • Tokens: Provide the corresponding token (SLACK_MCP_XOXC_TOKEN/SLACK_MCP_XOXD_TOKEN for xoxc/xoxd, SLACK_MCP_XOXP_TOKEN for xoxp, or SLACK_MCP_XOXB_TOKEN for xoxb).
      • Add Message Tool: Enable this to allow posting messages.
      • User-Agent: Change this if using Enterprise Slack.
    5. Enable the MCP Server.
    IMPORTANT

    If you encounter startup issues, you may need to disable the bundled node in Claude Desktop to use the node from your host machine (a known DXT bug).

  10. Run Slack MCP Server via Docker

    master

    You can run the server using Docker with stdio transport.

    Using Docker CLI

    export SLACK_MCP_XOXC_TOKEN=xoxc-...
    export SLACK_MCP_XOXD_TOKEN=xoxd-...
    
    docker pull ghcr.io/korotovsky/slack-mcp-server:latest
    docker run -i --rm \
      -e SLACK_MCP_XOXC_TOKEN \
      -e SLACK_MCP_XOXD_TOKEN \
      ghcr.io/korotovsky/slack-mcp-server:latest --transport stdio

    Using Docker Compose

    wget -O docker-compose.yml https://github.com/korotovsky/slack-mcp-server/releases/latest/download/docker-compose.yml
    wget -O .env https://github.com/korotovsky/slack-mcp-server/releases/latest/download/default.env.dist
    nano .env # Edit .env file with your tokens
    docker network create app-tier
    docker-compose up -d
  11. Security best practices for Slack MCP Server

    master

    When using the Slack MCP Server, follow these security guidelines to protect your workspace:

    • Never share API tokens: Treat your Slack API tokens as highly sensitive credentials.
    • Secure .env files: Ensure that any .env files containing configuration or credentials are kept secure and private. Do not commit them to version control.