Skip to content

MCP profiles part 5: Codex threads apply their profile's outside servers - #826

Merged
scuttletoby merged 5 commits into
mainfrom
fork/mcp-profile-codex
Nov 22, 2026
Merged

scuttletoby merged 5 commits into
mainfrom
fork/mcp-profile-codex

Conversation

@scuttletoby

Copy link
Copy Markdown
Owner

MCP profile design PR 5 (code; step 2 after the announce PR #801).

What and why

Today only Claude threads apply MCP profiles; a Codex thread whose profile is narrower than all is refused as its turn starts (#672). This makes Codex apply the profile's outside servers (design section 6), per thread on the shared app-server (design section 9).

  • apps/server/src/fork/codexMcpProfile.ts (new) wraps the Codex adapter's app-server client factory. For each thread/start, thread/resume and thread/fork that T3 sends, it does three things:

    • finds the T3 thread from T3CODE_THREAD_ID, which is already in the config, or for a resume from the Codex thread it loaded before;
    • resolves the profile the same way Claude does: the thread's pick, the project, the server default, or for a sub-agent its parent's profile cut down;
    • asks the same app-server, through config/read with the thread's folder, which MCP servers are set up. This covers config.toml, a project's .codex/config.toml, and servers added by -c mcp_servers… in the launch arguments (upstream [Bug]: Codex per-thread mcp_servers override replaces MCP servers added with -c launch args pingdotgg/t3code#15828). It then adds mcp_servers.<name>.enabled = false to that request's config for each server the profile leaves out. T3's own t3-code and t3-code-direct entries are never touched.
  • The overrides go only into that one request's config, so another thread on the same app-server keeps its own set.

  • Before each turn/start, and before a thread/goal/set that is not "paused", T3 reads the thread's live servers (mcpServerStatus/list, every page). If a server outside the profile is still on, it refuses the turn, says why and gives the fix: pick all for the thread, or fix the profile. It refuses when:

    • Codex had the thread loaded when the profile was narrowed. Codex ignores config on a resume of a loaded thread.
    • a Codex plugin added a server, which cannot be switched off this way.
  • These also refuse, and never start a thread with every server:

    • a missing or broken profile, or t3Tools not "all";
    • a server list T3 cannot read;
    • a server name that cannot be a config key;
    • a thread missing from T3's store;
    • once a narrower profile is in use on that app-server, a Codex thread T3 cannot match.

    Refusals use code -32001, not -32600, which the adapter reads as "thread not found". A thread on all is loaded exactly as before, with no extra request.

  • mcpProfile.ts: MCP_PROFILE_DRIVERS now includes codex, so the turn check (Narrowed MCP profile: refuse at turn start on providers that cannot apply it (#669 follow-ups) #672) no longer refuses Codex. Remote delegation keeps a separate MCP_PROFILE_REMOTE_DRIVERS (Claude only), because a machine that carries profiles may run a T3 from before this change.

  • claudeMcpProfile.ts: new makeThreadMcpProfilesById, which reads the profile by thread id from the store. It uses the same lineage reads as Claude.

  • The seam: two lines in CodexAdapterV2.ts, the import and the spread of the wrapped clientFactory. fork seams: announce the Codex MCP profile lines (MCP profiles part 5, step 1) #801 announced them; this PR moves them to added.

  • Docs: docs/fork/README.md (server.mcpProfiles) and FORK_CHANGES.md.

The server names come from config/read and not the existing listEnabledMcpServers: that one reads only the home config.toml and launch args, and misses project .codex/config.toml servers.

Tests

apps/server/src/fork/codexMcpProfile.test.ts (new, 27 tests) uses a fake app-server. Its config is per thread, and a resume of a loaded thread keeps the old config, as real Codex does. The tests cover:

  • a left-out server gets enabled=false on that thread only;
  • no leak between two threads with different profiles, in both orders;
  • kept servers and T3's own entries are unchanged;
  • a launch-arg server is turned off;
  • project servers and forks, read in the thread's folder;
  • a missing profile, narrowed t3Tools, a bad name, or an unreadable or malformed server list refuses with the fix;
  • the state question: runs again (same set), a profile narrowed while loaded refuses until reload (a paused goal still works), widened, empty server list, app-server restarted (a fresh client knows no thread), a thread T3 did not load is refused, stopped half-way in the turn check and in the load (nothing is sent; a retry runs), and pagination (endless and failing pages);
  • real settings and the SQLite store: a thread pick, a sub-agent cut to its parent, and a missing profile or a thread not in the store refuses;
  • the real createCodexAdapterV2 through the seam lines.

mcpProfileTurnCheck.test.ts is updated: Codex runs, and OpenCode is the refused example. These all pass:

Red checks: each line below was removed in turn, and a test failed each time.

Removed Test that failed
Per-thread scoping (one set cached per client) Both no-leak tests
The narrowed flag "a thread T3 did not load itself is refused"
The turn check 5 tests
The paused-goal exception "narrowed while loaded"
The seam spread line The adapter test
The store-null refusal "a thread the store does not have refuses"
The T3-own-entries guard "never T3's own"
codex in MCP_PROFILE_DRIVERS 2 turn-check tests

On the old code, the new tests fail. With main's driver list, Codex turns are refused.

No Codex binary was installed for this. A live check would add a real codex-cli app-server run of the same cases: per-thread enabled=false, a launch-arg server switched off, a resume ignoring config while the thread is loaded, project servers from config/read, and whether Codex's own sub-agents inherit the thread's config.

Follow-ups:

  • Reload a loaded thread automatically when its profile changes.
  • Remote Codex delegation.
  • Switch off plugin servers. Today they are refused, not switched off.
  • Server names that are not plain keys. Today they are refused; upstream's text generation uses an inline table for these.

General vs project

General: MCP profiles on Codex threads, for any T3 fork user. No project facts.

Upstream fit

Read only. This uses the same mcp_servers.<name>.enabled=false keys that upstream's CodexTextGeneration.ts uses. It is per-thread config, like upstream's own t3-code entry and its launch-arg handling (upstream issue pingdotgg#15828 and PR pingdotgg#15839). All logic is in a fork file, plus two seam lines. I found no upstream issue or PR about per-thread MCP profiles on Codex.

MCP profile design PR 5

After the fix round (#801 lenses): Codex threads get mcp_servers.<name>.enabled=false for each configured server the profile leaves out, and features.apps=false unless it names codex_apps. Codex's own sub-agents copy this config (checked in codex-rs child_config.rs). Every turn is checked against the live server list, including turns Codex starts itself for a goal or a sub-agent. A failing turn is stopped, its goal is paused, and it ends failed with the reason. A refused resume fails the turn instead of starting a fresh session. Follow-ups: #814.

🤖 Generated with Claude Code

scuttletoby and others added 2 commits November 21, 2026 21:47
Each Codex thread T3 loads on the shared app-server gets
mcp_servers.<name>.enabled = false in its own per-request config for
every server config/read lists for its folder that the profile leaves
out (launch-argument and project servers included; T3's own entries
stay). Each turn first reads the thread's live servers and refuses,
saying why and the fix, when one outside the profile is still on. A
missing or broken profile, a server list T3 cannot read, or a thread T3
cannot match is refused, never started with every server. Logic in
apps/server/src/fork/codexMcpProfile.ts; two seam lines in the Codex
adapter (announced in step 1). Remote delegation stays Claude-only.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
… and connectors

- Watch turn/started: a turn Codex starts on its own (a goal's next turn, a
  sub-agent's turn) gets the same check as turn/start; one that fails is
  stopped (goal paused, turn interrupted) and ends failed with the reason.
- Count Codex sub-agents as their parent's T3 thread (they copy the parent's
  loaded config, codex-rs child_config.rs), so their turns are checked too.
- Send features.apps=false when a narrowed profile leaves out codex_apps,
  which config/read never lists.
- A refused resume no longer becomes a fresh Codex session: the fallback
  start is refused once, so the history is kept.
- Tests for each, with Codex's real status words; docs updated.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Conflict: .github/fork-seams.json. Resolved as main's file plus this PR's
one intended seam change: the two CodexAdapterV2.ts lines move from
"announced" to "added". The branch's copy had also dropped other PRs'
announcements (environment facts P3, thread menu, HO5) and the
packages/shared/src/slotObserve* entry; those are kept from main.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby

Copy link
Copy Markdown
Owner Author

lens: code · reviewer: claude-opus-5-5 · read at: c0682b7

Head re-read after merge from main. I read only the merge commit (Merge origin/main into fork/mcp-profile-codex), not the earlier change again.

blocker: none
major: none
minor: none

  1. The diff against main is only this PR's own change.
  • The three-dot diff against main has the same 11 files as before.
  • Outside .github/fork-seams.json, the diff is the same as the branch's diff before the merge. Only hunk line numbers and blob ids differ, so the merge brought in no change to this PR's code.
  • In .github/fork-seams.json, the only change against main is the CodexAdapterV2.ts entry. Its two lines move from announced (since 2026-11-21) to added, and the why is the same.
  • Both lines are in the file at this head, as CodexAdapterV2.ts:114 (the import) and :1960 (the factory wrap).
  1. No other PR's seam entries were lost or changed.
  1. Seam check passes.
  • node .github/scripts/fork-seam-check.cjs --config-ref origin/main origin/main HEAD at this head exits 0 ("only the pinned seams").
  • The same check on a trial merge of this head with current main also exits 0.

State question:

  • Runs again: the seam list is data, so a second run of the check gives the same result.
  • Old or empty state: the lines were already in main's list as announced, and the check against main's list passes. When this PR lands, the entry becomes added, and nothing else in the list changes.

Verdict: SAFE (merge path unchanged; this lens covers only the merge from main).

scuttletoby and others added 2 commits November 22, 2026 03:27
Resolve FORK_CHANGES.md: main's table plus this PR's MCP profiles row change.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@scuttletoby
scuttletoby merged commit 85971cf into main Nov 22, 2026
40 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