Skip to content

Commit 42b98ff

Browse files
authored
Merge pull request #126 from redaphid/master
Default cache file creation to os cache dir
2 parents 0143265 + 44e6ba3 commit 42b98ff

File tree

2 files changed

+27
-6
lines changed

2 files changed

+27
-6
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,8 @@ Fetches a CSV directory of all users in the workspace.
135135
| `SLACK_MCP_ADD_MESSAGE_TOOL` | No | `nil` | Enable message posting via `conversations_add_message` by setting it to true for all channels, a comma-separated list of channel IDs to whitelist specific channels, or use `!` before a channel ID to allow all except specified ones, while an empty value disables posting by default. |
136136
| `SLACK_MCP_ADD_MESSAGE_MARK` | No | `nil` | When the `conversations_add_message` tool is enabled, any new message sent will automatically be marked as read. |
137137
| `SLACK_MCP_ADD_MESSAGE_UNFURLING` | No | `nil` | Enable to let Slack unfurl posted links or set comma-separated list of domains e.g. `github.com,slack.com` to whitelist unfurling only for them. If text contains whitelisted and unknown domain unfurling will be disabled for security reasons. |
138-
| `SLACK_MCP_USERS_CACHE` | No | `.users_cache.json` | Path to the users cache file. Used to cache Slack user information to avoid repeated API calls on startup. |
139-
| `SLACK_MCP_CHANNELS_CACHE` | No | `.channels_cache_v2.json` | Path to the channels cache file. Used to cache Slack channel information to avoid repeated API calls on startup. |
138+
| `SLACK_MCP_USERS_CACHE` | No | `~/Library/Caches/slack-mcp-server/users_cache.json` (macOS)<br>`~/.cache/slack-mcp-server/users_cache.json` (Linux)<br>`%LocalAppData%/slack-mcp-server/users_cache.json` (Windows) | Path to the users cache file. Used to cache Slack user information to avoid repeated API calls on startup. |
139+
| `SLACK_MCP_CHANNELS_CACHE` | No | `~/Library/Caches/slack-mcp-server/channels_cache_v2.json` (macOS)<br>`~/.cache/slack-mcp-server/channels_cache_v2.json` (Linux)<br>`%LocalAppData%/slack-mcp-server/channels_cache_v2.json` (Windows) | Path to the channels cache file. Used to cache Slack channel information to avoid repeated API calls on startup. |
140140
| `SLACK_MCP_LOG_LEVEL` | No | `info` | Log-level for stdout or stderr. Valid values are: `debug`, `info`, `warn`, `error`, `panic` and `fatal` |
141141

142142
*You need either `xoxp` **or** both `xoxc`/`xoxd` tokens for authentication.

pkg/provider/api.go

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"errors"
77
"io/ioutil"
88
"os"
9+
"path/filepath"
910
"strings"
1011

1112
"github.com/korotovsky/slack-mcp-server/pkg/limiter"
@@ -28,6 +29,22 @@ var PubChanType = "public_channel"
2829
var ErrUsersNotReady = errors.New(usersNotReadyMsg)
2930
var ErrChannelsNotReady = errors.New(channelsNotReadyMsg)
3031

32+
// getCacheDir returns the appropriate cache directory for slack-mcp-server
33+
func getCacheDir() string {
34+
cacheDir, err := os.UserCacheDir()
35+
if err != nil {
36+
// Fallback to current directory if we can't get user cache dir
37+
return "."
38+
}
39+
40+
dir := filepath.Join(cacheDir, "slack-mcp-server")
41+
if err := os.MkdirAll(dir, 0755); err != nil {
42+
// Fallback to current directory if we can't create cache dir
43+
return "."
44+
}
45+
return dir
46+
}
47+
3148
type UsersCache struct {
3249
Users map[string]slack.User `json:"users"`
3350
UsersInv map[string]string `json:"users_inv"`
@@ -324,12 +341,14 @@ func newWithXOXP(transport string, authProvider auth.ValueAuth, logger *zap.Logg
324341

325342
usersCache := os.Getenv("SLACK_MCP_USERS_CACHE")
326343
if usersCache == "" {
327-
usersCache = ".users_cache.json"
344+
cacheDir := getCacheDir()
345+
usersCache = filepath.Join(cacheDir, "users_cache.json")
328346
}
329347

330348
channelsCache := os.Getenv("SLACK_MCP_CHANNELS_CACHE")
331349
if channelsCache == "" {
332-
channelsCache = ".channels_cache_v2.json"
350+
cacheDir := getCacheDir()
351+
channelsCache = filepath.Join(cacheDir, "channels_cache_v2.json")
333352
}
334353

335354
if os.Getenv("SLACK_MCP_XOXP_TOKEN") == "demo" || (os.Getenv("SLACK_MCP_XOXC_TOKEN") == "demo" && os.Getenv("SLACK_MCP_XOXD_TOKEN") == "demo") {
@@ -366,12 +385,14 @@ func newWithXOXC(transport string, authProvider auth.ValueAuth, logger *zap.Logg
366385

367386
usersCache := os.Getenv("SLACK_MCP_USERS_CACHE")
368387
if usersCache == "" {
369-
usersCache = ".users_cache.json"
388+
cacheDir := getCacheDir()
389+
usersCache = filepath.Join(cacheDir, "users_cache.json")
370390
}
371391

372392
channelsCache := os.Getenv("SLACK_MCP_CHANNELS_CACHE")
373393
if channelsCache == "" {
374-
channelsCache = ".channels_cache_v2.json"
394+
cacheDir := getCacheDir()
395+
channelsCache = filepath.Join(cacheDir, "channels_cache_v2.json")
375396
}
376397

377398
if os.Getenv("SLACK_MCP_XOXP_TOKEN") == "demo" || (os.Getenv("SLACK_MCP_XOXC_TOKEN") == "demo" && os.Getenv("SLACK_MCP_XOXD_TOKEN") == "demo") {

0 commit comments

Comments
 (0)