Skip to content
judexzhuPublic

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

7 Commits

Folders and files

Repository files navigation

Slack MCP Server

A Model Context Protocol (MCP) server that provides seamless integration with Slack workspaces. This server enables AI assistants and automation tools to search messages, read threads, parse permalinks, reply to conversations, and retrieve complete channel content from Slack.

πŸš€ Features

  • Message Search: Search across your Slack workspace with flexible query options
  • Thread Management: Retrieve complete thread conversations with all replies (accepts channel name, ID, URL, or permalink)
  • Post Messages: Start new threads or reply to existing ones
  • Channel Content: Get all messages and threads from any channel by name, ID, or URL
  • Sidebar Sections: List your custom sidebar sections and their channels

πŸ“‹ Requirements

  • Python 3.13+
  • uv package manager (recommended) or pip
  • Slack workspace access with appropriate tokens
  • MCP-compatible client (e.g., Claude Desktop, Cline, etc.)

πŸ› οΈ Installation

Using uv (Highly Recommended) πŸš€

uv is an extremely fast Python package installer and resolver, written in Rust. It's the modern way to manage Python projects and dependencies.

Why uv?

  • ⚑ 10-100x faster than pip for dependency resolution and installation
  • πŸ”’ Reliable dependency locking with uv.lock for reproducible builds
  • πŸ›‘οΈ Automatic virtual environment management - no manual venv setup needed
  • 🎯 Drop-in replacement for pip, pip-tools, and virtualenv
  • πŸ“¦ Better caching and parallel downloads
# Install uv (if you haven't already)
curl -LsSf https://astral.sh/uv/install.sh | sh

# Clone the repository
git clone https://github.com/judexzhu/mcp-slack.git
cd mcp-slack

# Install dependencies (automatically creates and manages virtual environment)
uv sync

# Run the server
uv run python slack_mcp_server.py

Using pip (Alternative)

If you prefer traditional pip:

# Clone the repository
git clone https://github.com/judexzhu/mcp-slack.git
cd mcp-slack

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -e .

βš™οΈ Configuration

1. Slack Token Setup

You'll need two Slack tokens for authentication:

  • SLACK_XOXC_TOKEN: Session token for user authentication
  • SLACK_XOXD_TOKEN: Session token for request validation

Getting Your Tokens

  1. Open your Slack workspace in a web browser
  2. Open Developer Tools (F12)
  3. Go to the Network tab
  4. Make any request in Slack (send a message, change channel, etc.)
  5. Look for requests to slack.com/api/ endpoints
  6. In the request headers, find:
    • Authorization: Bearer xoxc-... (this is your XOXC token)
    • Cookie: d=xoxd-... (this is your XOXD token)

2. Environment Variables

Create a .env file in the project root:

SLACK_XOXC_TOKEN=xoxc-your-token-here
SLACK_XOXD_TOKEN=xoxd-your-token-here
SLACK_WORKSPACE_URL=https://your-workspace.slack.com

3. MCP Client Configuration

Claude Code (Recommended)

claude mcp add --scope user --transport stdio slack \
  -- uv run --directory /path/to/mcp-slack python slack_mcp_server.py

Set the environment variables in your shell profile (.zshrc / .bashrc) or .env file in the project root. Verify with /mcp inside a Claude Code session.

Other MCP Clients (Claude Desktop, Cline, etc.)

Add to your client's MCP config JSON:

{
  "mcpServers": {
    "slack": {
      "command": "uv",
      "args": ["run", "python", "/path/to/mcp-slack/slack_mcp_server.py"],
      "cwd": "/path/to/mcp-slack",
      "env": {
        "SLACK_XOXC_TOKEN": "xoxc-your-token-here",
        "SLACK_XOXD_TOKEN": "xoxd-your-token-here",
        "SLACK_WORKSPACE_URL": "https://your-workspace.slack.com"
      }
    }
  }
}

πŸ“– Available Tools

Core Functions

  • slack_search_messages: Search for messages across your Slack workspace with flexible query options
  • slack_get_thread_messages: Retrieve complete thread conversations -- accepts a channel name/ID/URL + thread timestamp, or a full permalink
  • slack_reply_to_thread: Post replies to existing threads with broadcast support (standard markdown rendered natively via Block Kit)
  • slack_post_message: Post a new message to any channel, starting a new thread
  • slack_get_channel_content: Get all messages and thread replies from a channel by name, ID, or URL
  • slack_list_sidebar_sections: List your custom sidebar sections and the channels in each one

