lean_ctx/tools/registered/
ctx_rules.rs1use rmcp::model::Tool;
2use rmcp::ErrorData;
3use serde_json::{json, Map, Value};
4
5use crate::server::tool_trait::{get_str, McpTool, ToolContext, ToolOutput};
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). Actions: sync (distribute rules to agents), diff (show drift), lint (check consistency), status (show sync state), init (create central config).",
19 json!({
20 "type": "object",
21 "properties": {
22 "action": {
23 "type": "string",
24 "enum": ["sync", "diff", "lint", "status", "init"],
25 "description": "Rules action to perform"
26 },
27 "agent": {
28 "type": "string",
29 "description": "Target agent name (for sync action only, e.g. 'cursor', 'claude')"
30 }
31 },
32 "required": ["action"]
33 }),
34 )
35 }
36
37 fn handle(
38 &self,
39 args: &Map<String, Value>,
40 _ctx: &ToolContext,
41 ) -> Result<ToolOutput, ErrorData> {
42 let action = get_str(args, "action").unwrap_or_default();
43 let agent = get_str(args, "agent");
44
45 let result = crate::tools::ctx_rules::handle(&action, agent.as_deref());
46 Ok(ToolOutput::simple(result))
47 }
48}