Repository navigation
fix(codex): define mocked MCP servers on the codex exec command - #398
Merged
Merged
Conversation
codex mcp add wrote each mocked server into the user's global ~/.codex/config.toml, replaced a same-named server of theirs, and left the mock there after the run. Define mocked servers with -c overrides on every codex exec and resume command instead, and fail early when the user's config already has a server with that name. Refs alibaba#360
Reject a mocked server that cannot be defined with -c flags instead of falling back to codex mcp add. Read existing names from codex mcp list --json and fail when the listing fails. Write each mock script to the run's artifact directory so several mocks do not lengthen the command.
Names that differ only in case shared one file on case-insensitive disks, and a .js file under a package.json with "type": "module" would break the built-in filesystem mock's require calls.
karanb192
requested review from
JHWang-1997,
hittyt and
zpzjzj
as code owners
November 12, 2026 18:44
Codex Review Summary: ✅ CompletedThis comment shows the latest Codex review activity on this pull request.
ℹ️ About Codex in GitHubYour team has set up Codex to review pull requests in this repo. Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 2298e30c7a
ℹ️ About Codex in GitHub
Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".
Docker and OpenSandbox runtimes of concurrent cases report the same workspace path, so keying by path let one case receive another's mocks. Key by runtime identity instead. Keep the record outside the adapter so the separate adapter the evaluator creates for an agent judge, which runs in the case's runtime, gets the case's mocked servers; its empty install does not clear them.
The per-runtime record outlived the case: nothing removed it when the evaluator closed the runtime. Agents can now implement RuntimeReleaser, and the evaluator calls it before closing a case's runtime, on success and when setup fails after the MCP install. The Codex adapter drops the case's record there. The same-path test now runs both cases concurrently.
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.
Summary
Mocked MCP servers for the
codexengine are defined with-c mcp_servers.<name>...overrides on eachcodex execandcodex exec resumecommand. They no longer go throughcodex mcp addorcodex mcp remove, so they do not replace or leave entries in the user's Codex config.Refs #360. Real MCP servers retain the existing installation path.
Details
RuntimeReleaserhook lets the evaluator drop the record before closing the runtime, including after setup failures.codex mcp list --jsonchecks for existing server names. A conflicting name, an unreadable list, or a mock definition the adapter cannot represent causes an error before execution instead of modifying the user's config.mcp-server-<n>.cjs. Numbered files avoid case-insensitive filename collisions, and.cjspreserves CommonJS behavior inside a module package. Upload failures stop execution and clean up the artifact directory.Test plan
Checked after merging current main, using Go 1.26.10 and the pinned lint tools:
make verifymake testmake e2enpm run docs:buildUnit tests cover first and resumed turns, sandbox and bypass modes, real-server installation, existing-name and listing failures, rejected definitions, upload cleanup, concurrent runtimes, judge adapters, and runtime release.
Earlier live checks with Codex CLI 0.167.1 verified invocation-only servers answered tool calls under
workspace-write, the Codex config stayed byte-identical, and generated overrides parsed correctly. Generated.cjsscripts also answered MCP requests. These live checks were not rerun for this main merge.Codex 0.80.0, the default pin, has not been run. Its binary contains the
mcp list --jsonhelp text but could not be launched in the test environment.