🎯 Token Optimization

This server is optimized to reduce token consumption while maintaining complete information integrity:

Key Optimizations:

  • Removed redundant fields: Eliminated computed values like message_count (use messages.length), is_thread (check thread_ts presence), and duplicate preview field
  • Conditional inclusion: Only includes non-empty arrays and true boolean flags
  • Shorter field names: timestamp β†’ ts for consistency with Slack API
  • No status wrappers: Returns error field only when errors occur, not ok field on success
  • Minimal response structure: Only essential data, derivable information excluded

Expected Token Savings: 30-40% compared to standard implementations

Output Schema Examples

slack_search_messages

{
  "messages": [
    {
      "channel_id": "C08P3DY9MEU",
      "channel_name": "general",
      "text": "Full message text",
      "ts": "1746036342.129679",
      "thread_ts": "1746036342.129679",  // Only if part of thread
      "user": "U1234567890",              // Only if present
      "username": "john.doe",             // Only if present
      "permalink": "https://..."          // Only if present
    }
  ]
}

slack_get_thread_messages

{
  "channel_id": "C08P3DY9MEU",
  "thread_ts": "1746036342.129679",
  "messages": [
    {
      "user": "U1234567890",
      "text": "Message text",
      "ts": "1746036342.129679",
      "reactions": [...],        // Only if present
      "attachments": [...],      // Only if present
      "files": [...]             // Only if present
    }
  ],
  "has_more": true               // Only if true
}

Error Response

{
  "error": "Error message",
  "messages": []                 // Partial data if available
}

πŸ–₯️ CLI Usage

The slk CLI lets you interact with Slack from the command line.

Install

# Local (in project)
uv sync

# Global
uv tool install . --force --reinstall

Commands

# Search messages
slk search "error in:#general" --count 10
slk search "from:@username" -o table

# Read a thread (permalink or channel + timestamp)
slk thread "https://workspace.slack.com/archives/C01234567/p1746036342129679"
slk thread C01234567 --thread-ts 1746036342.129679

# Reply to a thread
slk reply C01234567 1746036342.129679 "Thanks for the update"

# Post a new message
slk post general "Hello team"

# Get channel content
slk channel general --limit 50

# List sidebar sections
slk sections --name Adobe -o table

All commands support --output/-o json (default), --output/-o table, or --output/-o markdown.

Run slk --help for full details on all commands and options.

Claude Code Skill

A Claude Code skill is included at skills/mcp-slack/SKILL.md to teach AI agents how to use the CLI effectively.

πŸ”§ Development

Project Structure

mcp-slack/
β”œβ”€β”€ mcp_slack/
β”‚   β”œβ”€β”€ __init__.py         # Package version
β”‚   β”œβ”€β”€ client.py           # SlackClient class (auth + HTTP)
β”‚   β”œβ”€β”€ tools.py            # Business logic (async functions)
β”‚   β”œβ”€β”€ server.py           # FastMCP tool wrappers + main()
β”‚   └── cli.py              # Click-based CLI
β”œβ”€β”€ slack_mcp_server.py     # Backward-compat MCP entry point
β”œβ”€β”€ test_slack_tools.py     # Test suite
β”œβ”€β”€ skills/mcp-slack/
β”‚   └── SKILL.md            # Claude Code skill docs
β”œβ”€β”€ pyproject.toml          # Project configuration
β”œβ”€β”€ uv.lock                 # Lock file for dependencies
└── README.md               # This file

Key Components

  • client.py: SlackClient class β€” authentication, HTTP requests via httpx.AsyncClient
  • tools.py: All business logic as async functions, lazy client via get_client() singleton
  • server.py: @mcp.tool() thin wrappers delegating to tools.py, MCP server entry point
  • cli.py: Click CLI with matching commands for each tool
  • slack_mcp_server.py: Re-exports mcp for backward-compatible MCP discovery

⚠️ Security Notes

  • Keep your Slack tokens secure and never commit them to version control
  • Use environment variables or secure secret management
  • Tokens provide full access to your Slack workspace - handle with care
  • Consider using restricted tokens if available for your use case

About

No description, website, or topics provided.

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages