Skip to content

Allow tools to be disabled and thus hidden from mcp discovery - #447

Merged
Dumbris merged 8 commits into
smart-mcp-proxy:mainfrom
JasonLandbridge:block-tools
May 5, 2026
Merged

Dumbris merged 8 commits into
smart-mcp-proxy:mainfrom
JasonLandbridge:block-tools

Conversation

@JasonLandbridge

@JasonLandbridge JasonLandbridge commented May 4, 2026 •

Copy link
Copy Markdown
Contributor

Closes #432
image
image

image

Summary

  • treat disabled tools as non-callable/non-discoverable via centralized callable checks
  • filter disabled tools before retrieve_tools response construction
  • return TOOL_BLOCKED with clear message for direct calls to disabled tools
  • exclude disabled tools from server status health tool_count displays
  • add regression tests for callable predicate, discovery filtering, blocked call error, and re-enable visibility

Validation

  • go test ./internal/server -run 'TestIsToolCallable_DisabledTool|TestRetrieveTools_ExcludesDisabledToolsPreRanking|TestCallBlockedTool_ReturnsToolBlocked|TestReenableTool_VisibleAndCallable|TestHandleListUpstreams_FilteredForAgent'

Notes

  • security/admin introspection remains available via explicit quarantine/security endpoints
  • standard discovery and call planning no longer surfaces disabled tools

@JasonLandbridge JasonLandbridge changed the title fix: enforce hidden semantics for disabled tools Allow tools to be disabled and thus hidden from mcp discovery May 4, 2026
JasonLandbridge and others added 2 commits May 4, 2026 13:48
…den retrieve_tools test

Address review feedback on PR smart-mcp-proxy#447:

1. handleListUpstreams previously fell back to live ListTools only when
   p.mainServer == nil (test/standalone). In production the
   getVisibleToolCount path uses the supervisor's StateView snapshot,
   which is empty during startup before the supervisor hydrates - so the
   UI would show "0 tools" for a freshly-connected server with healthy
   tools. Restored the live ListTools fallback in production too,
   filtered by isToolCallable so disabled tools still don't inflate the
   count.

2. handleRetrieveTools called auth.AuthContextFromContext(ctx) inside
   the per-result loop. Hoisted it (and the IsAdmin check) above the
   loop - it's a per-request value and the lookup is repeated work for
   every search result.

3. TestRetrieveTools_ExcludesDisabledToolsPreRanking previously
   silent-passed if the response had no "tools" field. The query
   ("context7 resolve library id") only matched the disabled context7
   tool, so the enabled github tool wasn't a positive control - the
   test verified nothing once the disabled tool was filtered out.

   Rewrote both tools to share the same description so BM25 returns
   both, then asserted:
     - the enabled tool MUST appear (positive control catches an over-
       eager filter regression),
     - the disabled tool MUST NOT appear (negative control).

   Also dropped the silent early-return in favor of require.True on the
   tools field.

Verification:
- go test ./internal/server -count=1 -timeout 10m  PASS (434s)
- go vet ./...  clean

Co-Authored-By: Claude Opus 4.7 (1M context) <[email protected]>
@Dumbris

Dumbris commented May 4, 2026

Copy link
Copy Markdown
Member

Reviewed and pushed a8d01147 with three fixes plus the missing make swagger regeneration.

Review summary

The core mechanism — gating tool exposure on ToolApprovalRecord.Disabled via a centralized isToolCallable predicate that's checked in both handleRetrieveTools and handleCallToolVariant/handleCallTool — is sound. Tests pass with -race. A few issues worth fixing before merge:

1. Startup regression in handleListUpstreams (fixed)

getVisibleToolCount reads from the supervisor's StateView snapshot, which is empty during startup before the supervisor has hydrated. The fallback to live ListTools was gated on p.mainServer == nil — i.e. only ever runs in tests/standalone — so in production a freshly-connected server with healthy tools would render as "0 tools" in the UI until the next reconciliation cycle.

Restored the live fallback in production too, but filtered through isToolCallable so disabled tools still don't inflate the count:

toolCount = p.getVisibleToolCount(server.Name)
if toolCount == 0 {
    if tools, err := client.ListTools(context.Background()); err == nil {
        for _, tool := range tools {
            if p.isToolCallable(server.Name, tool.Name) {
                toolCount++
            }
        }
    }
}

2. Per-result auth.AuthContextFromContext(ctx) (fixed)

In the new handleRetrieveTools filter loop, the auth context lookup was inside the per-result for iteration:

