Skip to content

fix(mcp): scope tools loading state to each server's own query#5441

Merged
waleedlatif1 merged 1 commit into
stagingfrom
fix/mcp-tools-refresh-loading
Jul 6, 2026
Merged

fix(mcp): scope tools loading state to each server's own query#5441
waleedlatif1 merged 1 commit into
stagingfrom
fix/mcp-tools-refresh-loading

Conversation

@waleedlatif1

Copy link
Copy Markdown
Collaborator

Summary

  • Settings > MCP tools rows derived their "Loading..." text from a workspace-wide isLoading || isFetching aggregate across every server's tool query, instead of that specific server's own query — so a row could stay stuck (or flicker back) showing "Loading..." while its tools had actually already resolved, whenever any other server's query was fetching. Only a full page refresh cleared it.
  • useMcpToolsQuery now zips its per-server useQueries results with their serverIds into a toolsStateByServer map (replacing the previously unused perServer array), giving each row its own isLoading/isFetching/error.
  • mcp.tsx reads each row's loading state from toolsStateByServer.get(server.id) instead of the global aggregate.

Type of Change

  • Bug fix

Testing

Tested manually; bun run type-check, bunx biome check, and bun run check:react-query pass on the changed files.

Checklist

  • Code follows project style guidelines
  • Self-reviewed my changes
  • Tests added/updated and passing
  • No new warnings introduced
  • I confirm that I have read and agree to the terms outlined in the Contributor License Agreement (CLA)

Server rows derived "Loading..." from a workspace-wide isLoading/isFetching
aggregate instead of that server's own per-server query, so a row could sit
stuck on "Loading..." (or flicker back to it) whenever any other server's
tool query was fetching, only clearing after a full page reload.
@vercel

vercel Bot commented Jul 6, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
docs Skipped Skipped Jul 6, 2026 9:23pm

Request Review

@cursor

cursor Bot commented Jul 6, 2026

Copy link
Copy Markdown

PR Summary

Low Risk
Small UI/state wiring change in MCP settings; no auth, API, or data-model changes.

Overview
Fixes MCP settings list rows showing "Loading..." when another server's tool query was still fetching, even though that row's tools had already loaded.

useMcpToolsQuery now pairs each useQueries result with its serverId and exposes a toolsStateByServer map (isLoading, isFetching, error per server), replacing the unused perServer array. mcp.tsx reads each ServerListItem's loading flag from that map instead of workspace-wide isLoading || isFetching.

Reviewed by Cursor Bugbot for commit 4d257aa. Configure here.

@greptile-apps

greptile-apps Bot commented Jul 6, 2026

Copy link
Copy Markdown
Contributor

Greptile Summary

This PR fixes a cross-server loading-state contamination bug in the MCP settings UI where a single slow server query caused all other server rows to stay stuck on "Loading..." until a full page refresh. The fix is well-scoped: the per-server useQueries results are now zipped with their serverIds into a toolsStateByServer Map inside useMcpToolsQuery, and each row reads its own loading state from that map via toolsStateByServer.get(server.id).

  • hooks/queries/mcp.ts: Replaces the unused perServer results array with a toolsStateByServer Map built during the same aggregation loop; also correctly adds serverIds to the useMemo dependency array (previously missing).
  • mcp.tsx: Drops the workspace-wide toolsLoading/toolsFetching destructuring and uses per-server state from the new map, defaulting to false when a server has no entry (e.g. disabled servers, which are intentionally excluded from queries).

Confidence Score: 5/5

Safe to merge — the change is a targeted, well-reasoned fix with no new external dependencies and correct handling of edge cases (disabled servers, workspace switches, stale-data placeholder).

The index-aligned zip between results and serverIds is correct because useQueries preserves insertion order, and serverIds is built by the same useMemo that feeds the queries array. Adding serverIds to the aggregator's useMemo deps closes a pre-existing stale-closure gap. The fallback to false for unmapped servers is the right behaviour for disabled rows. The global isLoading/isFetching/error fields are preserved for any future consumers.

No files require special attention.

Important Files Changed

Filename Overview
apps/sim/hooks/queries/mcp.ts Introduces toolsStateByServer Map by zipping useQueries results with serverIds; adds serverIds to useMemo deps (fixing a pre-existing stale-closure risk); removes the previously-dead perServer array.
apps/sim/app/workspace/[workspaceId]/settings/components/mcp/mcp.tsx Consumes per-server loading state from toolsStateByServer.get(server.id) instead of the global aggregate booleans; defaulting to false when a server is absent from the map is correct for disabled/cross-workspace servers.

Flowchart

%%{init: {'theme': 'neutral'}}%%
flowchart TD
    A[useMcpServers] -->|servers list| B[serverIds memo]
    B -->|one query per ID| C[useQueries N parallel fetches]
    C -->|index-aligned results| D{useMemo aggregator}
    D --> E[toolsStateByServer Map]
    D --> F[data: McpTool flat list]
    E --> H[mcp.tsx filteredServers.map]
    F --> H
    H -->|.get server.id| I[Per-row isLoadingTools]
    I --> J[ServerListItem]
Loading
%%{init: {'theme': 'base', 'themeVariables': {"darkMode": true, "background": "#0d1117", "primaryColor": "#21262d", "primaryTextColor": "#e6edf3", "primaryBorderColor": "#8b949e", "lineColor": "#8b949e", "textColor": "#e6edf3", "edgeLabelBackground": "#161b22", "actorBkg": "#21262d", "actorBorder": "#8b949e", "actorTextColor": "#e6edf3", "actorLineColor": "#8b949e", "signalColor": "#8b949e", "signalTextColor": "#e6edf3", "noteBkgColor": "#373320", "noteBorderColor": "#d4a72c", "noteTextColor": "#f0e6c0", "labelBoxBkgColor": "#21262d", "labelBoxBorderColor": "#8b949e", "labelTextColor": "#e6edf3", "loopTextColor": "#e6edf3", "activationBkgColor": "#30363d", "activationBorderColor": "#8b949e"}}}%%
flowchart TD
    A[useMcpServers] -->|servers list| B[serverIds memo]
    B -->|one query per ID| C[useQueries N parallel fetches]
    C -->|index-aligned results| D{useMemo aggregator}
    D --> E[toolsStateByServer Map]
    D --> F[data: McpTool flat list]
    E --> H[mcp.tsx filteredServers.map]
    F --> H
    H -->|.get server.id| I[Per-row isLoadingTools]
    I --> J[ServerListItem]
Loading

Reviews (1): Last reviewed commit: "fix(mcp): scope tools loading state to e..." | Re-trigger Greptile

@waleedlatif1 waleedlatif1 merged commit a342424 into staging Jul 6, 2026
13 checks passed
@waleedlatif1 waleedlatif1 deleted the fix/mcp-tools-refresh-loading branch July 6, 2026 21:35
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.

1 participant