lean_ctx/tools/registered/
ctx_task.rs1use 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 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.\n\
19 WORKFLOW: action=create → action=list to review → action=update to change state.\n\
20 Actions: create|update|list|get|cancel|message|info.\n\
21 States: working|input-required|completed|failed|canceled.\n\
22 ANTIPATTERN: not for code execution — use ctx_shell or ctx_execute.",
23 json!({
24 "type": "object",
25 "properties": {
26 "action": {
27 "type": "string",
28 "enum": ["create", "update", "list", "get", "cancel", "message", "info"],
29 "description": "create|update|list|get|cancel|message|info"
30 },
31 "task_id": { "type": "string", "description": "Task ID (for update|get|cancel|message)" },
32 "to_agent": { "type": "string", "description": "Target agent ID (for create)" },
33 "description": { "type": "string", "description": "Task description (for create)" },
34 "state": { "type": "string", "description": "New state (working|input-required|completed|failed|canceled)" },
35 "message": { "type": "string", "description": "Message or reason" }
36 },
37 "required": ["action"]
38 }),
39 )
40 }
41
42 fn handle(
43 &self,
44 args: &Map<String, Value>,
45 ctx: &ToolContext,
46 ) -> Result<ToolOutput, ErrorData> {
47 let action = get_str(args, "action").unwrap_or_else(|| "list".to_string());
48 let current_agent_id = ctx
49 .agent_id
50 .as_ref()
51 .map(|a| a.blocking_read().clone())
52 .unwrap_or_default();
53 let task_id = get_str(args, "task_id");
54 let to_agent = get_str(args, "to_agent");
55 let description = get_str(args, "description");
56 let state = get_str(args, "state");
57 let message = get_str(args, "message");
58
59 let result = crate::tools::ctx_task::handle(
60 &action,
61 current_agent_id.as_deref(),
62 task_id.as_deref(),
63 to_agent.as_deref(),
64 description.as_deref(),
65 state.as_deref(),
66 message.as_deref(),
67 );
68
69 Ok(ToolOutput {
70 text: result,
71 original_tokens: 0,
72 saved_tokens: 0,
73 mode: Some(action),
74 path: None,
75 changed: false,
76 shell_outcome: None,
77 content_blocks: None,
78 })
79 }
80}