Skip to content

Commit 831e0fe

Browse files
authored
Merge pull request #30 from korotovsky/custom-ua
Possibility to redefine user agent
2 parents 44b645d + 31fb8e5 commit 831e0fe

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

docs/03-configuration-and-usage.md

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ If you have npm installed, this is the fastest way to get started with `slack-mc
88

99
Open your `claude_desktop_config.json` and add the mcp server to the list of `mcpServers`:
1010

11+
> [!WARNING]
12+
> If you are using Enterprise Slack, you may set `SLACK_MCP_USER_AGENT` environment variable to match your browser's User-Agent string from where you extracted `xoxc` and `xoxd`. This is required for the server to work properly in some environments with higher security policies.
13+
1114
**Option 1: Using XOXP Token**
1215
``` json
1316
{
@@ -202,13 +205,14 @@ docker-compose up -d
202205

203206
#### Environment Variables
204207

205-
| Variable | Required ? | Default | Description |
206-
|--------------------------------|------------|-------------|-------------------------------------------------------------------------------|
207-
| `SLACK_MCP_XOXC_TOKEN` | Yes | `nil` | Authentication data token field `token` from POST data field-set (`xoxc-...`) |
208-
| `SLACK_MCP_XOXD_TOKEN` | Yes | `nil` | Authentication data token from cookie `d` (`xoxd-...`) |
209-
| `SLACK_MCP_SERVER_PORT` | No | `3001` | Port for the MCP server to listen on |
210-
| `SLACK_MCP_SERVER_HOST` | No | `127.0.0.1` | Host for the MCP server to listen on |
211-
| `SLACK_MCP_SSE_API_KEY` | No | `nil` | Authorization Bearer token when `transport` is `sse` |
212-
| `SLACK_MCP_PROXY` | No | `nil` | Proxy URL for the MCP server to use |
213-
| `SLACK_MCP_SERVER_CA` | No | `nil` | Path to the CA certificate of the trust store |
214-
| `SLACK_MCP_SERVER_CA_INSECURE` | No | `false` | Trust all insecure requests (NOT RECOMMENDED) |
208+
| Variable | Required ? | Default | Description |
209+
|--------------------------------|------------|-------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
210+
| `SLACK_MCP_XOXC_TOKEN` | Yes | `nil` | Authentication data token field `token` from POST data field-set (`xoxc-...`) |
211+
| `SLACK_MCP_XOXD_TOKEN` | Yes | `nil` | Authentication data token from cookie `d` (`xoxd-...`) |
212+
| `SLACK_MCP_SERVER_PORT` | No | `3001` | Port for the MCP server to listen on |
213+
| `SLACK_MCP_SERVER_HOST` | No | `127.0.0.1` | Host for the MCP server to listen on |
214+
| `SLACK_MCP_SSE_API_KEY` | No | `nil` | Authorization Bearer token when `transport` is `sse` |
215+
| `SLACK_MCP_PROXY` | No | `nil` | Proxy URL for the MCP server to use |
216+
| `SLACK_MCP_USER_AGENT` | No | `nil` | User-Agent to use by MCP transport, may be required when you are located within Enterprise Slack environments with stricter security policies so it must match your browser from where you copied `xoxd` and `xoxc` values. |
217+
| `SLACK_MCP_SERVER_CA` | No | `nil` | Path to the CA certificate of the trust store |
218+
| `SLACK_MCP_SERVER_CA_INSECURE` | No | `false` | Trust all insecure requests (NOT RECOMMENDED) |

pkg/provider/api.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/slack-go/slack"
1616
)
1717

18+
var defaultUA = "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/136.0.0.0 Safari/537.36"
1819
var AllChanTypes = []string{"mpim", "im", "public_channel", "private_channel"}
1920
var PubChanType = "public_channel"
2021

@@ -45,7 +46,7 @@ func New() *ApiProvider {
4546
// Fall back to XOXC/XOXD tokens (session-based)
4647
xoxcToken := os.Getenv("SLACK_MCP_XOXC_TOKEN")
4748
xoxdToken := os.Getenv("SLACK_MCP_XOXD_TOKEN")
48-
49+
4950
if xoxcToken == "" || xoxdToken == "" {
5051
panic("Authentication required: Either SLACK_MCP_XOXP_TOKEN (User OAuth) or both SLACK_MCP_XOXC_TOKEN and SLACK_MCP_XOXD_TOKEN (session-based) environment variables must be provided")
5152
}
@@ -334,10 +335,15 @@ func withHTTPClientOption(cookie string) func(c *slack.Client) {
334335
},
335336
}
336337

338+
userAgent := defaultUA
339+
if os.Getenv("SLACK_MCP_USER_AGENT") != "" {
340+
userAgent = os.Getenv("SLACK_MCP_USER_AGENT")
341+
}
342+
337343
client := &http.Client{
338344
Transport: transport.New(
339345
customHTTPTransport,
340-
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/133.0.0.0 Safari/537.36",
346+
userAgent,
341347
cookie,
342348
),
343349
}

0 commit comments

Comments
 (0)