Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)<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. |
| `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. |
| `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.
Expand Down
29 changes: 25 additions & 4 deletions pkg/provider/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"errors"
"io/ioutil"
"os"
"path/filepath"
"strings"

"github.com/korotovsky/slack-mcp-server/pkg/limiter"
Expand All @@ -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"`
Expand Down Expand Up @@ -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") {
Expand Down Expand Up @@ -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") {
Expand Down