Skip to content
Closed
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ Codex CLI supports a rich set of configuration options, with preferences stored
- [Example prompts](./docs/getting-started.md#example-prompts)
- [Custom prompts](./docs/prompts.md)
- [Memory with AGENTS.md](./docs/getting-started.md#memory-with-agentsmd)
- [Shared agents workspace](./docs/getting-started.md#agents-home-agents)
- [Configuration](./docs/config.md)
- [**Sandbox & approvals**](./docs/sandbox.md)
- [**Authentication**](./docs/authentication.md)
Expand Down
1 change: 1 addition & 0 deletions codex-rs/app-server/src/codex_message_processor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1668,6 +1668,7 @@ async fn derive_config_from_params(
sandbox_mode,
model_provider,
codex_linux_sandbox_exe,
agents_home: None,
base_instructions,
include_apply_patch_tool,
include_view_image_tool: None,
Expand Down
56 changes: 56 additions & 0 deletions codex-rs/cli/tests/mcp_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,59 @@ async fn get_disabled_server_shows_single_line() -> Result<()> {

Ok(())
}

#[test]
fn list_includes_agents_home_servers() -> Result<()> {
let codex_home = TempDir::new()?;
let project = TempDir::new()?;
let agents_mcp_dir = project.path().join(".agents").join("mcp");
std::fs::create_dir_all(&agents_mcp_dir)?;
std::fs::write(
agents_mcp_dir.join("mcp.json"),
r#"
{
"docs": {
"command": "docs-server",
"args": ["--port", "8080"],
"env": {"TOKEN": "secret"}
}
}
"#,
)?;

let mut cmd = codex_command(codex_home.path())?;
let output = cmd
.current_dir(project.path())
.args(["mcp", "list", "--json"])
.output()?;
assert!(output.status.success());
let stdout = String::from_utf8(output.stdout)?;
let parsed: JsonValue = serde_json::from_str(&stdout)?;
assert_eq!(
parsed,
json!([
{
"name": "docs",
"enabled": true,
"transport": {
"type": "stdio",
"command": "docs-server",
"args": [
"--port",
"8080"
],
"env": {
"TOKEN": "secret"
},
"env_vars": [],
"cwd": null
},
"startup_timeout_sec": null,
"tool_timeout_sec": null,
"auth_status": "unsupported"
}
])
);

Ok(())
}
1 change: 1 addition & 0 deletions codex-rs/core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ tracing = { workspace = true, features = ["log"] }
tree-sitter = { workspace = true }
tree-sitter-bash = { workspace = true }
uuid = { workspace = true, features = ["serde", "v4"] }
walkdir = { workspace = true }
which = { workspace = true }
wildmatch = { workspace = true }

Expand Down
19 changes: 18 additions & 1 deletion codex-rs/core/src/codex.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,7 @@ impl Codex {
model_reasoning_summary: config.model_reasoning_summary,
user_instructions,
base_instructions: config.base_instructions.clone(),
agents_context_prompt: config.agents_context_prompt.clone(),
approval_policy: config.approval_policy,
sandbox_policy: config.sandbox_policy.clone(),
cwd: config.cwd.clone(),
Expand Down Expand Up @@ -266,6 +267,7 @@ pub(crate) struct TurnContext {
pub(crate) cwd: PathBuf,
pub(crate) base_instructions: Option<String>,
pub(crate) user_instructions: Option<String>,
pub(crate) agents_context_prompt: Option<String>,
pub(crate) approval_policy: AskForApproval,
pub(crate) sandbox_policy: SandboxPolicy,
pub(crate) shell_environment_policy: ShellEnvironmentPolicy,
Expand Down Expand Up @@ -300,6 +302,8 @@ pub(crate) struct SessionConfiguration {

/// Base instructions override.
base_instructions: Option<String>,
/// Aggregated agents context block surfaced before each turn.
agents_context_prompt: Option<String>,

/// When to escalate for approval for execution
approval_policy: AskForApproval,
Expand Down Expand Up @@ -405,6 +409,7 @@ impl Session {
cwd: session_configuration.cwd.clone(),
base_instructions: session_configuration.base_instructions.clone(),
user_instructions: session_configuration.user_instructions.clone(),
agents_context_prompt: session_configuration.agents_context_prompt.clone(),
approval_policy: session_configuration.approval_policy,
sandbox_policy: session_configuration.sandbox_policy.clone(),
shell_environment_policy: config.shell_environment_policy.clone(),
Expand Down Expand Up @@ -976,10 +981,19 @@ impl Session {
}

pub(crate) fn build_initial_context(&self, turn_context: &TurnContext) -> Vec<ResponseItem> {
let mut items = Vec::<ResponseItem>::with_capacity(2);
let mut items = Vec::<ResponseItem>::with_capacity(3);
if let Some(user_instructions) = turn_context.user_instructions.as_deref() {
items.push(UserInstructions::new(user_instructions.to_string()).into());
}
if let Some(agents_context) = turn_context.agents_context_prompt.as_ref() {
items.push(ResponseItem::Message {
id: None,
role: "user".to_string(),
content: vec![ContentItem::InputText {
text: agents_context.clone(),
}],
});
}
items.push(ResponseItem::from(EnvironmentContext::new(
Some(turn_context.cwd.clone()),
Some(turn_context.approval_policy),
Expand Down Expand Up @@ -1641,6 +1655,7 @@ async fn spawn_review_thread(
client,
tools_config,
user_instructions: None,
agents_context_prompt: None,
base_instructions: Some(base_instructions.clone()),
approval_policy: parent_turn_context.approval_policy,
sandbox_policy: parent_turn_context.sandbox_policy.clone(),
Expand Down Expand Up @@ -2623,6 +2638,7 @@ mod tests {
model_reasoning_summary: config.model_reasoning_summary,
user_instructions: config.user_instructions.clone(),
base_instructions: config.base_instructions.clone(),
agents_context_prompt: config.agents_context_prompt.clone(),
approval_policy: config.approval_policy,
sandbox_policy: config.sandbox_policy.clone(),
cwd: config.cwd.clone(),
Expand Down Expand Up @@ -2696,6 +2712,7 @@ mod tests {
model_reasoning_summary: config.model_reasoning_summary,
user_instructions: config.user_instructions.clone(),
base_instructions: config.base_instructions.clone(),
agents_context_prompt: config.agents_context_prompt.clone(),
approval_policy: config.approval_policy,
sandbox_policy: config.sandbox_policy.clone(),
cwd: config.cwd.clone(),
Expand Down
Loading