fix(mcp): keep last-known-good tools instead of flashing red on a transient failure#5839
Conversation
…nsient failure A connected server with cached tools was turning red 'Failed to discover' on a single transient discovery probe blip, even though the stored status stayed connected with tools — because useMcpToolsQuery dropped React Query's retained data on error, and the row's showDiscoveryError fired over a populated server. Now the aggregate keeps last-known-good tools across a failed refetch, and the row only hard-reds when there are genuinely no tools to show. A persistent failure still surfaces via the stored connectionStatus (gated by MAX_CONSECUTIVE_FAILURES), matching how Claude Code / LibreChat / OpenCode / VS Code handle a transient tools/list failure on a live connection. Validated against those clients' source + the MCP spec before changing; this supersedes the #5829 over-correction that showed the error even when tools existed.
|
The latest updates on your projects. Learn more about Vercel for GitHub. |
PR SummaryLow Risk Overview
MCP server list rows only treat a discovery error as a hard failure ( Tests cover transient refetch failure (tools preserved + error recorded) and persistent failure (stale tools cleared after list refresh shows Reviewed by Cursor Bugbot for commit b65d49c. Configure here. |
Greptile SummaryThis PR keeps cached MCP tools visible during transient discovery failures. The main changes are:
Confidence Score: 5/5No additional blocking issue qualifies for this follow-up review.
Important Files Changed
Reviews (2): Last reviewed commit: "fix(mcp): drop stale tools once a server..." | Re-trigger Greptile |
… on transient Sharpens the last-known-good behavior with the transient-vs-persistent distinction the reference clients make: keep cached tools through a transient discovery failure (stored status still healthy) so a populated server doesn't blank, but drop them once the stored connectionStatus crosses its failure threshold to error/disconnected — so the shared aggregate the workflow editor consumes stops offering a dead server's stale tool schemas.
|
@cursor review |
There was a problem hiding this comment.
✅ Bugbot reviewed your changes and found no new issues!
Comment @cursor review or bugbot run to trigger another review on this PR
Reviewed by Cursor Bugbot for commit b65d49c. Configure here.
Summary
A connected MCP server with cached tools was showing red "Failed to discover MCP tools" on a single transient discovery probe — even though the backend stored status was
connectedwith a valid tool count (verified in the DB while the UI showed red). It made healthy servers look like they "fail all the time" as probes oscillated against the origin's intermittent stalls.Two coordinated client-side display fixes:
useMcpToolsQueryno longer discards React Query's retaineddataon error — it kept the last successful tools around and we were throwing them away (if (result.data && !result.isError)→if (result.data)). The per-server error still rides intoolsStateByServer.showDiscoveryErroronly hard-reds when there are genuinely no tools to show (tools.length === 0). A populated, connected server stays on its tool count through a transient blip; a persistent failure still reads as failed via the storedconnectionStatus(gated byMAX_CONSECUTIVE_FAILURES).Validated against primary sources before changing (I'd over-corrected this exact condition in #5829): the MCP spec's discover-once +
tools/list_changedmodel, plus the actual behavior of Claude Code (which shipped this same fix as a bug removal — a transient failure no longer flags a healthy server), LibreChat (returns already-fetched tools rather than discarding; guards against overwriting with empty), OpenCode (if (!listed) return, leaves tools intact), and VS Code (persistent tool cache). None blanks a populated server on a transienttools/listfailure over a live connection. This supersedes the #5829 over-correction.Type of Change
Testing
useMcpToolsQuerytest: last-known-good tools survive a failing refetch (with the per-server error still exposed). 16 MCP query + settings tests green; tsc + biome clean.Checklist