Skip to main content

lean_ctx/tools/registered/
ctx_rules.rs

1use rmcp::ErrorData;
2use rmcp::model::Tool;
3use serde_json::{Map, Value, json};
4
5use crate::server::tool_trait::{McpTool, ToolContext, ToolOutput, get_str};
6use crate::tool_defs::tool_def;
7
8pub struct CtxRulesTool;
9
10impl McpTool for CtxRulesTool {
11    fn name(&self) -> &'static str {
12        "ctx_rules"
13    }
14
15    fn tool_def(&self) -> Tool {
16        tool_def(
17            "ctx_rules",
18            "Cross-agent rules governance (ContextOps).\n\
19             Actions: sync (distribute rules to agents), diff (show drift),\n\
20             lint (check consistency), status (sync state), init (create central config).\n\
21             WORKFLOW: run status first to check state, then sync if out of date.",
22            json!({
23                "type": "object",
24                "properties": {
25                    "action": {
26                        "type": "string",
27                        "enum": ["sync", "diff", "lint", "status", "init"]
28                    },
29                    "agent": {
30                        "type": "string",
31                        "description": "Target agent name (for sync)"
32                    }
33                },
34                "required": ["action"]
35            }),
36        )
37    }
38
39    fn handle(
40        &self,
41        args: &Map<String, Value>,
42        _ctx: &ToolContext,
43    ) -> Result<ToolOutput, ErrorData> {
44        let action = get_str(args, "action").unwrap_or_default();
45        let agent = get_str(args, "agent");
46
47        let result = crate::tools::ctx_rules::handle(&action, agent.as_deref());
48        Ok(ToolOutput::simple(result))
49    }
50}