Commit Graph

1067 Commits

Author SHA1 Message Date
Michael Bolin
72a5da99d2 feat: support mcp_servers in config.toml 2025-05-05 16:44:51 -07:00
Michael Bolin
11c5958966 merge commit for archive created by Sapling 2025-05-05 16:33:19 -07:00
Michael Bolin
1b9245bce7 feat: support mcp_servers in config.toml 2025-05-05 16:33:00 -07:00
Michael Bolin
ea338dabb8 merge commit for archive created by Sapling 2025-05-05 16:25:36 -07:00
Michael Bolin
67dfca74b9 feat: support mcp_servers in config.toml 2025-05-05 16:25:25 -07:00
Michael Bolin
2cf7aeeeb6 feat: initial McpClient for Rust (#822)
This PR introduces an initial `McpClient` that we will use to give Codex
itself programmatic access to foreign MCPs. This does not wire it up in
Codex itself yet, but the new `mcp-client` crate includes a `main.rs`
for basic testing for now.

Manually tested by sending a `tools/list` request to Codex's own MCP
server:

```
codex-rs$ cargo build
codex-rs$ cargo run --bin codex-mcp-client ./target/debug/codex-mcp-server
{
  "tools": [
    {
      "description": "Run a Codex session. Accepts configuration parameters matching the Codex Config struct.",
      "inputSchema": {
        "properties": {
          "approval-policy": {
            "description": "Execution approval policy expressed as the kebab-case variant name (`unless-allow-listed`, `auto-edit`, `on-failure`, `never`).",
            "enum": [
              "auto-edit",
              "unless-allow-listed",
              "on-failure",
              "never"
            ],
            "type": "string"
          },
          "cwd": {
            "description": "Working directory for the session. If relative, it is resolved against the server process's current working directory.",
            "type": "string"
          },
          "disable-response-storage": {
            "description": "Disable server-side response storage.",
            "type": "boolean"
          },
          "model": {
            "description": "Optional override for the model name (e.g. \"o3\", \"o4-mini\")",
            "type": "string"
          },
          "prompt": {
            "description": "The *initial user prompt* to start the Codex conversation.",
            "type": "string"
          },
          "sandbox-permissions": {
            "description": "Sandbox permissions using the same string values accepted by the CLI (e.g. \"disk-write-cwd\", \"network-full-access\").",
            "items": {
              "enum": [
                "disk-full-read-access",
                "disk-write-cwd",
                "disk-write-platform-user-temp-folder",
                "disk-write-platform-global-temp-folder",
                "disk-full-write-access",
                "network-full-access"
              ],
              "type": "string"
            },
            "type": "array"
          }
        },
        "required": [
          "prompt"
        ],
        "type": "object"
      },
      "name": "codex"
    }
  ]
}
```
2025-05-05 12:52:55 -07:00
Michael Bolin
29097728f0 merge commit for archive created by Sapling 2025-05-05 11:56:55 -07:00
Michael Bolin
e013db7ab9 feat: mcp-client 2025-05-05 11:56:45 -07:00
Michael Bolin
8368e177dc merge commit for archive created by Sapling 2025-05-05 10:52:34 -07:00
Michael Bolin
2a0b44c73e feat: mcp-client 2025-05-05 10:52:29 -07:00
Michael Bolin
fed1586cf7 merge commit for archive created by Sapling 2025-05-05 10:48:14 -07:00
Michael Bolin
db5cf3d288 feat: mcp-client 2025-05-05 10:48:09 -07:00
Anil Karaka
76a979007e fix: increase output limits for truncating collector (#575)
This Pull Request addresses an issue where the output of commands
executed in the raw-exec utility was being truncated due to restrictive
limits on the number of lines and bytes collected. The truncation caused
the message [Output truncated: too many lines or bytes] to appear when
processing large outputs, which could hinder the functionality of the
CLI.

Changes Made

Increased the maximum output limits in the
[createTruncatingCollector](https://github.com/openai/codex/pull/575)
utility:
Bytes: Increased from 10 KB to 100 KB.
Lines: Increased from 256 lines to 1024 lines.
Installed the @types/node package to resolve missing type definitions
for [NodeJS](https://github.com/openai/codex/pull/575) and
[Buffer](https://github.com/openai/codex/pull/575).
Verified and fixed any related errors in the
[createTruncatingCollector](https://github.com/openai/codex/pull/575)
implementation.

Issue Solved: 

This PR ensures that larger outputs can be processed without truncation,
improving the usability of the CLI for commands that generate extensive
output. https://github.com/openai/codex/issues/509

---------

Co-authored-by: Michael Bolin <bolinfest@gmail.com>
2025-05-05 10:26:55 -07:00
Michael Bolin
211f7609a3 merge commit for archive created by Sapling 2025-05-05 10:22:05 -07:00
Michael Bolin
2499a60f8a feat: mcp-client 2025-05-05 10:22:00 -07:00
Michael Bolin
96d7f812ff merge commit for archive created by Sapling 2025-05-05 10:20:38 -07:00
Michael Bolin
f9e4b00693 feat: mcp-client 2025-05-05 10:20:30 -07:00
Michael Bolin
8fc0d3f963 merge commit for archive created by Sapling 2025-05-05 10:16:02 -07:00
Michael Bolin
706364cc83 feat: mcp-client 2025-05-05 10:15:56 -07:00
Michael Bolin
ab1ea9f5d9 Merge 306d0b5618 into sapling-pr-archive-bolinfest 2025-05-05 09:57:45 -07:00
Michael Bolin
306d0b5618 feat: mcp-client 2025-05-05 09:57:35 -07:00
Andrey Mishchenko
7e97980cb4 Use "Title case" for ToC (#812) 2025-05-05 08:49:42 -07:00
Michael Bolin
2b72d05c5e feat: make Codex available as a tool when running it as an MCP server (#811)
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:

```shell
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:


https://github.com/user-attachments/assets/1975058c-b004-43ef-8c8d-800a953b8192

Note that while using the inspector, I did run into
https://github.com/modelcontextprotocol/inspector/issues/293, though the
tip about ensuring I had only one instance of the **MCP Inspector** tab
open in my browser seemed to fix things.
2025-05-05 07:16:19 -07:00
Michael Bolin
cf54cd1898 Merge ea3e4e126e into sapling-pr-archive-bolinfest 2025-05-04 23:05:27 -07:00
Michael Bolin
ea3e4e126e feat: initial work by Codex to create Codex MCP tool call 2025-05-04 22:33:44 -07:00
Michael Bolin
3e24b50a5d merge commit for archive created by Sapling 2025-05-04 17:14:11 -07:00
Michael Bolin
f73f053290 feat: initial work by Codex to create Codex MCP tool call 2025-05-04 17:13:24 -07:00
Michael Bolin
befb74af33 merge commit for archive created by Sapling 2025-05-04 17:05:35 -07:00
Michael Bolin
0c56a7826a feat: initial work by Codex to create Codex MCP tool call 2025-05-04 17:05:25 -07:00
Michael Bolin
28680d0b63 merge commit for archive created by Sapling 2025-05-04 16:36:33 -07:00
Michael Bolin
01ec277a50 feat: initial work by Codex to create Codex MCP tool call 2025-05-04 16:36:25 -07:00
Michael Bolin
c5db9e1db7 merge commit for archive created by Sapling 2025-05-04 14:54:47 -07:00
Michael Bolin
b5173536d1 feat: initial work by Codex to create Codex MCP tool call 2025-05-04 14:54:41 -07:00
Michael Bolin
e85b02e7bd Merge 7a3ebc6b03 into sapling-pr-archive-bolinfest 2025-05-04 13:08:42 -07:00
Michael Bolin
7a3ebc6b03 feat: initial work by Codex to create Codex MCP tool call 2025-05-04 13:08:35 -07:00
Michael Bolin
5d924d44cf fix: ensure apply_patch resolves relative paths against workdir or project cwd (#810)
https://github.com/openai/codex/pull/800 kicked off some work to be more
disciplined about honoring the `cwd` param passed in rather than
assuming `std::env::current_dir()` as the `cwd`. As part of this, we
need to ensure `apply_patch` calls honor the appropriate `cwd` as well,
which is significant if the paths in the `apply_patch` arg are not
absolute paths themselves. Failing that:

- The `apply_patch` function call can contain an optional`workdir`
param, so:
- If specified and is an absolute path, it should be used to resolve
relative paths
- If specified and is a relative path, should be resolved against
`Config.cwd` and then any relative paths will be resolved against the
result
- If `workdir` is not specified on the function call, relative paths
should be resolved against `Config.cwd`

Note that we had a similar issue in the TypeScript CLI that was fixed in
https://github.com/openai/codex/pull/556.

As part of the fix, this PR introduces `ApplyPatchAction` so clients can
deal with that instead of the raw `HashMap<PathBuf,
ApplyPatchFileChange>`. This enables us to enforce, by construction,
that all paths contained in the `ApplyPatchAction` are absolute paths.
2025-05-04 12:32:51 -07:00
Michael Bolin
76ed513b44 merge commit for archive created by Sapling 2025-05-04 12:21:21 -07:00
Michael Bolin
3c5104374f fix: ensure apply_patch resolves relative paths against workdir or project cwd 2025-05-04 12:21:16 -07:00
Michael Bolin
f53d9f73ac Merge f60e43a101 into sapling-pr-archive-bolinfest 2025-05-04 12:20:51 -07:00
Michael Bolin
f60e43a101 fix: ensure apply_patch resolves relative paths against workdir or project cwd 2025-05-04 12:20:40 -07:00
Michael Bolin
a134bdde49 fix: is_inside_git_repo should take the directory as a param (#809)
https://github.com/openai/codex/pull/800 made `cwd` a property of
`Config` and made it so the `cwd` is not necessarily
`std::env::current_dir()`. As such, `is_inside_git_repo()` should check
`Config.cwd` rather than `std::env::current_dir()`.

This PR updates `is_inside_git_repo()` to take `Config` instead of an
arbitrary `PathBuf` to force the check to operate on a `Config` where
`cwd` has been resolved to what the user specified.
2025-05-04 11:39:10 -07:00
Michael Bolin
1d4e6e275e merge commit for archive created by Sapling 2025-05-04 11:22:45 -07:00
Michael Bolin
92c5135060 fix: is_inside_git_repo should take the directory as a param 2025-05-04 11:22:41 -07:00
Michael Bolin
f8dae3f12c merge commit for archive created by Sapling 2025-05-04 11:22:35 -07:00
Michael Bolin
154fb92f02 fix: is_inside_git_repo should take the directory as a param 2025-05-04 11:22:31 -07:00
Michael Bolin
7fd16e13ec merge commit for archive created by Sapling 2025-05-04 11:21:58 -07:00
Michael Bolin
bb06b80404 fix: is_inside_git_repo should take the directory as a param 2025-05-04 11:21:53 -07:00
Michael Bolin
306f81f39c Merge 991bb2db44 into sapling-pr-archive-bolinfest 2025-05-04 11:17:45 -07:00
Michael Bolin
991bb2db44 fix: is_inside_git_repo should take the directory as a param 2025-05-04 11:17:29 -07:00
Michael Bolin
cd12f0c24a fix: TUI should use cwd from Config (#808)
https://github.com/openai/codex/pull/800 made `cwd` a property of
`Config`, so the TUI should use this instead of running
`std::env::current_dir()`.
2025-05-04 11:12:40 -07:00