mirror of
https://gitea.ingwaz.work/Ingwaz/openbrain-mcp.git
synced 2026-06-15 22:07:08 +00:00
feat(tools): add truth_status MCP tool (#38)
This commit is contained in:
@@ -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
52
src/tools/truth_status.rs
Normal 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())
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user