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
10 changes: 5 additions & 5 deletions rust/crates/commands/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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"));
Expand Down Expand Up @@ -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": {
Expand Down Expand Up @@ -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"),
workspace.join(".claw").join("settings.local.json"),
r#"{
"mcpServers": {
"everything": {"command": "npx", "args": ["-y", "@modelcontextprotocol/server-everything"]},
Expand All @@ -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.
Expand Down
97 changes: 96 additions & 1 deletion rust/crates/runtime/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -698,6 +713,25 @@ fn strip_untrusted_project_hooks(
}
}

fn strip_untrusted_project_mcp_servers(
source: ConfigSource,
object: &mut BTreeMap<String, JsonValue>,
path: &Path,
) -> Option<String> {
// 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<String>) -> Self {
Self {
Expand Down Expand Up @@ -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");
}
Expand Down
12 changes: 6 additions & 6 deletions rust/crates/rusty-claude-cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16638,18 +16638,18 @@ 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"]}
}
}
"#,
)
.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);
Expand Down Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions rust/crates/rusty-claude-cli/tests/output_format_contract.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down Expand Up @@ -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": {
Expand Down
Loading