fix(mcp): convert silently swallowed OK string errors into explicit JSON-RPC errors for task transitions and bulk entity operations

This commit is contained in:
Riz Ashraf committed 2026-09-26 08:32:04 +01:00
1 parent f81723a539
commit d96b4cf822
2 files changed
+15 -2

No files matched your search

+14 -1
View File
@@ -221,15 +221,22 @@ impl McpTool for DeleteEntitiesHandler {
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
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<MemoryState>) -> Result<String, String> {
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())
}
}
+1 -1
View File
@@ -257,7 +257,7 @@ impl McpTool for UpdateTaskStatusHandler {
});
if blocked {
Ok(format!(
Err(format!(
"Error: Cannot transition task. {}",
blocker_details
))