Skip to main content

clickup_cli/
mcp.rs

1use crate::client::ClickUpClient;
2use crate::config::Config;
3use crate::git;
4use crate::output::{compact_items, flatten_value};
5use serde_json::{json, Value};
6use tokio::io::{AsyncBufReadExt, BufReader};
7
8pub mod classify;
9pub mod filter;
10
11// ── JSON-RPC helpers ──────────────────────────────────────────────────────────
12
13fn ok_response(id: &Value, result: Value) -> Value {
14    json!({"jsonrpc":"2.0","id":id,"result":result})
15}
16
17fn error_response(id: &Value, code: i64, message: &str) -> Value {
18    json!({"jsonrpc":"2.0","id":id,"error":{"code":code,"message":message}})
19}
20
21fn tool_result(text: String) -> Value {
22    json!({"content":[{"type":"text","text":text}]})
23}
24
25fn tool_error(msg: String) -> Value {
26    json!({"content":[{"type":"text","text":msg}],"isError":true})
27}
28
29fn encode_query_value(value: &str) -> String {
30    value
31        .bytes()
32        .flat_map(|byte| match byte {
33            b'A'..=b'Z' | b'a'..=b'z' | b'0'..=b'9' | b'-' | b'_' | b'.' | b'~' => {
34                vec![byte as char]
35            }
36            _ => format!("%{:02X}", byte).chars().collect(),
37        })
38        .collect()
39}
40
41fn push_query_param(params: &mut Vec<String>, name: &str, value: impl ToString) {
42    params.push(format!(
43        "{}={}",
44        name,
45        encode_query_value(&value.to_string())
46    ));
47}
48
49fn push_string_array_query_params(
50    params: &mut Vec<String>,
51    args: &Value,
52    arg_name: &str,
53    query_name: &str,
54) {
55    if let Some(values) = args.get(arg_name).and_then(|v| v.as_array()) {
56        for value in values {
57            if let Some(value) = value.as_str() {
58                push_query_param(params, query_name, value);
59            }
60        }
61    }
62}
63
64fn push_number_array_query_params(
65    params: &mut Vec<String>,
66    args: &Value,
67    arg_name: &str,
68    query_name: &str,
69) {
70    if let Some(values) = args.get(arg_name).and_then(|v| v.as_array()) {
71        for value in values {
72            if let Some(value) = value.as_i64() {
73                push_query_param(params, query_name, value);
74            }
75        }
76    }
77}
78
79fn push_bool_query_param(params: &mut Vec<String>, args: &Value, arg_name: &str, query_name: &str) {
80    if let Some(value) = args.get(arg_name).and_then(|v| v.as_bool()) {
81        push_query_param(params, query_name, value);
82    }
83}
84
85fn push_i64_query_param(params: &mut Vec<String>, args: &Value, arg_name: &str, query_name: &str) {
86    if let Some(value) = args.get(arg_name).and_then(|v| v.as_i64()) {
87        push_query_param(params, query_name, value);
88    }
89}
90
91fn push_string_query_param(
92    params: &mut Vec<String>,
93    args: &Value,
94    arg_name: &str,
95    query_name: &str,
96) {
97    if let Some(value) = args.get(arg_name).and_then(|v| v.as_str()) {
98        push_query_param(params, query_name, value);
99    }
100}
101
102fn task_search_query_params(args: &Value) -> Vec<String> {
103    let mut params = Vec::new();
104
105    push_string_array_query_params(&mut params, args, "space_ids", "space_ids[]");
106    push_string_array_query_params(&mut params, args, "project_ids", "project_ids[]");
107    push_string_array_query_params(&mut params, args, "list_ids", "list_ids[]");
108    push_string_array_query_params(&mut params, args, "statuses", "statuses[]");
109    push_string_array_query_params(&mut params, args, "assignees", "assignees[]");
110    push_string_array_query_params(&mut params, args, "tags", "tags[]");
111    push_number_array_query_params(&mut params, args, "custom_items", "custom_items[]");
112
113    for key in [
114        "include_closed",
115        "subtasks",
116        "reverse",
117        "include_markdown_description",
118    ] {
119        push_bool_query_param(&mut params, args, key, key);
120    }
121
122    for key in [
123        "due_date_gt",
124        "due_date_lt",
125        "date_created_gt",
126        "date_created_lt",
127        "date_updated_gt",
128        "date_updated_lt",
129        "date_done_gt",
130        "date_done_lt",
131    ] {
132        push_i64_query_param(&mut params, args, key, key);
133    }
134
135    push_string_query_param(&mut params, args, "parent", "parent");
136    push_string_query_param(&mut params, args, "order_by", "order_by");
137
138    if let Some(custom_fields) = args.get("custom_fields").and_then(|v| v.as_array()) {
139        push_query_param(
140            &mut params,
141            "custom_fields",
142            serde_json::to_string(custom_fields).unwrap_or_else(|_| "[]".to_string()),
143        );
144    }
145
146    params
147}
148
149/// Inspects a `tools/call` request and returns a JSON-RPC response when the
150/// request can be resolved WITHOUT executing the tool itself (missing tool
151/// name, or tool is filtered out). Returns `None` when the caller should
152/// proceed to invoke the tool.
153pub fn handle_tools_call_early(
154    id: &Value,
155    params: &Value,
156    filter: &filter::Filter,
157) -> Option<Value> {
158    let tool_name = params.get("name").and_then(|v| v.as_str()).unwrap_or("");
159
160    if tool_name.is_empty() {
161        return Some(ok_response(id, tool_error("Missing tool name".to_string())));
162    }
163
164    if !filter.allows(tool_name) {
165        return Some(error_response(
166            id,
167            -32601,
168            &format!("Method not found: {} (filtered out at startup)", tool_name),
169        ));
170    }
171
172    None
173}
174
175// ── Tool definitions ──────────────────────────────────────────────────────────
176
177pub fn tool_list() -> Value {
178    json!([
179        {
180            "name": "clickup_whoami",
181            "description": "Get the currently authenticated ClickUp user",
182            "inputSchema": {
183                "type": "object",
184                "properties": {},
185                "required": []
186            }
187        },
188        {
189            "name": "clickup_workspace_list",
190            "description": "List all ClickUp workspaces (teams) accessible to the current user",
191            "inputSchema": {
192                "type": "object",
193                "properties": {},
194                "required": []
195            }
196        },
197        {
198            "name": "clickup_space_list",
199            "description": "List all spaces in a ClickUp workspace. Spaces are the top-level containers below the workspace and hold folders, lists, and tasks. Returns a compact array of space objects (id, name, private, archived). Use clickup_folder_list or clickup_list_list with a space_id to drill down.",
200            "inputSchema": {
201                "type": "object",
202                "properties": {
203                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config (defaults.workspace_id)."},
204                    "archived": {"type": "boolean", "description": "true = include archived spaces in the result; false or omitted = only active spaces. Defaults to false."}
205                },
206                "required": []
207            }
208        },
209        {
210            "name": "clickup_folder_list",
211            "description": "List all folders in a ClickUp space. Folders are optional groupings that contain lists; a space may also have folderless lists (use clickup_list_list with space_id for those). Returns a compact array of folder objects (id, name, task_count, archived).",
212            "inputSchema": {
213                "type": "object",
214                "properties": {
215                    "space_id": {"type": "string", "description": "ID of the parent space. Obtain from clickup_space_list (field: id)."},
216                    "archived": {"type": "boolean", "description": "true = include archived folders; false or omitted = only active folders. Defaults to false."}
217                },
218                "required": ["space_id"]
219            }
220        },
221        {
222            "name": "clickup_list_list",
223            "description": "List ClickUp lists under either a folder or a space (folderless lists). Exactly one of folder_id or space_id must be provided. Returns a compact array of list objects (id, name, task_count, archived). Use clickup_task_list to drill into a specific list.",
224            "inputSchema": {
225                "type": "object",
226                "properties": {
227                    "folder_id": {"type": "string", "description": "ID of the parent folder. Obtain from clickup_folder_list (field: id). Mutually exclusive with space_id."},
228                    "space_id": {"type": "string", "description": "ID of a space — returns only the folderless lists attached directly to the space. Obtain from clickup_space_list (field: id). Mutually exclusive with folder_id."},
229                    "archived": {"type": "boolean", "description": "true = include archived lists; false or omitted = only active lists. Defaults to false."}
230                },
231                "required": []
232            }
233        },
234        {
235            "name": "clickup_task_list",
236            "description": "List tasks in a specific ClickUp list with optional status/assignee filters. Returns the first page of task objects in compact form (id, name, status, assignees, due_date). For cross-list or cross-space queries use clickup_task_search instead; for a single task use clickup_task_get.",
237            "inputSchema": {
238                "type": "object",
239                "properties": {
240                    "list_id": {"type": "string", "description": "ID of the list to read tasks from. Obtain from clickup_list_list (field: id)."},
241                    "statuses": {
242                        "type": "array",
243                        "items": {"type": "string"},
244                        "description": "Status names to include (e.g. ['open','in progress']). Case-sensitive, must match a status defined on the list. Omit to return tasks in any open status."
245                    },
246                    "assignees": {
247                        "type": "array",
248                        "items": {"type": "string"},
249                        "description": "User IDs (as strings) to filter assignees. Obtain from clickup_member_list or clickup_user_get. Omit to return tasks regardless of assignee."
250                    },
251                    "include_closed": {"type": "boolean", "description": "true = include tasks whose status is in the 'closed' group; false or omitted = exclude closed tasks from the response."}
252                },
253                "required": ["list_id"]
254            }
255        },
256        {
257            "name": "clickup_task_get",
258            "description": "Fetch the full object for a single ClickUp task — name, description, status, assignees, tags, custom fields, checklists, due date, time estimates, dependencies, and more. Returns the task object. Use clickup_task_list or clickup_task_search to find a task_id.",
259            "inputSchema": {
260                "type": "object",
261                "properties": {
262                    "task_id": {"type": "string", "description": "ID of the task to fetch. Obtain from clickup_task_list (field: id) or clickup_task_search."},
263                    "include_subtasks": {"type": "boolean", "description": "true = include the task's subtasks in the response under the 'subtasks' field; false or omitted = return only the parent task."}
264                },
265                "required": ["task_id"]
266            }
267        },
268        {
269            "name": "clickup_task_create",
270            "description": "Create a new task in a ClickUp list. The task starts in the list's default status unless 'status' is supplied. Returns the created task object including its new id, which you can pass to clickup_task_update, clickup_task_get, etc.",
271            "inputSchema": {
272                "type": "object",
273                "properties": {
274                    "list_id": {"type": "string", "description": "ID of the list the task will live in. Obtain from clickup_list_list (field: id)."},
275                    "name": {"type": "string", "description": "Task title shown in the list view. Required and non-empty."},
276                    "description": {"type": "string", "description": "Task body. Markdown supported (headings, links, checkboxes, @mentions). Omit to create the task with no description."},
277                    "status": {"type": "string", "description": "Status name to start in (case-sensitive; must match a status configured on the list). Omit to use the list's default initial status."},
278                    "priority": {"type": "integer", "description": "Task priority: 1=Urgent, 2=High, 3=Normal, 4=Low. Omit for no priority."},
279                    "assignees": {
280                        "type": "array",
281                        "items": {"type": "integer"},
282                        "description": "User IDs to assign to the task. Obtain from clickup_member_list or clickup_user_get. Omit for an unassigned task."
283                    },
284                    "tags": {
285                        "type": "array",
286                        "items": {"type": "string"},
287                        "description": "Tag names to apply. Tags must already exist in the parent space (use clickup_tag_list to see available tags or clickup_tag_create to add new ones)."
288                    },
289                    "due_date": {"type": "integer", "description": "Due date as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01). Omit for no due date."}
290                },
291                "required": ["list_id", "name"]
292            }
293        },
294        {
295            "name": "clickup_task_update",
296            "description": "Update fields on an existing ClickUp task — name, description, status, priority, and incrementally add/remove assignees. Only provided fields are changed; omitted fields keep their current value. For tags use clickup_task_add_tag/remove_tag; for moving between lists use clickup_task_move. Returns the updated task object.",
297            "inputSchema": {
298                "type": "object",
299                "properties": {
300                    "task_id": {"type": "string", "description": "ID of the task to update. Obtain from clickup_task_list (field: id) or clickup_task_search."},
301                    "name": {"type": "string", "description": "New task title. Omit to keep current name."},
302                    "status": {"type": "string", "description": "New status name (case-sensitive, must match a status defined on the parent list). Omit to keep current status."},
303                    "priority": {"type": "integer", "description": "New priority: 1=Urgent, 2=High, 3=Normal, 4=Low. Omit to keep current priority."},
304                    "description": {"type": "string", "description": "New task body — replaces the current description entirely. Markdown supported. Omit to keep current description."},
305                    "add_assignees": {
306                        "type": "array",
307                        "items": {"type": "integer"},
308                        "description": "User IDs to add as assignees (additive; does not replace existing assignees). Obtain from clickup_member_list."
309                    },
310                    "rem_assignees": {
311                        "type": "array",
312                        "items": {"type": "integer"},
313                        "description": "User IDs to remove from assignees (no-op if the user is not currently assigned)."
314                    }
315                },
316                "required": ["task_id"]
317            }
318        },
319        {
320            "name": "clickup_task_delete",
321            "description": "Permanently delete a ClickUp task along with all its subtasks, comments, checklists, attachments, and time entries. Destructive, irreversible, and cascading — confirm with the user before calling. To mark a task done without deleting, use clickup_task_update with a 'closed' status instead. Returns an empty object on success.",
322            "inputSchema": {
323                "type": "object",
324                "properties": {
325                    "task_id": {"type": "string", "description": "ID of the task to delete. Obtain from clickup_task_list (field: id) or clickup_task_search. All subtasks, comments, checklists, attachments, and time entries on this task are deleted with it."}
326                },
327                "required": ["task_id"]
328            }
329        },
330        {
331            "name": "clickup_task_search",
332            "description": "Search tasks across an entire ClickUp workspace with ClickUp's filtered team tasks endpoint. Supports hierarchy, assignee, status, tag, date range, custom field, custom item type, parent/subtask, and ordering filters. Returns a paginated array of task objects. For tasks in a single list, prefer clickup_task_list (fewer parameters, same shape).",
333            "inputSchema": {
334                "type": "object",
335                "properties": {
336                    "team_id": {"type": "string", "description": "Workspace (team) ID to search within. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
337                    "space_ids": {
338                        "type": "array",
339                        "items": {"type": "string"},
340                        "description": "Restrict results to these space IDs. Obtain from clickup_space_list (field: id). Omit to search all spaces."
341                    },
342                    "project_ids": {
343                        "type": "array",
344                        "items": {"type": "string"},
345                        "description": "Restrict results to these folder/project IDs. ClickUp's API parameter is project_ids[]. Obtain IDs from clickup_folder_list."
346                    },
347                    "list_ids": {
348                        "type": "array",
349                        "items": {"type": "string"},
350                        "description": "Restrict results to these list IDs. Obtain from clickup_list_list (field: id). Omit to search all lists."
351                    },
352                    "statuses": {
353                        "type": "array",
354                        "items": {"type": "string"},
355                        "description": "Status names to include (e.g. ['open','in review']). Case-sensitive. Omit for any open status."
356                    },
357                    "assignees": {
358                        "type": "array",
359                        "items": {"type": "string"},
360                        "description": "User IDs (as strings) to restrict to tasks assigned to them. Obtain from clickup_member_list. Omit to return tasks regardless of assignee."
361                    },
362                    "tags": {
363                        "type": "array",
364                        "items": {"type": "string"},
365                        "description": "Tag names to filter by. Tags must match ClickUp tag names in the relevant spaces."
366                    },
367                    "include_closed": {"type": "boolean", "description": "true = include tasks in closed statuses; false or omitted = exclude closed tasks."},
368                    "subtasks": {"type": "boolean", "description": "true = include subtasks in search results; false or omitted = exclude subtasks unless parent is provided."},
369                    "parent": {"type": "string", "description": "Parent task ID. When set, returns subtasks under this parent task."},
370                    "order_by": {"type": "string", "description": "Sort field supported by ClickUp, such as id, created, updated, or due_date."},
371                    "reverse": {"type": "boolean", "description": "true = reverse the selected sort order."},
372                    "due_date_gt": {"type": "integer", "description": "Filter tasks with due_date greater than this Unix timestamp in milliseconds."},
373                    "due_date_lt": {"type": "integer", "description": "Filter tasks with due_date less than this Unix timestamp in milliseconds."},
374                    "date_created_gt": {"type": "integer", "description": "Filter tasks created after this Unix timestamp in milliseconds."},
375                    "date_created_lt": {"type": "integer", "description": "Filter tasks created before this Unix timestamp in milliseconds."},
376                    "date_updated_gt": {"type": "integer", "description": "Filter tasks updated after this Unix timestamp in milliseconds."},
377                    "date_updated_lt": {"type": "integer", "description": "Filter tasks updated before this Unix timestamp in milliseconds."},
378                    "date_done_gt": {"type": "integer", "description": "Filter tasks completed after this Unix timestamp in milliseconds."},
379                    "date_done_lt": {"type": "integer", "description": "Filter tasks completed before this Unix timestamp in milliseconds."},
380                    "custom_fields": {
381                        "type": "array",
382                        "items": {"type": "object"},
383                        "description": "ClickUp custom field filters. Each object is sent inside the custom_fields JSON query parameter, e.g. [{\"field_id\":\"...\",\"operator\":\"=\",\"value\":\"...\"}]. Use operators supported by ClickUp, including IS NULL / IS NOT NULL for unset/set checks."
384                    },
385                    "custom_items": {
386                        "type": "array",
387                        "items": {"type": "integer"},
388                        "description": "Filter by ClickUp custom task type IDs. Include 0 for regular tasks, 1 for milestones, or workspace-defined custom item type IDs."
389                    },
390                    "include_markdown_description": {"type": "boolean", "description": "true = ask ClickUp to return task descriptions in Markdown format."}
391                },
392                "required": []
393            }
394        },
395        {
396            "name": "clickup_comment_list",
397            "description": "List comments on a ClickUp task in chronological order (oldest first). Only top-level comments are returned; use clickup_comment_replies to fetch a threaded reply chain. Returns a compact array of comment objects (id, comment_text, user, resolved, date).",
398            "inputSchema": {
399                "type": "object",
400                "properties": {
401                    "task_id": {"type": "string", "description": "ID of the task to read comments from. Obtain from clickup_task_list (field: id) or clickup_task_search."}
402                },
403                "required": ["task_id"]
404            }
405        },
406        {
407            "name": "clickup_comment_create",
408            "description": "Post a new top-level comment on a ClickUp task. @mentions are recognised by ClickUp. Note: ClickUp's v2 comment API stores the body verbatim and does NOT render markdown. Tokens like `**bold**` appear as literal characters in the UI. Returns the created comment object including its new id, which you can pass to clickup_comment_reply, clickup_comment_update, etc.",
409            "inputSchema": {
410                "type": "object",
411                "properties": {
412                    "task_id": {"type": "string", "description": "ID of the task to comment on. Obtain from clickup_task_list (field: id) or clickup_task_search."},
413                    "text": {"type": "string", "description": "Comment body. @mentions (e.g. '@username') are rendered. Markdown is NOT rendered by ClickUp's v2 comment API. Markdown syntax is stored as literal text."},
414                    "assignee": {"type": "integer", "description": "Optional user ID to assign the comment to — they will receive a notification. Obtain from clickup_member_list."},
415                    "notify_all": {"type": "boolean", "description": "true = send a notification to every assignee of the task; false or omitted = only notify people mentioned or the explicit assignee."}
416                },
417                "required": ["task_id", "text"]
418            }
419        },
420        {
421            "name": "clickup_field_list",
422            "description": "List the custom field definitions available on a ClickUp list — field id, name, type (text, number, drop_down, labels, date, url, email, phone, money, progress, formula, etc.), and for drop_down/labels fields the permitted option values extracted from type_config.options. Use this before clickup_field_set to learn the correct field_id, option ids, and value shape. Returns an array of custom field definitions.",
423            "inputSchema": {
424                "type": "object",
425                "properties": {
426                    "list_id": {"type": "string", "description": "ID of the list whose custom fields to enumerate. Obtain from clickup_list_list (field: id). Fields are defined per-list (or inherited from folder/space)."}
427                },
428                "required": ["list_id"]
429            }
430        },
431        {
432            "name": "clickup_field_set",
433            "description": "Set or overwrite a single custom field value on a ClickUp task. The value's JSON shape must match the field type (string for text/url/email and for a drop_down option id, number for number/currency/progress, array of option ids for labels, Unix ms for date, etc.). Use clickup_field_list first to see the field type and option ids. Use clickup_field_unset to clear a value. Returns an empty object on success.",
434            "inputSchema": {
435                "type": "object",
436                "properties": {
437                    "task_id": {"type": "string", "description": "ID of the task whose field value should change. Obtain from clickup_task_list (field: id)."},
438                    "field_id": {"type": "string", "description": "ID of the custom field to set. Obtain from clickup_field_list (field: id) or clickup_task_get (custom_fields[].id)."},
439                    "value": {"description": "New value; the accepted type depends on the custom field type. Examples: 'hello' (text), 42 (number), 'option-uuid' (drop_down), ['option-uuid'] (labels), 1735689600000 (date as Unix ms). See clickup_field_list for the field's type and option ids."}
440                },
441                "required": ["task_id", "field_id", "value"]
442            }
443        },
444        {
445            "name": "clickup_time_start",
446            "description": "Start a live time-tracking timer for the authenticated user. If a timer is already running it will be stopped first. Pair with clickup_time_stop to end the timer and record the entry. Use clickup_time_current to inspect the running timer. Returns the newly started time entry object.",
447            "inputSchema": {
448                "type": "object",
449                "properties": {
450                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
451                    "task_id": {"type": "string", "description": "ID of the task to attribute this timer to. Obtain from clickup_task_list (field: id). Omit to track time without a task."},
452                    "description": {"type": "string", "description": "Free-text description shown on the time entry (e.g. 'pair debugging session'). Optional."},
453                    "billable": {"type": "boolean", "description": "true = mark this time entry as billable (shows as $ in reports); false or omitted = non-billable."}
454                },
455                "required": []
456            }
457        },
458        {
459            "name": "clickup_time_stop",
460            "description": "Stop the currently running time tracking entry",
461            "inputSchema": {
462                "type": "object",
463                "properties": {
464                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."}
465                },
466                "required": []
467            }
468        },
469        {
470            "name": "clickup_time_list",
471            "description": "List historical time tracking entries for a workspace, optionally filtered by date range and/or task. Covers both manually-created entries and stopped timers. Returns a compact array of time entry objects (id, user, task, start, duration, billable, description).",
472            "inputSchema": {
473                "type": "object",
474                "properties": {
475                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
476                    "start_date": {"type": "integer", "description": "Inclusive lower bound as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01). Omit for no lower bound."},
477                    "end_date": {"type": "integer", "description": "Inclusive upper bound as a Unix timestamp in milliseconds. Omit for no upper bound. Note: ClickUp caps the range to ~30 days by default."},
478                    "task_id": {"type": "string", "description": "Return only entries attributed to this task. Obtain from clickup_task_list (field: id). Omit to list entries across all tasks."}
479                },
480                "required": []
481            }
482        },
483        {
484            "name": "clickup_checklist_create",
485            "description": "Create a new checklist (to-do group) on a ClickUp task. The checklist starts empty — add items via clickup_checklist_add_item. A task can have multiple checklists. Returns the created checklist object including its new id.",
486            "inputSchema": {
487                "type": "object",
488                "properties": {
489                    "task_id": {"type": "string", "description": "ID of the task to attach the checklist to. Obtain from clickup_task_list (field: id)."},
490                    "name": {"type": "string", "description": "Display name for the checklist (e.g. 'Launch prep', 'QA steps'). Shown as a heading above the items."}
491                },
492                "required": ["task_id", "name"]
493            }
494        },
495        {
496            "name": "clickup_checklist_delete",
497            "description": "Permanently delete an entire checklist from a ClickUp task, including all its items. Destructive and irreversible. To remove a single item instead, use clickup_checklist_delete_item. Returns an empty object on success.",
498            "inputSchema": {
499                "type": "object",
500                "properties": {
501                    "checklist_id": {"type": "string", "description": "ID of the checklist to delete. Obtain from clickup_task_get (field: checklists[].id). All items on this checklist are deleted with it."}
502                },
503                "required": ["checklist_id"]
504            }
505        },
506        {
507            "name": "clickup_goal_list",
508            "description": "List all ClickUp goals in a workspace. Each goal represents an OKR-style objective and can have multiple key results (sub-targets). Returns a compact array of goal objects (id, name, percent_completed, due_date). Use clickup_goal_get for the full goal including its key_results.",
509            "inputSchema": {
510                "type": "object",
511                "properties": {
512                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
513                },
514                "required": []
515            }
516        },
517        {
518            "name": "clickup_goal_get",
519            "description": "Fetch a single ClickUp goal including its key results, owners, due date, and current percent-complete. Returns the goal object with its key_results array populated.",
520            "inputSchema": {
521                "type": "object",
522                "properties": {
523                    "goal_id": {"type": "string", "description": "ID of the goal to fetch. Obtain from clickup_goal_list (field: id). The authenticated user must have view access to the goal's workspace."}
524                },
525                "required": ["goal_id"]
526            }
527        },
528        {
529            "name": "clickup_goal_create",
530            "description": "Create a new OKR-style goal in a workspace. The goal starts with zero key results — add them via clickup_goal_add_kr. The goal's percent-complete is auto-calculated from the average progress of its key results. Returns the created goal object including its new id.",
531            "inputSchema": {
532                "type": "object",
533                "properties": {
534                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
535                    "name": {"type": "string", "description": "Goal title (e.g. 'Q1 revenue target'). Required and non-empty."},
536                    "due_date": {"type": "integer", "description": "Target completion date as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01)."},
537                    "description": {"type": "string", "description": "Goal description / rationale. Markdown supported. Omit for no description."},
538                    "owner_ids": {
539                        "type": "array",
540                        "items": {"type": "integer"},
541                        "description": "User IDs to assign as goal owners (they receive notifications about progress). Obtain from clickup_member_list."
542                    }
543                },
544                "required": ["name"]
545            }
546        },
547        {
548            "name": "clickup_goal_update",
549            "description": "Modify a ClickUp goal's top-level fields (name, description, due date). To change progress, update the goal's key results instead via clickup_goal_update_kr — the goal's percent complete is derived automatically. Returns the updated goal object.",
550            "inputSchema": {
551                "type": "object",
552                "properties": {
553                    "goal_id": {"type": "string", "description": "ID of the goal to update. Obtain from clickup_goal_list (field: id)."},
554                    "name": {"type": "string", "description": "New goal title. Omit to keep current name."},
555                    "due_date": {"type": "integer", "description": "New due date as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01)."},
556                    "description": {"type": "string", "description": "New goal description. Markdown supported."}
557                },
558                "required": ["goal_id"]
559            }
560        },
561        {
562            "name": "clickup_view_list",
563            "description": "List saved views (board, list, calendar, gantt, timeline, etc.) attached to a space, folder, list, or the whole workspace. Exactly one of space_id/folder_id/list_id must be provided — or omit all three to list workspace-level views. Returns a compact array of view objects (id, name, type).",
564            "inputSchema": {
565                "type": "object",
566                "properties": {
567                    "space_id": {"type": "string", "description": "Space ID whose views to list. Obtain from clickup_space_list. Mutually exclusive with folder_id/list_id."},
568                    "folder_id": {"type": "string", "description": "Folder ID whose views to list. Obtain from clickup_folder_list. Mutually exclusive with space_id/list_id."},
569                    "list_id": {"type": "string", "description": "List ID whose views to list. Obtain from clickup_list_list. Mutually exclusive with space_id/folder_id."},
570                    "team_id": {"type": "string", "description": "Workspace (team) ID — used when all three scope IDs are omitted, to return workspace-level (Everything) views. Obtain from clickup_workspace_list. Omit to use the default workspace from config."}
571                },
572                "required": []
573            }
574        },
575        {
576            "name": "clickup_view_tasks",
577            "description": "Fetch the tasks currently visible in a ClickUp view, honouring the view's configured filters, sort order, and grouping. Returns a paginated array of task objects. Use clickup_view_list to discover view IDs and clickup_view_get for the view's definition.",
578            "inputSchema": {
579                "type": "object",
580                "properties": {
581                    "view_id": {"type": "string", "description": "ID of the view to read tasks from. Obtain from clickup_view_list (field: id)."},
582                    "page": {"type": "integer", "description": "Zero-indexed page number (default 0). Each page returns up to 30 tasks; increment to paginate."}
583                },
584                "required": ["view_id"]
585            }
586        },
587        {
588            "name": "clickup_doc_list",
589            "description": "List all ClickUp docs in a workspace. Docs are long-form markdown documents separate from tasks and can contain nested pages. Returns a compact array of doc objects (id, name, date_created, date_updated). Use clickup_doc_get for a single doc or clickup_doc_pages to list a doc's pages. Uses v3 cursor pagination.",
590            "inputSchema": {
591                "type": "object",
592                "properties": {
593                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
594                },
595                "required": []
596            }
597        },
598        {
599            "name": "clickup_doc_get",
600            "description": "Fetch metadata for a single ClickUp doc — name, parent, dates, type. Does not return the page bodies; use clickup_doc_pages (with content=true) or clickup_doc_get_page for the markdown content. Returns the doc object.",
601            "inputSchema": {
602                "type": "object",
603                "properties": {
604                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
605                    "doc_id": {"type": "string", "description": "ID of the doc to fetch. Obtain from clickup_doc_list (field: id)."}
606                },
607                "required": ["doc_id"]
608            }
609        },
610        {
611            "name": "clickup_doc_pages",
612            "description": "List the pages inside a ClickUp doc, including any nested subpages. Returns an array of page objects (id, name, sub_title, parent_page_id, and optionally content). Pages are ordered by their tree position.",
613            "inputSchema": {
614                "type": "object",
615                "properties": {
616                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
617                    "doc_id": {"type": "string", "description": "ID of the parent doc. Obtain from clickup_doc_list (field: id)."},
618                    "content": {"type": "boolean", "description": "true = include each page's full markdown body in the 'content' field; false or omitted = return page metadata only (faster, smaller payload)."}
619                },
620                "required": ["doc_id"]
621            }
622        },
623        {
624            "name": "clickup_tag_list",
625            "description": "List all tags defined in a ClickUp space. Tags are space-scoped labels (with foreground/background hex colours) that can be applied to tasks within that space. Returns an array of tag objects (name, tag_fg, tag_bg, creator).",
626            "inputSchema": {
627                "type": "object",
628                "properties": {
629                    "space_id": {"type": "string", "description": "ID of the space whose tags to list. Obtain from clickup_space_list (field: id). Tags are defined per-space, not workspace-wide."}
630                },
631                "required": ["space_id"]
632            }
633        },
634        {
635            "name": "clickup_task_add_tag",
636            "description": "Attach an existing tag to a ClickUp task. The tag must already be defined in the task's parent space — use clickup_tag_list to check and clickup_tag_create to add a new tag first. Tags are identified by name, not ID. Returns an empty object on success.",
637            "inputSchema": {
638                "type": "object",
639                "properties": {
640                    "task_id": {"type": "string", "description": "ID of the task to tag. Obtain from clickup_task_list (field: id)."},
641                    "tag_name": {"type": "string", "description": "Name of the tag to apply (case-sensitive, must already exist in the task's space). Obtain from clickup_tag_list."}
642                },
643                "required": ["task_id", "tag_name"]
644            }
645        },
646        {
647            "name": "clickup_task_remove_tag",
648            "description": "Detach a tag from a ClickUp task. The tag definition itself is preserved in the space — only this task's association with it is removed. No-op if the tag was not on the task. Returns an empty object on success.",
649            "inputSchema": {
650                "type": "object",
651                "properties": {
652                    "task_id": {"type": "string", "description": "ID of the task to untag. Obtain from clickup_task_list (field: id) or clickup_task_get."},
653                    "tag_name": {"type": "string", "description": "Name of the tag to remove (case-sensitive). See clickup_task_get (field: tags[].name) for tags currently on the task."}
654                },
655                "required": ["task_id", "tag_name"]
656            }
657        },
658        {
659            "name": "clickup_webhook_list",
660            "description": "List all webhooks registered on a ClickUp workspace. Each webhook specifies a target endpoint, subscribed events, and optional scope. Returns an array of webhook objects (id, endpoint, events, status, secret, health). Use clickup_webhook_create/update/delete to manage them.",
661            "inputSchema": {
662                "type": "object",
663                "properties": {
664                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
665                },
666                "required": []
667            }
668        },
669        {
670            "name": "clickup_member_list",
671            "description": "List members (users with direct access) of a specific task or list. Exactly one of task_id or list_id must be provided. Returns an array of user objects (id, username, email, color). Use clickup_user_invite to add people to the workspace first; use clickup_guest_share_task/list to add guests.",
672            "inputSchema": {
673                "type": "object",
674                "properties": {
675                    "task_id": {"type": "string", "description": "Task ID whose members to list. Obtain from clickup_task_list (field: id). Mutually exclusive with list_id."},
676                    "list_id": {"type": "string", "description": "List ID whose members to list. Obtain from clickup_list_list (field: id). Mutually exclusive with task_id."}
677                },
678                "required": []
679            }
680        },
681        {
682            "name": "clickup_template_list",
683            "description": "List the task templates available in a workspace. Task templates are saved task shapes (name, description, checklists, subtasks, custom fields, etc.) that can be applied via clickup_template_apply_task to create new tasks quickly. Returns an array of template objects (id, name).",
684            "inputSchema": {
685                "type": "object",
686                "properties": {
687                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
688                    "page": {"type": "integer", "description": "Zero-indexed page number (default 0). Each page returns up to 100 templates; increment to paginate."}
689                },
690                "required": []
691            }
692        },
693        {
694            "name": "clickup_space_get",
695            "description": "Fetch the full object for a single ClickUp space — name, privacy, statuses, features (time tracking, tags, due dates enabled, etc.), and members. Returns the space object. Use clickup_folder_list or clickup_list_list to enumerate the space's contents.",
696            "inputSchema": {
697                "type": "object",
698                "properties": {
699                    "space_id": {"type": "string", "description": "ID of the space to fetch. Obtain from clickup_space_list (field: id)."}
700                },
701                "required": ["space_id"]
702            }
703        },
704        {
705            "name": "clickup_space_create",
706            "description": "Create a new top-level space in a ClickUp workspace. The new space uses the workspace's default feature set and statuses — customise later via the web UI or by creating folders/lists under it. Returns the created space object including its new id.",
707            "inputSchema": {
708                "type": "object",
709                "properties": {
710                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
711                    "name": {"type": "string", "description": "Display name for the space (shown in the sidebar)."},
712                    "private": {"type": "boolean", "description": "true = private space (only explicit members see it); false or omitted = visible to the whole workspace."}
713                },
714                "required": ["name"]
715            }
716        },
717        {
718            "name": "clickup_space_update",
719            "description": "Modify a ClickUp space — rename it, toggle privacy, or archive/unarchive it. Archiving is the reversible alternative to deletion: archived spaces are hidden from default views but retain all their folders, lists, and tasks. Returns the updated space object.",
720            "inputSchema": {
721                "type": "object",
722                "properties": {
723                    "space_id": {"type": "string", "description": "ID of the space to update. Obtain from clickup_space_list (field: id)."},
724                    "name": {"type": "string", "description": "New space name. Omit to keep current name."},
725                    "private": {"type": "boolean", "description": "true = space is private (visible only to explicit members); false = space is visible to the whole workspace."},
726                    "archived": {"type": "boolean", "description": "true = archive (hide but preserve); false = restore from archive."}
727                },
728                "required": ["space_id"]
729            }
730        },
731        {
732            "name": "clickup_space_delete",
733            "description": "Permanently delete a ClickUp space along with every folder, list, and task inside it. Destructive, irreversible, and widely cascading — confirm with the user before calling. To hide a space without destroying its contents, use clickup_space_update with archived=true instead (archival is reversible). Returns an empty object on success.",
734            "inputSchema": {
735                "type": "object",
736                "properties": {
737                    "space_id": {"type": "string", "description": "ID of the space to delete. Obtain from clickup_space_list (field: id). All descendant folders, lists, and tasks are deleted with it."}
738                },
739                "required": ["space_id"]
740            }
741        },
742        {
743            "name": "clickup_folder_get",
744            "description": "Fetch the full object for a single ClickUp folder — name, task_count (a string, per API), archived status, and its child lists. Returns the folder object. Use clickup_list_list with folder_id to get just the lists.",
745            "inputSchema": {
746                "type": "object",
747                "properties": {
748                    "folder_id": {"type": "string", "description": "ID of the folder to fetch. Obtain from clickup_folder_list (field: id)."}
749                },
750                "required": ["folder_id"]
751            }
752        },
753        {
754            "name": "clickup_folder_create",
755            "description": "Create a new folder inside a ClickUp space. Folders group related lists and start empty — add lists via clickup_list_create with folder_id. Returns the created folder object including its new id.",
756            "inputSchema": {
757                "type": "object",
758                "properties": {
759                    "space_id": {"type": "string", "description": "ID of the parent space. Obtain from clickup_space_list (field: id)."},
760                    "name": {"type": "string", "description": "Display name for the folder. Must be non-empty and unique within the space."}
761                },
762                "required": ["space_id", "name"]
763            }
764        },
765        {
766            "name": "clickup_folder_update",
767            "description": "Rename a ClickUp folder. Only the folder's display name can be changed via this endpoint — to move the folder to a different space, delete and recreate. Returns the updated folder object.",
768            "inputSchema": {
769                "type": "object",
770                "properties": {
771                    "folder_id": {"type": "string", "description": "ID of the folder to rename. Obtain from clickup_folder_list (field: id) or clickup_folder_get."},
772                    "name": {"type": "string", "description": "New display name for the folder. Must be non-empty and unique within its parent space."}
773                },
774                "required": ["folder_id", "name"]
775            }
776        },
777        {
778            "name": "clickup_folder_delete",
779            "description": "Permanently delete a ClickUp folder along with every list and task inside it. Destructive, irreversible, and cascading — confirm with the user before calling. If you only want to hide the folder, use clickup_space_update with archived=true on the parent space instead (archival is reversible). Returns an empty object on success.",
780            "inputSchema": {
781                "type": "object",
782                "properties": {
783                    "folder_id": {"type": "string", "description": "ID of the folder to delete. Obtain from clickup_folder_list (field: id). All descendant lists and tasks are deleted with it."}
784                },
785                "required": ["folder_id"]
786            }
787        },
788        {
789            "name": "clickup_list_get",
790            "description": "Fetch the full object for a single ClickUp list — name, content/description, statuses, task_count, assignees, due date, and parent folder/space. Returns the list object. Use clickup_task_list with list_id to enumerate tasks inside it.",
791            "inputSchema": {
792                "type": "object",
793                "properties": {
794                    "list_id": {"type": "string", "description": "ID of the list to fetch. Obtain from clickup_list_list (field: id)."}
795                },
796                "required": ["list_id"]
797            }
798        },
799        {
800            "name": "clickup_list_create",
801            "description": "Create a new task list inside either a folder or a space (folderless). Exactly one of folder_id or space_id must be provided. Returns the created list object including its new id — use it as list_id for clickup_task_create and related calls.",
802            "inputSchema": {
803                "type": "object",
804                "properties": {
805                    "folder_id": {"type": "string", "description": "ID of the parent folder. Obtain from clickup_folder_list (field: id). Mutually exclusive with space_id."},
806                    "space_id": {"type": "string", "description": "ID of the parent space — creates a folderless list attached directly to the space. Obtain from clickup_space_list (field: id). Mutually exclusive with folder_id."},
807                    "name": {"type": "string", "description": "Display name for the list. Required and non-empty."},
808                    "content": {"type": "string", "description": "List description shown at the top of the list. Markdown supported. Omit for no description."},
809                    "due_date": {"type": "integer", "description": "List-level due date as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01). Individual tasks retain their own due dates."},
810                    "status": {"type": "string", "description": "Default status for tasks added to this list. Must match a status name from the parent space's status set."}
811                },
812                "required": ["name"]
813            }
814        },
815        {
816            "name": "clickup_list_update",
817            "description": "Modify a ClickUp list's name, description, due date, or status. To move tasks between lists use clickup_task_move, and to add or remove this list from tasks with multi-list membership use clickup_list_add_task / clickup_list_remove_task. Returns the updated list object.",
818            "inputSchema": {
819                "type": "object",
820                "properties": {
821                    "list_id": {"type": "string", "description": "ID of the list to update. Obtain from clickup_list_list (field: id)."},
822                    "name": {"type": "string", "description": "New list name. Omit to keep current name."},
823                    "content": {"type": "string", "description": "New description for the list. Markdown supported."},
824                    "due_date": {"type": "integer", "description": "List-level due date as a Unix timestamp in milliseconds. Individual tasks retain their own due dates."},
825                    "status": {"type": "string", "description": "Default status for tasks added to this list (must match an existing status name in the list's status set)."}
826                },
827                "required": ["list_id"]
828            }
829        },
830        {
831            "name": "clickup_list_delete",
832            "description": "Permanently delete a ClickUp list along with every task inside it, plus their comments, checklists, and attachments. Destructive, irreversible, and cascading — confirm with the user before calling. To move tasks elsewhere first, use clickup_task_move on each, or use clickup_list_update to rename/archive instead. Returns an empty object on success.",
833            "inputSchema": {
834                "type": "object",
835                "properties": {
836                    "list_id": {"type": "string", "description": "ID of the list to delete. Obtain from clickup_list_list (field: id). All tasks inside are deleted with it."}
837                },
838                "required": ["list_id"]
839            }
840        },
841        {
842            "name": "clickup_list_add_task",
843            "description": "Add a task to a secondary list (multi-list membership) without moving it. The task remains in its original home list and becomes additionally visible in this one — useful for shared roadmaps. To change the home list instead, use clickup_task_move. Returns an empty object on success.",
844            "inputSchema": {
845                "type": "object",
846                "properties": {
847                    "list_id": {"type": "string", "description": "ID of the secondary list the task should also appear in. Obtain from clickup_list_list (field: id)."},
848                    "task_id": {"type": "string", "description": "ID of the task to add. Obtain from clickup_task_list (field: id)."}
849                },
850                "required": ["list_id", "task_id"]
851            }
852        },
853        {
854            "name": "clickup_list_remove_task",
855            "description": "Remove a task from a secondary list it was added to via clickup_list_add_task. The task itself is NOT deleted — it remains in its home list (and any other secondary lists). Use clickup_task_delete to remove the task entirely. Returns an empty object on success.",
856            "inputSchema": {
857                "type": "object",
858                "properties": {
859                    "list_id": {"type": "string", "description": "ID of the secondary list to detach the task from. Obtain from clickup_list_list (field: id). Must not be the task's home list."},
860                    "task_id": {"type": "string", "description": "ID of the task to detach. Obtain from clickup_task_list (field: id)."}
861                },
862                "required": ["list_id", "task_id"]
863            }
864        },
865        {
866            "name": "clickup_comment_update",
867            "description": "Edit the text, assignee, or resolution state of a ClickUp comment on a task, list, or view. The entire comment body is replaced by the new text (no partial edits). Marking resolved=true strikes through the comment and closes the thread. Returns the updated comment object.",
868            "inputSchema": {
869                "type": "object",
870                "properties": {
871                    "comment_id": {"type": "string", "description": "ID of the comment to edit. Obtain from clickup_comment_list (field: id)."},
872                    "text": {"type": "string", "description": "Replacement body for the comment. @mentions (e.g. '@username') are rendered. Markdown is NOT rendered by ClickUp's v2 comment API; markdown syntax is stored as literal text. The previous body is overwritten entirely."},
873                    "assignee": {"type": "integer", "description": "Reassign the comment to this user ID, who will receive a notification. Obtain from clickup_member_list."},
874                    "resolved": {"type": "boolean", "description": "true = mark the comment thread resolved/closed; false = reopen it."}
875                },
876                "required": ["comment_id", "text"]
877            }
878        },
879        {
880            "name": "clickup_comment_delete",
881            "description": "Permanently delete a ClickUp comment from a task, list, or view. Destructive and irreversible — the comment and any threaded replies are removed. Use clickup_comment_update with resolved=true instead if you only want to mark the comment as handled. Returns an empty object on success.",
882            "inputSchema": {
883                "type": "object",
884                "properties": {
885                    "comment_id": {"type": "string", "description": "ID of the comment to delete. Obtain from clickup_comment_list (field: id). The authenticated user must have edit permission on the parent task/list/view."}
886                },
887                "required": ["comment_id"]
888            }
889        },
890        {
891            "name": "clickup_task_add_dep",
892            "description": "Create a dependency relationship between two tasks — either 'task_id depends on depends_on' (blocks until that is done) or 'dependency_of depends on task_id' (task_id blocks that). Provide exactly one of depends_on or dependency_of. Use clickup_task_link for a simple non-blocking reference. Returns an empty object on success.",
893            "inputSchema": {
894                "type": "object",
895                "properties": {
896                    "task_id": {"type": "string", "description": "ID of the primary task. Obtain from clickup_task_list (field: id)."},
897                    "depends_on": {"type": "string", "description": "ID of a task that task_id should wait for (task_id is blocked until depends_on is complete). Obtain from clickup_task_list. Mutually exclusive with dependency_of."},
898                    "dependency_of": {"type": "string", "description": "ID of a task that depends on task_id (that task is blocked until task_id is complete). Obtain from clickup_task_list. Mutually exclusive with depends_on."}
899                },
900                "required": ["task_id"]
901            }
902        },
903        {
904            "name": "clickup_task_remove_dep",
905            "description": "Remove an existing dependency relationship between two tasks. Provide exactly one of depends_on or dependency_of, matching the direction you set with clickup_task_add_dep. The tasks themselves are not affected. Returns an empty object on success.",
906            "inputSchema": {
907                "type": "object",
908                "properties": {
909                    "task_id": {"type": "string", "description": "ID of the primary task in the dependency. Obtain from clickup_task_list (field: id) or clickup_task_get (field: dependencies[])."},
910                    "depends_on": {"type": "string", "description": "ID of the upstream task to detach from task_id (removes the 'task_id waits for this' edge). Mutually exclusive with dependency_of."},
911                    "dependency_of": {"type": "string", "description": "ID of the downstream task to detach (removes the 'this waits for task_id' edge). Mutually exclusive with depends_on."}
912                },
913                "required": ["task_id"]
914            }
915        },
916        {
917            "name": "clickup_task_link",
918            "description": "Create a bidirectional reference link between two tasks — a non-blocking 'see also' relationship, unlike dependencies. Both tasks show the other in their 'Linked tasks' panel. Use clickup_task_unlink to remove. For blocking relationships, use clickup_task_add_dep instead. Returns an empty object on success.",
919            "inputSchema": {
920                "type": "object",
921                "properties": {
922                    "task_id": {"type": "string", "description": "ID of the first task. Obtain from clickup_task_list (field: id)."},
923                    "links_to": {"type": "string", "description": "ID of the second task to link to. Obtain from clickup_task_list (field: id). The link is visible from both tasks."}
924                },
925                "required": ["task_id", "links_to"]
926            }
927        },
928        {
929            "name": "clickup_task_unlink",
930            "description": "Remove a bidirectional reference link previously created with clickup_task_link. The tasks themselves are not affected, only the link between them. No-op if no link exists. Returns an empty object on success.",
931            "inputSchema": {
932                "type": "object",
933                "properties": {
934                    "task_id": {"type": "string", "description": "ID of the first task. Obtain from clickup_task_list (field: id) or clickup_task_get (field: linked_tasks[])."},
935                    "links_to": {"type": "string", "description": "ID of the linked task to unlink from task_id."}
936                },
937                "required": ["task_id", "links_to"]
938            }
939        },
940        {
941            "name": "clickup_goal_delete",
942            "description": "Permanently delete a ClickUp goal along with all its key results. Destructive, irreversible, and cascading — confirm with the user before calling. Historical progress data on the goal is lost. Returns an empty object on success.",
943            "inputSchema": {
944                "type": "object",
945                "properties": {
946                    "goal_id": {"type": "string", "description": "ID of the goal to delete. Obtain from clickup_goal_list (field: id) or clickup_goal_get. All child key results are deleted with it."}
947                },
948                "required": ["goal_id"]
949            }
950        },
951        {
952            "name": "clickup_goal_add_kr",
953            "description": "Add a new key result (KR / sub-target) to a ClickUp goal. KRs drive the goal's overall percent-complete — each KR's progress is averaged. For 'automatic' KRs, link tasks or lists and progress is derived from their status; for number/currency/percentage KRs, report progress via clickup_goal_update_kr. Returns the created key result object.",
954            "inputSchema": {
955                "type": "object",
956                "properties": {
957                    "goal_id": {"type": "string", "description": "ID of the parent goal. Obtain from clickup_goal_list (field: id)."},
958                    "name": {"type": "string", "description": "Display name of the key result (e.g. 'MRR reaches $50k')."},
959                    "type": {"type": "string", "description": "Key result type: 'number' (numeric target), 'currency' (monetary target), 'boolean' (done/not-done), 'percentage' (0–100), or 'automatic' (derived from linked tasks/lists)."},
960                    "steps_start": {"type": "number", "description": "Starting value of the metric (e.g. 0 for a from-zero KR, current baseline otherwise). Ignored for 'boolean'."},
961                    "steps_end": {"type": "number", "description": "Target value the KR aims to reach. For 'percentage' KRs use 100; for 'boolean' use 1."},
962                    "unit": {"type": "string", "description": "Unit label shown next to numeric values (e.g. 'USD', 'users', 'signups'). Ignored for 'boolean' and 'automatic'."},
963                    "owner_ids": {"type": "array", "items": {"type": "integer"}, "description": "User IDs responsible for this KR. Obtain from clickup_member_list."},
964                    "task_ids": {"type": "array", "items": {"type": "string"}, "description": "Task IDs whose completion drives progress (only for type='automatic'). Obtain from clickup_task_list."},
965                    "list_ids": {"type": "array", "items": {"type": "string"}, "description": "List IDs whose task-completion percentage drives progress (only for type='automatic'). Obtain from clickup_list_list."}
966                },
967                "required": ["goal_id", "name", "type", "steps_start", "steps_end"]
968            }
969        },
970        {
971            "name": "clickup_goal_update_kr",
972            "description": "Update a key result (sub-target) on a ClickUp goal — typically to record current progress, rename, or adjust the unit label. The goal's completion percentage is auto-recalculated from all its key results. Returns the updated key result object.",
973            "inputSchema": {
974                "type": "object",
975                "properties": {
976                    "kr_id": {"type": "string", "description": "Key result ID. Obtain from clickup_goal_get (field: key_results[].id) or the response of clickup_goal_add_kr."},
977                    "steps_current": {"type": "number", "description": "Current progress toward steps_end. For boolean KRs use 0 (not done) or 1 (done). For percentage KRs use 0–100."},
978                    "name": {"type": "string", "description": "New display name for the key result. Omit to keep current name."},
979                    "unit": {"type": "string", "description": "Unit label shown next to numeric values (e.g. 'MRR', 'users'). Ignored for boolean and automatic types."}
980                },
981                "required": ["kr_id"]
982            }
983        },
984        {
985            "name": "clickup_goal_delete_kr",
986            "description": "Permanently delete a single key result from a ClickUp goal. Destructive and irreversible — the historical progress for this key result is lost, and the goal's overall completion percentage is recalculated from the remaining key results. Returns an empty object on success.",
987            "inputSchema": {
988                "type": "object",
989                "properties": {
990                    "kr_id": {"type": "string", "description": "ID of the key result to delete. Obtain from clickup_goal_get (field: key_results[].id)."}
991                },
992                "required": ["kr_id"]
993            }
994        },
995        {
996            "name": "clickup_time_get",
997            "description": "Fetch the full object for a single time tracking entry — user, task, start timestamp, duration, description, billable flag, and tags. Returns the time entry object.",
998            "inputSchema": {
999                "type": "object",
1000                "properties": {
1001                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1002                    "timer_id": {"type": "string", "description": "ID of the time entry. Obtain from clickup_time_list (field: id) or clickup_time_current."}
1003                },
1004                "required": ["timer_id"]
1005            }
1006        },
1007        {
1008            "name": "clickup_time_create",
1009            "description": "Manually record a historical time tracking entry with a fixed start and duration. Use this for backfilling time (e.g. work done offline). For live timing use clickup_time_start/stop instead. Returns the created time entry object including its new id.",
1010            "inputSchema": {
1011                "type": "object",
1012                "properties": {
1013                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1014                    "task_id": {"type": "string", "description": "ID of the task to attribute the time to. Obtain from clickup_task_list. Omit for a task-less time entry."},
1015                    "start": {"type": "integer", "description": "Entry start time as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01 00:00 UTC)."},
1016                    "duration": {"type": "integer", "description": "Duration in milliseconds (e.g. 3600000 for one hour)."},
1017                    "description": {"type": "string", "description": "Free-text description of the work logged. Optional."},
1018                    "billable": {"type": "boolean", "description": "true = mark as billable (shows with $ in reports); false or omitted = non-billable."}
1019                },
1020                "required": ["start", "duration"]
1021            }
1022        },
1023        {
1024            "name": "clickup_time_update",
1025            "description": "Modify a recorded time tracking entry. Only the supplied fields are changed; omitted fields keep their current value. Use clickup_time_add_tags / remove_tags for tag changes. Returns the updated time entry object.",
1026            "inputSchema": {
1027                "type": "object",
1028                "properties": {
1029                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1030                    "timer_id": {"type": "string", "description": "ID of the time entry to update. Obtain from clickup_time_list (field: id)."},
1031                    "start": {"type": "integer", "description": "New start time as a Unix timestamp in milliseconds. Omit to keep current start."},
1032                    "duration": {"type": "integer", "description": "New duration in milliseconds (e.g. 3600000 for one hour). Omit to keep current duration."},
1033                    "description": {"type": "string", "description": "New description for the entry. Omit to keep current description."},
1034                    "billable": {"type": "boolean", "description": "true = billable, false = non-billable. Omit to keep current value."}
1035                },
1036                "required": ["timer_id"]
1037            }
1038        },
1039        {
1040            "name": "clickup_time_delete",
1041            "description": "Permanently delete a recorded time tracking entry. Destructive and irreversible — the logged time is removed from reports. To stop a currently running timer, use clickup_time_stop instead (which preserves the record). Returns an empty object on success.",
1042            "inputSchema": {
1043                "type": "object",
1044                "properties": {
1045                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1046                    "timer_id": {"type": "string", "description": "ID of the time entry to delete. Obtain from clickup_time_list (field: id). Only the entry's owner (or a workspace admin) can delete it."}
1047                },
1048                "required": ["timer_id"]
1049            }
1050        },
1051        {
1052            "name": "clickup_view_get",
1053            "description": "Fetch the full definition of a single ClickUp view — name, type (list/board/calendar/gantt/etc.), parent scope, filters, grouping, sort order, and column layout. Does not return the tasks inside the view; use clickup_view_tasks for that. Returns the view object.",
1054            "inputSchema": {
1055                "type": "object",
1056                "properties": {
1057                    "view_id": {"type": "string", "description": "ID of the view to fetch. Obtain from clickup_view_list (field: id)."}
1058                },
1059                "required": ["view_id"]
1060            }
1061        },
1062        {
1063            "name": "clickup_view_create",
1064            "description": "Create a new saved view (board, list, calendar, timeline, etc.) attached to a space, folder, list, or the workspace. Creates an empty view with default filters — customise filters/grouping/sort later via the web UI. Returns the created view object including its new id.",
1065            "inputSchema": {
1066                "type": "object",
1067                "properties": {
1068                    "scope": {"type": "string", "description": "Where to attach the view: 'space', 'folder', 'list', or 'team' (workspace-level 'Everything' view)."},
1069                    "scope_id": {"type": "string", "description": "ID of the scope object. For scope='space' use a space_id, for 'folder' a folder_id, for 'list' a list_id, for 'team' a workspace/team id (from clickup_workspace_list)."},
1070                    "name": {"type": "string", "description": "Display name for the view."},
1071                    "type": {"type": "string", "description": "View type: 'list', 'board', 'calendar', 'table', 'timeline', 'gantt', 'map', 'workload', 'activity', 'chat', 'mind_map', 'doc', or 'form'."}
1072                },
1073                "required": ["scope", "scope_id", "name", "type"]
1074            }
1075        },
1076        {
1077            "name": "clickup_view_update",
1078            "description": "Rename a view or change its display type (e.g. from list to board). To change filters, grouping, or sort order, use the ClickUp web UI — those are not exposed via the API. Returns the updated view object.",
1079            "inputSchema": {
1080                "type": "object",
1081                "properties": {
1082                    "view_id": {"type": "string", "description": "ID of the view to update. Obtain from clickup_view_list (field: id)."},
1083                    "name": {"type": "string", "description": "New display name for the view."},
1084                    "type": {"type": "string", "description": "New view type: 'list', 'board', 'calendar', 'table', 'timeline', 'gantt', 'map', 'workload', 'activity', 'chat', 'mind_map', 'doc', or 'form'."}
1085                },
1086                "required": ["view_id", "name", "type"]
1087            }
1088        },
1089        {
1090            "name": "clickup_view_delete",
1091            "description": "Permanently delete a ClickUp view (board, list, calendar, gantt, etc.). Destructive and irreversible for custom views — default views cannot be deleted and will return a 400 error. The underlying tasks are not affected, only the view definition. Returns an empty object on success.",
1092            "inputSchema": {
1093                "type": "object",
1094                "properties": {
1095                    "view_id": {"type": "string", "description": "ID of the view to delete. Obtain from clickup_view_list (field: id). Must be a user-created view, not a ClickUp-default one."}
1096                },
1097                "required": ["view_id"]
1098            }
1099        },
1100        {
1101            "name": "clickup_doc_create",
1102            "description": "Create a new ClickUp doc in a workspace. The doc starts with no pages — add pages via clickup_doc_add_page. Optionally attach the doc under a parent space/folder/list/task instead of the workspace root. Returns the created doc object including its new id.",
1103            "inputSchema": {
1104                "type": "object",
1105                "properties": {
1106                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1107                    "name": {"type": "string", "description": "Display name for the doc (shown in the doc tree)."},
1108                    "parent": {"type": "object", "description": "Optional parent object to attach the doc under. Shape: { 'id': '<id>', 'type': <int> } where type is 4=space, 5=folder, 6=list, 7=everything, 12=workspace. Omit to create at the workspace root."}
1109                },
1110                "required": ["name"]
1111            }
1112        },
1113        {
1114            "name": "clickup_doc_add_page",
1115            "description": "Create a new page inside an existing ClickUp doc. Pages support a markdown body plus optional subtitle. Supply parent_page_id to nest the page under another page (creates a page tree). Returns the created page object including its new id, which you can pass to clickup_doc_edit_page or clickup_doc_get_page.",
1116            "inputSchema": {
1117                "type": "object",
1118                "properties": {
1119                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1120                    "doc_id": {"type": "string", "description": "ID of the parent doc. Obtain from clickup_doc_list (field: id)."},
1121                    "name": {"type": "string", "description": "Title shown in the doc's left-hand page navigator."},
1122                    "content": {"type": "string", "description": "Initial body of the page in ClickUp-flavoured markdown. Omit to create an empty page you can populate later via clickup_doc_edit_page."},
1123                    "sub_title": {"type": "string", "description": "Optional subtitle rendered under the page title."},
1124                    "parent_page_id": {"type": "string", "description": "ID of a sibling page to nest this page under. Omit to create a top-level page. Obtain from clickup_doc_pages (field: id)."}
1125                },
1126                "required": ["doc_id", "name"]
1127            }
1128        },
1129        {
1130            "name": "clickup_doc_edit_page",
1131            "description": "Rename or rewrite an existing page inside a ClickUp doc. By default the supplied content replaces the current page body. Pass mode='append' or mode='prepend' to merge with the existing body instead. For a fresh page use clickup_doc_add_page instead. Returns the updated page object.",
1132            "inputSchema": {
1133                "type": "object",
1134                "properties": {
1135                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1136                    "doc_id": {"type": "string", "description": "ID of the parent doc. Obtain from clickup_doc_list (field: id)."},
1137                    "page_id": {"type": "string", "description": "ID of the page to edit. Obtain from clickup_doc_pages (field: id)."},
1138                    "name": {"type": "string", "description": "New page title. Omit to keep current title."},
1139                    "content": {"type": "string", "description": "New page body in ClickUp-flavoured markdown. Replaces the existing body unless mode is set. Omit to leave content unchanged."},
1140                    "mode": {"type": "string", "description": "How to combine content with the existing body: 'replace' (default), 'append', or 'prepend'. Sent as content_edit_mode on the wire."}
1141                },
1142                "required": ["doc_id", "page_id"]
1143            }
1144        },
1145        {
1146            "name": "clickup_chat_channel_create",
1147            "description": "Create a new ClickUp Chat channel in a workspace. For one-on-one messages use clickup_chat_dm instead. Add members later via the channel-members endpoint. Returns the created channel object including its new id.",
1148            "inputSchema": {
1149                "type": "object",
1150                "properties": {
1151                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1152                    "name": {"type": "string", "description": "Channel name (e.g. 'product-launch'). Must be unique within the workspace."},
1153                    "description": {"type": "string", "description": "Optional channel topic/description shown in the header."},
1154                    "visibility": {"type": "string", "description": "Channel visibility: 'public' (any workspace member can join) or 'private' (invite only). Defaults to 'public'."}
1155                },
1156                "required": ["name"]
1157            }
1158        },
1159        {
1160            "name": "clickup_chat_channel_get",
1161            "description": "Fetch metadata for a single ClickUp chat channel — name, description, visibility, member count, latest activity. Does not return the messages themselves; use clickup_chat_message_list for that. Returns the channel object.",
1162            "inputSchema": {
1163                "type": "object",
1164                "properties": {
1165                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1166                    "channel_id": {"type": "string", "description": "ID of the channel to fetch. Obtain from clickup_chat_channel_list (field: id)."}
1167                },
1168                "required": ["channel_id"]
1169            }
1170        },
1171        {
1172            "name": "clickup_chat_channel_update",
1173            "description": "Rename a ClickUp chat channel or change its description. To change membership or visibility use the dedicated channel-members and channel-followers tools. Returns the updated channel object.",
1174            "inputSchema": {
1175                "type": "object",
1176                "properties": {
1177                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1178                    "channel_id": {"type": "string", "description": "ID of the channel to update. Obtain from clickup_chat_channel_list (field: id)."},
1179                    "name": {"type": "string", "description": "New display name for the channel. Must be unique within the workspace."},
1180                    "description": {"type": "string", "description": "New channel description shown in the channel header."}
1181                },
1182                "required": ["channel_id"]
1183            }
1184        },
1185        {
1186            "name": "clickup_chat_channel_delete",
1187            "description": "Permanently delete a ClickUp Chat channel along with every message and reply it contains. Destructive, irreversible, and cascading — confirm with the user before calling. The channel vanishes from the workspace for all members. Returns an empty object on success.",
1188            "inputSchema": {
1189                "type": "object",
1190                "properties": {
1191                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1192                    "channel_id": {"type": "string", "description": "ID of the channel to delete. Obtain from clickup_chat_channel_list (field: id). All messages and replies inside are deleted with it."}
1193                },
1194                "required": ["channel_id"]
1195            }
1196        },
1197        {
1198            "name": "clickup_chat_message_list",
1199            "description": "List messages in a ClickUp Chat channel, newest first. Only top-level messages are returned; use clickup_chat_reply_list for threaded replies. Uses v3 cursor pagination — pass the 'cursor' from the previous response to page further back. Returns an array of message objects plus a next_cursor.",
1200            "inputSchema": {
1201                "type": "object",
1202                "properties": {
1203                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1204                    "channel_id": {"type": "string", "description": "ID of the channel. Obtain from clickup_chat_channel_list (field: id)."},
1205                    "cursor": {"type": "string", "description": "Opaque pagination cursor from the previous response's next_cursor field. Omit for the first page (newest messages)."}
1206                },
1207                "required": ["channel_id"]
1208            }
1209        },
1210        {
1211            "name": "clickup_chat_message_send",
1212            "description": "Post a new top-level message to a ClickUp Chat channel. For replies inside a thread use clickup_chat_reply_send; for DMs use clickup_chat_dm. Returns the created message object including its new id, which you can pass to clickup_chat_reaction_add, clickup_chat_reply_send, etc.",
1213            "inputSchema": {
1214                "type": "object",
1215                "properties": {
1216                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1217                    "channel_id": {"type": "string", "description": "ID of the target channel. Obtain from clickup_chat_channel_list (field: id)."},
1218                    "content": {"type": "string", "description": "Message body. Supports markdown, @mentions (e.g. '@username'), and emoji."},
1219                    "type": {"type": "string", "description": "Message subtype. Defaults to 'message' (a normal chat message). Use 'post' for a long-form post. ClickUp requires this field server-side."}
1220                },
1221                "required": ["channel_id", "content"]
1222            }
1223        },
1224        {
1225            "name": "clickup_chat_message_delete",
1226            "description": "Permanently delete a message from a ClickUp chat channel or DM thread. Destructive and irreversible — the message and its threaded replies are removed for all viewers. Only the message author or a workspace admin can delete; other users will get a 403. Returns an empty object on success.",
1227            "inputSchema": {
1228                "type": "object",
1229                "properties": {
1230                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1231                    "message_id": {"type": "string", "description": "ID of the message to delete. Obtain from clickup_chat_message_list (field: id) or clickup_chat_reply_list."}
1232                },
1233                "required": ["message_id"]
1234            }
1235        },
1236        {
1237            "name": "clickup_chat_dm",
1238            "description": "Create or fetch the direct-message channel between the authenticated user and one or more other workspace members (ClickUp groups DMs around the participant set). Returns the channel object including its id. To send a message in the channel, follow with clickup_chat_message_send using the returned channel id.",
1239            "inputSchema": {
1240                "type": "object",
1241                "properties": {
1242                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1243                    "user_ids": {
1244                        "type": "array",
1245                        "items": {"type": "integer"},
1246                        "description": "Numeric user IDs of the DM participants (excluding the caller). ClickUp permits up to 15 participants for a group DM. Obtain IDs from clickup_member_list or clickup_user_get."
1247                    }
1248                },
1249                "required": ["user_ids"]
1250            }
1251        },
1252        {
1253            "name": "clickup_webhook_create",
1254            "description": "Register an HTTPS endpoint that ClickUp will POST events to as things happen in the workspace (tasks created, comments added, status changes, etc.). Optionally scope the webhook to a single space, folder, list, or task. The response includes a 'secret' you should use to verify the X-Signature header on incoming payloads. Returns the created webhook object.",
1255            "inputSchema": {
1256                "type": "object",
1257                "properties": {
1258                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1259                    "endpoint": {"type": "string", "description": "Public HTTPS URL that will receive event POSTs. Must respond 2xx within 5 seconds or ClickUp will retry/suspend."},
1260                    "events": {
1261                        "type": "array",
1262                        "items": {"type": "string"},
1263                        "description": "Event names to subscribe to (e.g. ['taskCreated','taskUpdated','taskStatusUpdated','commentPosted']). Pass ['*'] to subscribe to every event ClickUp emits."
1264                    },
1265                    "space_id": {"type": "string", "description": "Scope events to this space only. Mutually exclusive with folder_id/list_id/task_id."},
1266                    "folder_id": {"type": "string", "description": "Scope events to this folder only. Mutually exclusive with space_id/list_id/task_id."},
1267                    "list_id": {"type": "string", "description": "Scope events to this list only. Mutually exclusive with space_id/folder_id/task_id."},
1268                    "task_id": {"type": "string", "description": "Scope events to this task only. Mutually exclusive with space_id/folder_id/list_id."}
1269                },
1270                "required": ["endpoint", "events"]
1271            }
1272        },
1273        {
1274            "name": "clickup_webhook_update",
1275            "description": "Change the delivery endpoint, subscribed events, or active status of a ClickUp webhook. To temporarily pause deliveries without losing the webhook config, set status='suspended' (then resume later with status='active'). Returns the updated webhook object.",
1276            "inputSchema": {
1277                "type": "object",
1278                "properties": {
1279                    "webhook_id": {"type": "string", "description": "ID of the webhook to update. Obtain from clickup_webhook_list (field: id)."},
1280                    "endpoint": {"type": "string", "description": "New HTTPS URL that ClickUp will POST events to. Must be publicly reachable and respond with 2xx within 5 seconds."},
1281                    "events": {
1282                        "type": "array",
1283                        "items": {"type": "string"},
1284                        "description": "New list of event names to subscribe to (e.g. ['taskCreated','taskUpdated']). Pass ['*'] to subscribe to every event. Omit to leave subscriptions unchanged."
1285                    },
1286                    "status": {"type": "string", "description": "'active' to deliver events; 'suspended' to pause deliveries without deleting the webhook."}
1287                },
1288                "required": ["webhook_id"]
1289            }
1290        },
1291        {
1292            "name": "clickup_webhook_delete",
1293            "description": "Permanently delete a ClickUp webhook, stopping all future event deliveries to its endpoint. Destructive and irreversible: the webhook record is removed immediately. If you only want to pause deliveries, use clickup_webhook_update with status='inactive' instead. Returns an empty object on success.",
1294            "inputSchema": {
1295                "type": "object",
1296                "properties": {
1297                    "webhook_id": {"type": "string", "description": "ID of the webhook to delete. Obtain from clickup_webhook_list (field: id). The authenticated user must own the webhook or be a workspace admin."}
1298                },
1299                "required": ["webhook_id"]
1300            }
1301        },
1302        {
1303            "name": "clickup_checklist_add_item",
1304            "description": "Append a new item to an existing ClickUp checklist on a task. The item starts unresolved. To edit or resolve items use clickup_checklist_update_item; to remove them use clickup_checklist_delete_item. Returns the updated checklist object (with all items).",
1305            "inputSchema": {
1306                "type": "object",
1307                "properties": {
1308                    "checklist_id": {"type": "string", "description": "ID of the parent checklist. Obtain from clickup_task_get (field: checklists[].id)."},
1309                    "name": {"type": "string", "description": "Display text of the new checklist item (e.g. 'Send release notes')."},
1310                    "assignee": {"type": "integer", "description": "Optional user ID to assign this item to (they will see it on their assigned work). Obtain from clickup_member_list."}
1311                },
1312                "required": ["checklist_id", "name"]
1313            }
1314        },
1315        {
1316            "name": "clickup_checklist_update_item",
1317            "description": "Modify a single checklist item on a ClickUp task — rename it, toggle its resolved state, or change its assignee. Use clickup_checklist_add_item to create new items and clickup_checklist_delete_item to remove them. Returns the updated checklist object (all items).",
1318            "inputSchema": {
1319                "type": "object",
1320                "properties": {
1321                    "checklist_id": {"type": "string", "description": "ID of the parent checklist. Obtain from clickup_task_get (field: checklists[].id)."},
1322                    "item_id": {"type": "string", "description": "ID of the item to update. Obtain from clickup_task_get (field: checklists[].items[].id)."},
1323                    "name": {"type": "string", "description": "New text for the item. Omit to keep current text."},
1324                    "resolved": {"type": "boolean", "description": "true = mark as done (strike-through); false = mark as open."},
1325                    "assignee": {"type": "integer", "description": "Reassign the item to this user ID. Obtain user IDs from clickup_member_list or clickup_user_get. Pass no value to leave assignee unchanged."}
1326                },
1327                "required": ["checklist_id", "item_id"]
1328            }
1329        },
1330        {
1331            "name": "clickup_checklist_delete_item",
1332            "description": "Permanently delete a single item from a ClickUp checklist. Destructive and irreversible. To resolve the item (mark done) without deleting, use clickup_checklist_update_item with resolved=true. Returns the updated checklist object (remaining items).",
1333            "inputSchema": {
1334                "type": "object",
1335                "properties": {
1336                    "checklist_id": {"type": "string", "description": "ID of the parent checklist. Obtain from clickup_task_get (field: checklists[].id)."},
1337                    "item_id": {"type": "string", "description": "ID of the item to delete. Obtain from clickup_task_get (field: checklists[].items[].id)."}
1338                },
1339                "required": ["checklist_id", "item_id"]
1340            }
1341        },
1342        {
1343            "name": "clickup_user_get",
1344            "description": "Fetch the profile of a specific member of a ClickUp workspace — username, email, color, profile picture, role. Returns the user object. Use clickup_member_list for task/list members; use clickup_whoami for the authenticated user.",
1345            "inputSchema": {
1346                "type": "object",
1347                "properties": {
1348                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1349                    "user_id": {"type": "integer", "description": "Numeric user ID. Obtain from clickup_member_list or clickup_workspace_list (field: members[].user.id)."}
1350                },
1351                "required": ["user_id"]
1352            }
1353        },
1354        {
1355            "name": "clickup_workspace_seats",
1356            "description": "Get the seat-usage breakdown for a ClickUp workspace — how many paid member seats, guest seats, and internal seats are used vs. available. Useful before inviting new users to confirm capacity. Returns an object with member/guest/internal seat counts.",
1357            "inputSchema": {
1358                "type": "object",
1359                "properties": {
1360                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1361                },
1362                "required": []
1363            }
1364        },
1365        {
1366            "name": "clickup_workspace_plan",
1367            "description": "Get the current subscription plan of a ClickUp workspace (Free, Unlimited, Business, Business Plus, Enterprise), along with plan_name and plan_id. Some features (guests, audit logs, ACLs) require Enterprise. Returns the plan object.",
1368            "inputSchema": {
1369                "type": "object",
1370                "properties": {
1371                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1372                },
1373                "required": []
1374            }
1375        },
1376        {
1377            "name": "clickup_tag_create",
1378            "description": "Define a new tag in a ClickUp space. Tags are space-scoped and must be created before they can be applied to tasks via clickup_task_add_tag. Note: create uses tag_fg/tag_bg, but clickup_tag_update uses fg_color/bg_color (API inconsistency). Returns an empty object on success; use clickup_tag_list to see the created tag.",
1379            "inputSchema": {
1380                "type": "object",
1381                "properties": {
1382                    "space_id": {"type": "string", "description": "ID of the space to create the tag in. Obtain from clickup_space_list (field: id)."},
1383                    "name": {"type": "string", "description": "Tag name (e.g. 'blocked', 'priority'). Must be unique within the space."},
1384                    "tag_fg": {"type": "string", "description": "Text (foreground) hex colour including leading '#' (e.g. '#FFFFFF'). Omit for default."},
1385                    "tag_bg": {"type": "string", "description": "Pill (background) hex colour including leading '#' (e.g. '#FF0000'). Omit for default."}
1386                },
1387                "required": ["space_id", "name"]
1388            }
1389        },
1390        {
1391            "name": "clickup_tag_update",
1392            "description": "Rename a tag or change its colours within a ClickUp space. All tasks using the tag are automatically updated with the new name/colours. Note: update uses fg_color/bg_color whereas tag_create uses tag_fg/tag_bg (API inconsistency). Returns an empty object on success.",
1393            "inputSchema": {
1394                "type": "object",
1395                "properties": {
1396                    "space_id": {"type": "string", "description": "ID of the space containing the tag. Obtain from clickup_space_list (field: id)."},
1397                    "tag_name": {"type": "string", "description": "Current name of the tag to update. Obtain from clickup_tag_list (field: name)."},
1398                    "name": {"type": "string", "description": "New tag name. Omit to keep current name."},
1399                    "tag_fg": {"type": "string", "description": "New text (foreground) hex colour with leading '#'. Note: forwarded as fg_color to the API."},
1400                    "tag_bg": {"type": "string", "description": "New pill (background) hex colour with leading '#'. Note: forwarded as bg_color to the API."}
1401                },
1402                "required": ["space_id", "tag_name"]
1403            }
1404        },
1405        {
1406            "name": "clickup_tag_delete",
1407            "description": "Delete a tag from a ClickUp space. The tag is removed from every task that uses it (the tasks themselves are not affected). Destructive and irreversible. Returns an empty object on success.",
1408            "inputSchema": {
1409                "type": "object",
1410                "properties": {
1411                    "space_id": {"type": "string", "description": "ID of the space containing the tag. Obtain from clickup_space_list (field: id)."},
1412                    "tag_name": {"type": "string", "description": "Name of the tag to delete. Obtain from clickup_tag_list (field: name)."}
1413                },
1414                "required": ["space_id", "tag_name"]
1415            }
1416        },
1417        {
1418            "name": "clickup_field_unset",
1419            "description": "Clear a custom field value on a ClickUp task — sets it back to empty/unset. The field definition on the list remains intact. Use clickup_field_set to assign a new value instead. Returns an empty object on success.",
1420            "inputSchema": {
1421                "type": "object",
1422                "properties": {
1423                    "task_id": {"type": "string", "description": "ID of the task. Obtain from clickup_task_list (field: id)."},
1424                    "field_id": {"type": "string", "description": "ID of the custom field to clear. Obtain from clickup_field_list (field: id) or clickup_task_get (field: custom_fields[].id)."}
1425                },
1426                "required": ["task_id", "field_id"]
1427            }
1428        },
1429        {
1430            "name": "clickup_attachment_list",
1431            "description": "List files attached to a ClickUp task — each attachment's id, title, size, mime type, url, and uploader. Extracts the attachments array from the Get Task response (ClickUp has no dedicated list endpoint). Use clickup_attachment_upload to add a new file. Returns an array of attachment objects.",
1432            "inputSchema": {
1433                "type": "object",
1434                "properties": {
1435                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1436                    "task_id": {"type": "string", "description": "ID of the task whose attachments to list. Obtain from clickup_task_list (field: id)."}
1437                },
1438                "required": ["task_id"]
1439            }
1440        },
1441        {
1442            "name": "clickup_shared_list",
1443            "description": "List every task, list, and folder that has been explicitly shared with the authenticated user from outside their default hierarchy (e.g. items shared by other workspace members). Useful for discovering items you have access to but don't own. Returns an object with shared tasks, lists, and folders arrays.",
1444            "inputSchema": {
1445                "type": "object",
1446                "properties": {
1447                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1448                },
1449                "required": []
1450            }
1451        },
1452        {
1453            "name": "clickup_group_list",
1454            "description": "List user groups (also called 'teams' in the ClickUp UI) in a workspace. A group is a named collection of users that can be @-mentioned or assigned as a unit. Returns an array of group objects (id, name, members).",
1455            "inputSchema": {
1456                "type": "object",
1457                "properties": {
1458                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1459                    "group_ids": {
1460                        "type": "array",
1461                        "items": {"type": "string"},
1462                        "description": "Optional filter to return only these group IDs. Omit to return all groups in the workspace."
1463                    }
1464                },
1465                "required": []
1466            }
1467        },
1468        {
1469            "name": "clickup_group_create",
1470            "description": "Create a new user group ('team' in ClickUp's UI) in a workspace. Groups let you @-mention or assign multiple users as a unit. At least one initial member is required. Returns the created group object including its new id.",
1471            "inputSchema": {
1472                "type": "object",
1473                "properties": {
1474                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1475                    "name": {"type": "string", "description": "Display name for the group (e.g. 'Frontend Engineers')."},
1476                    "member_ids": {
1477                        "type": "array",
1478                        "items": {"type": "integer"},
1479                        "description": "User IDs to add as initial members. Obtain from clickup_member_list or clickup_user_get (field: id)."
1480                    }
1481                },
1482                "required": ["name"]
1483            }
1484        },
1485        {
1486            "name": "clickup_group_update",
1487            "description": "Rename a user group and/or add/remove its members. All changes are applied in one call. Use clickup_group_list first to see current membership. Returns the updated group object.",
1488            "inputSchema": {
1489                "type": "object",
1490                "properties": {
1491                    "group_id": {"type": "string", "description": "ID of the group to update. Obtain from clickup_group_list (field: id)."},
1492                    "name": {"type": "string", "description": "New display name. Omit to keep current name."},
1493                    "add_members": {
1494                        "type": "array",
1495                        "items": {"type": "integer"},
1496                        "description": "User IDs to add to the group (additive — does not replace current members)."
1497                    },
1498                    "rem_members": {
1499                        "type": "array",
1500                        "items": {"type": "integer"},
1501                        "description": "User IDs to remove from the group (no-op if not currently a member)."
1502                    }
1503                },
1504                "required": ["group_id"]
1505            }
1506        },
1507        {
1508            "name": "clickup_group_delete",
1509            "description": "Permanently delete a ClickUp user group. Destructive and irreversible — assignments and mentions that referenced the group remain as historical records, but the group can no longer be used going forward. The individual users are not affected. Returns an empty object on success.",
1510            "inputSchema": {
1511                "type": "object",
1512                "properties": {
1513                    "group_id": {"type": "string", "description": "ID of the group to delete. Obtain from clickup_group_list (field: id)."}
1514                },
1515                "required": ["group_id"]
1516            }
1517        },
1518        {
1519            "name": "clickup_role_list",
1520            "description": "List the custom roles defined in a ClickUp workspace (Member, Guest, Admin, Owner, plus any custom roles on Enterprise plans). Roles define baseline permissions assigned to users. Returns an array of role objects (id, name, members).",
1521            "inputSchema": {
1522                "type": "object",
1523                "properties": {
1524                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1525                },
1526                "required": []
1527            }
1528        },
1529        {
1530            "name": "clickup_guest_get",
1531            "description": "Fetch the profile of a specific guest user in a ClickUp workspace — email, permissions (can_edit_tags, can_see_time_spent, can_create_views), and shared items. Guests are external collaborators with limited access. Requires Enterprise plan. Returns the guest object.",
1532            "inputSchema": {
1533                "type": "object",
1534                "properties": {
1535                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1536                    "guest_id": {"type": "integer", "description": "Numeric guest user ID. Obtain from clickup_guest_invite (returns the new guest) or the guest's entry in a shared-item's members list."}
1537                },
1538                "required": ["guest_id"]
1539            }
1540        },
1541        {
1542            "name": "clickup_task_time_in_status",
1543            "description": "Report how long a task has spent in each status since creation (e.g. 3 days in 'open', 1 day in 'in review'). Useful for cycle-time analysis. Returns an object mapping status names to total-time and since-timestamp values (all times in milliseconds).",
1544            "inputSchema": {
1545                "type": "object",
1546                "properties": {
1547                    "task_id": {"type": "string", "description": "ID of the task. Obtain from clickup_task_list (field: id) or clickup_task_search."}
1548                },
1549                "required": ["task_id"]
1550            }
1551        },
1552        {
1553            "name": "clickup_task_move",
1554            "description": "Move a task to a different list (change home list)",
1555            "inputSchema": {
1556                "type": "object",
1557                "properties": {
1558                    "task_id": {"type": "string", "description": "Task ID"},
1559                    "list_id": {"type": "string", "description": "Destination list ID"},
1560                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."}
1561                },
1562                "required": ["task_id", "list_id"]
1563            }
1564        },
1565        {
1566            "name": "clickup_task_set_estimate",
1567            "description": "Set a per-user time estimate on a ClickUp task. Additive — other users' estimates are untouched. To replace all user estimates at once use clickup_task_replace_estimates instead. Estimates are used in workload views and reports. Returns the updated task estimate object.",
1568            "inputSchema": {
1569                "type": "object",
1570                "properties": {
1571                    "task_id": {"type": "string", "description": "ID of the task. Obtain from clickup_task_list (field: id)."},
1572                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1573                    "user_id": {"type": "integer", "description": "Numeric ID of the user whose estimate to set. Obtain from clickup_member_list."},
1574                    "time_estimate": {"type": "integer", "description": "Estimated effort in milliseconds (e.g. 3600000 = 1 hour, 28800000 = 8 hours)."}
1575                },
1576                "required": ["task_id", "user_id", "time_estimate"]
1577            }
1578        },
1579        {
1580            "name": "clickup_task_replace_estimates",
1581            "description": "Replace the full set of per-user time estimates on a task. The request body is an array; any user not in the array has their estimate removed. To set one user's estimate without disturbing others, use clickup_task_set_estimate instead. Body shape per ClickUp's spec: [{assignee, time}]. Requires Business plan for multiple owners.",
1582            "inputSchema": {
1583                "type": "object",
1584                "properties": {
1585                    "task_id": {"type": "string", "description": "Task ID. Custom task IDs (PROJ-42) are auto-detected."},
1586                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1587                    "estimates": {
1588                        "type": "array",
1589                        "description": "Full set of per-user estimates to replace with. Every assignee not present here will have their estimate removed. At least one entry required.",
1590                        "items": {
1591                            "type": "object",
1592                            "properties": {
1593                                "assignee": {"description": "User ID (integer) or the literal string 'unassigned'."},
1594                                "time": {"type": "integer", "description": "Time estimate in milliseconds (>= 0)."}
1595                            },
1596                            "required": ["assignee", "time"]
1597                        }
1598                    }
1599                },
1600                "required": ["task_id", "estimates"]
1601            }
1602        },
1603        {
1604            "name": "clickup_auth_check",
1605            "description": "Verify that the configured ClickUp API token is valid by hitting the /user endpoint. Returns an ok:true result if the token is accepted, or an error if it's missing, malformed, expired, or revoked. Use clickup_whoami instead to also get the authenticated user's profile.",
1606            "inputSchema": {
1607                "type": "object",
1608                "properties": {},
1609                "required": []
1610            }
1611        },
1612        {
1613            "name": "clickup_checklist_update",
1614            "description": "Rename a checklist or change its position among the task's checklists. Does not affect the checklist's items — use clickup_checklist_update_item / add_item / delete_item for those. Returns the updated checklist object.",
1615            "inputSchema": {
1616                "type": "object",
1617                "properties": {
1618                    "checklist_id": {"type": "string", "description": "ID of the checklist to update. Obtain from clickup_task_get (field: checklists[].id)."},
1619                    "name": {"type": "string", "description": "New display name for the checklist. Omit to keep current name."},
1620                    "position": {"type": "integer", "description": "Zero-indexed position among the task's checklists (0 = first). Omit to keep current position."}
1621                },
1622                "required": ["checklist_id"]
1623            }
1624        },
1625        {
1626            "name": "clickup_comment_replies",
1627            "description": "List the threaded replies attached to a top-level ClickUp comment, oldest first. Returns an array of reply objects (id, comment_text, user, date). Use clickup_comment_reply to post a new reply to the thread.",
1628            "inputSchema": {
1629                "type": "object",
1630                "properties": {
1631                    "comment_id": {"type": "string", "description": "ID of the parent comment. Obtain from clickup_comment_list (field: id)."}
1632                },
1633                "required": ["comment_id"]
1634            }
1635        },
1636        {
1637            "name": "clickup_comment_reply",
1638            "description": "Post a threaded reply under an existing ClickUp comment. Replies appear indented beneath the parent comment. Returns the created reply object including its new id. For a top-level comment, use clickup_comment_create instead.",
1639            "inputSchema": {
1640                "type": "object",
1641                "properties": {
1642                    "comment_id": {"type": "string", "description": "ID of the parent comment to reply to. Obtain from clickup_comment_list (field: id)."},
1643                    "text": {"type": "string", "description": "Reply body. @mentions are rendered. Markdown is NOT rendered by ClickUp's v2 comment API; markdown syntax is stored as literal text."},
1644                    "assignee": {"type": "integer", "description": "Optional user ID to assign the reply to — they receive a notification. Obtain from clickup_member_list."}
1645                },
1646                "required": ["comment_id", "text"]
1647            }
1648        },
1649        {
1650            "name": "clickup_chat_channel_list",
1651            "description": "List all ClickUp Chat channels in a workspace that the authenticated user can see. Uses v3 cursor pagination. Returns an array of channel objects (id, name, visibility, topic, last_message_at). Use clickup_chat_channel_create to create new channels.",
1652            "inputSchema": {
1653                "type": "object",
1654                "properties": {
1655                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1656                    "include_closed": {"type": "boolean", "description": "true = include archived/closed channels in the result; false or omitted = only active channels."}
1657                },
1658                "required": []
1659            }
1660        },
1661        {
1662            "name": "clickup_chat_channel_followers",
1663            "description": "List the users who follow (receive notifications from) a ClickUp Chat channel. Followers are a subset of members — a member may or may not be a follower. Returns an array of user objects.",
1664            "inputSchema": {
1665                "type": "object",
1666                "properties": {
1667                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1668                    "channel_id": {"type": "string", "description": "ID of the channel. Obtain from clickup_chat_channel_list (field: id)."}
1669                },
1670                "required": ["channel_id"]
1671            }
1672        },
1673        {
1674            "name": "clickup_chat_channel_members",
1675            "description": "List the users who are members of a ClickUp Chat channel (can read and post). For notification-receivers only use clickup_chat_channel_followers. Returns an array of user objects (id, username, email).",
1676            "inputSchema": {
1677                "type": "object",
1678                "properties": {
1679                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1680                    "channel_id": {"type": "string", "description": "ID of the channel. Obtain from clickup_chat_channel_list (field: id)."}
1681                },
1682                "required": ["channel_id"]
1683            }
1684        },
1685        {
1686            "name": "clickup_chat_message_update",
1687            "description": "Edit the body of an existing ClickUp Chat message. Only the author (or a workspace admin) can edit a message; others will get a 403. The supplied text replaces the existing body entirely. Returns the updated message object.",
1688            "inputSchema": {
1689                "type": "object",
1690                "properties": {
1691                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1692                    "message_id": {"type": "string", "description": "ID of the message to edit. Obtain from clickup_chat_message_list (field: id) or clickup_chat_reply_list."},
1693                    "text": {"type": "string", "description": "Replacement body for the message. Markdown, emoji, and @mentions supported. Overwrites the existing body entirely."}
1694                },
1695                "required": ["message_id", "text"]
1696            }
1697        },
1698        {
1699            "name": "clickup_chat_reaction_list",
1700            "description": "List the emoji reactions on a ClickUp Chat message grouped by emoji — each entry includes the emoji, count, and the users who reacted with it. Returns an array of reaction summary objects.",
1701            "inputSchema": {
1702                "type": "object",
1703                "properties": {
1704                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1705                    "message_id": {"type": "string", "description": "ID of the message whose reactions to list. Obtain from clickup_chat_message_list (field: id)."}
1706                },
1707                "required": ["message_id"]
1708            }
1709        },
1710        {
1711            "name": "clickup_chat_reaction_add",
1712            "description": "Add an emoji reaction from the authenticated user to a ClickUp Chat message. If the user has already reacted with the same emoji, the call is a no-op. Returns an empty object on success.",
1713            "inputSchema": {
1714                "type": "object",
1715                "properties": {
1716                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1717                    "message_id": {"type": "string", "description": "ID of the message to react to. Obtain from clickup_chat_message_list (field: id) or clickup_chat_reply_list."},
1718                    "emoji": {"type": "string", "description": "Unicode emoji character to add (e.g. '👍', '🎉', '❤️'). Custom Slack-style shortcodes (':+1:') are not supported — use the raw emoji character."}
1719                },
1720                "required": ["message_id", "emoji"]
1721            }
1722        },
1723        {
1724            "name": "clickup_chat_reaction_remove",
1725            "description": "Remove the authenticated user's emoji reaction from a ClickUp Chat message. Only removes your own reaction — other users' reactions of the same emoji are preserved. No-op if you haven't reacted with the given emoji. Returns an empty object on success.",
1726            "inputSchema": {
1727                "type": "object",
1728                "properties": {
1729                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1730                    "message_id": {"type": "string", "description": "ID of the message. Obtain from clickup_chat_message_list (field: id)."},
1731                    "emoji": {"type": "string", "description": "The Unicode emoji character to remove (e.g. '👍'). Must match the exact emoji you reacted with."}
1732                },
1733                "required": ["message_id", "emoji"]
1734            }
1735        },
1736        {
1737            "name": "clickup_chat_reply_list",
1738            "description": "List the threaded replies attached to a top-level ClickUp Chat message, oldest first. Returns an array of reply objects. Use clickup_chat_reply_send to post a new reply.",
1739            "inputSchema": {
1740                "type": "object",
1741                "properties": {
1742                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1743                    "message_id": {"type": "string", "description": "ID of the parent message. Obtain from clickup_chat_message_list (field: id)."}
1744                },
1745                "required": ["message_id"]
1746            }
1747        },
1748        {
1749            "name": "clickup_chat_reply_send",
1750            "description": "Post a threaded reply beneath an existing ClickUp Chat message. The reply appears in the message's thread panel. Returns the created reply object. Use clickup_chat_message_send for new top-level messages.",
1751            "inputSchema": {
1752                "type": "object",
1753                "properties": {
1754                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1755                    "message_id": {"type": "string", "description": "ID of the parent message to reply to. Obtain from clickup_chat_message_list (field: id)."},
1756                    "text": {"type": "string", "description": "Reply body. Markdown, emoji, and @mentions supported."}
1757                },
1758                "required": ["message_id", "text"]
1759            }
1760        },
1761        {
1762            "name": "clickup_chat_tagged_users",
1763            "description": "List the users explicitly @-mentioned (tagged) in a ClickUp Chat message body. Useful for reading who a message was addressed to. Returns an array of user objects.",
1764            "inputSchema": {
1765                "type": "object",
1766                "properties": {
1767                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1768                    "message_id": {"type": "string", "description": "ID of the message. Obtain from clickup_chat_message_list (field: id)."}
1769                },
1770                "required": ["message_id"]
1771            }
1772        },
1773        {
1774            "name": "clickup_time_current",
1775            "description": "Get the currently running time tracking entry",
1776            "inputSchema": {
1777                "type": "object",
1778                "properties": {
1779                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."}
1780                },
1781                "required": []
1782            }
1783        },
1784        {
1785            "name": "clickup_time_tags",
1786            "description": "List all time entry tags for a workspace",
1787            "inputSchema": {
1788                "type": "object",
1789                "properties": {
1790                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."}
1791                },
1792                "required": []
1793            }
1794        },
1795        {
1796            "name": "clickup_time_add_tags",
1797            "description": "Apply one or more tags to one or more time tracking entries in a single call. Tags are created automatically if they don't yet exist in the workspace's time-entry tag set. Use clickup_time_tags to list existing tags. Returns an empty object on success.",
1798            "inputSchema": {
1799                "type": "object",
1800                "properties": {
1801                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1802                    "entry_ids": {
1803                        "type": "array",
1804                        "items": {"type": "string"},
1805                        "description": "IDs of the time entries to tag. Obtain from clickup_time_list (field: id)."
1806                    },
1807                    "tag_names": {
1808                        "type": "array",
1809                        "items": {"type": "string"},
1810                        "description": "Tag names to apply. Created if they don't exist in the workspace's tag set."
1811                    }
1812                },
1813                "required": ["entry_ids", "tag_names"]
1814            }
1815        },
1816        {
1817            "name": "clickup_time_remove_tags",
1818            "description": "Detach one or more tags from one or more time tracking entries in a single call. The tag definitions themselves remain in the workspace. No-op for entries not currently carrying the tag. Returns an empty object on success.",
1819            "inputSchema": {
1820                "type": "object",
1821                "properties": {
1822                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1823                    "entry_ids": {
1824                        "type": "array",
1825                        "items": {"type": "string"},
1826                        "description": "IDs of the time entries to untag. Obtain from clickup_time_list (field: id)."
1827                    },
1828                    "tag_names": {
1829                        "type": "array",
1830                        "items": {"type": "string"},
1831                        "description": "Tag names to remove. Obtain from clickup_time_tags (field: name)."
1832                    }
1833                },
1834                "required": ["entry_ids", "tag_names"]
1835            }
1836        },
1837        {
1838            "name": "clickup_time_rename_tag",
1839            "description": "Rename a time-entry tag across the entire workspace. All historical time entries carrying the old name are updated. ClickUp's spec requires the new background and foreground hex colours on every rename call (pass the existing values if you don't want to change them). Returns an empty object on success.",
1840            "inputSchema": {
1841                "type": "object",
1842                "properties": {
1843                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1844                    "name": {"type": "string", "description": "Current name of the tag to rename. Obtain from clickup_time_tags (field: name)."},
1845                    "new_name": {"type": "string", "description": "Replacement name for the tag. Must not collide with an existing time-entry tag."},
1846                    "tag_bg": {"type": "string", "description": "Required. New background colour as a hex string (e.g. #000000). Pass the existing value to leave the colour unchanged."},
1847                    "tag_fg": {"type": "string", "description": "Required. New foreground colour as a hex string (e.g. #FFFFFF). Pass the existing value to leave the colour unchanged."}
1848                },
1849                "required": ["name", "new_name", "tag_bg", "tag_fg"]
1850            }
1851        },
1852        {
1853            "name": "clickup_time_history",
1854            "description": "Fetch the audit history of edits made to a time tracking entry — every start/duration/description/billable change, the user who made it, and when. Useful for auditing. Returns an array of history event objects.",
1855            "inputSchema": {
1856                "type": "object",
1857                "properties": {
1858                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1859                    "timer_id": {"type": "string", "description": "ID of the time entry. Obtain from clickup_time_list (field: id)."}
1860                },
1861                "required": ["timer_id"]
1862            }
1863        },
1864        {
1865            "name": "clickup_guest_invite",
1866            "description": "Invite a new external guest user to a ClickUp workspace by email. Guests have limited access and don't consume paid member seats (they use guest seats). The invitation email is sent automatically; the guest must accept before they can log in. Share specific items with them via clickup_guest_share_task / _share_list / _share_folder. Requires Enterprise plan. Returns the created guest object including its new id.",
1867            "inputSchema": {
1868                "type": "object",
1869                "properties": {
1870                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1871                    "email": {"type": "string", "description": "Email address to send the invitation to. Must be a valid email that isn't already a member or guest of the workspace."},
1872                    "can_edit_tags": {"type": "boolean", "description": "true = allow the guest to create/rename/delete tags on items shared with them; false or omitted = tag management denied."},
1873                    "can_see_time_spent": {"type": "boolean", "description": "true = allow the guest to see time-tracking data on shared tasks; false or omitted = hidden."},
1874                    "can_create_views": {"type": "boolean", "description": "true = allow the guest to create their own saved views on shared items; false or omitted = cannot create views."}
1875                },
1876                "required": ["email"]
1877            }
1878        },
1879        {
1880            "name": "clickup_guest_update",
1881            "description": "Update a ClickUp guest's workspace-wide capability flags (edit tags, see time spent, create views). Does not change which items are shared with them — use clickup_guest_share_* / _unshare_* for that. Requires Enterprise plan. Returns the updated guest object.",
1882            "inputSchema": {
1883                "type": "object",
1884                "properties": {
1885                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1886                    "guest_id": {"type": "integer", "description": "Numeric guest user ID. Obtain from clickup_guest_get or from clickup_guest_invite (response.id)."},
1887                    "can_edit_tags": {"type": "boolean", "description": "true = allow the guest to manage tags on shared items; false = deny. Omit to keep current value."},
1888                    "can_see_time_spent": {"type": "boolean", "description": "true = guest can see time-tracking on shared tasks; false = hidden. Omit to keep current value."},
1889                    "can_create_views": {"type": "boolean", "description": "true = guest can create saved views; false = cannot. Omit to keep current value."}
1890                },
1891                "required": ["guest_id"]
1892            }
1893        },
1894        {
1895            "name": "clickup_guest_remove",
1896            "description": "Permanently revoke a guest user's access to a ClickUp workspace. All share-records for the guest are deleted and they can no longer log in. Destructive and irreversible — to re-invite, use clickup_guest_invite (a new guest_id will be assigned). Requires Enterprise plan. Returns an empty object on success.",
1897            "inputSchema": {
1898                "type": "object",
1899                "properties": {
1900                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1901                    "guest_id": {"type": "integer", "description": "Numeric guest user ID to remove. Obtain from clickup_guest_get or clickup_guest_invite. All their shared-item access is revoked."}
1902                },
1903                "required": ["guest_id"]
1904            }
1905        },
1906        {
1907            "name": "clickup_guest_share_task",
1908            "description": "Grant a ClickUp guest user access to a single task at a specified permission level. Scopes strictly to that task — subtasks and the parent list are not shared. Use clickup_guest_unshare_task to revoke. Requires Enterprise plan. Returns the updated guest object.",
1909            "inputSchema": {
1910                "type": "object",
1911                "properties": {
1912                    "task_id": {"type": "string", "description": "ID of the task to share. Obtain from clickup_task_list (field: id) or clickup_task_search."},
1913                    "guest_id": {"type": "integer", "description": "Numeric ID of the guest user. Obtain from clickup_guest_get or clickup_guest_invite (response.id)."},
1914                    "permission": {"type": "string", "description": "Access level: 'read' (view only), 'comment' (view + comment), 'create' (comment + create subtasks), 'edit' (full edit rights on this task)."}
1915                },
1916                "required": ["task_id", "guest_id", "permission"]
1917            }
1918        },
1919        {
1920            "name": "clickup_guest_unshare_task",
1921            "description": "Revoke a guest's access to a task",
1922            "inputSchema": {
1923                "type": "object",
1924                "properties": {
1925                    "task_id": {"type": "string", "description": "Task ID"},
1926                    "guest_id": {"type": "integer", "description": "Guest user ID"}
1927                },
1928                "required": ["task_id", "guest_id"]
1929            }
1930        },
1931        {
1932            "name": "clickup_guest_share_list",
1933            "description": "Grant a ClickUp guest user access to a specific list at a chosen permission level. Guests are external collaborators (not paid workspace seats); this is how you scope what a guest can see/do. To revoke access later use clickup_guest_unshare_list. Requires Enterprise plan. Returns the updated guest object.",
1934            "inputSchema": {
1935                "type": "object",
1936                "properties": {
1937                    "list_id": {"type": "string", "description": "ID of the list to share. Obtain from clickup_list_list (field: id)."},
1938                    "guest_id": {"type": "integer", "description": "Numeric ID of the guest user. Obtain from clickup_guest_get or the response of clickup_guest_invite."},
1939                    "permission": {"type": "string", "description": "Access level: 'read' (view only), 'comment' (view + comment), 'create' (comment + create tasks), 'edit' (full edit rights on existing items)."}
1940                },
1941                "required": ["list_id", "guest_id", "permission"]
1942            }
1943        },
1944        {
1945            "name": "clickup_guest_unshare_list",
1946            "description": "Revoke a guest user's access to a specific list. The guest keeps any separate task-level or folder-level grants they may also have. Destructive in that the guest immediately loses access, but the guest account itself remains — re-share with clickup_guest_share_list. Requires Enterprise plan. Returns the updated guest object.",
1947            "inputSchema": {
1948                "type": "object",
1949                "properties": {
1950                    "list_id": {"type": "string", "description": "ID of the list whose access to revoke. Obtain from clickup_list_list (field: id)."},
1951                    "guest_id": {"type": "integer", "description": "Numeric guest user ID. Obtain from clickup_guest_get or clickup_guest_invite."}
1952                },
1953                "required": ["list_id", "guest_id"]
1954            }
1955        },
1956        {
1957            "name": "clickup_guest_share_folder",
1958            "description": "Grant a ClickUp guest user access to an entire folder — including all its lists and tasks — at a specified permission level. Use clickup_guest_share_list or _share_task for narrower scope. Use clickup_guest_unshare_folder to revoke. Requires Enterprise plan. Returns the updated guest object.",
1959            "inputSchema": {
1960                "type": "object",
1961                "properties": {
1962                    "folder_id": {"type": "string", "description": "ID of the folder to share. Obtain from clickup_folder_list (field: id). All descendant lists and tasks are accessible via this grant."},
1963                    "guest_id": {"type": "integer", "description": "Numeric ID of the guest user. Obtain from clickup_guest_get or clickup_guest_invite (response.id)."},
1964                    "permission": {"type": "string", "description": "Access level applied to every descendant: 'read' (view only), 'comment' (view + comment), 'create' (comment + create tasks), 'edit' (full edit rights)."}
1965                },
1966                "required": ["folder_id", "guest_id", "permission"]
1967            }
1968        },
1969        {
1970            "name": "clickup_guest_unshare_folder",
1971            "description": "Revoke a guest user's access to a folder (and, cascading, to every list and task under it granted via the folder). Separate list-level or task-level grants are preserved. Re-share later with clickup_guest_share_folder. Requires Enterprise plan. Returns the updated guest object.",
1972            "inputSchema": {
1973                "type": "object",
1974                "properties": {
1975                    "folder_id": {"type": "string", "description": "ID of the folder whose access to revoke. Obtain from clickup_folder_list (field: id)."},
1976                    "guest_id": {"type": "integer", "description": "Numeric guest user ID. Obtain from clickup_guest_get or clickup_guest_invite."}
1977                },
1978                "required": ["folder_id", "guest_id"]
1979            }
1980        },
1981        {
1982            "name": "clickup_user_invite",
1983            "description": "Invite a new paid member to a ClickUp workspace by email. Consumes a member seat (see clickup_workspace_seats for availability). For external collaborators who shouldn't have full access, use clickup_guest_invite instead. Returns the created user object.",
1984            "inputSchema": {
1985                "type": "object",
1986                "properties": {
1987                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1988                    "email": {"type": "string", "description": "Email address to send the invitation to. Must be a valid email not already a member or guest of the workspace."},
1989                    "admin": {"type": "boolean", "description": "true = grant the Admin role (can manage settings, billing, users); false or omitted = standard Member role."}
1990                },
1991                "required": ["email"]
1992            }
1993        },
1994        {
1995            "name": "clickup_user_update",
1996            "description": "Update a ClickUp workspace member's username and/or admin role. Only the authenticated user (if self) or a workspace admin can call this. To change per-item permissions use role-based or share endpoints instead. Returns the updated user object.",
1997            "inputSchema": {
1998                "type": "object",
1999                "properties": {
2000                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
2001                    "user_id": {"type": "integer", "description": "Numeric user ID to update. Obtain from clickup_member_list or clickup_user_get (field: id)."},
2002                    "username": {"type": "string", "description": "New display name. Omit to keep current username."},
2003                    "admin": {"type": "boolean", "description": "true = grant Admin role, false = revoke Admin (revert to Member). Omit to keep current role."}
2004                },
2005                "required": ["user_id"]
2006            }
2007        },
2008        {
2009            "name": "clickup_user_remove",
2010            "description": "Remove a member from a ClickUp workspace, freeing their paid seat. Destructive — their assignments and comments are preserved as historical records but they lose access immediately. To re-add, use clickup_user_invite (a new invitation will be sent). Returns an empty object on success.",
2011            "inputSchema": {
2012                "type": "object",
2013                "properties": {
2014                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
2015                    "user_id": {"type": "integer", "description": "Numeric user ID to remove. Obtain from clickup_member_list (field: id). Cannot remove the workspace Owner."}
2016                },
2017                "required": ["user_id"]
2018            }
2019        },
2020        {
2021            "name": "clickup_template_apply_task",
2022            "description": "Create a new task in a list by instantiating a saved task template. The new task inherits the template's description, checklists, subtasks, custom fields, etc., but uses the supplied name. Use clickup_template_list to discover templates. Returns the created task object.",
2023            "inputSchema": {
2024                "type": "object",
2025                "properties": {
2026                    "list_id": {"type": "string", "description": "ID of the list to create the task in. Obtain from clickup_list_list (field: id)."},
2027                    "template_id": {"type": "string", "description": "ID of the task template to instantiate. Obtain from clickup_template_list (field: id)."},
2028                    "name": {"type": "string", "description": "Name for the newly-created task. Overrides the template's default name."}
2029                },
2030                "required": ["list_id", "template_id", "name"]
2031            }
2032        },
2033        {
2034            "name": "clickup_template_apply_list",
2035            "description": "Create a list from a list template in a folder or space",
2036            "inputSchema": {
2037                "type": "object",
2038                "properties": {
2039                    "template_id": {"type": "string", "description": "Template ID"},
2040                    "name": {"type": "string", "description": "New list name"},
2041                    "folder_id": {"type": "string", "description": "Folder ID (mutually exclusive with space_id)"},
2042                    "space_id": {"type": "string", "description": "Space ID (mutually exclusive with folder_id)"}
2043                },
2044                "required": ["template_id", "name"]
2045            }
2046        },
2047        {
2048            "name": "clickup_template_apply_folder",
2049            "description": "Create a new folder in a space by instantiating a saved folder template. The new folder inherits the template's list structure, statuses, default fields, and other presets, using the supplied name. Use clickup_template_list to discover templates. Returns the created folder object.",
2050            "inputSchema": {
2051                "type": "object",
2052                "properties": {
2053                    "space_id": {"type": "string", "description": "ID of the parent space. Obtain from clickup_space_list (field: id)."},
2054                    "template_id": {"type": "string", "description": "ID of the folder template to instantiate. Obtain from clickup_template_list (field: id)."},
2055                    "name": {"type": "string", "description": "Name for the newly-created folder. Must be unique within the parent space."}
2056                },
2057                "required": ["space_id", "template_id", "name"]
2058            }
2059        },
2060        {
2061            "name": "clickup_attachment_upload",
2062            "description": "Upload a local file as an attachment on a ClickUp task. The file is read from disk, posted as multipart/form-data, and stored on ClickUp's CDN. Use clickup_attachment_list to see attachments afterward. Returns the created attachment object (id, title, size, url).",
2063            "inputSchema": {
2064                "type": "object",
2065                "properties": {
2066                    "task_id": {"type": "string", "description": "ID of the task to attach the file to. Obtain from clickup_task_list (field: id)."},
2067                    "file_path": {"type": "string", "description": "Absolute path to a readable file on the server running this MCP. The filename (basename) is used as the attachment title; size limits apply per workspace plan."}
2068                },
2069                "required": ["task_id", "file_path"]
2070            }
2071        },
2072        {
2073            "name": "clickup_task_type_list",
2074            "description": "List the custom task types (ClickUp 'Custom Items' — e.g. Bug, Epic, Feature) defined at the workspace level. Each has an id, name, and icon and can be chosen when creating tasks. Returns an array of custom item type objects.",
2075            "inputSchema": {
2076                "type": "object",
2077                "properties": {
2078                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
2079                },
2080                "required": []
2081            }
2082        },
2083        {
2084            "name": "clickup_doc_get_page",
2085            "description": "Fetch a single page from a ClickUp doc including its full markdown content, title, subtitle, and parent-page link. Use clickup_doc_pages to list all pages in a doc first. Returns the page object with content.",
2086            "inputSchema": {
2087                "type": "object",
2088                "properties": {
2089                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
2090                    "doc_id": {"type": "string", "description": "ID of the parent doc. Obtain from clickup_doc_list (field: id)."},
2091                    "page_id": {"type": "string", "description": "ID of the page to fetch. Obtain from clickup_doc_pages (field: id)."}
2092                },
2093                "required": ["doc_id", "page_id"]
2094            }
2095        },
2096        {
2097            "name": "clickup_audit_log_query",
2098            "description": "Query the ClickUp audit log (who did what, when) for a workspace. Requires Enterprise plan. Uses v3 cursor pagination. Body shape per ClickUp's OpenAPI spec: { applicability, filter?, pagination? }. Returns the raw response (data array plus pagination cursor).",
2099            "inputSchema": {
2100                "type": "object",
2101                "properties": {
2102                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
2103                    "applicability": {"type": "string", "description": "Required. Scope of the query. ClickUp's documented values: WORKSPACE, TEAMS, USERS."},
2104                    "event_type": {"type": "string", "description": "Optional filter on event category. ClickUp's documented categories include AUTH, HIERARCHY, USER, CUSTOM_FIELDS, AGENT, OTHER. Maps to filter.eventType."},
2105                    "event_status": {"type": "string", "description": "Optional filter on event status (e.g. SUCCESS, FAILURE). Maps to filter.eventStatus."},
2106                    "user_id": {
2107                        "type": "array",
2108                        "items": {"type": "string"},
2109                        "description": "Optional list of user IDs to filter on. Maps to filter.userId."
2110                    },
2111                    "user_email": {
2112                        "type": "array",
2113                        "items": {"type": "string"},
2114                        "description": "Optional list of user emails to filter on. Maps to filter.userEmail."
2115                    },
2116                    "start_time": {"type": "integer", "description": "Inclusive lower bound as a Unix timestamp in milliseconds. Maps to filter.startTime."},
2117                    "end_time": {"type": "integer", "description": "Inclusive upper bound as a Unix timestamp in milliseconds. Maps to filter.endTime."},
2118                    "page_rows": {"type": "integer", "description": "Pagination page size. Maps to pagination.pageRows."},
2119                    "page_timestamp": {"type": "integer", "description": "Pagination cursor timestamp. Maps to pagination.pageTimestamp."},
2120                    "page_direction": {"type": "string", "description": "Pagination direction (NEXT or PREVIOUS). Maps to pagination.pageDirection."}
2121                },
2122                "required": ["applicability"]
2123            }
2124        },
2125        {
2126            "name": "clickup_acl_update",
2127            "description": "Change the privacy (ACL) of a ClickUp hierarchy object — toggle private/public and grant or revoke per-user/per-group access. Uses the v3 ACL endpoint. Requires Enterprise plan. Body shape per ClickUp's OpenAPI spec: { private?: bool, entries?: [{kind, id, permission_level?}] }.",
2128            "inputSchema": {
2129                "type": "object",
2130                "properties": {
2131                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
2132                    "object_type": {"type": "string", "description": "Type of object to change: 'space', 'folder', or 'list'."},
2133                    "object_id": {"type": "string", "description": "ID of the space/folder/list. Obtain from the matching list endpoint (clickup_space_list, clickup_folder_list, or clickup_list_list)."},
2134                    "private": {"type": "boolean", "description": "true = make the object private (only explicit members see it); false = make it public (visible to the whole workspace). Omit to leave unchanged."},
2135                    "entries": {
2136                        "type": "array",
2137                        "description": "Grant or revoke per-principal access. Each entry: {kind: 'user'|'group', id: string, permission_level?: integer}. permission_level enum: 1=read, 3=comment, 4=edit, 5=create; pass 0 to revoke. Maps directly to ClickUp's `entries` array per the v3 spec.",
2138                        "items": {
2139                            "type": "object",
2140                            "properties": {
2141                                "kind": {"type": "string", "enum": ["user", "group"], "description": "Principal type."},
2142                                "id": {"type": "string", "description": "User ID (for kind='user') or user-group ID (for kind='group')."},
2143                                "permission_level": {"type": "integer", "description": "1=read, 3=comment, 4=edit, 5=create. Pass 0 to revoke. Defaults to read (1) if omitted on a grant."}
2144                            },
2145                            "required": ["kind", "id"]
2146                        }
2147                    }
2148                },
2149                "required": ["object_type", "object_id"]
2150            }
2151        }
2152    ])
2153}
2154
2155/// Returns `tool_list()` with any tool the filter disallows removed.
2156pub fn filtered_tool_list(filter: &filter::Filter) -> serde_json::Value {
2157    let all = tool_list();
2158    let filtered: Vec<serde_json::Value> = all
2159        .as_array()
2160        .map(|arr| {
2161            arr.iter()
2162                .filter(|tool| {
2163                    tool.get("name")
2164                        .and_then(|v| v.as_str())
2165                        .map(|n| filter.allows(n))
2166                        .unwrap_or(false)
2167                })
2168                .cloned()
2169                .collect()
2170        })
2171        .unwrap_or_default();
2172    serde_json::Value::Array(filtered)
2173}
2174
2175/// Compact custom field definitions while preserving option IDs for fields
2176/// whose possible values live in `type_config.options`.
2177pub fn compact_custom_fields(fields: &[Value]) -> Value {
2178    let compacted: Vec<Value> = fields
2179        .iter()
2180        .map(|field| {
2181            let mut obj = serde_json::Map::new();
2182            for key in ["id", "name", "type", "required"] {
2183                obj.insert(
2184                    key.to_string(),
2185                    Value::String(flatten_value(field.get(key))),
2186                );
2187            }
2188
2189            if let Some(options) = field
2190                .get("type_config")
2191                .and_then(|config| config.get("options"))
2192                .and_then(|options| options.as_array())
2193            {
2194                obj.insert("options".to_string(), Value::Array(options.clone()));
2195            }
2196
2197            Value::Object(obj)
2198        })
2199        .collect();
2200
2201    Value::Array(compacted)
2202}
2203
2204// ── Tool execution ────────────────────────────────────────────────────────────
2205
2206async fn call_tool(
2207    name: &str,
2208    args: &Value,
2209    client: &ClickUpClient,
2210    workspace_id: &Option<String>,
2211) -> Value {
2212    let result = dispatch_tool(name, args, client, workspace_id).await;
2213    match result {
2214        Ok(v) => tool_result(v.to_string()),
2215        Err(e) => tool_error(format!("Error: {}", e)),
2216    }
2217}
2218
2219async fn dispatch_tool(
2220    name: &str,
2221    args: &Value,
2222    client: &ClickUpClient,
2223    workspace_id: &Option<String>,
2224) -> Result<Value, String> {
2225    let empty = json!({});
2226    let args = if args.is_null() { &empty } else { args };
2227
2228    // Resolve workspace ID from args or config
2229    let resolve_workspace = |args: &Value| -> Result<String, String> {
2230        if let Some(id) = args.get("team_id").and_then(|v| v.as_str()) {
2231            return Ok(id.to_string());
2232        }
2233        workspace_id
2234            .clone()
2235            .ok_or_else(|| "No workspace_id found in config. Please run `clickup setup` or provide team_id in the tool arguments.".to_string())
2236    };
2237
2238    // Normalise a caller-supplied task_id and, if it's a custom-format ID
2239    // (e.g. `PROJ-42`), return the `custom_task_ids=true&team_id=<ws>` query
2240    // fragment that ClickUp requires. Returns the cleaned task id (with any
2241    // `CU-` prefix stripped) plus an optional query fragment to attach to the
2242    // request URL. The returned fragment does NOT include a leading `?` or `&`.
2243    let resolve_task = |args: &Value, key: &str| -> Result<(String, Option<String>), String> {
2244        let raw = args
2245            .get(key)
2246            .and_then(|v| v.as_str())
2247            .ok_or_else(|| format!("Missing required parameter: {}", key))?;
2248        let resolved = git::parse_task_id(raw);
2249        if resolved.is_custom {
2250            let ws = resolve_workspace(args)?;
2251            Ok((
2252                resolved.id,
2253                Some(format!("custom_task_ids=true&team_id={}", ws)),
2254            ))
2255        } else {
2256            Ok((resolved.id, None))
2257        }
2258    };
2259
2260    match name {
2261        "clickup_whoami" => {
2262            let resp = client.get("/v2/user").await.map_err(|e| e.to_string())?;
2263            let user = resp.get("user").cloned().unwrap_or(resp);
2264            Ok(compact_items(&[user], &["id", "username", "email"]))
2265        }
2266
2267        "clickup_workspace_list" => {
2268            let resp = client.get("/v2/team").await.map_err(|e| e.to_string())?;
2269            let teams = resp
2270                .get("teams")
2271                .and_then(|t| t.as_array())
2272                .cloned()
2273                .unwrap_or_default();
2274            let items: Vec<Value> = teams.iter().map(|ws| {
2275                json!({
2276                    "id": ws.get("id"),
2277                    "name": ws.get("name"),
2278                    "members": ws.get("members").and_then(|m| m.as_array()).map(|a| a.len()).unwrap_or(0),
2279                })
2280            }).collect();
2281            Ok(compact_items(&items, &["id", "name", "members"]))
2282        }
2283
2284        "clickup_space_list" => {
2285            let team_id = resolve_workspace(args)?;
2286            let archived = args
2287                .get("archived")
2288                .and_then(|v| v.as_bool())
2289                .unwrap_or(false);
2290            let path = format!("/v2/team/{}/space?archived={}", team_id, archived);
2291            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2292            let spaces = resp
2293                .get("spaces")
2294                .and_then(|s| s.as_array())
2295                .cloned()
2296                .unwrap_or_default();
2297            Ok(compact_items(
2298                &spaces,
2299                &["id", "name", "private", "archived"],
2300            ))
2301        }
2302
2303        "clickup_folder_list" => {
2304            let space_id = args
2305                .get("space_id")
2306                .and_then(|v| v.as_str())
2307                .ok_or("Missing required parameter: space_id")?;
2308            let archived = args
2309                .get("archived")
2310                .and_then(|v| v.as_bool())
2311                .unwrap_or(false);
2312            let path = format!("/v2/space/{}/folder?archived={}", space_id, archived);
2313            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2314            let folders = resp
2315                .get("folders")
2316                .and_then(|f| f.as_array())
2317                .cloned()
2318                .unwrap_or_default();
2319            let items: Vec<Value> = folders
2320                .iter()
2321                .map(|f| {
2322                    let list_count = f
2323                        .get("lists")
2324                        .and_then(|l| l.as_array())
2325                        .map(|a| a.len())
2326                        .unwrap_or(0);
2327                    json!({
2328                        "id": f.get("id"),
2329                        "name": f.get("name"),
2330                        "task_count": f.get("task_count"),
2331                        "list_count": list_count,
2332                    })
2333                })
2334                .collect();
2335            Ok(compact_items(
2336                &items,
2337                &["id", "name", "task_count", "list_count"],
2338            ))
2339        }
2340
2341        "clickup_list_list" => {
2342            let archived = args
2343                .get("archived")
2344                .and_then(|v| v.as_bool())
2345                .unwrap_or(false);
2346            let path = if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
2347                format!("/v2/folder/{}/list?archived={}", folder_id, archived)
2348            } else if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
2349                format!("/v2/space/{}/list?archived={}", space_id, archived)
2350            } else {
2351                return Err("Provide either folder_id or space_id".to_string());
2352            };
2353            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2354            let lists = resp
2355                .get("lists")
2356                .and_then(|l| l.as_array())
2357                .cloned()
2358                .unwrap_or_default();
2359            Ok(compact_items(
2360                &lists,
2361                &["id", "name", "task_count", "status", "due_date"],
2362            ))
2363        }
2364
2365        "clickup_task_list" => {
2366            let list_id = args
2367                .get("list_id")
2368                .and_then(|v| v.as_str())
2369                .ok_or("Missing required parameter: list_id")?;
2370            let mut qs = String::new();
2371            if let Some(include_closed) = args.get("include_closed").and_then(|v| v.as_bool()) {
2372                qs.push_str(&format!("&include_closed={}", include_closed));
2373            }
2374            if let Some(statuses) = args.get("statuses").and_then(|v| v.as_array()) {
2375                for s in statuses {
2376                    if let Some(s) = s.as_str() {
2377                        qs.push_str(&format!("&statuses[]={}", s));
2378                    }
2379                }
2380            }
2381            if let Some(assignees) = args.get("assignees").and_then(|v| v.as_array()) {
2382                for a in assignees {
2383                    if let Some(a) = a.as_str() {
2384                        qs.push_str(&format!("&assignees[]={}", a));
2385                    }
2386                }
2387            }
2388            let path = format!("/v2/list/{}/task?{}", list_id, qs.trim_start_matches('&'));
2389            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2390            let tasks = resp
2391                .get("tasks")
2392                .and_then(|t| t.as_array())
2393                .cloned()
2394                .unwrap_or_default();
2395            Ok(compact_items(
2396                &tasks,
2397                &["id", "name", "status", "priority", "assignees", "due_date"],
2398            ))
2399        }
2400
2401        "clickup_task_get" => {
2402            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2403            let include_subtasks = args
2404                .get("include_subtasks")
2405                .and_then(|v| v.as_bool())
2406                .unwrap_or(false);
2407            let path = match custom_q {
2408                Some(q) => format!(
2409                    "/v2/task/{}?include_subtasks={}&{}",
2410                    task_id, include_subtasks, q
2411                ),
2412                None => format!("/v2/task/{}?include_subtasks={}", task_id, include_subtasks),
2413            };
2414            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2415            Ok(compact_items(
2416                &[resp],
2417                &[
2418                    "id",
2419                    "name",
2420                    "status",
2421                    "priority",
2422                    "assignees",
2423                    "due_date",
2424                    "description",
2425                ],
2426            ))
2427        }
2428
2429        "clickup_task_create" => {
2430            let list_id = args
2431                .get("list_id")
2432                .and_then(|v| v.as_str())
2433                .ok_or("Missing required parameter: list_id")?;
2434            let name = args
2435                .get("name")
2436                .and_then(|v| v.as_str())
2437                .ok_or("Missing required parameter: name")?;
2438            let mut body = json!({"name": name});
2439            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2440                body["markdown_content"] = json!(desc);
2441            }
2442            if let Some(status) = args.get("status").and_then(|v| v.as_str()) {
2443                body["status"] = json!(status);
2444            }
2445            if let Some(priority) = args.get("priority").and_then(|v| v.as_i64()) {
2446                body["priority"] = json!(priority);
2447            }
2448            if let Some(assignees) = args.get("assignees") {
2449                body["assignees"] = assignees.clone();
2450            }
2451            if let Some(tags) = args.get("tags") {
2452                body["tags"] = tags.clone();
2453            }
2454            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) {
2455                body["due_date"] = json!(due_date);
2456            }
2457            let path = format!("/v2/list/{}/task", list_id);
2458            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2459            Ok(compact_items(
2460                &[resp],
2461                &["id", "name", "status", "priority", "assignees", "due_date"],
2462            ))
2463        }
2464
2465        "clickup_task_update" => {
2466            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2467            let mut body = json!({});
2468            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
2469                body["name"] = json!(name);
2470            }
2471            if let Some(status) = args.get("status").and_then(|v| v.as_str()) {
2472                body["status"] = json!(status);
2473            }
2474            if let Some(priority) = args.get("priority").and_then(|v| v.as_i64()) {
2475                body["priority"] = json!(priority);
2476            }
2477            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2478                body["markdown_content"] = json!(desc);
2479            }
2480            if let Some(add) = args.get("add_assignees") {
2481                body["assignees"] = json!({"add": add, "rem": args.get("rem_assignees").cloned().unwrap_or(json!([]))});
2482            } else if let Some(rem) = args.get("rem_assignees") {
2483                body["assignees"] = json!({"add": [], "rem": rem});
2484            }
2485            let path = match custom_q {
2486                Some(q) => format!("/v2/task/{}?{}", task_id, q),
2487                None => format!("/v2/task/{}", task_id),
2488            };
2489            let resp = client.put(&path, &body).await.map_err(|e| e.to_string())?;
2490            Ok(compact_items(
2491                &[resp],
2492                &["id", "name", "status", "priority", "assignees", "due_date"],
2493            ))
2494        }
2495
2496        "clickup_task_delete" => {
2497            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2498            let path = match custom_q {
2499                Some(q) => format!("/v2/task/{}?{}", task_id, q),
2500                None => format!("/v2/task/{}", task_id),
2501            };
2502            client.delete(&path).await.map_err(|e| e.to_string())?;
2503            Ok(json!({"message": format!("Task {} deleted", task_id)}))
2504        }
2505
2506        "clickup_task_search" => {
2507            let team_id = resolve_workspace(args)?;
2508            let params = task_search_query_params(args);
2509            let query = if params.is_empty() {
2510                String::new()
2511            } else {
2512                format!("?{}", params.join("&"))
2513            };
2514            let path = format!("/v2/team/{}/task{}", team_id, query);
2515            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2516            let tasks = resp
2517                .get("tasks")
2518                .and_then(|t| t.as_array())
2519                .cloned()
2520                .unwrap_or_default();
2521            Ok(compact_items(
2522                &tasks,
2523                &["id", "name", "status", "priority", "assignees", "due_date"],
2524            ))
2525        }
2526
2527        "clickup_comment_list" => {
2528            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2529            let path = match custom_q {
2530                Some(q) => format!("/v2/task/{}/comment?{}", task_id, q),
2531                None => format!("/v2/task/{}/comment", task_id),
2532            };
2533            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2534            let comments = resp
2535                .get("comments")
2536                .and_then(|c| c.as_array())
2537                .cloned()
2538                .unwrap_or_default();
2539            Ok(compact_items(
2540                &comments,
2541                &["id", "user", "date", "comment_text"],
2542            ))
2543        }
2544
2545        "clickup_comment_create" => {
2546            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2547            let text = args
2548                .get("text")
2549                .and_then(|v| v.as_str())
2550                .ok_or("Missing required parameter: text")?;
2551            let mut body = json!({"comment_text": text});
2552            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) {
2553                body["assignee"] = json!(assignee);
2554            }
2555            if let Some(notify_all) = args.get("notify_all").and_then(|v| v.as_bool()) {
2556                body["notify_all"] = json!(notify_all);
2557            }
2558            let path = match custom_q {
2559                Some(q) => format!("/v2/task/{}/comment?{}", task_id, q),
2560                None => format!("/v2/task/{}/comment", task_id),
2561            };
2562            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2563            Ok(json!({"message": "Comment created", "id": resp.get("id")}))
2564        }
2565
2566        "clickup_field_list" => {
2567            let list_id = args
2568                .get("list_id")
2569                .and_then(|v| v.as_str())
2570                .ok_or("Missing required parameter: list_id")?;
2571            let path = format!("/v2/list/{}/field", list_id);
2572            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2573            let fields = resp
2574                .get("fields")
2575                .and_then(|f| f.as_array())
2576                .cloned()
2577                .unwrap_or_default();
2578            Ok(compact_custom_fields(&fields))
2579        }
2580
2581        "clickup_field_set" => {
2582            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2583            let field_id = args
2584                .get("field_id")
2585                .and_then(|v| v.as_str())
2586                .ok_or("Missing required parameter: field_id")?;
2587            let value = args
2588                .get("value")
2589                .ok_or("Missing required parameter: value")?;
2590            let body = json!({"value": value});
2591            let path = match custom_q {
2592                Some(q) => format!("/v2/task/{}/field/{}?{}", task_id, field_id, q),
2593                None => format!("/v2/task/{}/field/{}", task_id, field_id),
2594            };
2595            client.post(&path, &body).await.map_err(|e| e.to_string())?;
2596            Ok(json!({"message": format!("Field {} set on task {}", field_id, task_id)}))
2597        }
2598
2599        "clickup_time_start" => {
2600            let team_id = resolve_workspace(args)?;
2601            let mut body = json!({});
2602            if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) {
2603                body["tid"] = json!(task_id);
2604            }
2605            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2606                body["description"] = json!(desc);
2607            }
2608            if let Some(billable) = args.get("billable").and_then(|v| v.as_bool()) {
2609                body["billable"] = json!(billable);
2610            }
2611            let path = format!("/v2/team/{}/time_entries/start", team_id);
2612            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2613            let data = resp.get("data").cloned().unwrap_or(resp);
2614            Ok(compact_items(
2615                &[data],
2616                &["id", "task", "duration", "start", "billable"],
2617            ))
2618        }
2619
2620        "clickup_time_stop" => {
2621            let team_id = resolve_workspace(args)?;
2622            let path = format!("/v2/team/{}/time_entries/stop", team_id);
2623            let resp = client
2624                .post(&path, &json!({}))
2625                .await
2626                .map_err(|e| e.to_string())?;
2627            let data = resp.get("data").cloned().unwrap_or(resp);
2628            Ok(compact_items(
2629                &[data],
2630                &["id", "task", "duration", "start", "end", "billable"],
2631            ))
2632        }
2633
2634        "clickup_time_list" => {
2635            let team_id = resolve_workspace(args)?;
2636            let mut qs = String::new();
2637            if let Some(start_date) = args.get("start_date").and_then(|v| v.as_i64()) {
2638                qs.push_str(&format!("&start_date={}", start_date));
2639            }
2640            if let Some(end_date) = args.get("end_date").and_then(|v| v.as_i64()) {
2641                qs.push_str(&format!("&end_date={}", end_date));
2642            }
2643            if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) {
2644                qs.push_str(&format!("&task_id={}", task_id));
2645            }
2646            let path = format!(
2647                "/v2/team/{}/time_entries?{}",
2648                team_id,
2649                qs.trim_start_matches('&')
2650            );
2651            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2652            let entries = resp
2653                .get("data")
2654                .and_then(|d| d.as_array())
2655                .cloned()
2656                .unwrap_or_default();
2657            Ok(compact_items(
2658                &entries,
2659                &["id", "task", "duration", "start", "billable"],
2660            ))
2661        }
2662
2663        "clickup_checklist_create" => {
2664            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2665            let name = args
2666                .get("name")
2667                .and_then(|v| v.as_str())
2668                .ok_or("Missing required parameter: name")?;
2669            let path = match custom_q {
2670                Some(q) => format!("/v2/task/{}/checklist?{}", task_id, q),
2671                None => format!("/v2/task/{}/checklist", task_id),
2672            };
2673            let body = json!({"name": name});
2674            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2675            let checklist = resp.get("checklist").cloned().unwrap_or(resp);
2676            Ok(compact_items(&[checklist], &["id", "name"]))
2677        }
2678
2679        "clickup_checklist_delete" => {
2680            let checklist_id = args
2681                .get("checklist_id")
2682                .and_then(|v| v.as_str())
2683                .ok_or("Missing required parameter: checklist_id")?;
2684            let path = format!("/v2/checklist/{}", checklist_id);
2685            client.delete(&path).await.map_err(|e| e.to_string())?;
2686            Ok(json!({"message": format!("Checklist {} deleted", checklist_id)}))
2687        }
2688
2689        "clickup_goal_list" => {
2690            let team_id = resolve_workspace(args)?;
2691            let path = format!("/v2/team/{}/goal", team_id);
2692            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2693            let goals = resp
2694                .get("goals")
2695                .and_then(|g| g.as_array())
2696                .cloned()
2697                .unwrap_or_default();
2698            Ok(compact_items(
2699                &goals,
2700                &["id", "name", "percent_completed", "due_date"],
2701            ))
2702        }
2703
2704        "clickup_goal_get" => {
2705            let goal_id = args
2706                .get("goal_id")
2707                .and_then(|v| v.as_str())
2708                .ok_or("Missing required parameter: goal_id")?;
2709            let path = format!("/v2/goal/{}", goal_id);
2710            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2711            let goal = resp.get("goal").cloned().unwrap_or(resp);
2712            Ok(compact_items(
2713                &[goal],
2714                &["id", "name", "percent_completed", "due_date", "description"],
2715            ))
2716        }
2717
2718        "clickup_goal_create" => {
2719            let team_id = resolve_workspace(args)?;
2720            let name = args
2721                .get("name")
2722                .and_then(|v| v.as_str())
2723                .ok_or("Missing required parameter: name")?;
2724            let mut body = json!({"name": name});
2725            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) {
2726                body["due_date"] = json!(due_date);
2727            }
2728            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2729                body["description"] = json!(desc);
2730            }
2731            // ClickUp's create-goal spec requires `multiple_owners` (bool).
2732            // Derive it from the size of the owner_ids array.
2733            let owner_count = args
2734                .get("owner_ids")
2735                .and_then(|v| v.as_array())
2736                .map(|a| a.len())
2737                .unwrap_or(0);
2738            body["multiple_owners"] = json!(owner_count > 1);
2739            if let Some(owner_ids) = args.get("owner_ids") {
2740                body["owners"] = owner_ids.clone();
2741            }
2742            let path = format!("/v2/team/{}/goal", team_id);
2743            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2744            let goal = resp.get("goal").cloned().unwrap_or(resp);
2745            Ok(compact_items(&[goal], &["id", "name"]))
2746        }
2747
2748        "clickup_goal_update" => {
2749            let goal_id = args
2750                .get("goal_id")
2751                .and_then(|v| v.as_str())
2752                .ok_or("Missing required parameter: goal_id")?;
2753            let mut body = json!({});
2754            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
2755                body["name"] = json!(name);
2756            }
2757            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) {
2758                body["due_date"] = json!(due_date);
2759            }
2760            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2761                body["description"] = json!(desc);
2762            }
2763            let path = format!("/v2/goal/{}", goal_id);
2764            let resp = client.put(&path, &body).await.map_err(|e| e.to_string())?;
2765            let goal = resp.get("goal").cloned().unwrap_or(resp);
2766            Ok(compact_items(&[goal], &["id", "name"]))
2767        }
2768
2769        "clickup_view_list" => {
2770            let path = if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
2771                format!("/v2/space/{}/view", space_id)
2772            } else if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
2773                format!("/v2/folder/{}/view", folder_id)
2774            } else if let Some(list_id) = args.get("list_id").and_then(|v| v.as_str()) {
2775                format!("/v2/list/{}/view", list_id)
2776            } else {
2777                let team_id = resolve_workspace(args)?;
2778                format!("/v2/team/{}/view", team_id)
2779            };
2780            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2781            let views = resp
2782                .get("views")
2783                .and_then(|v| v.as_array())
2784                .cloned()
2785                .unwrap_or_default();
2786            Ok(compact_items(&views, &["id", "name", "type"]))
2787        }
2788
2789        "clickup_view_tasks" => {
2790            let view_id = args
2791                .get("view_id")
2792                .and_then(|v| v.as_str())
2793                .ok_or("Missing required parameter: view_id")?;
2794            let page = args.get("page").and_then(|v| v.as_i64()).unwrap_or(0);
2795            let path = format!("/v2/view/{}/task?page={}", view_id, page);
2796            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2797            let tasks = resp
2798                .get("tasks")
2799                .and_then(|t| t.as_array())
2800                .cloned()
2801                .unwrap_or_default();
2802            Ok(compact_items(
2803                &tasks,
2804                &["id", "name", "status", "priority", "assignees", "due_date"],
2805            ))
2806        }
2807
2808        "clickup_doc_list" => {
2809            let team_id = resolve_workspace(args)?;
2810            let path = format!("/v3/workspaces/{}/docs", team_id);
2811            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2812            let docs = resp
2813                .get("docs")
2814                .and_then(|d| d.as_array())
2815                .cloned()
2816                .unwrap_or_default();
2817            Ok(compact_items(&docs, &["id", "name", "date_created"]))
2818        }
2819
2820        "clickup_doc_get" => {
2821            let team_id = resolve_workspace(args)?;
2822            let doc_id = args
2823                .get("doc_id")
2824                .and_then(|v| v.as_str())
2825                .ok_or("Missing required parameter: doc_id")?;
2826            let path = format!("/v3/workspaces/{}/docs/{}", team_id, doc_id);
2827            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2828            Ok(compact_items(&[resp], &["id", "name", "date_created"]))
2829        }
2830
2831        "clickup_doc_pages" => {
2832            let team_id = resolve_workspace(args)?;
2833            let doc_id = args
2834                .get("doc_id")
2835                .and_then(|v| v.as_str())
2836                .ok_or("Missing required parameter: doc_id")?;
2837            let content = args
2838                .get("content")
2839                .and_then(|v| v.as_bool())
2840                .unwrap_or(false);
2841            let path = format!("/v3/workspaces/{}/docs/{}/pages?content_format=text/md&max_page_depth=-1&include_content={}", team_id, doc_id, content);
2842            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2843            let pages = resp
2844                .get("pages")
2845                .and_then(|p| p.as_array())
2846                .cloned()
2847                .unwrap_or_default();
2848            Ok(compact_items(&pages, &["id", "name"]))
2849        }
2850
2851        "clickup_tag_list" => {
2852            let space_id = args
2853                .get("space_id")
2854                .and_then(|v| v.as_str())
2855                .ok_or("Missing required parameter: space_id")?;
2856            let path = format!("/v2/space/{}/tag", space_id);
2857            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2858            let tags = resp
2859                .get("tags")
2860                .and_then(|t| t.as_array())
2861                .cloned()
2862                .unwrap_or_default();
2863            Ok(compact_items(&tags, &["name", "tag_fg", "tag_bg"]))
2864        }
2865
2866        "clickup_task_add_tag" => {
2867            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2868            let tag_name = args
2869                .get("tag_name")
2870                .and_then(|v| v.as_str())
2871                .ok_or("Missing required parameter: tag_name")?;
2872            let path = match custom_q {
2873                Some(q) => format!("/v2/task/{}/tag/{}?{}", task_id, tag_name, q),
2874                None => format!("/v2/task/{}/tag/{}", task_id, tag_name),
2875            };
2876            client
2877                .post(&path, &json!({}))
2878                .await
2879                .map_err(|e| e.to_string())?;
2880            Ok(json!({"message": format!("Tag '{}' added to task {}", tag_name, task_id)}))
2881        }
2882
2883        "clickup_task_remove_tag" => {
2884            let (task_id, custom_q) = resolve_task(args, "task_id")?;
2885            let tag_name = args
2886                .get("tag_name")
2887                .and_then(|v| v.as_str())
2888                .ok_or("Missing required parameter: tag_name")?;
2889            let path = match custom_q {
2890                Some(q) => format!("/v2/task/{}/tag/{}?{}", task_id, tag_name, q),
2891                None => format!("/v2/task/{}/tag/{}", task_id, tag_name),
2892            };
2893            client.delete(&path).await.map_err(|e| e.to_string())?;
2894            Ok(json!({"message": format!("Tag '{}' removed from task {}", tag_name, task_id)}))
2895        }
2896
2897        "clickup_webhook_list" => {
2898            let team_id = resolve_workspace(args)?;
2899            let path = format!("/v2/team/{}/webhook", team_id);
2900            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2901            let webhooks = resp
2902                .get("webhooks")
2903                .and_then(|w| w.as_array())
2904                .cloned()
2905                .unwrap_or_default();
2906            Ok(compact_items(
2907                &webhooks,
2908                &["id", "endpoint", "events", "status"],
2909            ))
2910        }
2911
2912        "clickup_member_list" => {
2913            let path = if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) {
2914                format!("/v2/task/{}/member", task_id)
2915            } else if let Some(list_id) = args.get("list_id").and_then(|v| v.as_str()) {
2916                format!("/v2/list/{}/member", list_id)
2917            } else {
2918                return Err("Provide either task_id or list_id".to_string());
2919            };
2920            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2921            let members = resp
2922                .get("members")
2923                .and_then(|m| m.as_array())
2924                .cloned()
2925                .unwrap_or_default();
2926            Ok(compact_items(&members, &["id", "username", "email"]))
2927        }
2928
2929        "clickup_template_list" => {
2930            let team_id = resolve_workspace(args)?;
2931            let page = args.get("page").and_then(|v| v.as_i64()).unwrap_or(0);
2932            let path = format!("/v2/team/{}/taskTemplate?page={}", team_id, page);
2933            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2934            let templates = resp
2935                .get("templates")
2936                .and_then(|t| t.as_array())
2937                .cloned()
2938                .unwrap_or_default();
2939            Ok(compact_items(&templates, &["id", "name"]))
2940        }
2941
2942        "clickup_space_get" => {
2943            let space_id = args
2944                .get("space_id")
2945                .and_then(|v| v.as_str())
2946                .ok_or("Missing required parameter: space_id")?;
2947            let resp = client
2948                .get(&format!("/v2/space/{}", space_id))
2949                .await
2950                .map_err(|e| e.to_string())?;
2951            Ok(compact_items(
2952                &[resp],
2953                &["id", "name", "private", "archived"],
2954            ))
2955        }
2956
2957        "clickup_space_create" => {
2958            let team_id = resolve_workspace(args)?;
2959            let name = args
2960                .get("name")
2961                .and_then(|v| v.as_str())
2962                .ok_or("Missing required parameter: name")?;
2963            let mut body = json!({"name": name});
2964            if let Some(private) = args.get("private").and_then(|v| v.as_bool()) {
2965                body["private"] = json!(private);
2966            }
2967            let resp = client
2968                .post(&format!("/v2/team/{}/space", team_id), &body)
2969                .await
2970                .map_err(|e| e.to_string())?;
2971            Ok(compact_items(&[resp], &["id", "name", "private"]))
2972        }
2973
2974        "clickup_space_update" => {
2975            let space_id = args
2976                .get("space_id")
2977                .and_then(|v| v.as_str())
2978                .ok_or("Missing required parameter: space_id")?;
2979            let mut body = json!({});
2980            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
2981                body["name"] = json!(name);
2982            }
2983            if let Some(private) = args.get("private").and_then(|v| v.as_bool()) {
2984                body["private"] = json!(private);
2985            }
2986            if let Some(archived) = args.get("archived").and_then(|v| v.as_bool()) {
2987                body["archived"] = json!(archived);
2988            }
2989            let resp = client
2990                .put(&format!("/v2/space/{}", space_id), &body)
2991                .await
2992                .map_err(|e| e.to_string())?;
2993            Ok(compact_items(
2994                &[resp],
2995                &["id", "name", "private", "archived"],
2996            ))
2997        }
2998
2999        "clickup_space_delete" => {
3000            let space_id = args
3001                .get("space_id")
3002                .and_then(|v| v.as_str())
3003                .ok_or("Missing required parameter: space_id")?;
3004            client
3005                .delete(&format!("/v2/space/{}", space_id))
3006                .await
3007                .map_err(|e| e.to_string())?;
3008            Ok(json!({"message": format!("Space {} deleted", space_id)}))
3009        }
3010
3011        "clickup_folder_get" => {
3012            let folder_id = args
3013                .get("folder_id")
3014                .and_then(|v| v.as_str())
3015                .ok_or("Missing required parameter: folder_id")?;
3016            let resp = client
3017                .get(&format!("/v2/folder/{}", folder_id))
3018                .await
3019                .map_err(|e| e.to_string())?;
3020            Ok(compact_items(&[resp], &["id", "name", "task_count"]))
3021        }
3022
3023        "clickup_folder_create" => {
3024            let space_id = args
3025                .get("space_id")
3026                .and_then(|v| v.as_str())
3027                .ok_or("Missing required parameter: space_id")?;
3028            let name = args
3029                .get("name")
3030                .and_then(|v| v.as_str())
3031                .ok_or("Missing required parameter: name")?;
3032            let body = json!({"name": name});
3033            let resp = client
3034                .post(&format!("/v2/space/{}/folder", space_id), &body)
3035                .await
3036                .map_err(|e| e.to_string())?;
3037            Ok(compact_items(&[resp], &["id", "name"]))
3038        }
3039
3040        "clickup_folder_update" => {
3041            let folder_id = args
3042                .get("folder_id")
3043                .and_then(|v| v.as_str())
3044                .ok_or("Missing required parameter: folder_id")?;
3045            let name = args
3046                .get("name")
3047                .and_then(|v| v.as_str())
3048                .ok_or("Missing required parameter: name")?;
3049            let body = json!({"name": name});
3050            let resp = client
3051                .put(&format!("/v2/folder/{}", folder_id), &body)
3052                .await
3053                .map_err(|e| e.to_string())?;
3054            Ok(compact_items(&[resp], &["id", "name"]))
3055        }
3056
3057        "clickup_folder_delete" => {
3058            let folder_id = args
3059                .get("folder_id")
3060                .and_then(|v| v.as_str())
3061                .ok_or("Missing required parameter: folder_id")?;
3062            client
3063                .delete(&format!("/v2/folder/{}", folder_id))
3064                .await
3065                .map_err(|e| e.to_string())?;
3066            Ok(json!({"message": format!("Folder {} deleted", folder_id)}))
3067        }
3068
3069        "clickup_list_get" => {
3070            let list_id = args
3071                .get("list_id")
3072                .and_then(|v| v.as_str())
3073                .ok_or("Missing required parameter: list_id")?;
3074            let resp = client
3075                .get(&format!("/v2/list/{}", list_id))
3076                .await
3077                .map_err(|e| e.to_string())?;
3078            Ok(compact_items(
3079                &[resp],
3080                &["id", "name", "task_count", "status", "due_date"],
3081            ))
3082        }
3083
3084        "clickup_list_create" => {
3085            let name = args
3086                .get("name")
3087                .and_then(|v| v.as_str())
3088                .ok_or("Missing required parameter: name")?;
3089            let mut body = json!({"name": name});
3090            if let Some(content) = args.get("content").and_then(|v| v.as_str()) {
3091                body["markdown_content"] = json!(content);
3092            }
3093            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) {
3094                body["due_date"] = json!(due_date);
3095            }
3096            if let Some(status) = args.get("status").and_then(|v| v.as_str()) {
3097                body["status"] = json!(status);
3098            }
3099            let path = if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
3100                format!("/v2/folder/{}/list", folder_id)
3101            } else if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
3102                format!("/v2/space/{}/list", space_id)
3103            } else {
3104                return Err("Provide either folder_id or space_id".to_string());
3105            };
3106            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
3107            Ok(compact_items(&[resp], &["id", "name"]))
3108        }
3109
3110        "clickup_list_update" => {
3111            let list_id = args
3112                .get("list_id")
3113                .and_then(|v| v.as_str())
3114                .ok_or("Missing required parameter: list_id")?;
3115            let mut body = json!({});
3116            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
3117                body["name"] = json!(name);
3118            }
3119            if let Some(content) = args.get("content").and_then(|v| v.as_str()) {
3120                body["markdown_content"] = json!(content);
3121            }
3122            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) {
3123                body["due_date"] = json!(due_date);
3124            }
3125            if let Some(status) = args.get("status").and_then(|v| v.as_str()) {
3126                body["status"] = json!(status);
3127            }
3128            let resp = client
3129                .put(&format!("/v2/list/{}", list_id), &body)
3130                .await
3131                .map_err(|e| e.to_string())?;
3132            Ok(compact_items(
3133                &[resp],
3134                &["id", "name", "task_count", "status"],
3135            ))
3136        }
3137
3138        "clickup_list_delete" => {
3139            let list_id = args
3140                .get("list_id")
3141                .and_then(|v| v.as_str())
3142                .ok_or("Missing required parameter: list_id")?;
3143            client
3144                .delete(&format!("/v2/list/{}", list_id))
3145                .await
3146                .map_err(|e| e.to_string())?;
3147            Ok(json!({"message": format!("List {} deleted", list_id)}))
3148        }
3149
3150        "clickup_list_add_task" => {
3151            let list_id = args
3152                .get("list_id")
3153                .and_then(|v| v.as_str())
3154                .ok_or("Missing required parameter: list_id")?;
3155            let task_id = args
3156                .get("task_id")
3157                .and_then(|v| v.as_str())
3158                .ok_or("Missing required parameter: task_id")?;
3159            client
3160                .post(
3161                    &format!("/v2/list/{}/task/{}", list_id, task_id),
3162                    &json!({}),
3163                )
3164                .await
3165                .map_err(|e| e.to_string())?;
3166            Ok(json!({"message": format!("Task {} added to list {}", task_id, list_id)}))
3167        }
3168
3169        "clickup_list_remove_task" => {
3170            let list_id = args
3171                .get("list_id")
3172                .and_then(|v| v.as_str())
3173                .ok_or("Missing required parameter: list_id")?;
3174            let task_id = args
3175                .get("task_id")
3176                .and_then(|v| v.as_str())
3177                .ok_or("Missing required parameter: task_id")?;
3178            client
3179                .delete(&format!("/v2/list/{}/task/{}", list_id, task_id))
3180                .await
3181                .map_err(|e| e.to_string())?;
3182            Ok(json!({"message": format!("Task {} removed from list {}", task_id, list_id)}))
3183        }
3184
3185        "clickup_comment_update" => {
3186            let comment_id = args
3187                .get("comment_id")
3188                .and_then(|v| v.as_str())
3189                .ok_or("Missing required parameter: comment_id")?;
3190            let text = args
3191                .get("text")
3192                .and_then(|v| v.as_str())
3193                .ok_or("Missing required parameter: text")?;
3194            let mut body = json!({"comment_text": text});
3195            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) {
3196                body["assignee"] = json!(assignee);
3197            }
3198            if let Some(resolved) = args.get("resolved").and_then(|v| v.as_bool()) {
3199                body["resolved"] = json!(resolved);
3200            }
3201            client
3202                .put(&format!("/v2/comment/{}", comment_id), &body)
3203                .await
3204                .map_err(|e| e.to_string())?;
3205            Ok(json!({"message": format!("Comment {} updated", comment_id)}))
3206        }
3207
3208        "clickup_comment_delete" => {
3209            let comment_id = args
3210                .get("comment_id")
3211                .and_then(|v| v.as_str())
3212                .ok_or("Missing required parameter: comment_id")?;
3213            client
3214                .delete(&format!("/v2/comment/{}", comment_id))
3215                .await
3216                .map_err(|e| e.to_string())?;
3217            Ok(json!({"message": format!("Comment {} deleted", comment_id)}))
3218        }
3219
3220        "clickup_task_add_dep" => {
3221            let (task_id, custom_q) = resolve_task(args, "task_id")?;
3222            let mut body = json!({});
3223            if let Some(dep) = args.get("depends_on").and_then(|v| v.as_str()) {
3224                body["depends_on"] = json!(dep);
3225            }
3226            if let Some(dep) = args.get("dependency_of").and_then(|v| v.as_str()) {
3227                body["dependency_of"] = json!(dep);
3228            }
3229            let path = match custom_q {
3230                Some(q) => format!("/v2/task/{}/dependency?{}", task_id, q),
3231                None => format!("/v2/task/{}/dependency", task_id),
3232            };
3233            client.post(&path, &body).await.map_err(|e| e.to_string())?;
3234            Ok(json!({"message": format!("Dependency added to task {}", task_id)}))
3235        }
3236
3237        "clickup_task_remove_dep" => {
3238            let (task_id, custom_q) = resolve_task(args, "task_id")?;
3239            let mut body = json!({});
3240            if let Some(dep) = args.get("depends_on").and_then(|v| v.as_str()) {
3241                body["depends_on"] = json!(dep);
3242            }
3243            if let Some(dep) = args.get("dependency_of").and_then(|v| v.as_str()) {
3244                body["dependency_of"] = json!(dep);
3245            }
3246            let path = match custom_q {
3247                Some(q) => format!("/v2/task/{}/dependency?{}", task_id, q),
3248                None => format!("/v2/task/{}/dependency", task_id),
3249            };
3250            client
3251                .delete_with_body(&path, &body)
3252                .await
3253                .map_err(|e| e.to_string())?;
3254            Ok(json!({"message": format!("Dependency removed from task {}", task_id)}))
3255        }
3256
3257        "clickup_task_link" => {
3258            let (task_id, custom_q) = resolve_task(args, "task_id")?;
3259            let links_to = args
3260                .get("links_to")
3261                .and_then(|v| v.as_str())
3262                .ok_or("Missing required parameter: links_to")?;
3263            let path = match custom_q {
3264                Some(q) => format!("/v2/task/{}/link/{}?{}", task_id, links_to, q),
3265                None => format!("/v2/task/{}/link/{}", task_id, links_to),
3266            };
3267            let resp = client
3268                .post(&path, &json!({}))
3269                .await
3270                .map_err(|e| e.to_string())?;
3271            Ok(json!({"message": format!("Task {} linked to {}", task_id, links_to), "data": resp}))
3272        }
3273
3274        "clickup_task_unlink" => {
3275            let (task_id, custom_q) = resolve_task(args, "task_id")?;
3276            let links_to = args
3277                .get("links_to")
3278                .and_then(|v| v.as_str())
3279                .ok_or("Missing required parameter: links_to")?;
3280            let path = match custom_q {
3281                Some(q) => format!("/v2/task/{}/link/{}?{}", task_id, links_to, q),
3282                None => format!("/v2/task/{}/link/{}", task_id, links_to),
3283            };
3284            client.delete(&path).await.map_err(|e| e.to_string())?;
3285            Ok(json!({"message": format!("Task {} unlinked from {}", task_id, links_to)}))
3286        }
3287
3288        "clickup_goal_delete" => {
3289            let goal_id = args
3290                .get("goal_id")
3291                .and_then(|v| v.as_str())
3292                .ok_or("Missing required parameter: goal_id")?;
3293            client
3294                .delete(&format!("/v2/goal/{}", goal_id))
3295                .await
3296                .map_err(|e| e.to_string())?;
3297            Ok(json!({"message": format!("Goal {} deleted", goal_id)}))
3298        }
3299
3300        "clickup_goal_add_kr" => {
3301            let goal_id = args
3302                .get("goal_id")
3303                .and_then(|v| v.as_str())
3304                .ok_or("Missing required parameter: goal_id")?;
3305            let name = args
3306                .get("name")
3307                .and_then(|v| v.as_str())
3308                .ok_or("Missing required parameter: name")?;
3309            let kr_type = args
3310                .get("type")
3311                .and_then(|v| v.as_str())
3312                .ok_or("Missing required parameter: type")?;
3313            let steps_start = args
3314                .get("steps_start")
3315                .and_then(|v| v.as_f64())
3316                .ok_or("Missing required parameter: steps_start")?;
3317            let steps_end = args
3318                .get("steps_end")
3319                .and_then(|v| v.as_f64())
3320                .ok_or("Missing required parameter: steps_end")?;
3321            let mut body = json!({"name": name, "type": kr_type, "steps_start": steps_start, "steps_end": steps_end});
3322            if let Some(unit) = args.get("unit").and_then(|v| v.as_str()) {
3323                body["unit"] = json!(unit);
3324            }
3325            if let Some(owners) = args.get("owner_ids") {
3326                body["owners"] = owners.clone();
3327            }
3328            if let Some(task_ids) = args.get("task_ids") {
3329                body["task_ids"] = task_ids.clone();
3330            }
3331            if let Some(list_ids) = args.get("list_ids") {
3332                body["list_ids"] = list_ids.clone();
3333            }
3334            let resp = client
3335                .post(&format!("/v2/goal/{}/key_result", goal_id), &body)
3336                .await
3337                .map_err(|e| e.to_string())?;
3338            let kr = resp.get("key_result").cloned().unwrap_or(resp);
3339            Ok(compact_items(
3340                &[kr],
3341                &[
3342                    "id",
3343                    "name",
3344                    "type",
3345                    "steps_start",
3346                    "steps_end",
3347                    "steps_current",
3348                ],
3349            ))
3350        }
3351
3352        "clickup_goal_update_kr" => {
3353            let kr_id = args
3354                .get("kr_id")
3355                .and_then(|v| v.as_str())
3356                .ok_or("Missing required parameter: kr_id")?;
3357            let mut body = json!({});
3358            if let Some(v) = args.get("steps_current").and_then(|v| v.as_f64()) {
3359                body["steps_current"] = json!(v);
3360            }
3361            if let Some(v) = args.get("name").and_then(|v| v.as_str()) {
3362                body["name"] = json!(v);
3363            }
3364            if let Some(v) = args.get("unit").and_then(|v| v.as_str()) {
3365                body["unit"] = json!(v);
3366            }
3367            let resp = client
3368                .put(&format!("/v2/key_result/{}", kr_id), &body)
3369                .await
3370                .map_err(|e| e.to_string())?;
3371            let kr = resp.get("key_result").cloned().unwrap_or(resp);
3372            Ok(compact_items(
3373                &[kr],
3374                &["id", "name", "steps_current", "steps_end"],
3375            ))
3376        }
3377
3378        "clickup_goal_delete_kr" => {
3379            let kr_id = args
3380                .get("kr_id")
3381                .and_then(|v| v.as_str())
3382                .ok_or("Missing required parameter: kr_id")?;
3383            client
3384                .delete(&format!("/v2/key_result/{}", kr_id))
3385                .await
3386                .map_err(|e| e.to_string())?;
3387            Ok(json!({"message": format!("Key result {} deleted", kr_id)}))
3388        }
3389
3390        "clickup_time_get" => {
3391            let team_id = resolve_workspace(args)?;
3392            let timer_id = args
3393                .get("timer_id")
3394                .and_then(|v| v.as_str())
3395                .ok_or("Missing required parameter: timer_id")?;
3396            let resp = client
3397                .get(&format!("/v2/team/{}/time_entries/{}", team_id, timer_id))
3398                .await
3399                .map_err(|e| e.to_string())?;
3400            let data = resp.get("data").cloned().unwrap_or(resp);
3401            Ok(compact_items(
3402                &[data],
3403                &["id", "task", "duration", "start", "end", "billable"],
3404            ))
3405        }
3406
3407        "clickup_time_create" => {
3408            let team_id = resolve_workspace(args)?;
3409            let start = args
3410                .get("start")
3411                .and_then(|v| v.as_i64())
3412                .ok_or("Missing required parameter: start")?;
3413            let duration = args
3414                .get("duration")
3415                .and_then(|v| v.as_i64())
3416                .ok_or("Missing required parameter: duration")?;
3417            let mut body = json!({"start": start, "duration": duration});
3418            if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) {
3419                body["tid"] = json!(task_id);
3420            }
3421            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
3422                body["description"] = json!(desc);
3423            }
3424            if let Some(billable) = args.get("billable").and_then(|v| v.as_bool()) {
3425                body["billable"] = json!(billable);
3426            }
3427            let resp = client
3428                .post(&format!("/v2/team/{}/time_entries", team_id), &body)
3429                .await
3430                .map_err(|e| e.to_string())?;
3431            let data = resp.get("data").cloned().unwrap_or(resp);
3432            Ok(compact_items(
3433                &[data],
3434                &["id", "task", "duration", "start", "billable"],
3435            ))
3436        }
3437
3438        "clickup_time_update" => {
3439            let team_id = resolve_workspace(args)?;
3440            let timer_id = args
3441                .get("timer_id")
3442                .and_then(|v| v.as_str())
3443                .ok_or("Missing required parameter: timer_id")?;
3444            let mut body = json!({});
3445            if let Some(start) = args.get("start").and_then(|v| v.as_i64()) {
3446                body["start"] = json!(start);
3447            }
3448            if let Some(duration) = args.get("duration").and_then(|v| v.as_i64()) {
3449                body["duration"] = json!(duration);
3450            }
3451            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
3452                body["description"] = json!(desc);
3453            }
3454            if let Some(billable) = args.get("billable").and_then(|v| v.as_bool()) {
3455                body["billable"] = json!(billable);
3456            }
3457            let resp = client
3458                .put(
3459                    &format!("/v2/team/{}/time_entries/{}", team_id, timer_id),
3460                    &body,
3461                )
3462                .await
3463                .map_err(|e| e.to_string())?;
3464            let data = resp.get("data").cloned().unwrap_or(resp);
3465            Ok(compact_items(
3466                &[data],
3467                &["id", "task", "duration", "start", "billable"],
3468            ))
3469        }
3470
3471        "clickup_time_delete" => {
3472            let team_id = resolve_workspace(args)?;
3473            let timer_id = args
3474                .get("timer_id")
3475                .and_then(|v| v.as_str())
3476                .ok_or("Missing required parameter: timer_id")?;
3477            client
3478                .delete(&format!("/v2/team/{}/time_entries/{}", team_id, timer_id))
3479                .await
3480                .map_err(|e| e.to_string())?;
3481            Ok(json!({"message": format!("Time entry {} deleted", timer_id)}))
3482        }
3483
3484        "clickup_view_get" => {
3485            let view_id = args
3486                .get("view_id")
3487                .and_then(|v| v.as_str())
3488                .ok_or("Missing required parameter: view_id")?;
3489            let resp = client
3490                .get(&format!("/v2/view/{}", view_id))
3491                .await
3492                .map_err(|e| e.to_string())?;
3493            let view = resp.get("view").cloned().unwrap_or(resp);
3494            Ok(compact_items(&[view], &["id", "name", "type"]))
3495        }
3496
3497        "clickup_view_create" => {
3498            let scope = args
3499                .get("scope")
3500                .and_then(|v| v.as_str())
3501                .ok_or("Missing required parameter: scope")?;
3502            let scope_id = args
3503                .get("scope_id")
3504                .and_then(|v| v.as_str())
3505                .ok_or("Missing required parameter: scope_id")?;
3506            let name = args
3507                .get("name")
3508                .and_then(|v| v.as_str())
3509                .ok_or("Missing required parameter: name")?;
3510            let view_type = args
3511                .get("type")
3512                .and_then(|v| v.as_str())
3513                .ok_or("Missing required parameter: type")?;
3514            // ClickUp's view-create endpoint requires grouping / divide /
3515            // sorting / filters / columns / team_sidebar / settings. Reuse
3516            // the CLI helper for the documented neutral defaults so the MCP
3517            // tool also succeeds with just name + type.
3518            let body = crate::commands::view::default_view_body(name, view_type);
3519            let resp = client
3520                .post(&format!("/v2/{}/{}/view", scope, scope_id), &body)
3521                .await
3522                .map_err(|e| e.to_string())?;
3523            let view = resp.get("view").cloned().unwrap_or(resp);
3524            Ok(compact_items(&[view], &["id", "name", "type"]))
3525        }
3526
3527        "clickup_view_update" => {
3528            let view_id = args
3529                .get("view_id")
3530                .and_then(|v| v.as_str())
3531                .ok_or("Missing required parameter: view_id")?;
3532            let name = args
3533                .get("name")
3534                .and_then(|v| v.as_str())
3535                .ok_or("Missing required parameter: name")?;
3536            let view_type = args
3537                .get("type")
3538                .and_then(|v| v.as_str())
3539                .ok_or("Missing required parameter: type")?;
3540            let body = json!({"name": name, "type": view_type});
3541            let resp = client
3542                .put(&format!("/v2/view/{}", view_id), &body)
3543                .await
3544                .map_err(|e| e.to_string())?;
3545            let view = resp.get("view").cloned().unwrap_or(resp);
3546            Ok(compact_items(&[view], &["id", "name", "type"]))
3547        }
3548
3549        "clickup_view_delete" => {
3550            let view_id = args
3551                .get("view_id")
3552                .and_then(|v| v.as_str())
3553                .ok_or("Missing required parameter: view_id")?;
3554            client
3555                .delete(&format!("/v2/view/{}", view_id))
3556                .await
3557                .map_err(|e| e.to_string())?;
3558            Ok(json!({"message": format!("View {} deleted", view_id)}))
3559        }
3560
3561        "clickup_doc_create" => {
3562            let team_id = resolve_workspace(args)?;
3563            let name = args
3564                .get("name")
3565                .and_then(|v| v.as_str())
3566                .ok_or("Missing required parameter: name")?;
3567            let mut body = json!({"name": name});
3568            if let Some(parent) = args.get("parent") {
3569                body["parent"] = parent.clone();
3570            }
3571            let resp = client
3572                .post(&format!("/v3/workspaces/{}/docs", team_id), &body)
3573                .await
3574                .map_err(|e| e.to_string())?;
3575            Ok(compact_items(&[resp], &["id", "name"]))
3576        }
3577
3578        "clickup_doc_add_page" => {
3579            let team_id = resolve_workspace(args)?;
3580            let doc_id = args
3581                .get("doc_id")
3582                .and_then(|v| v.as_str())
3583                .ok_or("Missing required parameter: doc_id")?;
3584            let name = args
3585                .get("name")
3586                .and_then(|v| v.as_str())
3587                .ok_or("Missing required parameter: name")?;
3588            let mut body = json!({"name": name});
3589            if let Some(content) = args.get("content").and_then(|v| v.as_str()) {
3590                body["content"] = json!(content);
3591            }
3592            if let Some(subtitle) = args.get("sub_title").and_then(|v| v.as_str()) {
3593                body["sub_title"] = json!(subtitle);
3594            }
3595            if let Some(parent_page_id) = args.get("parent_page_id").and_then(|v| v.as_str()) {
3596                body["parent_page_id"] = json!(parent_page_id);
3597            }
3598            let resp = client
3599                .post(
3600                    &format!("/v3/workspaces/{}/docs/{}/pages", team_id, doc_id),
3601                    &body,
3602                )
3603                .await
3604                .map_err(|e| e.to_string())?;
3605            Ok(compact_items(&[resp], &["id", "name"]))
3606        }
3607
3608        "clickup_doc_edit_page" => {
3609            let team_id = resolve_workspace(args)?;
3610            let doc_id = args
3611                .get("doc_id")
3612                .and_then(|v| v.as_str())
3613                .ok_or("Missing required parameter: doc_id")?;
3614            let page_id = args
3615                .get("page_id")
3616                .and_then(|v| v.as_str())
3617                .ok_or("Missing required parameter: page_id")?;
3618            let mut body = json!({});
3619            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
3620                body["name"] = json!(name);
3621            }
3622            if let Some(content) = args.get("content").and_then(|v| v.as_str()) {
3623                body["content"] = json!(content);
3624            }
3625            if let Some(mode) = args.get("mode").and_then(|v| v.as_str()) {
3626                let allowed = ["replace", "append", "prepend"];
3627                if !allowed.contains(&mode) {
3628                    return Err(format!(
3629                        "Invalid mode '{}'. Valid values: {}",
3630                        mode,
3631                        allowed.join(", ")
3632                    ));
3633                }
3634                body["content_edit_mode"] = json!(mode);
3635            }
3636            let resp = client
3637                .put(
3638                    &format!(
3639                        "/v3/workspaces/{}/docs/{}/pages/{}",
3640                        team_id, doc_id, page_id
3641                    ),
3642                    &body,
3643                )
3644                .await
3645                .map_err(|e| e.to_string())?;
3646            Ok(compact_items(&[resp], &["id", "name"]))
3647        }
3648
3649        "clickup_chat_channel_create" => {
3650            let team_id = resolve_workspace(args)?;
3651            let name = args
3652                .get("name")
3653                .and_then(|v| v.as_str())
3654                .ok_or("Missing required parameter: name")?;
3655            let mut body = json!({"name": name});
3656            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
3657                body["description"] = json!(desc);
3658            }
3659            if let Some(vis) = args.get("visibility").and_then(|v| v.as_str()) {
3660                body["visibility"] = json!(vis);
3661            }
3662            let resp = client
3663                .post(&format!("/v3/workspaces/{}/chat/channels", team_id), &body)
3664                .await
3665                .map_err(|e| e.to_string())?;
3666            Ok(compact_items(&[resp], &["id", "name", "visibility"]))
3667        }
3668
3669        "clickup_chat_channel_get" => {
3670            let team_id = resolve_workspace(args)?;
3671            let channel_id = args
3672                .get("channel_id")
3673                .and_then(|v| v.as_str())
3674                .ok_or("Missing required parameter: channel_id")?;
3675            let resp = client
3676                .get(&format!(
3677                    "/v3/workspaces/{}/chat/channels/{}",
3678                    team_id, channel_id
3679                ))
3680                .await
3681                .map_err(|e| e.to_string())?;
3682            Ok(compact_items(&[resp], &["id", "name", "visibility"]))
3683        }
3684
3685        "clickup_chat_channel_update" => {
3686            let team_id = resolve_workspace(args)?;
3687            let channel_id = args
3688                .get("channel_id")
3689                .and_then(|v| v.as_str())
3690                .ok_or("Missing required parameter: channel_id")?;
3691            let mut body = json!({});
3692            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
3693                body["name"] = json!(name);
3694            }
3695            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
3696                body["description"] = json!(desc);
3697            }
3698            let resp = client
3699                .patch(
3700                    &format!("/v3/workspaces/{}/chat/channels/{}", team_id, channel_id),
3701                    &body,
3702                )
3703                .await
3704                .map_err(|e| e.to_string())?;
3705            Ok(compact_items(&[resp], &["id", "name"]))
3706        }
3707
3708        "clickup_chat_channel_delete" => {
3709            let team_id = resolve_workspace(args)?;
3710            let channel_id = args
3711                .get("channel_id")
3712                .and_then(|v| v.as_str())
3713                .ok_or("Missing required parameter: channel_id")?;
3714            client
3715                .delete(&format!(
3716                    "/v3/workspaces/{}/chat/channels/{}",
3717                    team_id, channel_id
3718                ))
3719                .await
3720                .map_err(|e| e.to_string())?;
3721            Ok(json!({"message": format!("Channel {} deleted", channel_id)}))
3722        }
3723
3724        "clickup_chat_message_list" => {
3725            let team_id = resolve_workspace(args)?;
3726            let channel_id = args
3727                .get("channel_id")
3728                .and_then(|v| v.as_str())
3729                .ok_or("Missing required parameter: channel_id")?;
3730            let mut path = format!(
3731                "/v3/workspaces/{}/chat/channels/{}/messages",
3732                team_id, channel_id
3733            );
3734            if let Some(cursor) = args.get("cursor").and_then(|v| v.as_str()) {
3735                path.push_str(&format!("?cursor={}", cursor));
3736            }
3737            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
3738            // v3 envelope: { "data": [...], "next_cursor": "..." }
3739            // Older shape used "messages" — fall back for safety.
3740            let messages = resp
3741                .get("data")
3742                .or_else(|| resp.get("messages"))
3743                .and_then(|m| m.as_array())
3744                .cloned()
3745                .unwrap_or_default();
3746            Ok(compact_items(&messages, &["id", "content", "date"]))
3747        }
3748
3749        "clickup_chat_message_send" => {
3750            let team_id = resolve_workspace(args)?;
3751            let channel_id = args
3752                .get("channel_id")
3753                .and_then(|v| v.as_str())
3754                .ok_or("Missing required parameter: channel_id")?;
3755            let content = args
3756                .get("content")
3757                .and_then(|v| v.as_str())
3758                .ok_or("Missing required parameter: content")?;
3759            let msg_type = args
3760                .get("type")
3761                .and_then(|v| v.as_str())
3762                .unwrap_or("message");
3763            let body = json!({"content": content, "type": msg_type});
3764            let resp = client
3765                .post(
3766                    &format!(
3767                        "/v3/workspaces/{}/chat/channels/{}/messages",
3768                        team_id, channel_id
3769                    ),
3770                    &body,
3771                )
3772                .await
3773                .map_err(|e| e.to_string())?;
3774            Ok(json!({"message": "Message sent", "id": resp.get("id")}))
3775        }
3776
3777        "clickup_chat_message_delete" => {
3778            let team_id = resolve_workspace(args)?;
3779            let message_id = args
3780                .get("message_id")
3781                .and_then(|v| v.as_str())
3782                .ok_or("Missing required parameter: message_id")?;
3783            client
3784                .delete(&format!(
3785                    "/v3/workspaces/{}/chat/messages/{}",
3786                    team_id, message_id
3787                ))
3788                .await
3789                .map_err(|e| e.to_string())?;
3790            Ok(json!({"message": format!("Message {} deleted", message_id)}))
3791        }
3792
3793        "clickup_chat_dm" => {
3794            let team_id = resolve_workspace(args)?;
3795            let user_ids = args
3796                .get("user_ids")
3797                .and_then(|v| v.as_array())
3798                .ok_or("Missing required parameter: user_ids (array of integers)")?;
3799            if user_ids.is_empty() {
3800                return Err("user_ids must contain at least one user id".to_string());
3801            }
3802            let body = json!({"user_ids": user_ids});
3803            let resp = client
3804                .post(
3805                    &format!("/v3/workspaces/{}/chat/channels/direct_message", team_id),
3806                    &body,
3807                )
3808                .await
3809                .map_err(|e| e.to_string())?;
3810            let channel = resp.get("data").cloned().unwrap_or(resp);
3811            Ok(json!({"message": "DM channel ready", "id": channel.get("id"), "channel": channel}))
3812        }
3813
3814        "clickup_webhook_create" => {
3815            let team_id = resolve_workspace(args)?;
3816            let endpoint = args
3817                .get("endpoint")
3818                .and_then(|v| v.as_str())
3819                .ok_or("Missing required parameter: endpoint")?;
3820            let events = args
3821                .get("events")
3822                .ok_or("Missing required parameter: events")?;
3823            let mut body = json!({"endpoint": endpoint, "events": events});
3824            if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
3825                body["space_id"] = json!(space_id);
3826            }
3827            if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
3828                body["folder_id"] = json!(folder_id);
3829            }
3830            if let Some(list_id) = args.get("list_id").and_then(|v| v.as_str()) {
3831                body["list_id"] = json!(list_id);
3832            }
3833            if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) {
3834                body["task_id"] = json!(task_id);
3835            }
3836            let resp = client
3837                .post(&format!("/v2/team/{}/webhook", team_id), &body)
3838                .await
3839                .map_err(|e| e.to_string())?;
3840            let webhook = resp.get("webhook").cloned().unwrap_or(resp);
3841            Ok(compact_items(
3842                &[webhook],
3843                &["id", "endpoint", "events", "status"],
3844            ))
3845        }
3846
3847        "clickup_webhook_update" => {
3848            let webhook_id = args
3849                .get("webhook_id")
3850                .and_then(|v| v.as_str())
3851                .ok_or("Missing required parameter: webhook_id")?;
3852            let mut body = json!({});
3853            if let Some(endpoint) = args.get("endpoint").and_then(|v| v.as_str()) {
3854                body["endpoint"] = json!(endpoint);
3855            }
3856            if let Some(events) = args.get("events") {
3857                body["events"] = events.clone();
3858            }
3859            if let Some(status) = args.get("status").and_then(|v| v.as_str()) {
3860                body["status"] = json!(status);
3861            }
3862            let resp = client
3863                .put(&format!("/v2/webhook/{}", webhook_id), &body)
3864                .await
3865                .map_err(|e| e.to_string())?;
3866            let webhook = resp.get("webhook").cloned().unwrap_or(resp);
3867            Ok(compact_items(
3868                &[webhook],
3869                &["id", "endpoint", "events", "status"],
3870            ))
3871        }
3872
3873        "clickup_webhook_delete" => {
3874            let webhook_id = args
3875                .get("webhook_id")
3876                .and_then(|v| v.as_str())
3877                .ok_or("Missing required parameter: webhook_id")?;
3878            client
3879                .delete(&format!("/v2/webhook/{}", webhook_id))
3880                .await
3881                .map_err(|e| e.to_string())?;
3882            Ok(json!({"message": format!("Webhook {} deleted", webhook_id)}))
3883        }
3884
3885        "clickup_checklist_add_item" => {
3886            let checklist_id = args
3887                .get("checklist_id")
3888                .and_then(|v| v.as_str())
3889                .ok_or("Missing required parameter: checklist_id")?;
3890            let name = args
3891                .get("name")
3892                .and_then(|v| v.as_str())
3893                .ok_or("Missing required parameter: name")?;
3894            let mut body = json!({"name": name});
3895            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) {
3896                body["assignee"] = json!(assignee);
3897            }
3898            let resp = client
3899                .post(
3900                    &format!("/v2/checklist/{}/checklist_item", checklist_id),
3901                    &body,
3902                )
3903                .await
3904                .map_err(|e| e.to_string())?;
3905            let item = resp.get("checklist").cloned().unwrap_or(resp);
3906            Ok(compact_items(&[item], &["id", "name"]))
3907        }
3908
3909        "clickup_checklist_update_item" => {
3910            let checklist_id = args
3911                .get("checklist_id")
3912                .and_then(|v| v.as_str())
3913                .ok_or("Missing required parameter: checklist_id")?;
3914            let item_id = args
3915                .get("item_id")
3916                .and_then(|v| v.as_str())
3917                .ok_or("Missing required parameter: item_id")?;
3918            let mut body = json!({});
3919            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
3920                body["name"] = json!(name);
3921            }
3922            if let Some(resolved) = args.get("resolved").and_then(|v| v.as_bool()) {
3923                body["resolved"] = json!(resolved);
3924            }
3925            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) {
3926                body["assignee"] = json!(assignee);
3927            }
3928            client
3929                .put(
3930                    &format!("/v2/checklist/{}/checklist_item/{}", checklist_id, item_id),
3931                    &body,
3932                )
3933                .await
3934                .map_err(|e| e.to_string())?;
3935            Ok(json!({"message": format!("Checklist item {} updated", item_id)}))
3936        }
3937
3938        "clickup_checklist_delete_item" => {
3939            let checklist_id = args
3940                .get("checklist_id")
3941                .and_then(|v| v.as_str())
3942                .ok_or("Missing required parameter: checklist_id")?;
3943            let item_id = args
3944                .get("item_id")
3945                .and_then(|v| v.as_str())
3946                .ok_or("Missing required parameter: item_id")?;
3947            client
3948                .delete(&format!(
3949                    "/v2/checklist/{}/checklist_item/{}",
3950                    checklist_id, item_id
3951                ))
3952                .await
3953                .map_err(|e| e.to_string())?;
3954            Ok(json!({"message": format!("Checklist item {} deleted", item_id)}))
3955        }
3956
3957        "clickup_user_get" => {
3958            let team_id = resolve_workspace(args)?;
3959            let user_id = args
3960                .get("user_id")
3961                .and_then(|v| v.as_i64())
3962                .ok_or("Missing required parameter: user_id")?;
3963            let resp = client
3964                .get(&format!("/v2/team/{}/user/{}", team_id, user_id))
3965                .await
3966                .map_err(|e| e.to_string())?;
3967            let member = resp.get("member").cloned().unwrap_or(resp);
3968            Ok(compact_items(&[member], &["user", "role"]))
3969        }
3970
3971        "clickup_workspace_seats" => {
3972            let team_id = resolve_workspace(args)?;
3973            let resp = client
3974                .get(&format!("/v2/team/{}/seats", team_id))
3975                .await
3976                .map_err(|e| e.to_string())?;
3977            Ok(json!(resp))
3978        }
3979
3980        "clickup_workspace_plan" => {
3981            let team_id = resolve_workspace(args)?;
3982            let resp = client
3983                .get(&format!("/v2/team/{}/plan", team_id))
3984                .await
3985                .map_err(|e| e.to_string())?;
3986            Ok(json!(resp))
3987        }
3988
3989        "clickup_tag_create" => {
3990            let space_id = args
3991                .get("space_id")
3992                .and_then(|v| v.as_str())
3993                .ok_or("Missing required parameter: space_id")?;
3994            let name = args
3995                .get("name")
3996                .and_then(|v| v.as_str())
3997                .ok_or("Missing required parameter: name")?;
3998            let mut tag = json!({"name": name});
3999            if let Some(fg) = args.get("tag_fg").and_then(|v| v.as_str()) {
4000                tag["tag_fg"] = json!(fg);
4001            }
4002            if let Some(bg) = args.get("tag_bg").and_then(|v| v.as_str()) {
4003                tag["tag_bg"] = json!(bg);
4004            }
4005            let body = json!({"tag": tag});
4006            client
4007                .post(&format!("/v2/space/{}/tag", space_id), &body)
4008                .await
4009                .map_err(|e| e.to_string())?;
4010            Ok(json!({"message": format!("Tag '{}' created in space {}", name, space_id)}))
4011        }
4012
4013        "clickup_tag_update" => {
4014            let space_id = args
4015                .get("space_id")
4016                .and_then(|v| v.as_str())
4017                .ok_or("Missing required parameter: space_id")?;
4018            let tag_name = args
4019                .get("tag_name")
4020                .and_then(|v| v.as_str())
4021                .ok_or("Missing required parameter: tag_name")?;
4022            let mut tag = json!({});
4023            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
4024                tag["name"] = json!(name);
4025            }
4026            // ClickUp's tag UPDATE endpoint uses `fg_color` / `bg_color`,
4027            // unlike CREATE which uses `tag_fg` / `tag_bg`. (Quirk confirmed
4028            // against the OpenAPI spec.) Keep the input arg names matching
4029            // CREATE for caller ergonomics; translate on the wire.
4030            if let Some(fg) = args.get("tag_fg").and_then(|v| v.as_str()) {
4031                tag["fg_color"] = json!(fg);
4032            }
4033            if let Some(bg) = args.get("tag_bg").and_then(|v| v.as_str()) {
4034                tag["bg_color"] = json!(bg);
4035            }
4036            let body = json!({"tag": tag});
4037            client
4038                .put(&format!("/v2/space/{}/tag/{}", space_id, tag_name), &body)
4039                .await
4040                .map_err(|e| e.to_string())?;
4041            Ok(json!({"message": format!("Tag '{}' updated", tag_name)}))
4042        }
4043
4044        "clickup_tag_delete" => {
4045            let space_id = args
4046                .get("space_id")
4047                .and_then(|v| v.as_str())
4048                .ok_or("Missing required parameter: space_id")?;
4049            let tag_name = args
4050                .get("tag_name")
4051                .and_then(|v| v.as_str())
4052                .ok_or("Missing required parameter: tag_name")?;
4053            client
4054                .delete(&format!("/v2/space/{}/tag/{}", space_id, tag_name))
4055                .await
4056                .map_err(|e| e.to_string())?;
4057            Ok(json!({"message": format!("Tag '{}' deleted from space {}", tag_name, space_id)}))
4058        }
4059
4060        "clickup_field_unset" => {
4061            let (task_id, custom_q) = resolve_task(args, "task_id")?;
4062            let field_id = args
4063                .get("field_id")
4064                .and_then(|v| v.as_str())
4065                .ok_or("Missing required parameter: field_id")?;
4066            let path = match custom_q {
4067                Some(q) => format!("/v2/task/{}/field/{}?{}", task_id, field_id, q),
4068                None => format!("/v2/task/{}/field/{}", task_id, field_id),
4069            };
4070            client.delete(&path).await.map_err(|e| e.to_string())?;
4071            Ok(json!({"message": format!("Field {} unset on task {}", field_id, task_id)}))
4072        }
4073
4074        "clickup_attachment_list" => {
4075            let (task_id, custom_q) = resolve_task(args, "task_id")?;
4076            // ClickUp has no dedicated list-attachments endpoint. The `attachments`
4077            // array is returned inline by GET /v2/task/{id}, per the API docs.
4078            let path = match custom_q {
4079                Some(q) => format!("/v2/task/{}?{}", task_id, q),
4080                None => format!("/v2/task/{}", task_id),
4081            };
4082            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
4083            let attachments = resp
4084                .get("attachments")
4085                .and_then(|a| a.as_array())
4086                .cloned()
4087                .unwrap_or_default();
4088            Ok(compact_items(&attachments, &["id", "title", "url", "date"]))
4089        }
4090
4091        "clickup_shared_list" => {
4092            let team_id = resolve_workspace(args)?;
4093            let resp = client
4094                .get(&format!("/v2/team/{}/shared", team_id))
4095                .await
4096                .map_err(|e| e.to_string())?;
4097            Ok(json!(resp))
4098        }
4099
4100        "clickup_group_list" => {
4101            let team_id = resolve_workspace(args)?;
4102            let mut qs = format!("team_id={}", team_id);
4103            if let Some(group_ids) = args.get("group_ids").and_then(|v| v.as_array()) {
4104                for id in group_ids {
4105                    if let Some(id) = id.as_str() {
4106                        qs.push_str(&format!("&group_ids[]={}", id));
4107                    }
4108                }
4109            }
4110            let resp = client
4111                .get(&format!("/v2/group?{}", qs))
4112                .await
4113                .map_err(|e| e.to_string())?;
4114            let groups = resp
4115                .get("groups")
4116                .and_then(|g| g.as_array())
4117                .cloned()
4118                .unwrap_or_default();
4119            Ok(compact_items(&groups, &["id", "name", "members"]))
4120        }
4121
4122        "clickup_group_create" => {
4123            let team_id = resolve_workspace(args)?;
4124            let name = args
4125                .get("name")
4126                .and_then(|v| v.as_str())
4127                .ok_or("Missing required parameter: name")?;
4128            let mut body = json!({"name": name});
4129            if let Some(members) = args.get("member_ids") {
4130                body["members"] = members.clone();
4131            }
4132            let resp = client
4133                .post(&format!("/v2/team/{}/group", team_id), &body)
4134                .await
4135                .map_err(|e| e.to_string())?;
4136            Ok(compact_items(&[resp], &["id", "name"]))
4137        }
4138
4139        "clickup_group_update" => {
4140            let group_id = args
4141                .get("group_id")
4142                .and_then(|v| v.as_str())
4143                .ok_or("Missing required parameter: group_id")?;
4144            let mut body = json!({});
4145            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
4146                body["name"] = json!(name);
4147            }
4148            if let Some(add) = args.get("add_members") {
4149                body["members"] = json!({"add": add, "rem": args.get("rem_members").cloned().unwrap_or(json!([]))});
4150            } else if let Some(rem) = args.get("rem_members") {
4151                body["members"] = json!({"add": [], "rem": rem});
4152            }
4153            let resp = client
4154                .put(&format!("/v2/group/{}", group_id), &body)
4155                .await
4156                .map_err(|e| e.to_string())?;
4157            Ok(compact_items(&[resp], &["id", "name"]))
4158        }
4159
4160        "clickup_group_delete" => {
4161            let group_id = args
4162                .get("group_id")
4163                .and_then(|v| v.as_str())
4164                .ok_or("Missing required parameter: group_id")?;
4165            client
4166                .delete(&format!("/v2/group/{}", group_id))
4167                .await
4168                .map_err(|e| e.to_string())?;
4169            Ok(json!({"message": format!("Group {} deleted", group_id)}))
4170        }
4171
4172        "clickup_role_list" => {
4173            let team_id = resolve_workspace(args)?;
4174            let resp = client
4175                .get(&format!("/v2/team/{}/customroles", team_id))
4176                .await
4177                .map_err(|e| e.to_string())?;
4178            let roles = resp
4179                .get("roles")
4180                .and_then(|r| r.as_array())
4181                .cloned()
4182                .unwrap_or_default();
4183            Ok(compact_items(&roles, &["id", "name"]))
4184        }
4185
4186        "clickup_guest_get" => {
4187            let team_id = resolve_workspace(args)?;
4188            let guest_id = args
4189                .get("guest_id")
4190                .and_then(|v| v.as_i64())
4191                .ok_or("Missing required parameter: guest_id")?;
4192            let resp = client
4193                .get(&format!("/v2/team/{}/guest/{}", team_id, guest_id))
4194                .await
4195                .map_err(|e| e.to_string())?;
4196            let guest = resp.get("guest").cloned().unwrap_or(resp);
4197            Ok(compact_items(&[guest], &["user", "role"]))
4198        }
4199
4200        "clickup_task_time_in_status" => {
4201            let (task_id, custom_q) = resolve_task(args, "task_id")?;
4202            let path = match custom_q {
4203                Some(q) => format!("/v2/task/{}/time_in_status?{}", task_id, q),
4204                None => format!("/v2/task/{}/time_in_status", task_id),
4205            };
4206            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
4207            Ok(resp)
4208        }
4209
4210        "clickup_task_move" => {
4211            let team_id = resolve_workspace(args)?;
4212            let task_id = args
4213                .get("task_id")
4214                .and_then(|v| v.as_str())
4215                .ok_or("Missing required parameter: task_id")?;
4216            let list_id = args
4217                .get("list_id")
4218                .and_then(|v| v.as_str())
4219                .ok_or("Missing required parameter: list_id")?;
4220            client
4221                .put(
4222                    &format!(
4223                        "/v3/workspaces/{}/tasks/{}/home_list/{}",
4224                        team_id, task_id, list_id
4225                    ),
4226                    &json!({}),
4227                )
4228                .await
4229                .map_err(|e| e.to_string())?;
4230            Ok(json!({"message": format!("Task {} moved to list {}", task_id, list_id)}))
4231        }
4232
4233        "clickup_task_set_estimate" => {
4234            let team_id = resolve_workspace(args)?;
4235            let task_id = args
4236                .get("task_id")
4237                .and_then(|v| v.as_str())
4238                .ok_or("Missing required parameter: task_id")?;
4239            let user_id = args
4240                .get("user_id")
4241                .and_then(|v| v.as_i64())
4242                .ok_or("Missing required parameter: user_id")?;
4243            let time_estimate = args
4244                .get("time_estimate")
4245                .and_then(|v| v.as_i64())
4246                .ok_or("Missing required parameter: time_estimate")?;
4247            let body =
4248                json!({"time_estimates": [{"user_id": user_id, "time_estimate": time_estimate}]});
4249            client
4250                .patch(
4251                    &format!(
4252                        "/v3/workspaces/{}/tasks/{}/time_estimates_by_user",
4253                        team_id, task_id
4254                    ),
4255                    &body,
4256                )
4257                .await
4258                .map_err(|e| e.to_string())?;
4259            Ok(json!({"message": format!("Time estimate set for task {}", task_id)}))
4260        }
4261
4262        "clickup_task_replace_estimates" => {
4263            let team_id = resolve_workspace(args)?;
4264            let task_id = args
4265                .get("task_id")
4266                .and_then(|v| v.as_str())
4267                .ok_or("Missing required parameter: task_id")?;
4268            // ClickUp's spec body is an ARRAY of {assignee, time}.
4269            // The previous shape {time_estimates: [{user_id, time_estimate}]}
4270            // had the wrong field names and the wrong wrapping, and it only
4271            // accepted a single user, silently erasing all other estimates.
4272            let estimates = args
4273                .get("estimates")
4274                .and_then(|v| v.as_array())
4275                .ok_or("Missing required parameter: estimates (array of {assignee, time})")?;
4276            if estimates.is_empty() {
4277                return Err(
4278                    "estimates must contain at least one {assignee, time} entry".to_string()
4279                );
4280            }
4281            let body = Value::Array(estimates.clone());
4282            client
4283                .put(
4284                    &format!(
4285                        "/v3/workspaces/{}/tasks/{}/time_estimates_by_user",
4286                        team_id, task_id
4287                    ),
4288                    &body,
4289                )
4290                .await
4291                .map_err(|e| e.to_string())?;
4292            Ok(json!({"message": format!("Time estimates replaced for task {}", task_id)}))
4293        }
4294
4295        "clickup_auth_check" => {
4296            client.get("/v2/user").await.map_err(|e| e.to_string())?;
4297            Ok(json!({"message": "Token valid"}))
4298        }
4299
4300        "clickup_checklist_update" => {
4301            let checklist_id = args
4302                .get("checklist_id")
4303                .and_then(|v| v.as_str())
4304                .ok_or("Missing required parameter: checklist_id")?;
4305            let mut body = json!({});
4306            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
4307                body["name"] = json!(name);
4308            }
4309            if let Some(position) = args.get("position").and_then(|v| v.as_i64()) {
4310                body["position"] = json!(position);
4311            }
4312            let resp = client
4313                .put(&format!("/v2/checklist/{}", checklist_id), &body)
4314                .await
4315                .map_err(|e| e.to_string())?;
4316            let checklist = resp.get("checklist").cloned().unwrap_or(resp);
4317            Ok(compact_items(&[checklist], &["id", "name"]))
4318        }
4319
4320        "clickup_comment_replies" => {
4321            let comment_id = args
4322                .get("comment_id")
4323                .and_then(|v| v.as_str())
4324                .ok_or("Missing required parameter: comment_id")?;
4325            let resp = client
4326                .get(&format!("/v2/comment/{}/reply", comment_id))
4327                .await
4328                .map_err(|e| e.to_string())?;
4329            let comments = resp
4330                .get("comments")
4331                .or_else(|| resp.get("replies"))
4332                .and_then(|c| c.as_array())
4333                .cloned()
4334                .unwrap_or_default();
4335            Ok(compact_items(
4336                &comments,
4337                &["id", "user", "date", "comment_text"],
4338            ))
4339        }
4340
4341        "clickup_comment_reply" => {
4342            let comment_id = args
4343                .get("comment_id")
4344                .and_then(|v| v.as_str())
4345                .ok_or("Missing required parameter: comment_id")?;
4346            let text = args
4347                .get("text")
4348                .and_then(|v| v.as_str())
4349                .ok_or("Missing required parameter: text")?;
4350            let mut body = json!({"comment_text": text});
4351            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) {
4352                body["assignee"] = json!(assignee);
4353            }
4354            let resp = client
4355                .post(&format!("/v2/comment/{}/reply", comment_id), &body)
4356                .await
4357                .map_err(|e| e.to_string())?;
4358            Ok(json!({"message": "Reply posted", "id": resp.get("id")}))
4359        }
4360
4361        "clickup_chat_channel_list" => {
4362            let team_id = resolve_workspace(args)?;
4363            let mut path = format!("/v3/workspaces/{}/chat/channels", team_id);
4364            if let Some(include_closed) = args.get("include_closed").and_then(|v| v.as_bool()) {
4365                path.push_str(&format!("?include_closed={}", include_closed));
4366            }
4367            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
4368            // v3 envelope wraps the list in "data"; older shape used "channels".
4369            let channels = resp
4370                .get("data")
4371                .or_else(|| resp.get("channels"))
4372                .and_then(|c| c.as_array())
4373                .cloned()
4374                .unwrap_or_default();
4375            Ok(compact_items(&channels, &["id", "name", "type"]))
4376        }
4377
4378        "clickup_chat_channel_followers" => {
4379            let team_id = resolve_workspace(args)?;
4380            let channel_id = args
4381                .get("channel_id")
4382                .and_then(|v| v.as_str())
4383                .ok_or("Missing required parameter: channel_id")?;
4384            let resp = client
4385                .get(&format!(
4386                    "/v3/workspaces/{}/chat/channels/{}/followers",
4387                    team_id, channel_id
4388                ))
4389                .await
4390                .map_err(|e| e.to_string())?;
4391            Ok(resp)
4392        }
4393
4394        "clickup_chat_channel_members" => {
4395            let team_id = resolve_workspace(args)?;
4396            let channel_id = args
4397                .get("channel_id")
4398                .and_then(|v| v.as_str())
4399                .ok_or("Missing required parameter: channel_id")?;
4400            let resp = client
4401                .get(&format!(
4402                    "/v3/workspaces/{}/chat/channels/{}/members",
4403                    team_id, channel_id
4404                ))
4405                .await
4406                .map_err(|e| e.to_string())?;
4407            Ok(resp)
4408        }
4409
4410        "clickup_chat_message_update" => {
4411            let team_id = resolve_workspace(args)?;
4412            let message_id = args
4413                .get("message_id")
4414                .and_then(|v| v.as_str())
4415                .ok_or("Missing required parameter: message_id")?;
4416            let text = args
4417                .get("text")
4418                .and_then(|v| v.as_str())
4419                .ok_or("Missing required parameter: text")?;
4420            let body = json!({"content": text});
4421            client
4422                .patch(
4423                    &format!("/v3/workspaces/{}/chat/messages/{}", team_id, message_id),
4424                    &body,
4425                )
4426                .await
4427                .map_err(|e| e.to_string())?;
4428            Ok(json!({"message": format!("Message {} updated", message_id)}))
4429        }
4430
4431        "clickup_chat_reaction_list" => {
4432            let team_id = resolve_workspace(args)?;
4433            let message_id = args
4434                .get("message_id")
4435                .and_then(|v| v.as_str())
4436                .ok_or("Missing required parameter: message_id")?;
4437            let resp = client
4438                .get(&format!(
4439                    "/v3/workspaces/{}/chat/messages/{}/reactions",
4440                    team_id, message_id
4441                ))
4442                .await
4443                .map_err(|e| e.to_string())?;
4444            Ok(resp)
4445        }
4446
4447        "clickup_chat_reaction_add" => {
4448            let team_id = resolve_workspace(args)?;
4449            let message_id = args
4450                .get("message_id")
4451                .and_then(|v| v.as_str())
4452                .ok_or("Missing required parameter: message_id")?;
4453            let emoji = args
4454                .get("emoji")
4455                .and_then(|v| v.as_str())
4456                .ok_or("Missing required parameter: emoji")?;
4457            let body = json!({"reaction": emoji});
4458            client
4459                .post(
4460                    &format!(
4461                        "/v3/workspaces/{}/chat/messages/{}/reactions",
4462                        team_id, message_id
4463                    ),
4464                    &body,
4465                )
4466                .await
4467                .map_err(|e| e.to_string())?;
4468            Ok(json!({"message": format!("Reaction '{}' added to message {}", emoji, message_id)}))
4469        }
4470
4471        "clickup_chat_reaction_remove" => {
4472            let team_id = resolve_workspace(args)?;
4473            let message_id = args
4474                .get("message_id")
4475                .and_then(|v| v.as_str())
4476                .ok_or("Missing required parameter: message_id")?;
4477            let emoji = args
4478                .get("emoji")
4479                .and_then(|v| v.as_str())
4480                .ok_or("Missing required parameter: emoji")?;
4481            // Emoji typically contain bytes outside the URL path's unreserved
4482            // set; percent-encode the segment so the request is well-formed.
4483            let encoded_emoji = encode_query_value(emoji);
4484            client
4485                .delete(&format!(
4486                    "/v3/workspaces/{}/chat/messages/{}/reactions/{}",
4487                    team_id, message_id, encoded_emoji
4488                ))
4489                .await
4490                .map_err(|e| e.to_string())?;
4491            Ok(
4492                json!({"message": format!("Reaction '{}' removed from message {}", emoji, message_id)}),
4493            )
4494        }
4495
4496        "clickup_chat_reply_list" => {
4497            let team_id = resolve_workspace(args)?;
4498            let message_id = args
4499                .get("message_id")
4500                .and_then(|v| v.as_str())
4501                .ok_or("Missing required parameter: message_id")?;
4502            let resp = client
4503                .get(&format!(
4504                    "/v3/workspaces/{}/chat/messages/{}/replies",
4505                    team_id, message_id
4506                ))
4507                .await
4508                .map_err(|e| e.to_string())?;
4509            // v3 envelope: { "data": [...], "next_cursor": "..." }
4510            // Older shape used "replies"; bare array also seen in practice.
4511            let replies = resp
4512                .get("data")
4513                .or_else(|| resp.get("replies"))
4514                .and_then(|v| v.as_array())
4515                .cloned()
4516                .unwrap_or_else(|| resp.as_array().cloned().unwrap_or_default());
4517            Ok(compact_items(&replies, &["id", "content", "date"]))
4518        }
4519
4520        "clickup_chat_reply_send" => {
4521            let team_id = resolve_workspace(args)?;
4522            let message_id = args
4523                .get("message_id")
4524                .and_then(|v| v.as_str())
4525                .ok_or("Missing required parameter: message_id")?;
4526            let text = args
4527                .get("text")
4528                .and_then(|v| v.as_str())
4529                .ok_or("Missing required parameter: text")?;
4530            let body = json!({"content": text});
4531            let resp = client
4532                .post(
4533                    &format!(
4534                        "/v3/workspaces/{}/chat/messages/{}/replies",
4535                        team_id, message_id
4536                    ),
4537                    &body,
4538                )
4539                .await
4540                .map_err(|e| e.to_string())?;
4541            Ok(json!({"message": "Reply sent", "id": resp.get("id")}))
4542        }
4543
4544        "clickup_chat_tagged_users" => {
4545            let team_id = resolve_workspace(args)?;
4546            let message_id = args
4547                .get("message_id")
4548                .and_then(|v| v.as_str())
4549                .ok_or("Missing required parameter: message_id")?;
4550            let resp = client
4551                .get(&format!(
4552                    "/v3/workspaces/{}/chat/messages/{}/tagged_users",
4553                    team_id, message_id
4554                ))
4555                .await
4556                .map_err(|e| e.to_string())?;
4557            Ok(resp)
4558        }
4559
4560        "clickup_time_current" => {
4561            let team_id = resolve_workspace(args)?;
4562            let resp = client
4563                .get(&format!("/v2/team/{}/time_entries/current", team_id))
4564                .await
4565                .map_err(|e| e.to_string())?;
4566            let data = resp.get("data").cloned().unwrap_or(resp);
4567            Ok(compact_items(
4568                &[data],
4569                &["id", "task", "duration", "start", "billable"],
4570            ))
4571        }
4572
4573        "clickup_time_tags" => {
4574            let team_id = resolve_workspace(args)?;
4575            let resp = client
4576                .get(&format!("/v2/team/{}/time_entries/tags", team_id))
4577                .await
4578                .map_err(|e| e.to_string())?;
4579            let tags = resp
4580                .get("data")
4581                .and_then(|d| d.as_array())
4582                .cloned()
4583                .unwrap_or_default();
4584            Ok(compact_items(&tags, &["name"]))
4585        }
4586
4587        "clickup_time_add_tags" => {
4588            let team_id = resolve_workspace(args)?;
4589            let entry_ids = args
4590                .get("entry_ids")
4591                .and_then(|v| v.as_array())
4592                .ok_or("Missing required parameter: entry_ids")?;
4593            let tag_names = args
4594                .get("tag_names")
4595                .and_then(|v| v.as_array())
4596                .ok_or("Missing required parameter: tag_names")?;
4597            let tags: Vec<Value> = tag_names
4598                .iter()
4599                .filter_map(|n| n.as_str())
4600                .map(|n| json!({"name": n}))
4601                .collect();
4602            let body = json!({"time_entry_ids": entry_ids, "tags": tags});
4603            client
4604                .post(&format!("/v2/team/{}/time_entries/tags", team_id), &body)
4605                .await
4606                .map_err(|e| e.to_string())?;
4607            Ok(json!({"message": "Tags added to time entries"}))
4608        }
4609
4610        "clickup_time_remove_tags" => {
4611            let team_id = resolve_workspace(args)?;
4612            let entry_ids = args
4613                .get("entry_ids")
4614                .and_then(|v| v.as_array())
4615                .ok_or("Missing required parameter: entry_ids")?;
4616            let tag_names = args
4617                .get("tag_names")
4618                .and_then(|v| v.as_array())
4619                .ok_or("Missing required parameter: tag_names")?;
4620            let tags: Vec<Value> = tag_names
4621                .iter()
4622                .filter_map(|n| n.as_str())
4623                .map(|n| json!({"name": n}))
4624                .collect();
4625            let body = json!({"time_entry_ids": entry_ids, "tags": tags});
4626            client
4627                .delete_with_body(&format!("/v2/team/{}/time_entries/tags", team_id), &body)
4628                .await
4629                .map_err(|e| e.to_string())?;
4630            Ok(json!({"message": "Tags removed from time entries"}))
4631        }
4632
4633        "clickup_time_rename_tag" => {
4634            let team_id = resolve_workspace(args)?;
4635            let name = args
4636                .get("name")
4637                .and_then(|v| v.as_str())
4638                .ok_or("Missing required parameter: name")?;
4639            let new_name = args
4640                .get("new_name")
4641                .and_then(|v| v.as_str())
4642                .ok_or("Missing required parameter: new_name")?;
4643            // ClickUp's spec marks tag_bg and tag_fg as required on the
4644            // PUT /v2/team/{ws}/time_entries/tags endpoint, even when the
4645            // caller only wants to rename. Callers can repeat the existing
4646            // hex colours to leave them unchanged.
4647            let tag_bg = args
4648                .get("tag_bg")
4649                .and_then(|v| v.as_str())
4650                .ok_or("Missing required parameter: tag_bg")?;
4651            let tag_fg = args
4652                .get("tag_fg")
4653                .and_then(|v| v.as_str())
4654                .ok_or("Missing required parameter: tag_fg")?;
4655            let body =
4656                json!({"name": name, "new_name": new_name, "tag_bg": tag_bg, "tag_fg": tag_fg});
4657            client
4658                .put(&format!("/v2/team/{}/time_entries/tags", team_id), &body)
4659                .await
4660                .map_err(|e| e.to_string())?;
4661            Ok(json!({"message": format!("Tag '{}' renamed to '{}'", name, new_name)}))
4662        }
4663
4664        "clickup_time_history" => {
4665            let team_id = resolve_workspace(args)?;
4666            let timer_id = args
4667                .get("timer_id")
4668                .and_then(|v| v.as_str())
4669                .ok_or("Missing required parameter: timer_id")?;
4670            let resp = client
4671                .get(&format!(
4672                    "/v2/team/{}/time_entries/{}/history",
4673                    team_id, timer_id
4674                ))
4675                .await
4676                .map_err(|e| e.to_string())?;
4677            Ok(resp)
4678        }
4679
4680        "clickup_guest_invite" => {
4681            let team_id = resolve_workspace(args)?;
4682            let email = args
4683                .get("email")
4684                .and_then(|v| v.as_str())
4685                .ok_or("Missing required parameter: email")?;
4686            let mut body = json!({"email": email});
4687            if let Some(v) = args.get("can_edit_tags").and_then(|v| v.as_bool()) {
4688                body["can_edit_tags"] = json!(v);
4689            }
4690            if let Some(v) = args.get("can_see_time_spent").and_then(|v| v.as_bool()) {
4691                body["can_see_time_spent"] = json!(v);
4692            }
4693            if let Some(v) = args.get("can_create_views").and_then(|v| v.as_bool()) {
4694                body["can_create_views"] = json!(v);
4695            }
4696            let resp = client
4697                .post(&format!("/v2/team/{}/guest", team_id), &body)
4698                .await
4699                .map_err(|e| e.to_string())?;
4700            let guest = resp.get("guest").cloned().unwrap_or(resp);
4701            let user = guest.get("user").cloned().unwrap_or(guest);
4702            Ok(compact_items(&[user], &["id", "email"]))
4703        }
4704
4705        "clickup_guest_update" => {
4706            let team_id = resolve_workspace(args)?;
4707            let guest_id = args
4708                .get("guest_id")
4709                .and_then(|v| v.as_i64())
4710                .ok_or("Missing required parameter: guest_id")?;
4711            let mut body = json!({});
4712            if let Some(v) = args.get("can_edit_tags").and_then(|v| v.as_bool()) {
4713                body["can_edit_tags"] = json!(v);
4714            }
4715            if let Some(v) = args.get("can_see_time_spent").and_then(|v| v.as_bool()) {
4716                body["can_see_time_spent"] = json!(v);
4717            }
4718            if let Some(v) = args.get("can_create_views").and_then(|v| v.as_bool()) {
4719                body["can_create_views"] = json!(v);
4720            }
4721            client
4722                .put(&format!("/v2/team/{}/guest/{}", team_id, guest_id), &body)
4723                .await
4724                .map_err(|e| e.to_string())?;
4725            Ok(json!({"message": format!("Guest {} updated", guest_id)}))
4726        }
4727
4728        "clickup_guest_remove" => {
4729            let team_id = resolve_workspace(args)?;
4730            let guest_id = args
4731                .get("guest_id")
4732                .and_then(|v| v.as_i64())
4733                .ok_or("Missing required parameter: guest_id")?;
4734            client
4735                .delete(&format!("/v2/team/{}/guest/{}", team_id, guest_id))
4736                .await
4737                .map_err(|e| e.to_string())?;
4738            Ok(json!({"message": format!("Guest {} removed", guest_id)}))
4739        }
4740
4741        "clickup_guest_share_task" => {
4742            let task_id = args
4743                .get("task_id")
4744                .and_then(|v| v.as_str())
4745                .ok_or("Missing required parameter: task_id")?;
4746            let guest_id = args
4747                .get("guest_id")
4748                .and_then(|v| v.as_i64())
4749                .ok_or("Missing required parameter: guest_id")?;
4750            let permission = args
4751                .get("permission")
4752                .and_then(|v| v.as_str())
4753                .ok_or("Missing required parameter: permission")?;
4754            let body = json!({"permission_level": permission});
4755            client
4756                .post(&format!("/v2/task/{}/guest/{}", task_id, guest_id), &body)
4757                .await
4758                .map_err(|e| e.to_string())?;
4759            Ok(json!({"message": format!("Task {} shared with guest {}", task_id, guest_id)}))
4760        }
4761
4762        "clickup_guest_unshare_task" => {
4763            let task_id = args
4764                .get("task_id")
4765                .and_then(|v| v.as_str())
4766                .ok_or("Missing required parameter: task_id")?;
4767            let guest_id = args
4768                .get("guest_id")
4769                .and_then(|v| v.as_i64())
4770                .ok_or("Missing required parameter: guest_id")?;
4771            client
4772                .delete(&format!("/v2/task/{}/guest/{}", task_id, guest_id))
4773                .await
4774                .map_err(|e| e.to_string())?;
4775            Ok(json!({"message": format!("Guest {} unshared from task {}", guest_id, task_id)}))
4776        }
4777
4778        "clickup_guest_share_list" => {
4779            let list_id = args
4780                .get("list_id")
4781                .and_then(|v| v.as_str())
4782                .ok_or("Missing required parameter: list_id")?;
4783            let guest_id = args
4784                .get("guest_id")
4785                .and_then(|v| v.as_i64())
4786                .ok_or("Missing required parameter: guest_id")?;
4787            let permission = args
4788                .get("permission")
4789                .and_then(|v| v.as_str())
4790                .ok_or("Missing required parameter: permission")?;
4791            let body = json!({"permission_level": permission});
4792            client
4793                .post(&format!("/v2/list/{}/guest/{}", list_id, guest_id), &body)
4794                .await
4795                .map_err(|e| e.to_string())?;
4796            Ok(json!({"message": format!("List {} shared with guest {}", list_id, guest_id)}))
4797        }
4798
4799        "clickup_guest_unshare_list" => {
4800            let list_id = args
4801                .get("list_id")
4802                .and_then(|v| v.as_str())
4803                .ok_or("Missing required parameter: list_id")?;
4804            let guest_id = args
4805                .get("guest_id")
4806                .and_then(|v| v.as_i64())
4807                .ok_or("Missing required parameter: guest_id")?;
4808            client
4809                .delete(&format!("/v2/list/{}/guest/{}", list_id, guest_id))
4810                .await
4811                .map_err(|e| e.to_string())?;
4812            Ok(json!({"message": format!("Guest {} unshared from list {}", guest_id, list_id)}))
4813        }
4814
4815        "clickup_guest_share_folder" => {
4816            let folder_id = args
4817                .get("folder_id")
4818                .and_then(|v| v.as_str())
4819                .ok_or("Missing required parameter: folder_id")?;
4820            let guest_id = args
4821                .get("guest_id")
4822                .and_then(|v| v.as_i64())
4823                .ok_or("Missing required parameter: guest_id")?;
4824            let permission = args
4825                .get("permission")
4826                .and_then(|v| v.as_str())
4827                .ok_or("Missing required parameter: permission")?;
4828            let body = json!({"permission_level": permission});
4829            client
4830                .post(
4831                    &format!("/v2/folder/{}/guest/{}", folder_id, guest_id),
4832                    &body,
4833                )
4834                .await
4835                .map_err(|e| e.to_string())?;
4836            Ok(json!({"message": format!("Folder {} shared with guest {}", folder_id, guest_id)}))
4837        }
4838
4839        "clickup_guest_unshare_folder" => {
4840            let folder_id = args
4841                .get("folder_id")
4842                .and_then(|v| v.as_str())
4843                .ok_or("Missing required parameter: folder_id")?;
4844            let guest_id = args
4845                .get("guest_id")
4846                .and_then(|v| v.as_i64())
4847                .ok_or("Missing required parameter: guest_id")?;
4848            client
4849                .delete(&format!("/v2/folder/{}/guest/{}", folder_id, guest_id))
4850                .await
4851                .map_err(|e| e.to_string())?;
4852            Ok(json!({"message": format!("Guest {} unshared from folder {}", guest_id, folder_id)}))
4853        }
4854
4855        "clickup_user_invite" => {
4856            let team_id = resolve_workspace(args)?;
4857            let email = args
4858                .get("email")
4859                .and_then(|v| v.as_str())
4860                .ok_or("Missing required parameter: email")?;
4861            let mut body = json!({"email": email});
4862            if let Some(admin) = args.get("admin").and_then(|v| v.as_bool()) {
4863                body["admin"] = json!(admin);
4864            }
4865            let resp = client
4866                .post(&format!("/v2/team/{}/user", team_id), &body)
4867                .await
4868                .map_err(|e| e.to_string())?;
4869            let member = resp.get("member").cloned().unwrap_or(resp);
4870            let user = member.get("user").cloned().unwrap_or(member);
4871            Ok(compact_items(&[user], &["id", "username", "email"]))
4872        }
4873
4874        "clickup_user_update" => {
4875            let team_id = resolve_workspace(args)?;
4876            let user_id = args
4877                .get("user_id")
4878                .and_then(|v| v.as_i64())
4879                .ok_or("Missing required parameter: user_id")?;
4880            let mut body = json!({});
4881            if let Some(username) = args.get("username").and_then(|v| v.as_str()) {
4882                body["username"] = json!(username);
4883            }
4884            if let Some(admin) = args.get("admin").and_then(|v| v.as_bool()) {
4885                body["admin"] = json!(admin);
4886            }
4887            client
4888                .put(&format!("/v2/team/{}/user/{}", team_id, user_id), &body)
4889                .await
4890                .map_err(|e| e.to_string())?;
4891            Ok(json!({"message": format!("User {} updated", user_id)}))
4892        }
4893
4894        "clickup_user_remove" => {
4895            let team_id = resolve_workspace(args)?;
4896            let user_id = args
4897                .get("user_id")
4898                .and_then(|v| v.as_i64())
4899                .ok_or("Missing required parameter: user_id")?;
4900            client
4901                .delete(&format!("/v2/team/{}/user/{}", team_id, user_id))
4902                .await
4903                .map_err(|e| e.to_string())?;
4904            Ok(json!({"message": format!("User {} removed from workspace", user_id)}))
4905        }
4906
4907        "clickup_template_apply_task" => {
4908            let list_id = args
4909                .get("list_id")
4910                .and_then(|v| v.as_str())
4911                .ok_or("Missing required parameter: list_id")?;
4912            let template_id = args
4913                .get("template_id")
4914                .and_then(|v| v.as_str())
4915                .ok_or("Missing required parameter: template_id")?;
4916            let name = args
4917                .get("name")
4918                .and_then(|v| v.as_str())
4919                .ok_or("Missing required parameter: name")?;
4920            let body = json!({"name": name});
4921            let resp = client
4922                .post(
4923                    &format!("/v2/list/{}/taskTemplate/{}", list_id, template_id),
4924                    &body,
4925                )
4926                .await
4927                .map_err(|e| e.to_string())?;
4928            Ok(compact_items(&[resp], &["id", "name"]))
4929        }
4930
4931        "clickup_template_apply_list" => {
4932            let template_id = args
4933                .get("template_id")
4934                .and_then(|v| v.as_str())
4935                .ok_or("Missing required parameter: template_id")?;
4936            let name = args
4937                .get("name")
4938                .and_then(|v| v.as_str())
4939                .ok_or("Missing required parameter: name")?;
4940            let body = json!({"name": name});
4941            let path = if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
4942                format!("/v2/folder/{}/list_template/{}", folder_id, template_id)
4943            } else if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
4944                format!("/v2/space/{}/list_template/{}", space_id, template_id)
4945            } else {
4946                return Err("Provide either folder_id or space_id".to_string());
4947            };
4948            client.post(&path, &body).await.map_err(|e| e.to_string())?;
4949            Ok(json!({"message": format!("List '{}' created from template {}", name, template_id)}))
4950        }
4951
4952        "clickup_template_apply_folder" => {
4953            let space_id = args
4954                .get("space_id")
4955                .and_then(|v| v.as_str())
4956                .ok_or("Missing required parameter: space_id")?;
4957            let template_id = args
4958                .get("template_id")
4959                .and_then(|v| v.as_str())
4960                .ok_or("Missing required parameter: template_id")?;
4961            let name = args
4962                .get("name")
4963                .and_then(|v| v.as_str())
4964                .ok_or("Missing required parameter: name")?;
4965            let body = json!({"name": name});
4966            client
4967                .post(
4968                    &format!("/v2/space/{}/folder_template/{}", space_id, template_id),
4969                    &body,
4970                )
4971                .await
4972                .map_err(|e| e.to_string())?;
4973            Ok(
4974                json!({"message": format!("Folder '{}' created from template {}", name, template_id)}),
4975            )
4976        }
4977
4978        "clickup_attachment_upload" => {
4979            let (task_id, custom_q) = resolve_task(args, "task_id")?;
4980            let file_path = args
4981                .get("file_path")
4982                .and_then(|v| v.as_str())
4983                .ok_or("Missing required parameter: file_path")?;
4984            let path = match custom_q {
4985                Some(q) => format!("/v2/task/{}/attachment?{}", task_id, q),
4986                None => format!("/v2/task/{}/attachment", task_id),
4987            };
4988            let resp = client
4989                .upload_file(&path, std::path::Path::new(file_path))
4990                .await
4991                .map_err(|e| e.to_string())?;
4992            Ok(json!({"message": "File uploaded", "id": resp.get("id"), "url": resp.get("url")}))
4993        }
4994
4995        "clickup_task_type_list" => {
4996            let team_id = resolve_workspace(args)?;
4997            let resp = client
4998                .get(&format!("/v2/team/{}/custom_item", team_id))
4999                .await
5000                .map_err(|e| e.to_string())?;
5001            let items = resp
5002                .get("custom_items")
5003                .and_then(|i| i.as_array())
5004                .cloned()
5005                .unwrap_or_default();
5006            Ok(compact_items(&items, &["id", "name", "name_plural"]))
5007        }
5008
5009        "clickup_doc_get_page" => {
5010            let team_id = resolve_workspace(args)?;
5011            let doc_id = args
5012                .get("doc_id")
5013                .and_then(|v| v.as_str())
5014                .ok_or("Missing required parameter: doc_id")?;
5015            let page_id = args
5016                .get("page_id")
5017                .and_then(|v| v.as_str())
5018                .ok_or("Missing required parameter: page_id")?;
5019            let resp = client
5020                .get(&format!(
5021                    "/v3/workspaces/{}/docs/{}/pages/{}",
5022                    team_id, doc_id, page_id
5023                ))
5024                .await
5025                .map_err(|e| e.to_string())?;
5026            Ok(resp)
5027        }
5028
5029        "clickup_audit_log_query" => {
5030            let team_id = resolve_workspace(args)?;
5031            let applicability = args
5032                .get("applicability")
5033                .and_then(|v| v.as_str())
5034                .ok_or("Missing required parameter: applicability")?;
5035
5036            // ClickUp's audit-log body per the v3 OpenAPI spec:
5037            //   { applicability, filter?: {...}, pagination?: {...} }
5038            // The previous implementation invented `{type, user_id, date_filter}`,
5039            // which the endpoint does not recognise.
5040            let mut body = json!({"applicability": applicability});
5041
5042            let mut filter = serde_json::Map::new();
5043            if let Some(t) = args.get("event_type").and_then(|v| v.as_str()) {
5044                filter.insert("eventType".into(), json!(t));
5045            }
5046            if let Some(s) = args.get("event_status").and_then(|v| v.as_str()) {
5047                filter.insert("eventStatus".into(), json!(s));
5048            }
5049            if let Some(ids) = args.get("user_id").and_then(|v| v.as_array()) {
5050                filter.insert("userId".into(), Value::Array(ids.clone()));
5051            }
5052            if let Some(emails) = args.get("user_email").and_then(|v| v.as_array()) {
5053                filter.insert("userEmail".into(), Value::Array(emails.clone()));
5054            }
5055            if let Some(t) = args.get("start_time").and_then(|v| v.as_i64()) {
5056                filter.insert("startTime".into(), json!(t));
5057            }
5058            if let Some(t) = args.get("end_time").and_then(|v| v.as_i64()) {
5059                filter.insert("endTime".into(), json!(t));
5060            }
5061            if !filter.is_empty() {
5062                body["filter"] = Value::Object(filter);
5063            }
5064
5065            let mut pagination = serde_json::Map::new();
5066            if let Some(n) = args.get("page_rows").and_then(|v| v.as_i64()) {
5067                pagination.insert("pageRows".into(), json!(n));
5068            }
5069            if let Some(t) = args.get("page_timestamp").and_then(|v| v.as_i64()) {
5070                pagination.insert("pageTimestamp".into(), json!(t));
5071            }
5072            if let Some(d) = args.get("page_direction").and_then(|v| v.as_str()) {
5073                pagination.insert("pageDirection".into(), json!(d));
5074            }
5075            if !pagination.is_empty() {
5076                body["pagination"] = Value::Object(pagination);
5077            }
5078
5079            let resp = client
5080                .post(&format!("/v3/workspaces/{}/auditlogs", team_id), &body)
5081                .await
5082                .map_err(|e| e.to_string())?;
5083            Ok(resp)
5084        }
5085
5086        "clickup_acl_update" => {
5087            let team_id = resolve_workspace(args)?;
5088            let object_type = args
5089                .get("object_type")
5090                .and_then(|v| v.as_str())
5091                .ok_or("Missing required parameter: object_type")?;
5092            let object_id = args
5093                .get("object_id")
5094                .and_then(|v| v.as_str())
5095                .ok_or("Missing required parameter: object_id")?;
5096            let mut body = json!({});
5097            if let Some(private) = args.get("private").and_then(|v| v.as_bool()) {
5098                body["private"] = json!(private);
5099            }
5100            if let Some(entries) = args.get("entries").and_then(|v| v.as_array()) {
5101                let mut normalized: Vec<Value> = Vec::with_capacity(entries.len());
5102                for (i, entry) in entries.iter().enumerate() {
5103                    let kind = entry
5104                        .get("kind")
5105                        .and_then(|v| v.as_str())
5106                        .ok_or_else(|| format!("entries[{}] missing required field 'kind'", i))?;
5107                    if kind != "user" && kind != "group" {
5108                        return Err(format!(
5109                            "entries[{}] kind must be 'user' or 'group' (got '{}')",
5110                            i, kind
5111                        ));
5112                    }
5113                    let id = entry
5114                        .get("id")
5115                        .and_then(|v| v.as_str())
5116                        .ok_or_else(|| format!("entries[{}] missing required field 'id'", i))?;
5117                    let mut out = serde_json::Map::new();
5118                    out.insert("kind".into(), json!(kind));
5119                    out.insert("id".into(), json!(id));
5120                    if let Some(level) = entry.get("permission_level").and_then(|v| v.as_i64()) {
5121                        out.insert("permission_level".into(), json!(level));
5122                    }
5123                    normalized.push(Value::Object(out));
5124                }
5125                if !normalized.is_empty() {
5126                    body["entries"] = Value::Array(normalized);
5127                }
5128            }
5129            client
5130                .patch(
5131                    &format!(
5132                        "/v3/workspaces/{}/{}/{}/acls",
5133                        team_id, object_type, object_id
5134                    ),
5135                    &body,
5136                )
5137                .await
5138                .map_err(|e| e.to_string())?;
5139            Ok(json!({"message": format!("ACL updated for {} {}", object_type, object_id)}))
5140        }
5141
5142        unknown => Err(format!("Unknown tool: {}", unknown)),
5143    }
5144}
5145
5146// ── Main server loop ──────────────────────────────────────────────────────────
5147
5148pub async fn serve(filter: filter::Filter) -> Result<(), Box<dyn std::error::Error>> {
5149    // Resolve token: CLICKUP_TOKEN env > config file
5150    let token = std::env::var("CLICKUP_TOKEN")
5151        .ok()
5152        .filter(|t| !t.is_empty())
5153        .or_else(|| {
5154            Config::load()
5155                .ok()
5156                .map(|c| c.auth.token)
5157                .filter(|t| !t.is_empty())
5158        })
5159        .ok_or("No API token. Set CLICKUP_TOKEN env var or run `clickup setup`.")?;
5160
5161    // Resolve workspace: CLICKUP_WORKSPACE env > config file
5162    let workspace_id = std::env::var("CLICKUP_WORKSPACE")
5163        .ok()
5164        .filter(|w| !w.is_empty())
5165        .or_else(|| Config::load().ok().and_then(|c| c.defaults.workspace_id));
5166
5167    let client = ClickUpClient::new(&token, 30)
5168        .map_err(|e| format!("Failed to create HTTP client: {}", e))?;
5169
5170    let stdin = tokio::io::stdin();
5171    let reader = BufReader::new(stdin);
5172    let mut lines = reader.lines();
5173
5174    let groups_str = filter
5175        .groups
5176        .as_ref()
5177        .map(|g| format!(", groups=[{}]", g.join(",")))
5178        .unwrap_or_default();
5179    let excluded_groups_str = filter
5180        .exclude_groups
5181        .as_ref()
5182        .map(|g| format!(", exclude-groups=[{}]", g.join(",")))
5183        .unwrap_or_default();
5184    eprintln!(
5185        "MCP: profile={}{}{}, exposing {}/{} tools",
5186        filter.profile.as_str(),
5187        groups_str,
5188        excluded_groups_str,
5189        filter.allowed_count(),
5190        tool_list().as_array().map(Vec::len).unwrap_or(0),
5191    );
5192
5193    while let Some(line) = lines.next_line().await? {
5194        let line = line.trim().to_string();
5195        if line.is_empty() {
5196            continue;
5197        }
5198
5199        let msg: Value = match serde_json::from_str(&line) {
5200            Ok(v) => v,
5201            Err(e) => {
5202                // Parse error — send error response with null id
5203                let resp = error_response(&Value::Null, -32700, &format!("Parse error: {}", e));
5204                println!("{}", resp);
5205                continue;
5206            }
5207        };
5208
5209        // Notifications have no id — don't respond
5210        let id = msg.get("id").cloned().unwrap_or(Value::Null);
5211        let method = msg.get("method").and_then(|v| v.as_str()).unwrap_or("");
5212
5213        if id.is_null() && method.starts_with("notifications/") {
5214            // Notification — no response needed
5215            continue;
5216        }
5217
5218        let resp = match method {
5219            "initialize" => {
5220                let version = msg
5221                    .get("params")
5222                    .and_then(|p| p.get("protocolVersion"))
5223                    .and_then(|v| v.as_str())
5224                    .unwrap_or("2024-11-05");
5225                ok_response(
5226                    &id,
5227                    json!({
5228                        "protocolVersion": version,
5229                        "capabilities": {"tools": {}},
5230                        "serverInfo": {
5231                            "name": "clickup-cli",
5232                            "version": env!("CARGO_PKG_VERSION")
5233                        }
5234                    }),
5235                )
5236            }
5237
5238            "tools/list" => ok_response(&id, json!({"tools": filtered_tool_list(&filter)})),
5239
5240            "tools/call" => {
5241                let params = msg.get("params").cloned().unwrap_or(json!({}));
5242                if let Some(response) = handle_tools_call_early(&id, &params, &filter) {
5243                    response
5244                } else {
5245                    let tool_name = params.get("name").and_then(|v| v.as_str()).unwrap_or("");
5246                    let arguments = params.get("arguments").cloned().unwrap_or(json!({}));
5247                    let result = call_tool(tool_name, &arguments, &client, &workspace_id).await;
5248                    ok_response(&id, result)
5249                }
5250            }
5251
5252            other => {
5253                // Unknown method
5254                eprintln!("Unknown method: {}", other);
5255                error_response(&id, -32601, &format!("Method not found: {}", other))
5256            }
5257        };
5258
5259        println!("{}", resp);
5260    }
5261
5262    Ok(())
5263}
5264
5265#[cfg(test)]
5266mod tests {
5267    use super::*;
5268
5269    #[test]
5270    fn task_search_query_params_include_rich_filters() {
5271        let args = json!({
5272            "space_ids": ["space 1"],
5273            "project_ids": ["folder-1"],
5274            "list_ids": ["list-1"],
5275            "statuses": ["in progress"],
5276            "assignees": ["123"],
5277            "tags": ["release train"],
5278            "include_closed": true,
5279            "subtasks": true,
5280            "parent": "parent-1",
5281            "order_by": "due_date",
5282            "reverse": true,
5283            "due_date_gt": 1700000000000_i64,
5284            "date_updated_lt": 1800000000000_i64,
5285            "custom_items": [0, 1300],
5286            "include_markdown_description": true,
5287            "custom_fields": [
5288                {"field_id": "cf-1", "operator": "IS NOT NULL"},
5289                {"field_id": "cf-2", "operator": "=", "value": "ready"}
5290            ]
5291        });
5292
5293        let params = task_search_query_params(&args);
5294
5295        assert!(params.contains(&"space_ids[]=space%201".to_string()));
5296        assert!(params.contains(&"project_ids[]=folder-1".to_string()));
5297        assert!(params.contains(&"list_ids[]=list-1".to_string()));
5298        assert!(params.contains(&"statuses[]=in%20progress".to_string()));
5299        assert!(params.contains(&"assignees[]=123".to_string()));
5300        assert!(params.contains(&"tags[]=release%20train".to_string()));
5301        assert!(params.contains(&"include_closed=true".to_string()));
5302        assert!(params.contains(&"subtasks=true".to_string()));
5303        assert!(params.contains(&"parent=parent-1".to_string()));
5304        assert!(params.contains(&"order_by=due_date".to_string()));
5305        assert!(params.contains(&"reverse=true".to_string()));
5306        assert!(params.contains(&"due_date_gt=1700000000000".to_string()));
5307        assert!(params.contains(&"date_updated_lt=1800000000000".to_string()));
5308        assert!(params.contains(&"custom_items[]=0".to_string()));
5309        assert!(params.contains(&"custom_items[]=1300".to_string()));
5310        assert!(params.contains(&"include_markdown_description=true".to_string()));
5311        assert!(
5312            params.iter().any(|param| {
5313                param.starts_with("custom_fields=%5B")
5314                    && param.contains("IS%20NOT%20NULL")
5315                    && param.contains("%22value%22%3A%22ready%22")
5316            }),
5317            "custom_fields should be serialized as one encoded JSON query value: {:?}",
5318            params
5319        );
5320    }
5321}