This adds initial support for MCP servers in the style of Claude Desktop and Cursor. Note this PR is the bare minimum to get things working end to end: all configured MCP servers are launched every time Codex is run, there is no recovery for MCP servers that crash, etc. (Also, I took some shortcuts to change some fields of `Session` to be `pub(crate)`, which also means there are circular deps between `codex.rs` and `mcp_tool_call.rs`, but I will clean that up in a subsequent PR.) `codex-rs/README.md` is updated as part of this PR to explain how to use this feature. There is a bit of plumbing to route the new settings from `Config` to the business logic in `codex.rs`. The most significant chunks for new code are in `mcp_connection_manager.rs` (which defines the `McpConnectionManager` struct) and `mcp_tool_call.rs`, which is responsible for tool calls. This PR also introduces new `McpToolCallBegin` and `McpToolCallEnd` event types to the protocol, but does not add any handlers for them. (See https://github.com/openai/codex/pull/836 for initial usage.) To test, I added the following to my `~/.codex/config.toml`: ```toml # Local build of https://github.com/hideya/mcp-server-weather-js [mcp_servers.weather] command = "/Users/mbolin/code/mcp-server-weather-js/dist/index.js" args = [] ``` And then I ran the following: ``` codex-rs$ cargo run --bin codex exec 'what is the weather in san francisco' [2025-05-06T22:40:05] Task started: 1 [2025-05-06T22:40:18] Agent message: Here’s the latest National Weather Service forecast for San Francisco (downtown, near 37.77° N, 122.42° W): This Afternoon (Tue): • Sunny, high near 69 °F • West-southwest wind around 12 mph Tonight: • Partly cloudy, low around 52 °F • SW wind 7–10 mph ... ``` Note that Codex itself is not able to make network calls, so it would not normally be able to get live weather information like this. However, the weather MCP is [currently] not run under the Codex sandbox, so it is able to hit `api.weather.gov` and fetch current weather information. --- [//]: # (BEGIN SAPLING FOOTER) Stack created with [Sapling](https://sapling-scm.com). Best reviewed with [ReviewStack](https://reviewstack.dev/openai/codex/pull/829). * #836 * __->__ #829
65 lines
1.4 KiB
TOML
65 lines
1.4 KiB
TOML
[package]
|
|
name = "codex-core"
|
|
version = "0.1.0"
|
|
edition = "2021"
|
|
|
|
[lib]
|
|
name = "codex_core"
|
|
path = "src/lib.rs"
|
|
|
|
[dependencies]
|
|
anyhow = "1"
|
|
async-channel = "2.3.1"
|
|
base64 = "0.21"
|
|
bytes = "1.10.1"
|
|
clap = { version = "4", features = ["derive", "wrap_help"], optional = true }
|
|
codex-apply-patch = { path = "../apply-patch" }
|
|
codex-mcp-client = { path = "../mcp-client" }
|
|
dirs = "6"
|
|
env-flags = "0.1.1"
|
|
eventsource-stream = "0.2.3"
|
|
fs-err = "3.1.0"
|
|
futures = "0.3"
|
|
mcp-types = { path = "../mcp-types" }
|
|
mime_guess = "2.0"
|
|
patch = "0.7"
|
|
path-absolutize = "3.1.1"
|
|
rand = "0.9"
|
|
reqwest = { version = "0.12", features = ["json", "stream"] }
|
|
serde = { version = "1", features = ["derive"] }
|
|
serde_json = "1"
|
|
thiserror = "2.0.12"
|
|
tokio = { version = "1", features = [
|
|
"io-std",
|
|
"macros",
|
|
"process",
|
|
"rt-multi-thread",
|
|
"signal",
|
|
] }
|
|
tokio-util = "0.7.14"
|
|
toml = "0.8.20"
|
|
tracing = { version = "0.1.41", features = ["log"] }
|
|
tree-sitter = "0.25.3"
|
|
tree-sitter-bash = "0.23.3"
|
|
|
|
[target.'cfg(target_os = "linux")'.dependencies]
|
|
libc = "0.2.172"
|
|
landlock = "0.4.1"
|
|
seccompiler = "0.5.0"
|
|
|
|
# Build OpenSSL from source for musl builds.
|
|
[target.x86_64-unknown-linux-musl.dependencies]
|
|
openssl-sys = { version = "*", features = ["vendored"] }
|
|
|
|
[dev-dependencies]
|
|
assert_cmd = "2"
|
|
predicates = "3"
|
|
tempfile = "3"
|
|
wiremock = "0.6"
|
|
|
|
[features]
|
|
default = []
|
|
|
|
# Separate feature so that `clap` is not a mandatory dependency.
|
|
cli = ["clap"]
|