From 05e3e532177b8c9626cd275820e2a9fd21d6f211 Mon Sep 17 00:00:00 2001 From: Riz Ashraf Date: Sat, 26 Sep 2026 09:00:00 +0100 Subject: [PATCH] fix(mcp): extract and elevate struct docstrings into root tool schema descriptions to restore semantic LLM visibility --- server/src/mcp.rs | 10 ++++++++-- server/src/tools.rs | 2 +- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/server/src/mcp.rs b/server/src/mcp.rs index 1f6f67d..b0a156d 100644 --- a/server/src/mcp.rs +++ b/server/src/mcp.rs @@ -20,13 +20,19 @@ pub fn error(id: serde_json::Value, code: i32, message: &str) -> serde_json::Val }) } -pub fn tool_def(name: &str, description: &str) -> serde_json::Value { +pub fn tool_def(name: &str, fallback_desc: &str) -> serde_json::Value { let schema = schemars::schema_for!(T); 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. json!({ "name": name, - "description": description, + "description": desc, "inputSchema": schema_val }) } diff --git a/server/src/tools.rs b/server/src/tools.rs index 1a7bbc6..f75f2f7 100644 --- a/server/src/tools.rs +++ b/server/src/tools.rs @@ -55,7 +55,7 @@ pub struct DeleteRelationsTool { pub relations: Vec, } -/// 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)] pub struct ReadGraphTool { /// Optional namespace to restrict the read to.