Skip to content

feat(mcp): read and move MCP servers from agents' own config files - #48632

Merged
AmoabaKelvin merged 6 commits into
mainfrom
mcp-import
Nov 25, 2026
Merged

AmoabaKelvin merged 6 commits into
mainfrom
mcp-import

Conversation

@AmoabaKelvin

@AmoabaKelvin AmoabaKelvin commented Nov 25, 2026 •

Copy link
Copy Markdown
Collaborator

ELI5

People set up MCP servers inside each coding agent's own settings (Claude Code, Codex, Gemini and others). Orca is about to get one MCP server list of its own. This adds the pieces that find those agent-side servers, take them out of an agent's settings file safely when the user moves them into Orca, and read a pasted server config. Nothing calls these pieces yet.

Files Added Deleted Net
Test 4 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​420 0 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​420
Prod 13 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1784 $\color{#cf222e}{\Huge{\mathbf{−}}}$​17 $\color{#1a7f37}{\Huge{\mathbf{+}}}$​1767

What Changed

Three modules for the "MCP servers in Orca" feature. None is wired to a screen or RPC in this PR.

  • Readers for each agent's own MCP config:

    • Claude Code: user scope and per-project local scope in ~/.claude.json, plus the repo .mcp.json.
    • Codex: config.toml, from a CODEX_HOME the user set, else ~/.codex.
    • Gemini, OpenCode (1.x mcp.<name> and 2.x mcp.servers.<name>), Cursor, Copilot, Grok, Droid, Pi and Amp.

    Entries are read into Orca's server shape. Rows merge across agents when the name and the whole definition match (URL or command line, headers, env). Orca's own bridge entries (orca mcp connect/exec), which a later PR writes into Grok, Cursor and Droid, are recognised and never listed.

  • Move and Copy service.

    • Move adds the server to Orca's list first, through an injected add. It then removes the matching entries from every agent file, and from Orca's managed Claude account profiles where the copy is identical.
    • Edits are text splices: the JSON parse tree for JSON, a line splice for TOML. Comments, key order and CRLF stay as they were.
    • Each splice is checked against the parsed file, and must equal the old config minus exactly those entries.
    • The edited file is published only if it still holds the bytes the edit was made from. A rolling .bak keeps the previous contents.
    • Claude's files are edited under the same lock Claude Code takes.
    • Claude local-scope servers stay limited to their repo or folder workspace in Orca. An agent copy that was switched off stays off for that agent.
  • parseMcpServersPaste in src/shared/bot-tool-paste.ts. It reads the Custom server field: a URL, a start command, an mcpServers JSON block (JSONC, a single entry, or a copied "name": {…} fragment), and claude mcp add, claude mcp add-json and codex mcp add lines. The bots parser parseBotToolPaste is unchanged.

An entry Orca can't run exactly as its agent does is left in the agent and never moved. That covers:

  • SSE servers;
  • values the agent fills in itself: ${VAR}, {env:VAR}, {file:…}, Gemini's $VAR, Pi's !cmd, and Codex's bearer_token_env_var;
  • an entry's own OAuth client;
  • tool allow and deny lists, in the entry or file-wide like Grok's disabled_mcp_tools;
  • a working folder of its own.

Why

The approved design lists servers found in agents under "In your agents", with Move to Orca and Copy to Orca. The Custom server field also has to accept pasted configs. These modules land on main first, so the wiring PR stacked on the host-list PR stays small.

Moving from Codex edits only Codex's own home. Orca's managed CODEX_HOME mirror already drops servers it mirrored before, so the change reaches managed homes on the next launch. Claude's managed account profiles only copy servers forward from ~/.claude.json and never remove one, which is why Move cleans those copies directly.

Linked Issue

N/A: part of the MCP servers fleet (task 2 of 10). There is no issue.

Visual Proof

N/A: no UI. The screens come in the desktop and mobile UI PRs.

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

The tests cover the paste parser (JSON, CLI-line and refusal cases) and the TOML and JSON splices (dotted keys, inline entries, CRLF, the last table in a file). A fixture home with all ten agents' files checks discovery per agent. It also moves servers and checks the exact file bytes afterwards, the .bak contents, Claude profile copies (removed when identical, kept when the headers differ), local-scope workspaces, and refusal when an entry changed after it was listed. pnpm check:changed passes.

Gate-off equals main: nothing in production imports these modules yet. The only shared-file changes are the new parseMcpServersPaste export next to an untouched parseBotToolPaste, and the Claude config lock moved into claude-global-config-lock.ts with the same options and queue. The follow-up wiring calls the modules only from mcpServers.discover/move/copy, which refuse with mcp_servers_off while ORCA_MCP_SERVERS is unset.

Performance

None, because nothing calls this code yet. Once wired, it runs only when the MCP servers settings page asks for discovery, or when the user moves or copies a server. It reads about ten small files with non-blocking I/O.

Risk

The risky part is Move editing a user's agent config. Several guards stand between Move and a lost setting:

  • the parse-equality check;
  • the compare-and-swap write;
  • the .bak file;
  • Claude's own lock;
  • refusing entries Orca can't carry faithfully.

A plain revert backs it out. Nothing here persists state of its own.

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

Cross-platform: paths go through node:path; Windows quoted executable paths in a paste stay commands; CRLF is kept in TOML edits; the Windows read-only .bak handling matches the existing hooks writer. Remote hosts: these run on the execution host once wired, so each host reads its own agents' files.

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 discovery and parsing for MCP servers in multiple agent configuration formats. It adds operations to list, copy, move, and remove discovered servers, with checks for changed files and config locks. It also adds parsing for pasted JSONC configurations and Claude or Codex MCP add commands.

Merge Risk: Moderate · up to e2d19

The new MCP config import code is not yet wired into production. Several correctness edge cases remain open: a Move can overwrite a concurrent config save, can miss a stale entry, and can miss a disabled-state change, and some valid pasted configs are rejected. Address or explicitly accept these before merge.

Pre-merge checks: Passed 3 · Inconclusive 1

Failed Failed checks: 1 inconclusive

Check name Status Explanation Resolution
Description check Inconclusive The description follows the template sections: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, Review, Notes, and Checklist. It explains the three modules and why they… Add a Linked Issue, or confirm the author is a maintainer who may skip it. Mark whether manual testing was done, or explain why it was not. Confirm that pnpm lint, typecheck, test, and build pass, or note that CI will cover them. The AI Dis…
Passed Passed checks: 3 passed

Check name Status Explanation
Title check Passed The title "feat(mcp): read and move MCP servers from agents' own config files" matches the main change. The PR adds readers for agent MCP configs and a move service that removes entries from agent fil…
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 "feat(mcp): read and move MCP servers from agents' own config files" matches the main change. The PR adds readers for agent MCP configs and a move service that removes entries from agent files. It does not mention the paste parser, and the changes are not yet wired into production. The title is specific and accurate.

Full details: Description check

Explanation

The description follows the template sections: ELI5, What Changed, Why, Linked Issue, Visual Proof, Testing, Performance, Risk, Review, Notes, and Checklist. It explains the three modules and why they land first. The Linked Issue section says there is no issue, which the template requires for outside contributors. The AI Disclosure section is empty. The Testing checkboxes for manual testing are unchecked, and the lint, typecheck, test, and build checklist item is unchecked. The Risk level is set to Low.

Resolution

Add a Linked Issue, or confirm the author is a maintainer who may skip it. Mark whether manual testing was done, or explain why it was not. Confirm that pnpm lint, typecheck, test, and build pass, or note that CI will cover them. The AI Disclosure section is blank. Fill it in, or state that it does not apply.

  • 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: 2055acbd-47f1-44d5-b46b-392c565ace8b
Commits

Reviewing files that changed from the base of the PR and between 70161a9 and e2d196b.

Files selected for processing: 2

  • src/main/mcp-servers/agent-configs/agent-mcp-config-removal.test.ts
  • src/main/mcp-servers/agent-configs/agent-mcp-import.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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 7

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: b25a9faf-5a4a-4f04-a3ac-1c91c81a13e3
Commits

Reviewing files that changed from the base of the PR and between 315dacd and c14295b.

Files selected for processing: 17

  • src/main/claude/configuration/claude-folder-trust-file.ts
  • src/main/claude/configuration/claude-global-config-lock.ts
  • src/main/mcp-servers/agent-configs/agent-config-file-write.ts
  • src/main/mcp-servers/agent-configs/agent-mcp-config-locations.ts
  • src/main/mcp-servers/agent-configs/agent-mcp-config-read.ts
  • src/main/mcp-servers/agent-configs/agent-mcp-config-removal.test.ts
  • src/main/mcp-servers/agent-configs/agent-mcp-config-removal.ts
  • src/main/mcp-servers/agent-configs/agent-mcp-import.ts
  • src/main/mcp-servers/agent-configs/json-property-removal.test.ts
  • src/main/mcp-servers/agent-configs/json-property-removal.ts
  • src/main/mcp-servers/agent-configs/toml-mcp-server-removal.test.ts
  • src/main/mcp-servers/agent-configs/toml-mcp-server-removal.ts
  • src/renderer/src/i18n/locales/en.json
  • src/shared/bot-tool-paste.test.ts
  • src/shared/bot-tool-paste.ts
  • src/shared/mcp/agent-mcp-config-entry.ts
  • src/shared/mcp/mcp-add-command-paste.ts

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

throw new AgentMcpConfigEditError('unparseable', path)
}
const wanted = new Set(sources.map((source) => JSON.stringify(source.keyPath)))
const listed = current.filter((found) => wanted.has(JSON.stringify(found.source.keyPath)))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Check raw entry presence before treating an entry as deleted.

