refactor: Enforce agentic API design across mcp-memory handlers
- Replaced unconstrained JSON serialization (serde_json) with dense YAML (serde_yaml) to prevent context window bloat (ADR-0122). - Replaced 404/empty array dead ends with token-efficient LLM fallback hints in router and meta/graph handlers. - Ensured graceful error fallbacks instead of hard crashes.
This commit is contained in:
1 parent
f56750f596
commit
2024d9521b
3 files changed
+18
-18
No files matched your search
+12
-12
@@ -65,9 +65,9 @@ impl McpResource for GraphEntitiesResource {
|
||||
"_meta": format!("Showing 100 of {} total entities. Use omni_search or get_subgraph for targeted entity discovery.", data.len()),
|
||||
"entities": truncated
|
||||
});
|
||||
Ok(serde_json::to_string_pretty(&res)?)
|
||||
Ok(serde_yaml::to_string(&res)?)
|
||||
} else {
|
||||
Ok(serde_json::to_string_pretty(&data)?)
|
||||
Ok(serde_yaml::to_string(&data)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -93,9 +93,9 @@ impl McpResource for GraphRelationsResource {
|
||||
"_meta": format!("Showing 200 of {} total relations. Use query_graph_path or get_subgraph for targeted relation discovery.", data.len()),
|
||||
"relations": truncated
|
||||
});
|
||||
Ok(serde_json::to_string_pretty(&res)?)
|
||||
Ok(serde_yaml::to_string(&res)?)
|
||||
} else {
|
||||
Ok(serde_json::to_string_pretty(&data)?)
|
||||
Ok(serde_yaml::to_string(&data)?)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -120,7 +120,7 @@ impl McpResource for TasksActiveResource {
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
let data: Vec<_> = tasks.iter().filter(|t| t.is_active()).collect();
|
||||
Ok(serde_json::to_string_pretty(&data)?)
|
||||
Ok(serde_yaml::to_string(&data)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,7 +144,7 @@ impl McpResource for DecisionsActiveResource {
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
let data: Vec<_> = adrs.iter().filter(|a| a.status == "accepted").collect();
|
||||
Ok(serde_json::to_string_pretty(&data)?)
|
||||
Ok(serde_yaml::to_string(&data)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ impl McpResource for TechDebtActiveResource {
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
let data: Vec<_> = debts.iter().filter(|d| !d.is_resolved).collect();
|
||||
Ok(serde_json::to_string_pretty(&data)?)
|
||||
Ok(serde_yaml::to_string(&data)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -267,7 +267,7 @@ impl McpResource for SessionDeltaResource {
|
||||
"timestamp": now,
|
||||
});
|
||||
|
||||
Ok(serde_json::to_string_pretty(&delta)?)
|
||||
Ok(serde_yaml::to_string(&delta)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -360,7 +360,7 @@ impl MemoryHandler {
|
||||
.cache
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
Ok(serde_json::to_string_pretty(&*items)?)
|
||||
Ok(serde_yaml::to_string(&*items)?)
|
||||
}
|
||||
}
|
||||
struct RecentActivitiesResource;
|
||||
@@ -382,7 +382,7 @@ impl MemoryHandler {
|
||||
.cache
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
Ok(serde_json::to_string_pretty(&*items)?)
|
||||
Ok(serde_yaml::to_string(&*items)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -405,7 +405,7 @@ impl MemoryHandler {
|
||||
.cache
|
||||
.read()
|
||||
.unwrap_or_else(|e| e.into_inner());
|
||||
Ok(serde_json::to_string_pretty(&*items)?)
|
||||
Ok(serde_yaml::to_string(&*items)?)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -660,7 +660,7 @@ impl MemoryHandler {
|
||||
Err(e) => Some(crate::mcp::error(id, -32603, &e.to_string())),
|
||||
}
|
||||
} else {
|
||||
Some(crate::mcp::error(id, -32602, "Resource not found"))
|
||||
Some(crate::mcp::error(id, -32602, "Resource not found. To see available resources, call the list_resources tool or query the 'resources/list' endpoint." ))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user