From 846ee0d0a7da6f6aead19ad16ee854adc05e53c1 Mon Sep 17 00:00:00 2001 From: Adrian Martinez Garcia Date: Tue, 1 Dec 2026 15:08:41 +0000 Subject: [PATCH 1/3] fix(config): strip project-scoped mcpServers like untrusted project hooks Project settings come from the repository, and project mcpServers entries survive discovery: their stdio commands start at startup tool discovery with no trust decision, even before auth. Mirror the existing project hooks strip for mcpServers so both are dropped with a matching warning; user and local settings remain eligible. --- rust/crates/runtime/src/config.rs | 97 ++++++++++++++++++++++++++++++- 1 file changed, 96 insertions(+), 1 deletion(-) diff --git a/rust/crates/runtime/src/config.rs b/rust/crates/runtime/src/config.rs index 67c274cb35..3d30cc5a8f 100644 --- a/rust/crates/runtime/src/config.rs +++ b/rust/crates/runtime/src/config.rs @@ -485,6 +485,11 @@ impl ConfigLoader { { all_warnings.push(warning); } + if let Some(warning) = + strip_untrusted_project_mcp_servers(entry.source, &mut object, &entry.path) + { + all_warnings.push(warning); + } let validation = crate::config_validate::validate_config_file(&object, &source, &entry.path); if !validation.is_ok() { @@ -532,6 +537,11 @@ impl ConfigLoader { { all_warnings.push(warning); } + if let Some(warning) = + strip_untrusted_project_mcp_servers(entry.source, &mut object, &entry.path) + { + all_warnings.push(warning); + } let validation = crate::config_validate::validate_config_file(&object, &source, &entry.path); if !validation.is_ok() { @@ -612,6 +622,11 @@ impl ConfigLoader { { warnings.push(warning); } + if let Some(warning) = + strip_untrusted_project_mcp_servers(entry.source, &mut object, &entry.path) + { + warnings.push(warning); + } let validation = crate::config_validate::validate_config_file(&object, &source, &entry.path); if !validation.is_ok() { @@ -698,6 +713,25 @@ fn strip_untrusted_project_hooks( } } +fn strip_untrusted_project_mcp_servers( + source: ConfigSource, + object: &mut BTreeMap, + path: &Path, +) -> Option { + // Project settings come from the repository and there is no project MCP + // server trust approval flow yet. User and local settings remain eligible. + // Unreviewed stdio commands in `mcpServers` start at startup tool + // discovery, so they are dropped here exactly like project hooks. + if source == ConfigSource::Project && object.remove("mcpServers").is_some() { + Some(format!( + "Ignoring project MCP servers in {} because project MCP server trust approval is not supported.", + path.display() + )) + } else { + None + } +} + impl ConfigFileReport { fn loaded(entry: ConfigEntry, precedence_rank: usize, key_paths: Vec) -> Self { Self { @@ -2798,7 +2832,68 @@ mod tests { ); assert_eq!(loaded.permission_rules().ask(), &["Edit".to_string()]); assert!(loaded.mcp().get("home").is_some()); - assert!(loaded.mcp().get("project").is_some()); + // Project MCP servers are stripped with the hooks: the repo has no + // trust approval flow, and their stdio commands start at discovery. + assert!(loaded.mcp().get("project").is_none()); + + fs::remove_dir_all(root).expect("cleanup temp dir"); + } + + #[test] + fn project_config_mcp_servers_cannot_execute_commands() { + let root = temp_dir(); + let cwd = root.join("project"); + let home = root.join("home").join(".claw"); + let project_settings = cwd.join(".claw").join("settings.json"); + let project_legacy_settings = cwd.join(".claw.json"); + fs::create_dir_all(project_settings.parent().expect("project config dir")) + .expect("create project config dir"); + fs::create_dir_all(&home).expect("home config dir"); + fs::write( + &project_legacy_settings, + serde_json::json!({"mcpServers": {"legacy": {"command": "echo", "args": ["compromised"]}}}) + .to_string(), + ) + .expect("write untrusted legacy project mcp server"); + fs::write( + &project_settings, + serde_json::json!({"mcpServers": {"project": {"command": "echo", "args": ["compromised"]}}}) + .to_string(), + ) + .expect("write untrusted project mcp server"); + + let loader = ConfigLoader::new(&cwd, &home); + let loaded = loader.load().expect("config should load"); + assert!(loaded.mcp().get("legacy").is_none()); + assert!(loaded.mcp().get("project").is_none()); + + let (collected, warnings) = loader + .load_collecting_warnings() + .expect("collecting config should load"); + assert!(collected.mcp().get("legacy").is_none()); + assert!(collected.mcp().get("project").is_none()); + assert_eq!( + warnings + .iter() + .filter(|warning| warning.contains("Ignoring project MCP servers")) + .count(), + 2 + ); + let inspected = loader.inspect_collecting_warnings(); + assert_eq!( + inspected + .warnings + .iter() + .filter(|warning| warning.contains("Ignoring project MCP servers")) + .count(), + 2 + ); + assert!(inspected + .runtime_config + .expect("inspection should produce runtime config") + .mcp() + .get("legacy") + .is_none()); fs::remove_dir_all(root).expect("cleanup temp dir"); } From 97653c27d60ed67a05e19e03fe9cfb4510866a49 Mon Sep 17 00:00:00 2001 From: Adrian Martinez Garcia Date: Tue, 1 Dec 2026 16:07:26 +0000 Subject: [PATCH 2/3] test(commands): keep mcp report fixtures out of project scope Project-scoped mcpServers are now stripped like project hooks, so the mcp report fixtures move to user scope (config_home/settings.json) and the report test asserts the user scope. The #440 degraded-envelope coverage is unchanged. --- rust/crates/commands/src/lib.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/rust/crates/commands/src/lib.rs b/rust/crates/commands/src/lib.rs index b1b9b92964..00aae24101 100644 --- a/rust/crates/commands/src/lib.rs +++ b/rust/crates/commands/src/lib.rs @@ -6897,7 +6897,7 @@ mod tests { fs::create_dir_all(workspace.join(".claw")).expect("workspace config dir"); fs::create_dir_all(&config_home).expect("config home"); fs::write( - workspace.join(".claw").join("settings.json"), + config_home.join("settings.json"), r#"{ "mcpServers": { "alpha": { @@ -6940,7 +6940,7 @@ mod tests { assert!(list.contains("Configured servers 2")); assert!(list.contains("alpha")); assert!(list.contains("stdio")); - assert!(list.contains("project")); + assert!(list.contains("user")); assert!(list.contains("uvx alpha-server")); assert!(list.contains("remote")); assert!(list.contains("ws")); @@ -6976,7 +6976,7 @@ mod tests { fs::create_dir_all(workspace.join(".claw")).expect("workspace config dir"); fs::create_dir_all(&config_home).expect("config home"); fs::write( - workspace.join(".claw").join("settings.json"), + config_home.join("settings.json"), r#"{ "mcpServers": { "alpha": { @@ -7065,7 +7065,7 @@ mod tests { fs::create_dir_all(&config_home).expect("create config home"); // One valid server + one malformed entry missing `command`. fs::write( - workspace.join(".claw.json"), + config_home.join("settings.json"), r#"{ "mcpServers": { "everything": {"command": "npx", "args": ["-y", "@modelcontextprotocol/server-everything"]}, From e180731c8468ae447b45c500bbd8e38d0d7b13a2 Mon Sep 17 00:00:00 2001 From: Kalt2212 <107548841+kalt2212@users.noreply.github.com> Date: Tue, 1 Dec 2026 18:11:16 +0100 Subject: [PATCH 3/3] test(mcp): isolate trusted configuration fixtures Use workspace-local MCP settings in five report-contract tests so project configuration stays blocked and malformed test data does not leak into another workspace. --- rust/crates/commands/src/lib.rs | 4 ++-- rust/crates/rusty-claude-cli/src/main.rs | 12 ++++++------ .../rusty-claude-cli/tests/output_format_contract.rs | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/rust/crates/commands/src/lib.rs b/rust/crates/commands/src/lib.rs index 00aae24101..1a13d8e871 100644 --- a/rust/crates/commands/src/lib.rs +++ b/rust/crates/commands/src/lib.rs @@ -7065,7 +7065,7 @@ mod tests { fs::create_dir_all(&config_home).expect("create config home"); // One valid server + one malformed entry missing `command`. fs::write( - config_home.join("settings.json"), + workspace.join(".claw").join("settings.local.json"), r#"{ "mcpServers": { "everything": {"command": "npx", "args": ["-y", "@modelcontextprotocol/server-everything"]}, @@ -7074,7 +7074,7 @@ mod tests { } "#, ) - .expect("write malformed .claw.json"); + .expect("write malformed local MCP settings"); let loader = ConfigLoader::new(&workspace, &config_home); // list action: must return Ok (not Err) with degraded envelope. diff --git a/rust/crates/rusty-claude-cli/src/main.rs b/rust/crates/rusty-claude-cli/src/main.rs index 7257f95a58..b37aa1dbad 100644 --- a/rust/crates/rusty-claude-cli/src/main.rs +++ b/rust/crates/rusty-claude-cli/src/main.rs @@ -16638,10 +16638,10 @@ mod tests { let root = temp_dir(); let cwd = root.join("project-with-malformed-mcp-for-plugins"); let config_home = root.join("config-home"); - std::fs::create_dir_all(&cwd).expect("project dir should exist"); + std::fs::create_dir_all(cwd.join(".claw")).expect("local config dir should exist"); std::fs::create_dir_all(&config_home).expect("config home should exist"); std::fs::write( - cwd.join(".claw.json"), + cwd.join(".claw").join("settings.local.json"), r#"{ "mcpServers": { "missing-command": {"args": ["arg-only-no-command"]} @@ -16649,7 +16649,7 @@ mod tests { } "#, ) - .expect("write malformed .claw.json"); + .expect("write malformed local MCP settings"); let previous_config_home = std::env::var("CLAW_CONFIG_HOME").ok(); std::env::set_var("CLAW_CONFIG_HOME", &config_home); @@ -16693,18 +16693,18 @@ mod tests { let _guard = env_lock(); let root = temp_dir(); let cwd = root.join("project-with-malformed-mcp"); - std::fs::create_dir_all(&cwd).expect("project dir should exist"); + std::fs::create_dir_all(cwd.join(".claw")).expect("local config dir should exist"); // Top-level `mcpServers` shape errors still degrade through the // config_load_error path; per-server errors are handled by the #440 // MCP validation summary instead. std::fs::write( - cwd.join(".claw.json"), + cwd.join(".claw").join("settings.local.json"), r#"{ "mcpServers": "not-an-object" } "#, ) - .expect("write malformed .claw.json"); + .expect("write malformed local MCP settings"); let context = with_current_dir(&cwd, || { super::status_context(None) diff --git a/rust/crates/rusty-claude-cli/tests/output_format_contract.rs b/rust/crates/rusty-claude-cli/tests/output_format_contract.rs index 8b32f83e3b..f7ab762a13 100644 --- a/rust/crates/rusty-claude-cli/tests/output_format_contract.rs +++ b/rust/crates/rusty-claude-cli/tests/output_format_contract.rs @@ -1835,7 +1835,7 @@ fn mcp_json_reports_required_optional_and_redacts_secret_values() { fs::create_dir_all(&config_home).expect("config home should exist"); fs::create_dir_all(&home).expect("home should exist"); fs::write( - root.join(".claw").join("settings.json"), + root.join(".claw").join("settings.local.json"), r#"{ "mcpServers": { "required-stdio": { @@ -1923,11 +1923,11 @@ fn mcp_degraded_config_and_failed_usage_are_distinct_json_contracts() { let workspace = root.join("workspace"); let config_home = root.join("config-home"); let home = root.join("home"); - fs::create_dir_all(&workspace).expect("workspace should exist"); + fs::create_dir_all(workspace.join(".claw")).expect("local config dir should exist"); fs::create_dir_all(&config_home).expect("config home should exist"); fs::create_dir_all(&home).expect("home should exist"); fs::write( - workspace.join(".claw.json"), + workspace.join(".claw").join("settings.local.json"), r#"{ "mcpServers": { "valid-server": {