If a listed server gains an unsupported cwd field before removal, agentMcpConfigServersIn excludes it from current. Both listed and present are then empty. Line 94 returns without a stale-entry error, and moveAgentMcpServer reports success with the older imported definition.

Check the original key paths in the parsed config. In refuse mode, reject an existing entry that no longer normalizes. Continue to skip entries that are actually absent.

const added = await add(found.server, scope)
const configName = found.sources[0]!.keyPath.at(-1)!
const mergeKey = agentMcpServerMergeKey(configName, found.server)
await removeAgentMcpServerEntries(found.sources, mergeKey)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Data Integrity & Integration · Quick win

The removal guard ignores a disabled-state change made after listing.

moveAgentMcpServer adds the server with the scope captured at listing, then removes the agent entries by merge key. agentMcpServerMergeKey does not include disabled. If the user disables or enables the entry in the agent file while add is pending, removalFrom still matches it and removes it. The Orca server keeps the state captured at listing, so the user's change is lost without a refusal.

Require the removal guard to compare each matched entry's disabled state with the state captured in sources when the server was listed. On a mismatch, removeAgentMcpServerEntries should refuse the move when differing is 'refuse', and skip that entry when differing is 'skip'. Keep the merge-key comparison unchanged for other edits.

Comment on lines +104 to +106
if (char === "'") {
quoted = !quoted
} else if (!quoted && char === '$' && /[A-Za-z_]/.test(line[index + 1] ?? '')) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Honor escapes when detecting variable expansion.

