feat(tools): add truth_status MCP tool (#38)

This commit is contained in:
Agent Zero
2026-04-04 04:07:28 +00:00
parent 50d0a944b5
commit 40d5ab2595
2 changed files with 63 additions and 0 deletions

View File

@@ -4,6 +4,7 @@ pub mod batch_store;
pub mod purge; pub mod purge;
pub mod query; pub mod query;
pub mod store; pub mod store;
pub mod truth_status;
use anyhow::Result; use anyhow::Result;
use serde_json::{json, Value}; use serde_json::{json, Value};
@@ -139,6 +140,15 @@ pub fn get_tool_definitions() -> Vec<Value> {
"required": ["confirm"] "required": ["confirm"]
} }
}), }),
json!({
"name": "truth_status",
"description": "Get aggregated truth scoring statistics for the memory store",
"inputSchema": {
"type": "object",
"properties": {},
"required": []
}
}),
] ]
} }
@@ -152,6 +162,7 @@ pub async fn execute_tool(
"batch_store" => batch_store::execute(state, arguments).await, "batch_store" => batch_store::execute(state, arguments).await,
"query" => query::execute(state, arguments).await, "query" => query::execute(state, arguments).await,
"purge" => purge::execute(state, arguments).await, "purge" => purge::execute(state, arguments).await,
"truth_status" => truth_status::execute(state, arguments).await,
_ => anyhow::bail!("Unknown tool: {}", tool_name), _ => anyhow::bail!("Unknown tool: {}", tool_name),
} }
} }

52
src/tools/truth_status.rs Normal file
View File

@@ -0,0 +1,52 @@
//! Truth Status Tool - Return aggregated truth scoring statistics
use anyhow::{Context, Result};
use serde_json::Value;
use std::sync::Arc;
use tracing::debug;
use crate::AppState;
/// Execute the truth_status tool
pub async fn execute(state: &Arc<AppState>, _arguments: Value) -> Result<String> {
// Check if truth scoring is enabled
if !state.config.truth.enabled {
debug!("Truth status requested but truth scoring is not enabled");
return Ok(serde_json::json!({
"enabled": false,
"message": "Truth scoring is not enabled"
})
.to_string());
}
// Fetch aggregated stats from the database
let stats = state
.db
.get_truth_stats()
.await
.context("Failed to get truth scoring statistics")?;
debug!(
"Truth stats: total={}, scored={}, coverage={:.1}%",
stats.total_memories, stats.scored_memories, stats.coverage_pct
);
Ok(serde_json::json!({
"enabled": true,
"total_memories": stats.total_memories,
"scored_memories": stats.scored_memories,
"unscored_memories": stats.unscored_memories,
"coverage_pct": stats.coverage_pct,
"avg_truth_value": stats.avg_truth_value,
"avg_confidence": stats.avg_confidence,
"categories": {
"verified": stats.category_verified,
"plausible": stats.category_plausible,
"unverified": stats.category_unverified,
"contradicted": stats.category_contradicted
},
"scoring_interval_seconds": state.config.truth.scoring_interval_seconds,
"batch_size": state.config.truth.batch_size
})
.to_string())
}