From d96b4cf822cfffd001f99a58c2c6de5798eabbb4 Mon Sep 17 00:00:00 2001 From: Riz Ashraf Date: Sat, 26 Sep 2026 08:32:04 +0100 Subject: [PATCH] fix(mcp): convert silently swallowed OK string errors into explicit JSON-RPC errors for task transitions and bulk entity operations --- server/src/handlers/graph.rs | 15 ++++++++++++++- server/src/handlers/tasks.rs | 2 +- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/server/src/handlers/graph.rs b/server/src/handlers/graph.rs index e9771e7..6ca552c 100644 --- a/server/src/handlers/graph.rs +++ b/server/src/handlers/graph.rs @@ -221,15 +221,22 @@ impl McpTool for DeleteEntitiesHandler { async fn execute(&self, args: Value, state: Arc) -> Result { let req: DeleteEntitiesTool = serde_json::from_value(args).map_err(|e| e.to_string())?; let to_delete: std::collections::HashSet<_> = req.entity_names.into_iter().collect(); + let mut missing = Vec::new(); state.modify_graph(|master| { for name in &to_delete { - master.entities.remove(name); + if master.entities.remove(name).is_none() { + missing.push(name.clone()); + } } master .relations .retain(|r| !to_delete.contains(&r.from) && !to_delete.contains(&r.to)); }); + if !missing.is_empty() { + return Err(format!("Error: Entities not found: {}", missing.join(", "))); + } + let idx = state .search_index .read() @@ -292,10 +299,16 @@ impl McpTool for DeleteRelationsHandler { async fn execute(&self, args: Value, state: Arc) -> Result { let req: DeleteRelationsTool = serde_json::from_value(args).map_err(|e| e.to_string())?; + let mut missing_count = 0; state.modify_graph(|master| { let to_rem: HashSet<_> = req.relations.into_iter().collect(); + let initial_len = master.relations.len(); master.relations.retain(|r| !to_rem.contains(r)); + missing_count = to_rem.len() - (initial_len - master.relations.len()); }); + if missing_count > 0 { + return Err(format!("Error: {} relation(s) not found in graph", missing_count)); + } Ok("Relations deleted".to_string()) } } diff --git a/server/src/handlers/tasks.rs b/server/src/handlers/tasks.rs index 78743a8..4100014 100644 --- a/server/src/handlers/tasks.rs +++ b/server/src/handlers/tasks.rs @@ -257,7 +257,7 @@ impl McpTool for UpdateTaskStatusHandler { }); if blocked { - Ok(format!( + Err(format!( "Error: Cannot transition task. {}", blocker_details ))