lean_ctx/tools/registered/
ctx_task.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 CtxTaskTool;
9
10impl McpTool for CtxTaskTool {
11 fn name(&self) -> &'static str {
12 "ctx_task"
13 }
14
15 fn tool_def(&self) -> Tool {
16 tool_def(
17 "ctx_task",
18 "Multi-agent task orchestration. Actions: create|update|list|get|cancel|message|info.",
19 json!({
20 "type": "object",
21 "properties": {
22 "action": {
23 "type": "string",
24 "enum": ["create", "update", "list", "get", "cancel", "message", "info"],
25 "description": "Task operation"
26 },
27 "task_id": { "type": "string", "description": "Task ID (required for update|get|cancel|message)" },
28 "to_agent": { "type": "string", "description": "Target agent ID (required for create)" },
29 "description": { "type": "string", "description": "Task description (for create)" },
30 "state": { "type": "string", "description": "New state for update (working|input-required|completed|failed|canceled)" },
31 "message": { "type": "string", "description": "Optional message / reason" }
32 },
33 "required": ["action"]
34 }),
35 )
36 }
37
38 fn handle(
39 &self,
40 args: &Map<String, Value>,
41 ctx: &ToolContext,
42 ) -> Result<ToolOutput, ErrorData> {
43 let action = get_str(args, "action").unwrap_or_else(|| "list".to_string());
44 let current_agent_id = ctx
45 .agent_id
46 .as_ref()
47 .map(|a| a.blocking_read().clone())
48 .unwrap_or_default();
49 let task_id = get_str(args, "task_id");
50 let to_agent = get_str(args, "to_agent");
51 let description = get_str(args, "description");
52 let state = get_str(args, "state");
53 let message = get_str(args, "message");
54
55 let result = crate::tools::ctx_task::handle(
56 &action,
57 current_agent_id.as_deref(),
58 task_id.as_deref(),
59 to_agent.as_deref(),
60 description.as_deref(),
61 state.as_deref(),
62 message.as_deref(),
63 );
64
65 Ok(ToolOutput {
66 text: result,
67 original_tokens: 0,
68 saved_tokens: 0,
69 mode: Some(action),
70 path: None,
71 changed: false,
72 })
73 }
74}