Skip to main content
Glama
sdancy10

Slack MCP Server

by sdancy10
README.md
# Slack MCP Server

MCP server for Slack API integration with HTTP transport.

## Authentication Methods

### Option 1: Bot/User Token (Recommended)

Standard Slack API tokens. Requires a Slack app with appropriate scopes.

```bash
export SLACK_TOKEN=xoxb-your-bot-token
# or
export SLACK_TOKEN=xoxp-your-user-token
```

### Option 2: Cookie-Based Auth (User Impersonation)

Uses browser session cookies to impersonate a logged-in user. Useful when:
- You don't have admin approval for a Slack app
- You need to act as a specific user
- You want to access private channels the user is a member of

#### Extracting Tokens from Chrome

1. **Open Chrome DevTools** on your Slack workspace:
   - Navigate to `https://your-workspace.slack.com`
   - Press `F12` or right-click → "Inspect"
   - Go to the **Application** tab

2. **Get the `xoxc` token:**
   - In DevTools, go to **Console** tab
   - Paste and run:
     ```javascript
     JSON.parse(localStorage.localConfig_v2).teams[Object.keys(JSON.parse(localStorage.localConfig_v2).teams)[0]].token
     ```
   - Copy the `xoxc-...` token

3. **Get the `xoxd` cookie:**
   - In DevTools, go to **Application** → **Cookies** → `https://your-workspace.slack.com`
   - Find the cookie named `d`
   - Copy the **Value** (starts with `xoxd-...`)
   - ⚠️ The value is URL-encoded — keep it as-is

4. **Get workspace details:**
   - **Team ID**: In Console, run:
     ```javascript
     JSON.parse(localStorage.localConfig_v2).teams[Object.keys(JSON.parse(localStorage.localConfig_v2).teams)[0]].id
     ```
   - **User ID**: Run:
     ```javascript
     JSON.parse(localStorage.localConfig_v2).teams[Object.keys(JSON.parse(localStorage.localConfig_v2).teams)[0]].user_id
     ```
   - **Domain**: Your Slack URL (e.g., `your-workspace.slack.com`)

5. **Create your env file:**
   ```bash
   cp cookie-tokens.env.example /path/to/secrets/cookie-tokens.env
   # Edit the file with your extracted values
   ```

#### Using the Cookie Client

A shell script is provided for quick API calls:

```bash
# Set up your tokens
source /path/to/secrets/cookie-tokens.env

# Test authentication
./scripts/slack-cookie-client.sh auth

# List channels
./scripts/slack-cookie-client.sh channels 20

# Get channel history
./scripts/slack-cookie-client.sh history C0123ABCDEF 10

# Send a message
./scripts/slack-cookie-client.sh send C0123ABCDEF "Hello from the script!"

# Search messages
./scripts/slack-cookie-client.sh search "keyword"

# List users
./scripts/slack-cookie-client.sh users 50
```

#### Token Expiration

Cookie tokens expire when:
- You log out of Slack in the browser
- You change your password
- Slack rotates session tokens (typically every few weeks)

When tokens expire, repeat the extraction process.

---

## Setup (Standard Token)

1. Get a Slack token (Bot Token `xoxb-...` or User Token `xoxp-...`)

2. Configure environment:
```bash
export SLACK_TOKEN=xoxb-your-token
```

3. Run:
```bash
npm install
npm run start:http
```

## Docker

```bash
docker build -t slack-mcp .
docker run -d -p 3929:3929 -e SLACK_TOKEN=xoxb-... slack-mcp
```

## Endpoints

- `GET /health` - Health check
- `GET /tools` - List available tools
- `POST /call` - Call a tool

## Available Tools

| Tool | Description |
|------|-------------|
| `slack_list_channels` | List channels |
| `slack_get_channel_history` | Get channel messages |
| `slack_post_message` | Send a message |
| `slack_update_message` | Edit a message |
| `slack_delete_message` | Delete a message |
| `slack_add_reaction` | Add emoji reaction |
| `slack_get_user_info` | Get user details |
| `slack_list_users` | List workspace users |
| `slack_search_messages` | Search messages |

## Example

```bash
# List channels
curl -X POST http://localhost:3929/call \
  -H "Content-Type: application/json" \
  -d '{"name": "slack_list_channels", "arguments": {}}'

# Post message
curl -X POST http://localhost:3929/call \
  -H "Content-Type: application/json" \
  -d '{"name": "slack_post_message", "arguments": {"channel": "C123", "text": "Hello!"}}'
```

## Token Scopes Required

For Bot Token (`xoxb-...`):
- `channels:read`, `channels:history`
- `chat:write`
- `users:read`
- `reactions:write`
- `search:read` (for search)

For User Token (`xoxp-...`):
- Same as above, plus any additional scopes for your use case

For Cookie Auth:
- No scopes needed — inherits all permissions of the logged-in user