Skip to content

feat: make Codex available as a tool when running it as an MCP server #811

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
May 5, 2025

Conversation

bolinfest
Copy link
Collaborator

@bolinfest bolinfest commented May 4, 2025

This PR replaces the placeholder "echo" tool call in the MCP server with a "codex" tool that calls Codex. Events such as ExecApprovalRequest and ApplyPatchApprovalRequest are not handled properly yet, but I have approval_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 to ConfigOverrides, as the param is used to help create the Config used to start the Codex session, though it also includes the prompt 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 the verify_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:

mcp-server$ RUST_LOG=debug npx @modelcontextprotocol/inspector cargo run --

In the video, you can see the flow of:

  • requesting the list of tools
  • choosing the codex tool
  • entering a value for prompt and then making the tool call

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.

@bolinfest bolinfest force-pushed the pr811 branch 4 times, most recently from 0c56a78 to f73f053 Compare May 5, 2025 00:14
@bolinfest bolinfest marked this pull request as ready for review May 5, 2025 06:19
@bolinfest bolinfest changed the title feat: initial work by Codex to create Codex MCP tool call feat: make Codex available as a tool when running it as an MCP server May 5, 2025
@bolinfest bolinfest merged commit 2b72d05 into main May 5, 2025
16 checks passed
@bolinfest bolinfest deleted the pr811 branch May 5, 2025 14:16
@github-actions github-actions bot locked and limited conversation to collaborators May 5, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant