feat: add enabled parameter support for tool registration #712
+693
−28
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🚀 Add Dynamic Tool Enabling Support
📋 Summary
This PR introduces the ability to conditionally enable/disable tools during registration via an optional
enabled
parameter in theregisterTool
configuration. This addresses the need for dynamic tool management based on environment variables, feature flags, permissions, or other runtime conditions.🎯 Motivation
Why is this change needed?
Many MCP server implementations require conditional tool availability based on:
Currently, developers must implement workarounds like wrapper functions or conditional registration logic, making code less clean and maintainable.
✨ What's Changed
Core Implementation
enabled?: boolean
parameter toregisterTool
config object_createRegisteredTool
to accept enabled state with defaulttrue
New Capabilities
🔧 Technical Details
Minimal Implementation
_createRegisteredTool
andregisterTool
enabled: true
When
enabled: false
:tools/list
responses.enable()/.disable()
methods📚 Documentation & Examples
Comprehensive Documentation Added:
Real-world Use Cases:
Advanced Pattern Example:
✅ Testing
🔄 Migration Path
Existing Code: No changes required
New Code: Opt-in enabled control
🎯 Impact
This change enables:
📝 Checklist
Type: Enhancement
Breaking Change: No
Backwards Compatible: Yes
This enhancement provides immediate value while maintaining the stability and simplicity that makes MCP TypeScript SDK great to work with.