Repository navigation
feat(mcp): add preserveUnownedMcpServers to keep host-app Codex CLI servers - #4028
Merged
dyoshikawa merged 3 commits intoNov 30, 2026
Merged
Conversation
…ervers Codex CLI generation replaced the whole `mcp_servers` table of `config.toml`, so servers the Codex desktop app writes there itself (such as `node_repl`) were deleted on every `generate` and `--check` reported drift. With the new config-file-only `preserveUnownedMcpServers` option, every `[mcp_servers.<name>]` table the sources do not declare is kept verbatim and the declared servers are written over it (declared wins on a name clash). Default stays off. Closes #4025 Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…version Build the preserveUnownedMcpServers exclusion set from every declared server name as Codex normalizes it, so a declared server dropped for an invalid transport does not resurrect an older same-name entry. Document that servers no longer targeted at Codex CLI are left behind too, and point to the option from the global-mode guide. Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
…mand config mock Co-Authored-By: Claude Opus 5.5 <[email protected]> Claude-Session: https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4
dyoshikawa
deleted the
resolve-issue-4025-codexcli-preserve-unowned-mcp
branch
November 30, 2026 14:08
This was referenced Nov 30, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #4025
Summary
Codex CLI MCP generation replaced the whole
mcp_serverstable of.codex/config.toml/~/.codex/config.tomlwith the servers declared in.rulesync/mcp.jsonc. Servers the Codex desktop app writes into that table itself (e.g.node_repl) were deleted on everygenerate, andgenerate --checkreported the file as out of date.This adds an opt-in
preserveUnownedMcpServerskey torulesync.jsonc(defaultfalse, so behavior is unchanged):CodexcliMcp.fromRulesyncMcpkeeps every existing[mcp_servers.<name>]table the sources do not declare, verbatim, and writes the declared servers over it. A declared server wins on a name clash (including a declared server dropped for having no non-empty configuration, which is not resurrected from the old file).config.tomlare untouched as before; per-tool approval merging for declared servers is unchanged.generate --checksees the same merged content, so preserved servers do not report drift.Config.getPreserveUnownedMcpServers(), resolver default/pick,McpProcessor({ preserveUnownedMcpServers })→fromRulesyncMcp({ preserveUnowned })(new optional field onToolMcpFromRulesyncMcpParams).docs/guide/configuration.mdand a Codex CLI note indocs/reference/file-formats.md(docs-content regenerated).Tests
codexcli-mcp.test.ts: default replaces the table; preserve keeps unowned + declared wins; generating twice is byte-identical; empty sources keep unowned servers (twice, stable); a dropped declared server is not carried over.mcp-processor.test.ts: the flag is forwarded aspreserveUnowned(defaultfalse).config-resolver.test.ts: read fromrulesync.jsonc, defaultfalse.generate.test.ts: the config value reachesMcpProcessor.e2e-mcp.spec.ts, global mode): generate →--checkreports up to date → generate again →--deletetwice;config.tomlstays byte-identical and the host-app server survives.Design decisions
preserveUnownedHooks/preserveUnownedSkills/preserveUnmanagedRuleContent, which are all config-file only because ownership is a property of the destination file, not of a single run. (The issue suggested a CLI flag too; I kept consistency with the existing siblings.)config.tomlis a file the host app actively writes server entries into. Other targets that useapplySharedConfigPatchwithreplace-owned-keyshave heterogeneous server shapes/keys; extending the option to them is possible later via the samepreserveUnownedparam onToolMcpFromRulesyncMcpParams, which every other adapter currently ignores (documented on the type and in the docs).preserveUnownedSkills, Rulesync keeps no record of servers it generated earlier, so with the option on a server removed frommcp.jsoncis left behind and must be removed by hand. This is documented as the trade-off. A lock-based approach likepreserveUnownedHookswould add a new file next to~/.codex/config.toml; I kept the change minimal and can follow up if wanted.config.tomlis non-deletable (isDeletable() === false), so--deleteandretireTargetsnever touch it with or without the option; the E2E test runs--deletetwice to confirm preserved entries survive.🤖 Generated with Claude Code
https://claude.ai/code/session_01JdNNKCxxrKAMDANMGDEGP4