Skip to content

perf(mcp): read the credential store once per MCP server list, check and switch - #49123

Merged
AmoabaKelvin merged 6 commits into
mainfrom
fix/mcp-host-list-credential-reads
Nov 25, 2026
Merged

AmoabaKelvin merged 6 commits into
mainfrom
fix/mcp-host-list-credential-reads

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

Opening the MCP servers list made Orca unlock every saved MCP password once per server that had one. With 50 such servers that's 2,550 unlocks for one list. Checking the servers' health and turning one server on or off did the same, and a switch also searched the whole list once per server. Now one unlock serves the whole list, and each server finds its old saved entry straight away.

Files Added Deleted Net
Test 1 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​111 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​111
Prod 6 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​105 $\color{#cf222e}{\Huge{\mathbf{−}}}$​48 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​57

What Changed

  • Listing (mcpServers.list, a bot's tools list) reads the encrypted credential store once and looks up every row's sign-in state from that one read (botToolCredentialsReader, taken lazily so a list with no credentials reads nothing). Before, every row with a credential re-read and re-decrypted the whole store (botOwnTool → botToolSignInState → readBotToolOAuth).
  • The tools-file writer (writeServers) finds each entry's previous one through a name map built once per write, not an array search per row. It also checks every row's sign-in address from one store read, not one read per credentialed row. This is the path every host MCP switch takes (agent on/off, workspaces, shared process), since those pass every entry with its extras.
  • The tools check (mcpServers.problems, a bot's tools check) asks whether each credentialed server is an Orca sign-in from one store read, not one per row.
  • A write that replaces saved values keeps each old value for its rollback from the writer's same store read, not one read per replaced credential.
  • changeBotToolServers (bot tool edits, removals, package apply) gives its change the snapshot's servers directly. It no longer builds and filters every row's extras just to drop them. The writer still carries each row's extras over from its previous entry, as before.

Nothing visible changes and stored files are byte-for-byte the same.

Why

The bot-tools layer answered per-row questions with whole-store work. botOwnTool and writeServers were written for a bot's own tools list, usually a handful of servers edited now and then, where a store read per row didn't matter. The per-host MCP list put every host server on that layer, listed it from every client and switched rows one at a time. That turned the per-row reads quadratic.

The fix is where the per-row decision lives, so the MCP list, the bots tools list and every write path all get it, on local, SSH and paired-server hosts alike. Callers don't need to change. A cache of the decrypted store was rejected: it would be a second copy of secrets in memory with its own invalidation, when reading once per request is enough.

Linked Issue

Linear: STA-18109, STA-18111, STA-18115

Visual Proof

N/A: no visible change. The lists and the saved files are identical; only the amount of work behind them changes.

Testing

  • I manually tested these changes locally
  • Automated tests added/updated, or explained why not below
  • Every added test fails without this change and avoids the test anti-patterns

Counted on macOS against unfixed main and this branch:

Work N / 10N before after
credential decrypts per host list 10 / 100 110 / 10,100 20 / 200
credential decrypts per switch 10 / 100 130 / 10,300 40 / 400
credential decrypts per bot tools list 10 / 100 110 / 10,100 20 / 200
credential decrypts per tools check 10 / 100 110 / 10,100 20 / 200
credential decrypts per write replacing every saved value 10 / 100 120 / 10,200 30 / 300
previous-entry search comparisons per switch 100 / 1,000 5,051 / 500,501 1 / 1
extras derivations per servers-only edit 10 / 100 20 / 200 10 / 100

The perf contract mcp-host-list.performance.test.ts pins all five decrypt counts at N and 10N. On unfixed main it fails (expected 110 to be 20). The search and extras counts came from a scratch instrumented run, because neither is visible from outside the writer. The existing host list, bot tools file, credentials, OAuth, relay, plugin sync and launch tests (13 files) pass unchanged.

Performance

This removes work. Every list, tools check and write now does a fixed number of credential-store reads instead of one per credentialed server. Each switch does one name-map build instead of a quadratic search. Servers-only edits skip a discarded pass over every row. See the table above.

Risk

Low. The riskiest part is the writer reading every sign-in, and every old value kept for a rollback, from one store read instead of one read per row. Nothing writes the store between that read and the writer's own credential changes, which come after it inside the same per-folder transaction. So every row sees the same state it saw before, and a rollback restores the same values. A plain revert backs it out.

Level: Low

AI Disclosure

Review

Agent skill upstream boundary

  • Not applicable, or this change copies or mechanically translates no upstream skill-installer source, tests, fixtures, registry entries, path tables, comments, or documentation.

Notes

Ensure no issues in: Security, Cross-platform support (Linux, Windows, Mac), Remote SSH, Mobile, general backwards compatibility, performance

No wire, file-format or platform-specific change. SSH and paired hosts run the same host-side code.

Checklist

  • This PR is small and focused
  • I explained what changed and why (ELI5, the user-facing before/after, the mechanism, and why over the alternatives)
  • I stated the risk: what could break, for whom, and how to back it out
  • Before/after screenshots or videos attached for UI changes, or N/A with reason
  • Self-reviewed for correctness, security, and performance
  • Cross-platform, SSH/remote, and path/shortcut impact considered (or N/A)
  • pnpm lint, pnpm typecheck, pnpm test, and pnpm build pass (or CI will cover; local preferred)

@coderabbitai

coderabbitai Bot commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Explain Change →

No actionable comments were generated in the recent review.

Walkthrough

The change adds a lazy credential reader that reuses an opened credential store for credential and OAuth lookups. Bot tool writes, listings, and problem checks use shared credential access. MCP host listing builds bot tool views in a batch. New performance tests count credential-store decryptions across listing, switching, checking, and replacement operations.

Merge Risk: Minimal · up to 3bd2c

This change cuts repeated credential-store reads when listing and checking MCP servers, without changing saved files or visible behavior. No concrete defect was found, so the merge risk is minimal. CI should confirm lint, typecheck, and tests.

Pre-merge checks: Passed 4

Check name Status Explanation
Title check Passed The title "perf(mcp): read the credential store once per MCP server list, check and switch" matches the main change. The diff makes MCP server listing, problem checks, and switches read the encrypted …
Description check Passed The description follows the template closely. It has an ELI5 section, a What Changed section, a Why section, a Linked Issue section with Linear references, a Visual Proof section marked N/A with a rea…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title "perf(mcp): read the credential store once per MCP server list, check and switch" matches the main change. The diff makes MCP server listing, problem checks, and switches read the encrypted credential store once instead of once per credentialed server. The title is specific and follows a conventional commit style. It is a long single sentence, but it names the primary change.

Full details: Description check

Explanation

The description follows the template closely. It has an ELI5 section, a What Changed section, a Why section, a Linked Issue section with Linear references, a Visual Proof section marked N/A with a reason, a Testing section with measured before and after counts, a Performance section, and a Risk section with a level and a rollback path. The Linked Issue section uses Linear IDs rather than a GitHub 'Fixes #' line, which the template asks for. The AI Disclosure section is empty. The unchecked lint, typecheck, test, and build item is left open with a note that CI may cover it.

  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

Recent review info

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Repository UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 0f577ce5-bfe3-407b-9978-340356e5d289
Commits

Reviewing files that changed from the base of the PR and between 49d03ee and 3bd2c17.

Files selected for processing: 1

  • src/main/mcp-servers/mcp-host-list.ts

Included review availability: This review used your included allowance. Your plan provides up to 10 included reviews per hour; 0 remain after this review.

…ot tools list

Listing the host's MCP servers or a bot's tools opened every saved
credential once per credentialed row, and each write did the same for
every row's sign-in check. One read now serves every row. The writer
finds each entry's previous one by name instead of scanning, and a
servers-only edit no longer derives extras it throws away.
The tools check (mcpServers.problems, bots tools problems) asked the
credential store whether each credentialed server was an Orca sign-in,
opening the whole store per row. It now uses the same one-read sign-in
lookup as the lists and the writer, which takes its read lazily.
A write that replaced saved values read the whole credential store once
per replaced credential to keep the old values for a rollback. The
writer's one store read now answers those too.
@AmoabaKelvin
AmoabaKelvin force-pushed the fix/mcp-host-list-credential-reads branch from 49d03ee to 3bd2c17 Compare November 25, 2026 17:07
@AmoabaKelvin
AmoabaKelvin merged commit 3e53fe1 into main Nov 25, 2026
58 checks passed
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