feat: Add DISABLED_TOOLS environment variable for tool filtering (Issue #410)

Added DISABLED_TOOLS environment variable to filter specific tools from registration at startup, enabling deployment-specific tool configuration for multi-tenant deployments, security hardening, and feature flags.

## Implementation

- Added getDisabledTools() method to parse comma-separated tool names from env var
- Modified ListToolsRequestSchema handler to filter both documentation and management tools
- Modified CallToolRequestSchema handler to reject disabled tool calls with clear error messages
- Added defense-in-depth guard in executeTool() method

## Features

- Environment variable format: DISABLED_TOOLS=tool1,tool2,tool3
- O(1) lookup performance using Set data structure
- Clear error messages with TOOL_DISABLED code
- Backward compatible (no DISABLED_TOOLS = all tools enabled)
- Comprehensive logging for observability

## Use Cases

- Multi-tenant: Hide tools that check global env vars
- Security: Disable management tools in production
- Feature flags: Gradually roll out new tools
- Deployment-specific: Different tool sets for cloud vs self-hosted

## Testing

- 45 comprehensive tests (all passing)
- 95% feature code coverage
- Unit tests + additional test scenarios
- Performance tested with 1000 tools (<100ms)

## Files Modified

- src/mcp/server.ts - Core implementation (~40 lines)
- .env.example, .env.docker - Configuration documentation
- tests/unit/mcp/disabled-tools*.test.ts - Comprehensive tests
- package.json, package.runtime.json - Version bump to 2.22.14
- CHANGELOG.md - Full documentation

Resolves #410

Conceived by Romuald Członkowski - www.aiadvisors.pl/en
This commit is contained in:
czlonkowski
2025-11-09 16:26:47 +01:00
parent 2010d77ed8
commit 53252adc68
10 changed files with 1645 additions and 13 deletions

View File

@@ -103,6 +103,23 @@ AUTH_TOKEN=your-secure-token-here
# For local development with local n8n:
# WEBHOOK_SECURITY_MODE=moderate
# Disabled Tools Configuration
# Filter specific tools from registration at startup
# Useful for multi-tenant deployments, security hardening, or feature flags
#
# Format: Comma-separated list of tool names
# Example: DISABLED_TOOLS=n8n_diagnostic,n8n_health_check,custom_tool
#
# Common use cases:
# - Multi-tenant: Hide tools that check env vars instead of instance context
# Example: DISABLED_TOOLS=n8n_diagnostic,n8n_health_check
# - Security: Disable management tools in production for certain users
# - Feature flags: Gradually roll out new tools
# - Deployment-specific: Different tool sets for cloud vs self-hosted
#
# Default: (empty - all tools enabled)
# DISABLED_TOOLS=
# =========================
# MULTI-TENANT CONFIGURATION
# =========================