fix(mcp): prevent internal handler serialization errors from being silently discarded or defaulting to empty strings
This commit is contained in:
1 parent
8f32a09399
commit
febd48c65d
5 files changed
+12
-12
No files matched your search
@@ -353,7 +353,7 @@ impl McpTool for ReadGraphHandler {
|
||||
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
|
||||
let req: ReadGraphTool = serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
let data = state.read_graph(|full| {
|
||||
let data = state.read_graph(|full| -> Result<String, String> {
|
||||
if let Some(ns) = req.namespace {
|
||||
let mut filtered = BorrowedGraph::default();
|
||||
for (k, v) in &full.entities {
|
||||
@@ -366,11 +366,11 @@ impl McpTool for ReadGraphHandler {
|
||||
filtered.relations.push(r);
|
||||
}
|
||||
}
|
||||
serde_json::to_string(&filtered).unwrap_or_default()
|
||||
serde_json::to_string(&filtered).map_err(|e| e.to_string())
|
||||
} else {
|
||||
serde_json::to_string(full).unwrap_or_default()
|
||||
serde_json::to_string(full).map_err(|e| e.to_string())
|
||||
}
|
||||
});
|
||||
})?;
|
||||
Ok(data)
|
||||
}
|
||||
}
|
||||
@@ -396,7 +396,7 @@ impl McpTool for SearchNodesHandler {
|
||||
vec![]
|
||||
};
|
||||
|
||||
let data = state.read_graph(|full| {
|
||||
let data = state.read_graph(|full| -> Result<String, String> {
|
||||
let mut result = BorrowedGraph::default();
|
||||
for (id, doc_type, _, _, _) in &matches {
|
||||
if doc_type == "entity"
|
||||
@@ -425,7 +425,7 @@ impl McpTool for OpenNodesHandler {
|
||||
|
||||
async fn execute(&self, args: Value, state: Arc<MemoryState>) -> Result<String, String> {
|
||||
let req: OpenNodesTool = serde_json::from_value(args).map_err(|e| e.to_string())?;
|
||||
let data = state.read_graph(|full| {
|
||||
let data = state.read_graph(|full| -> Result<String, String> {
|
||||
let targets: HashSet<&str> = req.names.iter().map(|s| s.as_str()).collect();
|
||||
let mut result = BorrowedGraph::default();
|
||||
let mut connected: HashSet<&str> = HashSet::new();
|
||||
@@ -650,7 +650,7 @@ impl McpTool for FindOrphansHandler {
|
||||
.cloned()
|
||||
.collect::<Vec<String>>()
|
||||
});
|
||||
let data = serde_json::to_string(&orphans).unwrap_or_default();
|
||||
let data = serde_json::to_string(&orphans).map_err(|e| e.to_string())?;
|
||||
Ok(data)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user