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:
1 parent
f81723a539
commit
d96b4cf822
2 files changed
+15
-2
No files matched your search
@@ -221,15 +221,22 @@ impl McpTool for DeleteEntitiesHandler {
|
|||||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
|
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 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 to_delete: std::collections::HashSet<_> = req.entity_names.into_iter().collect();
|
||||||
|
let mut missing = Vec::new();
|
||||||
state.modify_graph(|master| {
|
state.modify_graph(|master| {
|
||||||
for name in &to_delete {
|
for name in &to_delete {
|
||||||
master.entities.remove(name);
|
if master.entities.remove(name).is_none() {
|
||||||
|
missing.push(name.clone());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
master
|
master
|
||||||
.relations
|
.relations
|
||||||
.retain(|r| !to_delete.contains(&r.from) && !to_delete.contains(&r.to));
|
.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
|
let idx = state
|
||||||
.search_index
|
.search_index
|
||||||
.read()
|
.read()
|
||||||
@@ -292,10 +299,16 @@ impl McpTool for DeleteRelationsHandler {
|
|||||||
|
|
||||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
|
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 req: DeleteRelationsTool = serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||||
|
let mut missing_count = 0;
|
||||||
state.modify_graph(|master| {
|
state.modify_graph(|master| {
|
||||||
let to_rem: HashSet<_> = req.relations.into_iter().collect();
|
let to_rem: HashSet<_> = req.relations.into_iter().collect();
|
||||||
|
let initial_len = master.relations.len();
|
||||||
master.relations.retain(|r| !to_rem.contains(r));
|
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())
|
Ok("Relations deleted".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -257,7 +257,7 @@ impl McpTool for UpdateTaskStatusHandler {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if blocked {
|
if blocked {
|
||||||
Ok(format!(
|
Err(format!(
|
||||||
"Error: Cannot transition task. {}",
|
"Error: Cannot transition task. {}",
|
||||||
blocker_details
|
blocker_details
|
||||||
))
|
))
|
||||||
|
|||||||
Reference in new issue
Block a user