feat: add --enabled-tools flag to filter available MCP tools#173
feat: add --enabled-tools flag to filter available MCP tools#173korotovsky merged 10 commits intokorotovsky:masterfrom
Conversation
Add a new CLI flag `--enabled-tools` (alias `-e`) and environment variable `SLACK_MCP_ENABLED_TOOLS` to allow users to specify which MCP tools should be loaded. This provides flexibility to limit tool exposure based on security requirements or use case. - If not set, all tools are enabled (backward compatible) - Accepts comma-separated tool names - CLI flag takes precedence over environment variable Available tools: conversations_history, conversations_replies, conversations_add_message, reactions_add, reactions_remove, attachment_get_data, conversations_search_messages, channels_list Example usage: slack-mcp-server --enabled-tools=conversations_history,channels_list SLACK_MCP_ENABLED_TOOLS=channels_list slack-mcp-server Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
Somehow closes #167 |
|
How does this work when for example you need explicitly enable |
These are separate concerns:
If ENABLED_TOOLS is empty, all tools are exposed. But even then, ADD_MESSAGE_TOOL must be set for the handler to accept message actions. When both are used, they act together restrictively: My vision is that it's enough to rely on ENABLED_TOOLS going forward — it’s more generic and precise. The per-tool flags still work but are optional if exposure is already controlled. |
|
The problem with "If ENABLED_TOOLS is empty, all tools are exposed" is everyone who is running MCP on |
Simplify the logic so that: - ENABLED_TOOLS only controls which tools are registered/exposed via MCP - Empty ENABLED_TOOLS = all tools registered (no filtering) - Runtime permissions (ADD_MESSAGE_TOOL, REACTION_TOOL, ATTACHMENT_TOOL) are always enforced in handlers regardless of ENABLED_TOOLS This keeps the two concerns separate: 1. Registration/visibility (ENABLED_TOOLS) 2. Runtime permissions (individual tool env vars) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
- Add Tool* constants to avoid magic strings in tool registration - Add ValidToolNames slice and ValidateEnabledTools function - Validate tool names at startup, fail with helpful error message - Update tests to use constants Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
@korotovsky I've added tests and some more changes. But my understanding that those 2 flags work in a different "layers". The current one in runtime, and the one that I've proposed should work on registration. Let me know what should i add or change further, to achive the goal. Thanks. |
|
It is a secondary layer, right, but then it somehow becomes confusing when we set empty value for "all tools", but then later on somehow the tool would be disfunctional (but enabled) so +1 extra env is needed. What is the goal of the PR? Do you want to automatically get all new tools once MCP gets updated, or you just one to get control over selectivity what is enabled in the MCP server when it's running? |
|
My goals
⸻ Behavior |
|
@korotovsky could you kindly tell me what should I do to progress with MR or could you close it as not desired change? |
|
Hi @RedSlowpoke, I see main issue with existing SLACK_MCP_ADD_MESSAGE_TOOL, if it's not defined and you also not set any configuration for this new PR == default value equals all tools, which results in a very contradictory config in my opinion - your "feature" dictate all tools are enabled (incl. message tool? That would have been logical), but fact that SLACK_MCP_ADD_MESSAGE_TOOL is not set would take priority over and user will get an error and it will be very awkward behavior. |
|
I may propose the following strategy: Slack message sending behavior
Legend: Do you think it's transparent and awkward, or how can I do this better? |
Write tools (conversations_add_message, reactions_add, reactions_remove, attachment_get_data) now require explicit enablement: - If ENABLED_TOOLS explicitly includes the tool, register it - If ENABLED_TOOLS is empty, only register if tool-specific env var is set - If ENABLED_TOOLS excludes the tool, don't register This resolves the conflict where ENABLED_TOOLS="" would register all tools but SLACK_MCP_ADD_MESSAGE_TOOL="" would fail at runtime with an error. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
From what I could see here 2ef39fe#diff-fe7a244e18e92d8f347af17363209172e1d79224f086b0585a1bbeef3b626c4eR268-R275 did I understand correctly, that |
- Merge shouldAddTool and shouldAddWriteTool into single function - Remove redundant comments - Add envVarName parameter for write tools requiring explicit enablement Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
yes, if set
Yes Basically the idea, that if you use the latest introduced flag - you understand how it works, and if you don't use it. It works (almost) as it was when the oldest flags were introduced. |
docs/03-configuration-and-usage.md
Outdated
| | `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_LOG_LEVEL` | No | `info` | Log-level for stdout or stderr. Valid values are: `debug`, `info`, `warn`, `error`, `panic` and `fatal` | | ||
| | `SLACK_MCP_ENABLED_TOOLS` | No | `nil` | Comma-separated list of tools to register. If not set, all tools are registered. Use this to limit which tools are exposed via MCP. Note: Runtime permissions (e.g., `SLACK_MCP_ADD_MESSAGE_TOOL`) are still enforced regardless of this setting. Available tools: `conversations_history`, `conversations_replies`, `conversations_add_message`, `reactions_add`, `reactions_remove`, `attachment_get_data`, `conversations_search_messages`, `channels_list`. | |
There was a problem hiding this comment.
Let's the docs also cover SLACK_MCP_ADD_MESSAGE_MARK.
|
OK I think we are quite close to get that merged, could you improve a general docs about how new functionality works with a couple of examples (not tool prompts), (I will also use it in the release notes later) and then we will merge it. |
- SLACK_MCP_ADD_MESSAGE_MARK now mentions both enablement methods - SLACK_MCP_ENABLED_TOOLS clarifies write tools behavior - SLACK_MCP_ADD_MESSAGE_TOOL clarifies fallback to ENABLED_TOOLS Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Add dedicated documentation section explaining ENABLED_TOOLS feature with: - Overview of two-layer system (registration vs runtime permissions) - Four practical configuration examples - Behavior matrix showing all combinations Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
Resolve conflict in README.md by keeping updated env var descriptions that document the SLACK_MCP_ENABLED_TOOLS interaction. Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
|
As I understand this is a breaking change for people for a) updates on |
|
Write tools are no longer registered by default Write tools (conversations_add_message, reactions_add, reactions_remove, attachment_get_data) If you had these env vars configured:
No action needed - tools will be registered and work as before. If you didn't: You'll see fewer tools in the list. This is intentional - they weren't Alternative: Use |
Summary
--enabled-tools(alias-e) to specify which MCP tools to loadSLACK_MCP_ENABLED_TOOLSenvironment variable as fallbackChanges
cmd/slack-mcp-server/main.go: Add flag parsing and env var supportpkg/server/server.go: AddshouldAddTool()helper and conditional tool registrationREADME.mdanddocs/03-configuration-and-usage.md: Document the new featureExample Usage
Available Tools
conversations_history,conversations_replies,conversations_add_message,reactions_add,reactions_remove,attachment_get_data,conversations_search_messages,channels_listTest plan
go build ./cmd/slack-mcp-servergo test ./...--helpshows new flags