for _, result := range results {
    ...
    if authCtx := auth.AuthContextFromContext(ctx); authCtx != nil && !authCtx.IsAdmin() {
        if !authCtx.CanAccessServer(serverName) { continue }
    }
    ...
}

context.Value is a hash lookup per call, and the auth context is a per-request value — repeated work for every search result. Hoisted it (and the IsAdmin check) to a single resolution above the loop.

3. TestRetrieveTools_ExcludesDisabledToolsPreRanking silent-passed (fixed)

The previous form had a quiet escape hatch:

toolsValue, exists := payload["tools"]
if !exists || toolsValue == nil {
    return  // ← silent pass
}

…and the indexed pair (context7:resolve-library-id disabled, github:get_file_contents enabled) didn't share keywords with the BM25 query (context7 resolve library id), so the only hit was the disabled tool. Once filtered out, the response had no tools field, and the test silently passed without verifying anything — including failing to catch a regression where the github tool also got accidentally filtered.

Rewrote the fixture so both indexed tools share the same description ("library documentation lookup helper") and BM25 returns both; replaced the silent return with require.True and added a positive control:

assert.Contains(t, names, "github:library-lookup",
    "enabled tool must survive ranking and filtering")
assert.NotContains(t, names, "context7:library-lookup",
    "disabled tool must be filtered out before ranking")

4. make swagger regeneration (fixed)

The new blocked_count field on QuarantineStats wasn't reflected in oas/swagger.yaml/oas/docs.go. The pre-push hook caught this — regenerated and included.

Verification

go test ./internal/server -count=1 -timeout 10m   PASS (434s)
go test ./internal/runtime -count=1                PASS
go test ./internal/httpapi -count=1                PASS
go vet ./...                                       clean

Other observations (not changed)

  • Frontend router/index.ts: removal of scrollBehavior looks unrelated to the spec - worth either a separate PR or a sentence in the description so reviewers know why it's bundled.
  • isToolCallable BBolt cost: two BBolt reads per result (GetUpstreamServer + GetToolApproval). Fine at current retrieve_tools limit ≤ 100, but if that ever loosens, batch-fetching disabled tool names per server up-front would scale better.
  • Stale _test.go fixture in tool_quarantine_test.go: ParamsJSON: \\"schema\"`(escaped quotes inside a backtick string) parses as the literal text"schema"`, not a valid JSON string. Hashes still match because both sides use the same literal, but the data isn't what the field is documented to hold. Cosmetic.
  • Disabling does not invalidate live MCP sessions: an in-flight tool call started before the disable will still complete. If you want strict cut-over semantics, you'd need to thread the check into the per-call middleware. Probably fine as-is — disabling is administrative.

@Dumbris
Dumbris merged commit 4bf17a0 into smart-mcp-proxy:main May 5, 2026
23 checks passed
@Dumbris

Dumbris commented May 5, 2026

Copy link
Copy Markdown
Member

Thanks @JasonLandbridge! Merged. The TOOL_BLOCKED + isToolCallable centralization is a clean pattern - we'll be able to reuse it for the per-agent visibility work coming next.

@JasonLandbridge

Copy link
Copy Markdown
Contributor Author

Thanks!

electrolobzik pushed a commit to HaloCollar/mcpproxy-go that referenced this pull request May 13, 2026
…mcp-proxy#447)

Closes smart-mcp-proxy#432
<img width="2188" height="602" alt="image" src="https://github.com/user-attachments/assets/8aef92a4-09de-4caa-acf0-24994c04c113" />
<img width="3281" height="742" alt="image" src="https://github.com/user-attachments/assets/7f445aa8-16f2-461d-8b99-173539b59cb3" />

<img width="3289" height="1483" alt="image" src="https://github.com/user-attachments/assets/a809983d-a61a-4b8c-b000-24da70ea9fd4" />

- treat disabled tools as non-callable/non-discoverable via centralized callable checks
- filter disabled tools before retrieve_tools response construction
- return TOOL_BLOCKED with clear message for direct calls to disabled tools
- exclude disabled tools from server status health tool_count displays
- add regression tests for callable predicate, discovery filtering, blocked call error, and re-enable visibility

- go test ./internal/server -run 'TestIsToolCallable_DisabledTool|TestRetrieveTools_ExcludesDisabledToolsPreRanking|TestCallBlockedTool_ReturnsToolBlocked|TestReenableTool_VisibleAndCallable|TestHandleListUpstreams_FilteredForAgent'

- security/admin introspection remains available via explicit quarantine/security endpoints
- standard discovery and call planning no longer surfaces disabled tools
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Add ability to disable individual tools in MCP servers after approval

3 participants