feat(mcp): switch to YAML serialization for tool outputs

- Replaced serde_json with serde_yaml in all handler endpoints.

- This drastically reduces token consumption for large list/graph responses by removing JSON braces and quotes.
This commit is contained in:
Riz Ashraf committed 2026-10-08 23:46:32 +01:00
1 parent 410b0c42ca
commit cb0c55775a
12 files changed
+65 -37

No files matched your search

+8 -8
View File
@@ -542,7 +542,7 @@ impl McpTool for ReadGraphHandler {
})
};
let mut result_json = serde_json::to_string(&serialized)?;
let mut result_json = serde_yaml::to_string(&serialized)?;
if let Some(max_tok) = max_tokens {
let max_chars = max_tok * 4;
@@ -579,7 +579,7 @@ impl McpTool for ReadGraphHandler {
obj.insert("has_more".to_string(), serde_json::Value::Bool(true));
}
if let Ok(trunc_str) = serde_json::to_string(&truncated_val)
if let Ok(trunc_str) = serde_yaml::to_string(&truncated_val)
&& (trunc_str.len() <= max_chars || keep_count == 1) {
result_json = trunc_str;
break;
@@ -638,7 +638,7 @@ impl McpTool for SearchNodesHandler {
}
}
}
Ok::<String, crate::error::AppError>(serde_json::to_string(&matched_entities)?)
Ok::<String, crate::error::AppError>(serde_yaml::to_string(&matched_entities)?)
})?;
Ok(data)
}
@@ -679,7 +679,7 @@ impl McpTool for OpenNodesHandler {
result.entities.insert(name, e);
}
}
Ok::<String, crate::error::AppError>(serde_json::to_string(&result)?)
Ok::<String, crate::error::AppError>(serde_yaml::to_string(&result)?)
})?;
Ok(data)
}
@@ -954,7 +954,7 @@ impl McpTool for FindOrphansHandler {
.cloned()
.collect::<Vec<String>>()
});
let data = Ok::<String, crate::error::AppError>(serde_json::to_string(&orphans)?)?;
let data = Ok::<String, crate::error::AppError>(serde_yaml::to_string(&orphans)?)?;
Ok(data)
}
}
@@ -1047,7 +1047,7 @@ impl McpTool for GetSubgraphHandler {
"relations": matched_relations,
});
Ok(serde_json::to_string_pretty(&result)?)
Ok(serde_yaml::to_string(&result)?)
}
}
@@ -1146,7 +1146,7 @@ impl McpTool for SweepGraphHealthHandler {
"health_score": if orphans.is_empty() && duplicates.is_empty() && stale_entities.is_empty() { "100%" } else { "Needs Maintenance" }
});
Ok(serde_json::to_string_pretty(&report)?)
Ok(serde_yaml::to_string(&report)?)
}
}
@@ -1203,7 +1203,7 @@ impl McpTool for ResolveStaleSymbolsHandler {
"status": "success"
});
Ok(serde_json::to_string_pretty(&report)?)
Ok(serde_yaml::to_string(&report)?)
}
}