@jtalk22/slack-mcp 1.0.3 → 1.0.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -1,88 +1,188 @@
1
1
  # Slack MCP Server
2
2
 
3
- [![CI](https://github.com/jtalk22/slack-mcp-server/actions/workflows/ci.yml/badge.svg)](https://github.com/jtalk22/slack-mcp-server/actions/workflows/ci.yml)
3
+ [![npm](https://img.shields.io/npm/v/@jtalk22/slack-mcp?color=blue)](https://www.npmjs.com/package/@jtalk22/slack-mcp)
4
+ [![Docker](https://img.shields.io/badge/docker-ghcr.io-blue)](https://github.com/jtalk22/slack-mcp-server/pkgs/container/slack-mcp-server)
4
5
  [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
5
6
  [![Node.js](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen.svg)](https://nodejs.org/)
6
7
  [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](https://github.com/jtalk22/slack-mcp-server/pulls)
7
- [![GitHub Sponsors](https://img.shields.io/github/sponsors/jtalk22?style=social)](https://github.com/sponsors/jtalk22)
8
8
 
9
- A [Model Context Protocol](https://modelcontextprotocol.io/) server that gives Claude full access to your Slack workspace - including **DMs**, channels, and message history.
9
+ A [Model Context Protocol](https://modelcontextprotocol.io/) server that gives Claude **unrestricted access** to your Slack workspace - including DMs, private channels, and full message history. No OAuth. No app approval. No per-conversation authorization.
10
10
 
11
11
  <p align="center">
12
12
  <img src="docs/images/demo-main.png" alt="Slack MCP Server Web UI" width="800">
13
13
  </p>
14
14
 
15
- > **[Try the Interactive Demo](https://jtalk22.github.io/slack-mcp-server/public/demo.html)** - See the Web UI in action with mock data
15
+ > **[Try the Interactive Demo](https://jtalk22.github.io/slack-mcp-server/public/demo.html)** - See the Web UI in action
16
16
 
17
- ## Why This Exists
17
+ ---
18
18
 
19
- Official Slack integrations require OAuth and can't access DMs without explicit per-conversation authorization. This server uses your browser session tokens to provide the same access you have in Slack's web interface.
19
+ ## How It Works: The Cookie Heist
20
20
 
21
- **Works with:**
22
- - Claude Desktop (macOS/Windows)
23
- - Claude Code (CLI)
24
- - claude.ai (via Web UI)
21
+ This server bypasses Slack's OAuth entirely by extracting your browser session tokens. You already have access to everything in Slack's web interface - we just give that same access to Claude.
22
+
23
+ ```mermaid
24
+ sequenceDiagram
25
+ participant Chrome as Chrome Browser
26
+ participant Script as AppleScript
27
+ participant Store as Token Store
28
+ participant MCP as MCP Server
29
+ participant Slack as Slack API
30
+
31
+ Note over Chrome: You're logged into Slack
32
+ Script->>Chrome: Execute JavaScript in Slack tab
33
+ Chrome-->>Script: xoxc- token + xoxd- cookie
34
+ Script->>Store: Save to ~/.slack-mcp-tokens.json
35
+ Store->>Store: Encrypt in macOS Keychain
36
+
37
+ Note over MCP: Claude asks for DMs
38
+ MCP->>Store: Load credentials
39
+ Store-->>MCP: Token + Cookie
40
+ MCP->>Slack: GET conversations.history
41
+ Slack-->>MCP: Full message history
42
+ MCP-->>MCP: Return to Claude
43
+ ```
44
+
45
+ ### Why Not OAuth?
46
+
47
+ ```mermaid
48
+ flowchart LR
49
+ subgraph Traditional["Traditional Slack App (OAuth)"]
50
+ A[Create App] --> B[Request Scopes]
51
+ B --> C[Admin Approval]
52
+ C --> D[User Authorization]
53
+ D --> E[Limited Access]
54
+ E --> F["No DMs without<br/>per-conversation consent"]
55
+ end
56
+
57
+ subgraph ThisServer["This Server (Browser Tokens)"]
58
+ G[Open Slack in Chrome] --> H[Extract Session]
59
+ H --> I[Full Access]
60
+ I --> J["All DMs, Channels,<br/>Search, Everything"]
61
+ end
62
+
63
+ style Traditional fill:#ffcccc
64
+ style ThisServer fill:#ccffcc
65
+ ```
66
+
67
+ **The trade-off:** Tokens expire every 1-2 weeks, but auto-refresh keeps things running seamlessly.
68
+
69
+ ---
25
70
 
26
71
  ## Features
27
72
 
28
- - **Read Messages** - Fetch history from any DM or channel
29
- - **Full Export** - Export conversations with threads and resolved usernames
30
- - **Search** - Search messages across your workspace
31
- - **Send Messages** - Send to DMs or channels
32
- - **Auto Token Recovery** - Refreshes expired tokens from Chrome automatically
33
- - **Rate Limit Handling** - Automatic retry with exponential backoff
34
- - **Web UI** - Browser interface for use with claude.ai
73
+ ### Core Capabilities
74
+ - **Read Any Message** - DMs, private channels, public channels
75
+ - **Full Export** - Conversations with threads and resolved usernames
76
+ - **Search** - Query across your entire workspace
77
+ - **Send Messages** - DMs or channels, with thread support
78
+ - **User Directory** - List and search 500+ users with pagination
79
+
80
+ ### Stability (v1.0.6+)
81
+ - **Auto Token Refresh** - Extracts fresh tokens from Chrome automatically *(macOS only)*
82
+ - **Atomic Writes** - File operations use temp-file-then-rename to prevent corruption
83
+ - **Zombie Protection** - Background timers use `unref()` for clean process exit
84
+ - **Race Condition Safety** - Mutex locks prevent concurrent token extraction
85
+ - **Rate Limit Handling** - Exponential backoff with jitter
86
+
87
+ ### Tools
88
+ | Tool | Description |
89
+ |------|-------------|
90
+ | `slack_health_check` | Verify token validity and workspace info |
91
+ | `slack_token_status` | **New:** Detailed token age, health, and cache stats |
92
+ | `slack_refresh_tokens` | Auto-extract fresh tokens from Chrome |
93
+ | `slack_list_conversations` | List DMs/channels (with lazy discovery cache) |
94
+ | `slack_conversations_history` | Get messages from a channel or DM |
95
+ | `slack_get_full_conversation` | Export full history with threads |
96
+ | `slack_search_messages` | Search across workspace |
97
+ | `slack_send_message` | Send a message to any conversation |
98
+ | `slack_get_thread` | Get thread replies |
99
+ | `slack_users_info` | Get user details |
100
+ | `slack_list_users` | List workspace users (paginated, 500+ supported) |
101
+
102
+ ---
35
103
 
36
104
  ## Quick Start
37
105
 
38
- ### 1. Install
106
+ ### Option A: npm (Recommended)
107
+
108
+ ```bash
109
+ npm install -g @jtalk22/slack-mcp
110
+ ```
111
+
112
+ ### Option B: Clone Repository
39
113
 
40
114
  ```bash
41
- # Clone the repository
42
115
  git clone https://github.com/jtalk22/slack-mcp-server.git
43
116
  cd slack-mcp-server
44
-
45
- # Install dependencies
46
117
  npm install
47
118
  ```
48
119
 
120
+ ### Option C: Docker
121
+
122
+ ```bash
123
+ docker pull ghcr.io/jtalk22/slack-mcp-server:latest
49
124
  ```
50
125
 
51
- ### 2. Get Your Slack Tokens
126
+ ---
52
127
 
53
- You need two tokens from your browser session:
128
+ ## Configuration
54
129
 
55
- **Option A: Automatic (Recommended)**
130
+ ### Step 1: Get Your Tokens
131
+
132
+ #### macOS (Automatic)
56
133
  ```bash
57
- # Open Chrome with Slack (app.slack.com) logged in
58
- npm run tokens:auto
134
+ # Have Chrome open with Slack (app.slack.com) logged in
135
+ npx @jtalk22/slack-mcp tokens:auto
136
+ # Or if cloned: npm run tokens:auto
59
137
  ```
60
138
 
61
- **Option B: Manual**
139
+ #### Linux/Windows (Manual)
140
+
141
+ Auto-refresh requires macOS + Chrome. On other platforms, extract tokens manually:
62
142
 
63
- 1. Open https://app.slack.com in Chrome
64
- 2. Press F12 → ApplicationCookies → Find `d` cookie (starts with `xoxd-`)
65
- 3. Press F12 → Console → Run:
143
+ 1. Open https://app.slack.com in your browser
144
+ 2. Press F12 → ConsoleRun:
66
145
  ```javascript
146
+ // Get token
67
147
  JSON.parse(localStorage.localConfig_v2).teams[Object.keys(JSON.parse(localStorage.localConfig_v2).teams)[0]].token
68
148
  ```
69
- 4. Copy both values and run:
70
- ```bash
71
- npm run tokens:refresh
149
+ 3. Press F12 → Application → Cookies → Copy the `d` cookie value (starts with `xoxd-`)
150
+ 4. Create `~/.slack-mcp-tokens.json`:
151
+ ```json
152
+ {
153
+ "SLACK_TOKEN": "xoxc-your-token-here",
154
+ "SLACK_COOKIE": "xoxd-your-cookie-here",
155
+ "updated_at": "2024-01-01T00:00:00.000Z"
156
+ }
72
157
  ```
73
158
 
74
- ### 3. Configure Claude
159
+ ### Step 2: Configure Claude
75
160
 
76
- #### For Claude Desktop
161
+ #### Claude Desktop (macOS)
77
162
 
78
- Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) or `%APPDATA%\Claude\claude_desktop_config.json` (Windows):
163
+ Edit `~/Library/Application Support/Claude/claude_desktop_config.json`:
79
164
 
80
165
  ```json
81
166
  {
82
167
  "mcpServers": {
83
168
  "slack": {
84
- "command": "node",
85
- "args": ["/path/to/slack-mcp-server/src/server.js"],
169
+ "command": "npx",
170
+ "args": ["-y", "@jtalk22/slack-mcp"]
171
+ }
172
+ }
173
+ }
174
+ ```
175
+
176
+ #### Claude Desktop (Windows)
177
+
178
+ Edit `%APPDATA%\Claude\claude_desktop_config.json`:
179
+
180
+ ```json
181
+ {
182
+ "mcpServers": {
183
+ "slack": {
184
+ "command": "npx",
185
+ "args": ["-y", "@jtalk22/slack-mcp"],
86
186
  "env": {
87
187
  "SLACK_TOKEN": "xoxc-your-token",
88
188
  "SLACK_COOKIE": "xoxd-your-cookie"
@@ -92,7 +192,9 @@ Edit `~/Library/Application Support/Claude/claude_desktop_config.json` (macOS) o
92
192
  }
93
193
  ```
94
194
 
95
- #### For Claude Code
195
+ > **Note:** Windows/Linux users must provide tokens via `env` since auto-refresh is macOS-only.
196
+
197
+ #### Claude Code (CLI)
96
198
 
97
199
  Add to `~/.claude.json`:
98
200
 
@@ -101,8 +203,8 @@ Add to `~/.claude.json`:
101
203
  "mcpServers": {
102
204
  "slack": {
103
205
  "type": "stdio",
104
- "command": "node",
105
- "args": ["/path/to/slack-mcp-server/src/server.js"]
206
+ "command": "npx",
207
+ "args": ["-y", "@jtalk22/slack-mcp"]
106
208
  }
107
209
  }
108
210
  }
@@ -110,37 +212,82 @@ Add to `~/.claude.json`:
110
212
 
111
213
  Claude Code reads tokens from `~/.slack-mcp-tokens.json` automatically.
112
214
 
113
- ### 4. Restart Claude
215
+ #### Docker Configuration
114
216
 
115
- The Slack tools will now be available.
217
+ ```json
218
+ {
219
+ "mcpServers": {
220
+ "slack": {
221
+ "command": "docker",
222
+ "args": ["run", "-i", "--rm",
223
+ "-v", "~/.slack-mcp-tokens.json:/root/.slack-mcp-tokens.json",
224
+ "ghcr.io/jtalk22/slack-mcp-server"]
225
+ }
226
+ }
227
+ }
228
+ ```
116
229
 
117
- ## Available Tools
230
+ ### Step 3: Restart Claude
118
231
 
119
- | Tool | Description |
120
- |------|-------------|
121
- | `slack_health_check` | Verify token validity and show workspace info |
122
- | `slack_refresh_tokens` | Auto-extract fresh tokens from Chrome |
123
- | `slack_list_conversations` | List DMs and channels with resolved names |
124
- | `slack_conversations_history` | Get messages from a channel or DM |
125
- | `slack_get_full_conversation` | Export full history with threads |
126
- | `slack_search_messages` | Search across workspace |
127
- | `slack_send_message` | Send a message |
128
- | `slack_get_thread` | Get thread replies |
129
- | `slack_users_info` | Get user details |
130
- | `slack_list_users` | List workspace users |
232
+ Fully quit and reopen Claude. The Slack tools will appear.
233
+
234
+ ---
235
+
236
+ ## Architecture
237
+
238
+ ### Token Persistence (4 Layers)
239
+
240
+ ```
241
+ Priority 1: Environment Variables (SLACK_TOKEN, SLACK_COOKIE)
242
+ fallback
243
+ Priority 2: Token File (~/.slack-mcp-tokens.json)
244
+ ↓ fallback
245
+ Priority 3: macOS Keychain (encrypted)
246
+ ↓ fallback
247
+ Priority 4: Chrome Auto-Extraction (macOS only)
248
+ ```
249
+
250
+ ### Stability Features
251
+
252
+ #### Atomic Writes
253
+ All file operations (tokens, DM cache) use atomic writes:
254
+ ```
255
+ Write to temp file → chmod 600 → rename to target
256
+ ```
257
+ This prevents JSON corruption if the process is killed mid-write.
258
+
259
+ #### Zombie Process Protection
260
+ Background refresh timers use `unref()`:
261
+ ```javascript
262
+ const timer = setInterval(refreshTokens, 4 * 60 * 60 * 1000);
263
+ timer.unref(); // Process can exit even if timer is pending
264
+ ```
265
+ When Claude closes the MCP connection, the server exits cleanly.
266
+
267
+ #### Race Condition Prevention
268
+ A mutex lock prevents concurrent Chrome extractions:
269
+ ```javascript
270
+ if (refreshInProgress) return null; // Skip if already refreshing
271
+ refreshInProgress = true;
272
+ try { return extractFromChromeInternal(); }
273
+ finally { refreshInProgress = false; }
274
+ ```
275
+
276
+ ---
131
277
 
132
278
  ## Web UI (for claude.ai)
133
279
 
134
- Since claude.ai doesn't support MCP, you can use the web server:
280
+ Since claude.ai doesn't support MCP, use the REST server:
135
281
 
136
282
  ```bash
137
283
  npm run web
284
+ # Or: npx @jtalk22/slack-mcp web
138
285
  ```
139
286
 
140
- Open http://localhost:3000 in your browser. It auto-connects with the default API key (`slack-mcp-local`).
287
+ Open http://localhost:3000. API key is auto-generated and displayed in the console.
141
288
 
142
289
  <details>
143
- <summary><strong>View Web UI Screenshots</strong></summary>
290
+ <summary><strong>Screenshots</strong></summary>
144
291
 
145
292
  | DMs View | Channels View |
146
293
  |----------|---------------|
@@ -148,148 +295,107 @@ Open http://localhost:3000 in your browser. It auto-connects with the default AP
148
295
 
149
296
  </details>
150
297
 
151
- ### Auto-Start on Login (macOS)
152
-
153
- ```bash
154
- # Create LaunchAgent
155
- cat > ~/Library/LaunchAgents/com.slack-mcp-server.plist << 'EOF'
156
- <?xml version="1.0" encoding="UTF-8"?>
157
- <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
158
- <plist version="1.0">
159
- <dict>
160
- <key>Label</key>
161
- <string>com.slack-mcp-server</string>
162
- <key>ProgramArguments</key>
163
- <array>
164
- <string>/usr/local/bin/node</string>
165
- <string>/path/to/slack-mcp-server/src/web-server.js</string>
166
- </array>
167
- <key>WorkingDirectory</key>
168
- <string>/path/to/slack-mcp-server</string>
169
- <key>RunAtLoad</key>
170
- <true/>
171
- <key>KeepAlive</key>
172
- <true/>
173
- </dict>
174
- </plist>
175
- EOF
176
-
177
- launchctl load ~/Library/LaunchAgents/com.slack-mcp-server.plist
178
- ```
179
-
180
- ## Token Management
181
-
182
- Tokens are stored in multiple layers for reliability:
298
+ ---
183
299
 
184
- 1. **Environment variables** - From MCP config
185
- 2. **Token file** - `~/.slack-mcp-tokens.json` (chmod 600)
186
- 3. **macOS Keychain** - Encrypted persistent storage
187
- 4. **Chrome auto-extraction** - Fallback when tokens expire
188
-
189
- ### When Tokens Expire
190
-
191
- Tokens typically last 1-2 weeks. When they expire:
300
+ ## Troubleshooting
192
301
 
302
+ ### Tokens Expired
193
303
  ```bash
194
- # Option 1: In Claude
195
- slack_refresh_tokens
304
+ # macOS: Auto-refresh from Chrome
305
+ slack_refresh_tokens # In Claude
306
+ # Or: npm run tokens:auto
196
307
 
197
- # Option 2: CLI
198
- npm run tokens:auto
308
+ # Linux/Windows: Manual update
309
+ # Edit ~/.slack-mcp-tokens.json with fresh values
199
310
  ```
200
311
 
201
- ## Troubleshooting
202
-
203
312
  ### DMs Not Showing
204
-
205
- This is handled automatically. The server discovers DMs by calling `conversations.open` for each user (Slack's `conversations.list` doesn't return DMs with browser tokens).
206
-
207
- ### Rate Limiting
208
-
209
- The client implements automatic retry with exponential backoff. If you still hit limits, reduce batch sizes in your queries.
210
-
211
- ### Claude Desktop Not Seeing Tools
212
-
213
- 1. Verify JSON syntax in config
214
- 2. Check logs: `~/Library/Logs/Claude/mcp-server-slack.log`
215
- 3. Fully restart Claude Desktop (Cmd+Q, then reopen)
313
+ Use `discover_dms: true` to force discovery:
314
+ ```
315
+ slack_list_conversations with discover_dms=true
316
+ ```
317
+ This caches DM channel IDs for 24 hours.
216
318
 
217
319
  ### Chrome Extraction Fails
320
+ - Chrome must be **running** (not minimized to Dock)
321
+ - Slack tab must be open at `app.slack.com`
322
+ - You must be logged in
218
323
 
219
- - Chrome must be running (not just in Dock)
220
- - Have a Slack tab open at `app.slack.com`
221
- - Be logged into Slack
222
-
223
- ## How It Works
224
-
225
- This server uses Slack's internal Web API with browser session tokens (`xoxc-` token and `xoxd-` cookie). This provides the same access level as the Slack web interface.
226
-
227
- **Why not a Slack App?**
228
-
229
- Slack apps require OAuth and cannot access DMs without explicit per-conversation authorization from users. Browser tokens bypass this limitation.
230
-
231
- **Trade-offs:**
232
- - ✅ Full access to all conversations
233
- - ✅ No per-conversation authorization
234
- - ❌ Tokens expire every 1-2 weeks
235
- - ❌ Requires Chrome for token extraction
236
- - ❌ Not officially supported by Slack
237
-
238
- ## Security Notes
324
+ ### Claude Desktop Not Seeing Tools
325
+ 1. Verify JSON syntax in config file
326
+ 2. Check logs: `~/Library/Logs/Claude/mcp*.log`
327
+ 3. Fully restart Claude (Cmd+Q, then reopen)
239
328
 
240
- - Tokens are stored with `chmod 600` (owner read/write only)
241
- - macOS Keychain provides encrypted storage
242
- - Never commit tokens to version control
243
- - Web server only accessible on localhost by default
329
+ ---
244
330
 
245
331
  ## Project Structure
246
332
 
247
333
  ```
248
334
  slack-mcp-server/
249
335
  ├── src/
250
- │ ├── server.js # MCP server entry point
336
+ │ ├── server.js # MCP server (stdio transport)
251
337
  │ └── web-server.js # REST API + Web UI
252
338
  ├── lib/
253
- │ ├── token-store.js # 4-layer token persistence
254
- │ ├── slack-client.js # API client with retry logic
339
+ │ ├── token-store.js # 4-layer persistence + atomic writes
340
+ │ ├── slack-client.js # API client, LRU cache, retry logic
255
341
  │ ├── tools.js # MCP tool definitions
256
342
  │ └── handlers.js # Tool implementations
257
343
  ├── public/
258
344
  │ ├── index.html # Web UI
259
- │ └── demo.html # Interactive demo with mock data
260
- ├── scripts/
261
- └── token-cli.js # Token management CLI
262
- └── docs/
263
- ├── images/ # Screenshots
264
- ├── SETUP.md # Detailed setup guide
265
- ├── API.md # Tool reference
266
- ├── WEB-API.md # REST API reference
267
- └── TROUBLESHOOTING.md
345
+ │ └── demo.html # Interactive demo
346
+ └── scripts/
347
+ └── token-cli.js # Token management CLI
268
348
  ```
269
349
 
270
- ## Contributing
350
+ ---
351
+
352
+ ## Security
353
+
354
+ - Token files stored with `chmod 600` (owner-only)
355
+ - macOS Keychain provides encrypted backup
356
+ - Web server binds to localhost only
357
+ - Never commit tokens to version control
358
+ - API keys are cryptographically random (`crypto.randomBytes`)
359
+
360
+ ---
271
361
 
272
- Contributions welcome! Please:
362
+ ## Platform Support
363
+
364
+ | Feature | macOS | Linux | Windows |
365
+ |---------|-------|-------|---------|
366
+ | MCP Server | Yes | Yes | Yes |
367
+ | Token File | Yes | Yes | Yes |
368
+ | Auto-Refresh from Chrome | Yes | No | No |
369
+ | Keychain Storage | Yes | No | No |
370
+ | Web UI | Yes | Yes | Yes |
371
+
372
+ ---
373
+
374
+ ## Contributing
273
375
 
274
376
  1. Fork the repository
275
377
  2. Create a feature branch
276
378
  3. Make your changes
277
- 4. Submit a pull request
379
+ 4. Run `node --check` on modified files
380
+ 5. Submit a pull request
381
+
382
+ ---
278
383
 
279
384
  ## Support
280
385
 
281
- If you find this useful, consider supporting the project:
386
+ If this saved you from OAuth hell, consider:
282
387
 
283
388
  - [GitHub Sponsors](https://github.com/sponsors/jtalk22)
284
- - [Ko-fi](https://ko-fi.com/jtalk22)
285
- - [Buy Me a Coffee](https://www.buymeacoffee.com/jtalk22)
389
+ - Star the repo
286
390
 
287
- Star the repo if it helped you!
391
+ ---
288
392
 
289
393
  ## License
290
394
 
291
- MIT - See [LICENSE](LICENSE) for details.
395
+ MIT - See [LICENSE](LICENSE)
396
+
397
+ ---
292
398
 
293
399
  ## Disclaimer
294
400
 
295
- This project uses unofficial Slack APIs. Use at your own risk. The authors are not responsible for any account issues that may arise from using this software.
401
+ This project uses unofficial Slack APIs. Use at your own risk. Not affiliated with or endorsed by Slack Technologies.