Merge pull request 'feat(tools): add truth_status MCP tool (#38)' (#51) from feature/truth-status-tool into main

Merge truth_status MCP tool (#38)
This commit is contained in:
2026-04-04 10:03:26 +00:00
2 changed files with 63 additions and 0 deletions

View File

@@ -5,6 +5,7 @@ pub mod evaluate;
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};
@@ -158,6 +159,15 @@ pub fn get_tool_definitions() -> Vec<Value> {
"required": ["claim"] "required": ["claim"]
} }
}), }),
json!({
"name": "truth_status",
"description": "Get aggregated truth scoring statistics for the memory store",
"inputSchema": {
"type": "object",
"properties": {},
"required": []
}
}),
] ]
} }
@@ -172,6 +182,7 @@ pub async fn execute_tool(
"query" => query::execute(state, arguments).await, "query" => query::execute(state, arguments).await,
"purge" => purge::execute(state, arguments).await, "purge" => purge::execute(state, arguments).await,
"evaluate" => evaluate::execute(state, arguments).await, "evaluate" => evaluate::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())
}