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:
1 parent
410b0c42ca
commit
cb0c55775a
12 files changed
+65
-37
No files matched your search
+12
-12
@@ -142,7 +142,7 @@ impl McpTool for SearchErrorFixesHandler {
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok::<String, crate::error::AppError>(serde_json::to_string_pretty(&suggestions)?)
|
||||
Ok::<String, crate::error::AppError>(serde_yaml::to_string(&suggestions)?)
|
||||
})?;
|
||||
return Ok(data);
|
||||
}
|
||||
@@ -169,7 +169,7 @@ impl McpTool for SearchErrorFixesHandler {
|
||||
}
|
||||
})
|
||||
.collect();
|
||||
Ok::<String, crate::error::AppError>(serde_json::to_string_pretty(&filtered)?)
|
||||
Ok::<String, crate::error::AppError>(serde_yaml::to_string(&filtered)?)
|
||||
})?;
|
||||
Ok(data)
|
||||
}
|
||||
@@ -358,7 +358,7 @@ impl McpTool for QueryRecentChangesHandler {
|
||||
.take(limit)
|
||||
.cloned()
|
||||
.collect();
|
||||
Ok::<String, crate::error::AppError>(serde_json::to_string(&filtered)?)
|
||||
Ok::<String, crate::error::AppError>(serde_yaml::to_string(&filtered)?)
|
||||
})?;
|
||||
Ok(data)
|
||||
}
|
||||
@@ -575,7 +575,7 @@ impl McpTool for DecisionsHandler {
|
||||
.collect();
|
||||
|
||||
if include_body {
|
||||
Ok::<String, crate::error::AppError>(serde_json::to_string(&filtered)?)
|
||||
Ok::<String, crate::error::AppError>(serde_yaml::to_string(&filtered)?)
|
||||
} else {
|
||||
let compact: Vec<_> = filtered
|
||||
.iter()
|
||||
@@ -592,7 +592,7 @@ impl McpTool for DecisionsHandler {
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
Ok::<String, crate::error::AppError>(serde_json::to_string(&compact)?)
|
||||
Ok::<String, crate::error::AppError>(serde_yaml::to_string(&compact)?)
|
||||
}
|
||||
})?;
|
||||
Ok(data)
|
||||
@@ -738,7 +738,7 @@ impl McpTool for TechDebtHandler {
|
||||
}),
|
||||
})
|
||||
.collect();
|
||||
let mut json_str = serde_json::to_string(&filtered)?;
|
||||
let mut json_str = serde_yaml::to_string(&filtered)?;
|
||||
if let Some(max_t) = req.max_tokens {
|
||||
let char_limit = max_t * 4;
|
||||
if json_str.len() > char_limit {
|
||||
@@ -1305,7 +1305,7 @@ impl McpTool for ManageCheckpointHandler {
|
||||
for s in snaps {
|
||||
list.push(serde_json::json!({"type": "snapshot", "id": s.id, "description": s.description, "namespace": s.namespace}));
|
||||
}
|
||||
Ok(serde_json::to_string_pretty(&list)?)
|
||||
Ok(serde_yaml::to_string(&list)?)
|
||||
}
|
||||
CheckpointAction::Delete => {
|
||||
let name = req.name_or_id.ok_or_else(|| {
|
||||
@@ -1427,7 +1427,7 @@ impl McpTool for QueryLineageHandler {
|
||||
"timeline": timeline
|
||||
});
|
||||
|
||||
Ok(serde_json::to_string_pretty(&res)?)
|
||||
Ok(serde_yaml::to_string(&res)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1486,7 +1486,7 @@ impl McpTool for GetNextActionableTasksHandler {
|
||||
"tasks": actionable
|
||||
});
|
||||
|
||||
Ok(serde_json::to_string_pretty(&res)?)
|
||||
Ok(serde_yaml::to_string(&res)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1555,7 +1555,7 @@ impl McpTool for HypothesesHandler {
|
||||
})
|
||||
.collect();
|
||||
|
||||
Ok(serde_json::to_string_pretty(&filtered)?)
|
||||
Ok(serde_yaml::to_string(&filtered)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1634,7 +1634,7 @@ impl McpTool for GetPreflightContextHandler {
|
||||
"recent_activities": recent_activities
|
||||
});
|
||||
|
||||
Ok(serde_json::to_string_pretty(&preflight)?)
|
||||
Ok(serde_yaml::to_string(&preflight)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1742,7 +1742,7 @@ impl McpTool for AgentSignalsHandler {
|
||||
.collect::<Vec<_>>()
|
||||
});
|
||||
|
||||
Ok(serde_json::to_string_pretty(&filtered)?)
|
||||
Ok(serde_yaml::to_string(&filtered)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user