@@ -51,8 +51,14 @@ func (r *Registry) isFeatureFlagAllowed(ctx context.Context, enableFlag, disable
5151}
5252
5353// isToolEnabled checks if a specific tool is enabled based on current filters.
54+ // Filter evaluation order:
55+ // 1. Tool.Enabled (tool self-filtering)
56+ // 2. FeatureFlagEnable/FeatureFlagDisable
57+ // 3. Read-only filter
58+ // 4. Builder filters (via WithFilter)
59+ // 5. Toolset/additional tools
5460func (r * Registry )isToolEnabled (ctx context.Context ,tool * ServerTool )bool {
55- // Check tool's own Enabled function first
61+ //1. Check tool's own Enabled function first
5662if tool .Enabled != nil {
5763enabled ,err := tool .Enabled (ctx )
5864if err != nil {
@@ -63,15 +69,15 @@ func (r *Registry) isToolEnabled(ctx context.Context, tool *ServerTool) bool {
6369return false
6470}
6571}
66- // Check feature flags
72+ //2. Check feature flags
6773if ! r .isFeatureFlagAllowed (ctx ,tool .FeatureFlagEnable ,tool .FeatureFlagDisable ) {
6874return false
6975}
70- // Check read-only filter (applies to all tools)
76+ //3. Check read-only filter (applies to all tools)
7177if r .readOnly && ! tool .IsReadOnly () {
7278return false
7379}
74- // Apply builder filters
80+ //4. Apply builder filters
7581for _ ,filter := range r .filters {
7682allowed ,err := filter (ctx ,tool )
7783if err != nil {
@@ -82,11 +88,11 @@ func (r *Registry) isToolEnabled(ctx context.Context, tool *ServerTool) bool {
8288return false
8389}
8490}
85- // Check if tool is in additionalTools (bypasses toolset filter)
91+ //5. Check if tool is in additionalTools (bypasses toolset filter)
8692if r .additionalTools != nil && r .additionalTools [tool .Tool .Name ] {
8793return true
8894}
89- // Check toolset filter
95+ //5. Check toolset filter
9096if ! r .isToolsetEnabled (tool .Toolset .ID ) {
9197return false
9298}
@@ -269,7 +275,14 @@ func (r *Registry) EnabledToolsetIDs() []ToolsetID {
269275}
270276
271277// FilteredTools returns tools filtered by the Enabled function and builder filters.
272- // This is an alias for AvailableTools for clarity when focusing on filtering behavior.
278+ // This provides an explicit API for accessing filtered tools, currently implemented
279+ // as an alias for AvailableTools.
280+ //
281+ // The error return is currently always nil but is included for future extensibility.
282+ // Library consumers (e.g., remote server implementations) may need to surface
283+ // recoverable filter errors rather than silently logging them. Having the error
284+ // return in the API now avoids breaking changes later.
285+ //
273286// The context is used for Enabled function evaluation and builder filter checks.
274287func (r * Registry )FilteredTools (ctx context.Context ) ([]ServerTool ,error ) {
275288return r .AvailableTools (ctx ),nil