fix(mcp): propagate internal serialization errors instead of silently swallowing them to prevent LLM hallucination

This commit is contained in:
Riz Ashraf committed 2026-09-27 22:19:43 +01:00
1 parent f8925050db
commit 8f32a09399
13 files changed
+235 -63

No files matched your search

+13 -4
View File
@@ -185,7 +185,10 @@ impl McpTool for DeleteSnippetHandler {
drop(idx.delete_document(&req.name));
Ok("Snippet deleted.".to_string())
} else {
Err("Snippet not found. Please verify the snippet ID using search_snippets.".to_string())
Err(
"Snippet not found. Please verify the snippet ID using search_snippets."
.to_string(),
)
}
}
}
@@ -270,7 +273,10 @@ impl McpTool for ListContextWorkspacesHandler {
let req: ListContextWorkspacesTool =
serde_json::from_value(args).map_err(|e| e.to_string())?;
let data = state.context_workspaces.read_with(|ws| {
let filtered: Vec<_> = ws.iter().filter(|w| req.namespace.as_ref().map_or(true, |ns| &w.namespace == ns)).collect();
let filtered: Vec<_> = ws
.iter()
.filter(|w| req.namespace.as_ref().map_or(true, |ns| &w.namespace == ns))
.collect();
serde_json::to_string(&filtered).map_err(|e| e.to_string())
})?;
Ok(data)
@@ -295,10 +301,13 @@ impl McpTool for DeleteContextWorkspaceHandler {
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
let req: crate::tools::DeleteContextWorkspaceTool =
serde_json::from_value(args).map_err(|e| e.to_string())?;
let mut found = false;
state.context_workspaces.modify(|ws| {
if let Some(pos) = ws.iter().position(|w| w.namespace == req.namespace && w.name == req.name) {
if let Some(pos) = ws
.iter()
.position(|w| w.namespace == req.namespace && w.name == req.name)
{
ws.remove(pos);
found = true;
}