fix(mcp): extract and elevate struct docstrings into root tool schema descriptions to restore semantic LLM visibility

This commit is contained in:
Riz Ashraf committed 2026-09-26 09:00:00 +01:00
1 parent e84c101515
commit 05e3e53217
2 files changed
+9 -3

No files matched your search

+8 -2
View File
@@ -20,13 +20,19 @@ pub fn error(id: serde_json::Value, code: i32, message: &str) -> serde_json::Val
}) })
} }
pub fn tool_def<T: JsonSchema>(name: &str, description: &str) -> serde_json::Value { pub fn tool_def<T: JsonSchema>(name: &str, fallback_desc: &str) -> serde_json::Value {
let schema = schemars::schema_for!(T); let schema = schemars::schema_for!(T);
let schema_val = serde_json::to_value(&schema).unwrap_or_default(); let schema_val = serde_json::to_value(&schema).unwrap_or_default();
let desc = schema_val.get("description")
.and_then(|d| d.as_str())
.unwrap_or(fallback_desc)
.to_string();
// MCP expects standard JSON schema. Schemars returns draft-07. // MCP expects standard JSON schema. Schemars returns draft-07.
json!({ json!({
"name": name, "name": name,
"description": description, "description": desc,
"inputSchema": schema_val "inputSchema": schema_val
}) })
} }
+1 -1
View File
@@ -55,7 +55,7 @@ pub struct DeleteRelationsTool {
pub relations: Vec<crate::models::Relation>, pub relations: Vec<crate::models::Relation>,
} }
/// Read the entire knowledge graph. /// Read the entire knowledge graph. WARNING: For large graphs, use search_nodes instead to avoid context limits.
#[derive(Debug, Deserialize, Serialize, JsonSchema)] #[derive(Debug, Deserialize, Serialize, JsonSchema)]
pub struct ReadGraphTool { pub struct ReadGraphTool {
/// Optional namespace to restrict the read to. /// Optional namespace to restrict the read to.