On Darwin, claude mcp add demo -- node server.js --label \$HOME contains a literal $HOME argument. The tokenizer correctly consumes the escape, but this scan still reports an expansion and rejects the command.

Track escapes and both quote types consistently with the tokenizer. Keep unescaped $HOME rejected.

const text = source.trim()
let servers: BotToolServer[]
// A quoted executable path (a Windows "Program Files" one) is a command, not a JSON fragment.
if (text.startsWith('{') || /^"[^"\\]*"\s*:/.test(text)) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Recognize JSONC after leading comments.

A paste that starts with // copied configuration followed by {"command":"npx","args":["server"]} enters the command path. The object line then fails in parseBotToolPaste, although the input is a supported JSONC configuration.

Detect the configuration after leading JSONC comments. Keep quoted executable paths on the command path.

servers = text
// A shell line continuation joins the lines exactly where it sits.
.replace(/\\\r?\n/g, '')
.split(/\r?\n/)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor · Functional Correctness · Quick win

Keep newlines inside quoted arguments.

A claude mcp add-json command can contain a single-quoted, formatted JSON argument. This split separates that argument into commands. The first fragment then fails with an unclosed quote.

Split command lines only outside quoted arguments. Preserve support for several complete commands in one paste.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

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: 07cb1866-8ed6-4031-8e09-74061f011070
Commits

Reviewing files that changed from the base of the PR and between c14295b and 70161a9.

Files selected for processing: 2

  • src/main/mcp-servers/agent-configs/agent-mcp-config-removal.test.ts
  • src/main/mcp-servers/agent-configs/agent-mcp-import.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.

@AmoabaKelvin
AmoabaKelvin merged commit 6ad7809 into main Nov 25, 2026
57 of 58 checks passed
dluxhu added a commit to dluxhu/orca that referenced this pull request Nov 27, 2026
…'s agent folders

v1.4.279 reads and moves MCP servers in agents' own config files
(upstream stablyai#48632). In an app profile, Codex and the gemini settings live
in the profile's agent folders, so the fallback paths go through
agentHomeDirIn like the other agent paths. The home path scan also
allows v1.4.279's new Antigravity paths in ~/.gemini: agy has no folder
variable.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
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