diff --git a/README.md b/README.md index c34405a..9a626b0 100644 --- a/README.md +++ b/README.md @@ -135,8 +135,8 @@ Fetches a CSV directory of all users in the workspace. | `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. | | `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. | | `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. | -| `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. | -| `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. | +| `SLACK_MCP_USERS_CACHE` | No | `~/Library/Caches/slack-mcp-server/users_cache.json` (macOS)
`~/.cache/slack-mcp-server/users_cache.json` (Linux)
`%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. | +| `SLACK_MCP_CHANNELS_CACHE` | No | `~/Library/Caches/slack-mcp-server/channels_cache_v2.json` (macOS)
`~/.cache/slack-mcp-server/channels_cache_v2.json` (Linux)
`%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. | | `SLACK_MCP_LOG_LEVEL` | No | `info` | Log-level for stdout or stderr. Valid values are: `debug`, `info`, `warn`, `error`, `panic` and `fatal` | *You need either `xoxp` **or** both `xoxc`/`xoxd` tokens for authentication. diff --git a/pkg/provider/api.go b/pkg/provider/api.go index 0681567..0af3a40 100644 --- a/pkg/provider/api.go +++ b/pkg/provider/api.go @@ -6,6 +6,7 @@ import ( "errors" "io/ioutil" "os" + "path/filepath" "strings" "github.com/korotovsky/slack-mcp-server/pkg/limiter" @@ -28,6 +29,22 @@ var PubChanType = "public_channel" var ErrUsersNotReady = errors.New(usersNotReadyMsg) var ErrChannelsNotReady = errors.New(channelsNotReadyMsg) +// getCacheDir returns the appropriate cache directory for slack-mcp-server +func getCacheDir() string { + cacheDir, err := os.UserCacheDir() + if err != nil { + // Fallback to current directory if we can't get user cache dir + return "." + } + + dir := filepath.Join(cacheDir, "slack-mcp-server") + if err := os.MkdirAll(dir, 0755); err != nil { + // Fallback to current directory if we can't create cache dir + return "." + } + return dir +} + type UsersCache struct { Users map[string]slack.User `json:"users"` UsersInv map[string]string `json:"users_inv"` @@ -324,12 +341,14 @@ func newWithXOXP(transport string, authProvider auth.ValueAuth, logger *zap.Logg usersCache := os.Getenv("SLACK_MCP_USERS_CACHE") if usersCache == "" { - usersCache = ".users_cache.json" + cacheDir := getCacheDir() + usersCache = filepath.Join(cacheDir, "users_cache.json") } channelsCache := os.Getenv("SLACK_MCP_CHANNELS_CACHE") if channelsCache == "" { - channelsCache = ".channels_cache_v2.json" + cacheDir := getCacheDir() + channelsCache = filepath.Join(cacheDir, "channels_cache_v2.json") } 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 usersCache := os.Getenv("SLACK_MCP_USERS_CACHE") if usersCache == "" { - usersCache = ".users_cache.json" + cacheDir := getCacheDir() + usersCache = filepath.Join(cacheDir, "users_cache.json") } channelsCache := os.Getenv("SLACK_MCP_CHANNELS_CACHE") if channelsCache == "" { - channelsCache = ".channels_cache_v2.json" + cacheDir := getCacheDir() + channelsCache = filepath.Join(cacheDir, "channels_cache_v2.json") } if os.Getenv("SLACK_MCP_XOXP_TOKEN") == "demo" || (os.Getenv("SLACK_MCP_XOXC_TOKEN") == "demo" && os.Getenv("SLACK_MCP_XOXD_TOKEN") == "demo") {