feat: make Codex available as a tool when running it as an MCP server #811
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.
This PR replaces the placeholder
"echo"
tool call in the MCP server with a"codex"
tool that calls Codex. Events such asExecApprovalRequest
andApplyPatchApprovalRequest
are not handled properly yet, but I haveapproval_policy = "never"
set in my~/.codex/config.toml
such that those codepaths are not exercised.The schema for this MPC tool is defined by a new
CodexToolCallParam
struct introduced in this PR. It is fairly similar toConfigOverrides
, as the param is used to help create theConfig
used to start the Codex session, though it also includes theprompt
used to kick off the session.This PR also introduces the use of the third-party
schemars
crate to generate the JSON schema, which is verified in theverify_codex_tool_json_schema()
unit test.Events that are dispatched during the Codex session are sent back to the MCP client as MCP notifications. This gives the client a way to monitor progress as the tool call itself may take minutes to complete depending on the complexity of the task requested by the user.
In the video below, I launched the server via:
In the video, you can see the flow of:
Note that I left the other fields blank because when unspecified, the values in my
~/.codex/config.toml
were used:mcp-server-ask-to-run-ls.mov
Note that while using the inspector, I did run into modelcontextprotocol/inspector#293, though the tip about ensuring I had only one instance of the MCP Inspector tab open in my browser seemed to fix things.