lean_ctx/tools/registered/
ctx_plan.rs1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput};
6use crate::tool_defs::tool_def;
7
8pub struct CtxPlanTool;
9
10impl McpTool for CtxPlanTool {
11 fn name(&self) -> &'static str {
12 "ctx_plan"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_plan",
18 "Context planning (CFT). Computes optimal context plan with Phi scoring, budget allocation, and policy-driven view selection.",
19 json!({
20 "type": "object",
21 "properties": {
22 "task": { "type": "string", "description": "Task description" },
23 "budget": { "type": "integer", "description": "Token budget (default: 12000)" },
24 "profile": { "type": "string", "description": "ultra_lean|balanced|forensic" }
25 },
26 "required": ["task"]
27 }),
28 )
29 }
30
31 fn handle(
32 &self,
33 args: &Map<String, Value>,
34 ctx: &ToolContext,
35 ) -> Result<ToolOutput, ErrorData> {
36 let ledger = crate::core::context_ledger::ContextLedger::load();
37
38 let root = if let Some(ref session_lock) = ctx.session {
39 let session = tokio::task::block_in_place(|| session_lock.blocking_read());
40 session.project_root.clone().unwrap_or_default()
41 } else {
42 ctx.project_root.clone()
43 };
44
45 let policies = crate::core::context_policies::PolicySet::load_project(
46 &std::path::PathBuf::from(&root),
47 );
48 let result = crate::tools::ctx_plan::handle(Some(args), &ledger, &policies);
49
50 Ok(ToolOutput::simple(result))
51 }
52}