Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions codex-rs/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion codex-rs/config.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
This file has moved. Please see the latest configuration documentation here:

- Full config docs: [docs/config.md](../docs/config.md)
- MCP servers section: [docs/config.md#mcp_servers](../docs/config.md#mcp_servers)
- MCP servers section: [docs/config.md#mcp_servers](../docs/config.md#mcp_servers)
16 changes: 15 additions & 1 deletion codex-rs/core/src/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -576,6 +576,9 @@ impl Session {
}
}

// Kick off background MCP tool initialization/loading without blocking the UI.
sess.mcp_connection_manager.refresh_tools_in_background();

Ok((sess, turn_context))
}

Expand Down Expand Up @@ -1286,7 +1289,12 @@ async fn submission_loop(
let tx_event = sess.tx_event.clone();
let sub_id = sub.id.clone();

// This is a cheap lookup from the connection manager's cache.
// Refresh tools on-demand to give users an up-to-date list.
// This runs in the foreground for this operation only.
if let Err(e) = sess.mcp_connection_manager.refresh_tools().await {
warn!("failed to refresh MCP tools: {e:#}");
}

let tools = sess.mcp_connection_manager.list_all_tools();
let event = Event {
id: sub_id,
Expand Down Expand Up @@ -1613,6 +1621,12 @@ async fn run_turn(
sub_id: String,
input: Vec<ResponseItem>,
) -> CodexResult<Vec<ProcessedResponseItem>> {
// Give MCP tools a brief moment to arrive if background discovery is still running.
// This avoids an empty tool list in the first turn right after startup.
sess.mcp_connection_manager
.wait_for_tools_with_timeout(std::time::Duration::from_millis(800))
.await;

let tools = get_openai_tools(
&turn_context.tools_config,
Some(sess.mcp_connection_manager.list_all_tools()),
Expand Down
27 changes: 19 additions & 8 deletions codex-rs/core/src/config_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,25 @@ use serde::Serialize;
use strum_macros::Display;

#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct McpServerConfig {
pub command: String,

#[serde(default)]
pub args: Vec<String>,

#[serde(default)]
pub env: Option<HashMap<String, String>>,
#[serde(untagged)]
pub enum McpServerConfig {
/// MCP server launched as a subprocess that communicates over stdio.
Stdio {
command: String,

#[serde(default)]
args: Vec<String>,

#[serde(default)]
env: Option<HashMap<String, String>>,
},
/// MCP server reachable via the Streamable HTTP transport.
StreamableHttp {
url: String,

#[serde(default)]
headers: Option<HashMap<String, String>>,
},
}

#[derive(Deserialize, Debug, Copy, Clone, PartialEq)]
Expand Down
Loading
Loading