Repository navigation
fix(runtime): index approved tools immediately after approval + upstream refresh op - #876
Conversation
…eam refresh op (#873) Approval mutations (ApproveTools/ApproveAllTools/BlockTools/SetToolEnabled and their bulk variants) only wrote BBolt records and emitted events. Indexing happened solely in applyDifferentialToolUpdate, reached from discovery (boot sweep, 5-min periodic sweep, connect, tools/list_changed) — never from approval. So an approved tool was callable immediately (call-time gates read BBolt live) but invisible to retrieve_tools/describe_tool until the next sweep; blocked/ disabled tools lingered in the index just as long. Add reindexServerToolsAfterApprovalChange, triggered async from the approval/ block/enable paths, which re-runs applyDifferentialToolUpdate against the last- good tool snapshot. A SECURITY-CRITICAL guard returns early unless the server exists, is enabled, and is NOT quarantined — applyDifferentialToolUpdate does not itself withhold a quarantined server's tools, so an unguarded call would index descriptions the search-side quarantine model deliberately withholds. DiscoverAndIndexToolsForServer now also populates lastGoodTools so single-server connects have a snapshot; the reindex falls back to a full rediscover otherwise. Add operator recovery op: upstream_servers "refresh" (pure rediscover+reindex, no security-state change) and REST POST /api/v1/servers/{id}/refresh (alias of discover-tools). Also fix pre-existing enum drift: enable/disable/restart were dispatched but not advertised in the operation enum — now listed alongside refresh. refresh is intentionally left out of the agent-token block list (it mutates no config/security state). The unquarantine path already schedules a full reindex via HandleUpstreamServerChange, so the extra differential pass from approveBaselineToolsForServer is a cheap no-op (and a no-op under the guard while the server is still quarantined).
… regen golden (#873) The upstream_servers 'refresh' op (and the reactive discovery callbacks) reach DiscoverAndIndexToolsForServer, which fed applyDifferentialToolUpdate with no quarantine/enabled guard — the same gap reindexServerToolsAfterApprovalChange already defends. A refresh on a still-connected quarantined server therefore re-indexed its (possibly TPA-poisoned) tool descriptions into retrieve_tools/ describe_tool. Extract serverEligibleForIndexing (exists+enabled+!quarantined) and gate DiscoverAndIndexToolsForServer on it; unquarantine reindexes via the full sweep, so newly-trusted servers are unaffected. Also block 'refresh' for non-admin agent tokens (defense-in-depth, matching enable/disable/restart), and regenerate the Spec-085 pre-feature golden's upstream_servers entry for the intended enable/disable/restart/refresh enum + description change so TestMenuSurface_ExactDeltaFromPreFeature passes.
Deploying mcpproxy-docs with
|
| Latest commit: |
e1ee5e4
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://b1e1f46c.mcpproxy-docs.pages.dev |
| Branch Preview URL: | https://fix-873-reindex-on-approval.mcpproxy-docs.pages.dev |
|
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
📦 Build ArtifactsWorkflow Run: View Run Available Artifacts
How to DownloadOption 1: GitHub Web UI (easiest)
Option 2: GitHub CLI gh run download 29826387029 --repo smart-mcp-proxy/mcpproxy-go
|
…empty refresh (#873) Codex cross-review follow-ups on PR #876: 1. REST POST /servers/{id}/refresh accepted agent tokens while the MCP upstream_servers 'refresh' op blocks them. Gate the REST alias with the strictest sibling pattern (admin-only), matching handleSetToolEnabled, so agents cannot bypass the MCP restriction over HTTP. 2. TOCTOU: single-server discovery and the approval-driven reindex checked eligibility before the seconds-wide ListTools / snapshot diff, so a server quarantined mid-flight could have its tools written back into the index after quarantine already deleted them. Re-check eligibility immediately before the index write and bail if ineligible (a microsecond window remains, documented). 3. A successful discovery returning zero tools exited early without reconciling the index or last-good snapshot, so an explicit refresh reported success while stale tools stayed searchable and a later approval reindex could resurface them. Split the entry point: reactive discovery stays lenient (transient empty ignored); the explicit refresh/discover path (RefreshServerTools) treats zero tools as authoritative, clearing stale entries and the snapshot. Regenerated oas/ for the new 403 response on the refresh endpoint.
…-tools (#873) Codex round 2 on PR #876: 1. The discovery sweep (discoverAndIndexTools) still bypassed the eligibility guard at both index-write sites. The upstream manager already skips quarantined/disabled servers when listing, but the last-good fallback loop iterates all known servers and reapplies a connected server's snapshot — and a quarantined server stays connected keeping its pre-quarantine snapshot, so the sweep QuarantineServer triggers right after deleting the server's index entries would restore them. Route both sweep writes through a shared applyServerDiffIfEligible helper that re-checks eligibility immediately before the write. 2. REST POST /servers/{id}/discover-tools was still agent-token-accessible and is an alias reaching the same authoritative RefreshServerTools path, bypassing the /refresh admin gate. Gate it with the identical IsAdmin() check. Regenerated oas/ for the new 403 on discover-tools.
|
Cross-model review (Codex): clean after 3 rounds. R1: REST |
Fixes #873
ApproveTools/ApproveAllToolsonly wrote approval records — indexing happens exclusively inapplyDifferentialToolUpdate, reached only from discovery. So a just-approved tool was immediately callable but invisible toretrieve_tools/describe_tooluntil the next sweep (default 5 min; indefinitely with sweeps disabled). Reproduced live with a rug-pull test server.Change
reindexServerToolsAfterApprovalChange(async,AppContext-scoped) runs afterApproveTools/BlockTools/SetToolEnabledchanges: takes the last-good tool snapshot (now also populated by the single-server discovery path) and re-runsapplyDifferentialToolUpdate— so profile indexes and the spec-085 signature cache stay consistent for free, and block/disable now removes tools promptly too.applyDifferentialToolUpdateitself never checks server quarantine, so an unguarded call would index a quarantined server's withheld tool descriptions.DiscoverAndIndexToolsForServergot the same guard (review found the newrefreshop could otherwise index a quarantined server, and was reachable by non-admin agent tokens — both closed).upstream_serversoperationrefresh(pure rediscover+reindex, no security-state change) + RESTPOST /api/v1/servers/{id}/refresh; the operation enum also now advertises the previously-undocumentedenable/disable/restart.Verification
tool_discovery_interval=30mso no sweep could mask the result): pending tool invisible →approve_all_tools→ visible toretrieve_tools/describe_toolwithin seconds;refreshop works via MCP and REST; quarantined-server probe confirms tools stay withheld.go test -racegreen, API E2E green, lint clean.Draft: @neylwalecki mentioned having a patch for this — happy to reconcile.