Skip to main content

clickup_cli/
mcp.rs

1use crate::client::ClickUpClient;
2use crate::config::Config;
3use crate::output::compact_items;
4use serde_json::{json, Value};
5use tokio::io::{AsyncBufReadExt, BufReader};
6
7pub mod classify;
8pub mod filter;
9
10// ── JSON-RPC helpers ──────────────────────────────────────────────────────────
11
12fn ok_response(id: &Value, result: Value) -> Value {
13    json!({"jsonrpc":"2.0","id":id,"result":result})
14}
15
16fn error_response(id: &Value, code: i64, message: &str) -> Value {
17    json!({"jsonrpc":"2.0","id":id,"error":{"code":code,"message":message}})
18}
19
20fn tool_result(text: String) -> Value {
21    json!({"content":[{"type":"text","text":text}]})
22}
23
24fn tool_error(msg: String) -> Value {
25    json!({"content":[{"type":"text","text":msg}],"isError":true})
26}
27
28/// Inspects a `tools/call` request and returns a JSON-RPC response when the
29/// request can be resolved WITHOUT executing the tool itself (missing tool
30/// name, or tool is filtered out). Returns `None` when the caller should
31/// proceed to invoke the tool.
32pub fn handle_tools_call_early(
33    id: &Value,
34    params: &Value,
35    filter: &filter::Filter,
36) -> Option<Value> {
37    let tool_name = params.get("name").and_then(|v| v.as_str()).unwrap_or("");
38
39    if tool_name.is_empty() {
40        return Some(ok_response(id, tool_error("Missing tool name".to_string())));
41    }
42
43    if !filter.allows(tool_name) {
44        return Some(error_response(
45            id,
46            -32601,
47            &format!("Method not found: {} (filtered out at startup)", tool_name),
48        ));
49    }
50
51    None
52}
53
54// ── Tool definitions ──────────────────────────────────────────────────────────
55
56pub fn tool_list() -> Value {
57    json!([
58        {
59            "name": "clickup_whoami",
60            "description": "Get the currently authenticated ClickUp user",
61            "inputSchema": {
62                "type": "object",
63                "properties": {},
64                "required": []
65            }
66        },
67        {
68            "name": "clickup_workspace_list",
69            "description": "List all ClickUp workspaces (teams) accessible to the current user",
70            "inputSchema": {
71                "type": "object",
72                "properties": {},
73                "required": []
74            }
75        },
76        {
77            "name": "clickup_space_list",
78            "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.",
79            "inputSchema": {
80                "type": "object",
81                "properties": {
82                    "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)."},
83                    "archived": {"type": "boolean", "description": "true = include archived spaces in the result; false or omitted = only active spaces. Defaults to false."}
84                },
85                "required": []
86            }
87        },
88        {
89            "name": "clickup_folder_list",
90            "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).",
91            "inputSchema": {
92                "type": "object",
93                "properties": {
94                    "space_id": {"type": "string", "description": "ID of the parent space. Obtain from clickup_space_list (field: id)."},
95                    "archived": {"type": "boolean", "description": "true = include archived folders; false or omitted = only active folders. Defaults to false."}
96                },
97                "required": ["space_id"]
98            }
99        },
100        {
101            "name": "clickup_list_list",
102            "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.",
103            "inputSchema": {
104                "type": "object",
105                "properties": {
106                    "folder_id": {"type": "string", "description": "ID of the parent folder. Obtain from clickup_folder_list (field: id). Mutually exclusive with space_id."},
107                    "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."},
108                    "archived": {"type": "boolean", "description": "true = include archived lists; false or omitted = only active lists. Defaults to false."}
109                },
110                "required": []
111            }
112        },
113        {
114            "name": "clickup_task_list",
115            "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.",
116            "inputSchema": {
117                "type": "object",
118                "properties": {
119                    "list_id": {"type": "string", "description": "ID of the list to read tasks from. Obtain from clickup_list_list (field: id)."},
120                    "statuses": {
121                        "type": "array",
122                        "items": {"type": "string"},
123                        "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."
124                    },
125                    "assignees": {
126                        "type": "array",
127                        "items": {"type": "string"},
128                        "description": "User IDs (as strings) to filter assignees. Obtain from clickup_member_list or clickup_user_get. Omit to return tasks regardless of assignee."
129                    },
130                    "include_closed": {"type": "boolean", "description": "true = include tasks whose status is in the 'closed' group; false or omitted = exclude closed tasks from the response."}
131                },
132                "required": ["list_id"]
133            }
134        },
135        {
136            "name": "clickup_task_get",
137            "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.",
138            "inputSchema": {
139                "type": "object",
140                "properties": {
141                    "task_id": {"type": "string", "description": "ID of the task to fetch. Obtain from clickup_task_list (field: id) or clickup_task_search."},
142                    "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."}
143                },
144                "required": ["task_id"]
145            }
146        },
147        {
148            "name": "clickup_task_create",
149            "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.",
150            "inputSchema": {
151                "type": "object",
152                "properties": {
153                    "list_id": {"type": "string", "description": "ID of the list the task will live in. Obtain from clickup_list_list (field: id)."},
154                    "name": {"type": "string", "description": "Task title shown in the list view. Required and non-empty."},
155                    "description": {"type": "string", "description": "Task body. Markdown supported (headings, links, checkboxes, @mentions). Omit to create the task with no description."},
156                    "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."},
157                    "priority": {"type": "integer", "description": "Task priority: 1=Urgent, 2=High, 3=Normal, 4=Low. Omit for no priority."},
158                    "assignees": {
159                        "type": "array",
160                        "items": {"type": "integer"},
161                        "description": "User IDs to assign to the task. Obtain from clickup_member_list or clickup_user_get. Omit for an unassigned task."
162                    },
163                    "tags": {
164                        "type": "array",
165                        "items": {"type": "string"},
166                        "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)."
167                    },
168                    "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."}
169                },
170                "required": ["list_id", "name"]
171            }
172        },
173        {
174            "name": "clickup_task_update",
175            "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.",
176            "inputSchema": {
177                "type": "object",
178                "properties": {
179                    "task_id": {"type": "string", "description": "ID of the task to update. Obtain from clickup_task_list (field: id) or clickup_task_search."},
180                    "name": {"type": "string", "description": "New task title. Omit to keep current name."},
181                    "status": {"type": "string", "description": "New status name (case-sensitive, must match a status defined on the parent list). Omit to keep current status."},
182                    "priority": {"type": "integer", "description": "New priority: 1=Urgent, 2=High, 3=Normal, 4=Low. Omit to keep current priority."},
183                    "description": {"type": "string", "description": "New task body — replaces the current description entirely. Markdown supported. Omit to keep current description."},
184                    "add_assignees": {
185                        "type": "array",
186                        "items": {"type": "integer"},
187                        "description": "User IDs to add as assignees (additive; does not replace existing assignees). Obtain from clickup_member_list."
188                    },
189                    "rem_assignees": {
190                        "type": "array",
191                        "items": {"type": "integer"},
192                        "description": "User IDs to remove from assignees (no-op if the user is not currently assigned)."
193                    }
194                },
195                "required": ["task_id"]
196            }
197        },
198        {
199            "name": "clickup_task_delete",
200            "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.",
201            "inputSchema": {
202                "type": "object",
203                "properties": {
204                    "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."}
205                },
206                "required": ["task_id"]
207            }
208        },
209        {
210            "name": "clickup_task_search",
211            "description": "Search tasks across an entire ClickUp workspace with optional space/list/status/assignee filters — useful for cross-list queries. Returns a paginated array of task objects. For tasks in a single list, prefer clickup_task_list (fewer parameters, same shape).",
212            "inputSchema": {
213                "type": "object",
214                "properties": {
215                    "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."},
216                    "space_ids": {
217                        "type": "array",
218                        "items": {"type": "string"},
219                        "description": "Restrict results to these space IDs. Obtain from clickup_space_list (field: id). Omit to search all spaces."
220                    },
221                    "list_ids": {
222                        "type": "array",
223                        "items": {"type": "string"},
224                        "description": "Restrict results to these list IDs. Obtain from clickup_list_list (field: id). Omit to search all lists."
225                    },
226                    "statuses": {
227                        "type": "array",
228                        "items": {"type": "string"},
229                        "description": "Status names to include (e.g. ['open','in review']). Case-sensitive. Omit for any open status."
230                    },
231                    "assignees": {
232                        "type": "array",
233                        "items": {"type": "string"},
234                        "description": "User IDs (as strings) to restrict to tasks assigned to them. Obtain from clickup_member_list. Omit to return tasks regardless of assignee."
235                    }
236                },
237                "required": []
238            }
239        },
240        {
241            "name": "clickup_comment_list",
242            "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).",
243            "inputSchema": {
244                "type": "object",
245                "properties": {
246                    "task_id": {"type": "string", "description": "ID of the task to read comments from. Obtain from clickup_task_list (field: id) or clickup_task_search."}
247                },
248                "required": ["task_id"]
249            }
250        },
251        {
252            "name": "clickup_comment_create",
253            "description": "Post a new top-level comment on a ClickUp task. Supports markdown and @mentions in the text body. Returns the created comment object including its new id, which you can pass to clickup_comment_reply, clickup_comment_update, etc.",
254            "inputSchema": {
255                "type": "object",
256                "properties": {
257                    "task_id": {"type": "string", "description": "ID of the task to comment on. Obtain from clickup_task_list (field: id) or clickup_task_search."},
258                    "text": {"type": "string", "description": "Comment body. Markdown and @mentions (e.g. '@username') are supported."},
259                    "assignee": {"type": "integer", "description": "Optional user ID to assign the comment to — they will receive a notification. Obtain from clickup_member_list."},
260                    "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."}
261                },
262                "required": ["task_id", "text"]
263            }
264        },
265        {
266            "name": "clickup_field_list",
267            "description": "List the custom field definitions available on a ClickUp list — field id, name, type (text, number, dropdown, labels, date, url, email, phone, money, progress, formula, etc.), and for dropdown/labels fields the permitted option values. Use this before clickup_field_set to learn the correct field_id and value shape. Returns an array of custom field definitions.",
268            "inputSchema": {
269                "type": "object",
270                "properties": {
271                    "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)."}
272                },
273                "required": ["list_id"]
274            }
275        },
276        {
277            "name": "clickup_field_set",
278            "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, number for number/currency/progress, array of option ids for dropdown/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.",
279            "inputSchema": {
280                "type": "object",
281                "properties": {
282                    "task_id": {"type": "string", "description": "ID of the task whose field value should change. Obtain from clickup_task_list (field: id)."},
283                    "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)."},
284                    "value": {"description": "New value; the accepted type depends on the custom field type. Examples: 'hello' (text), 42 (number), ['option-uuid'] (dropdown), 1735689600000 (date as Unix ms). See clickup_field_list for the field's type."}
285                },
286                "required": ["task_id", "field_id", "value"]
287            }
288        },
289        {
290            "name": "clickup_time_start",
291            "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.",
292            "inputSchema": {
293                "type": "object",
294                "properties": {
295                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
296                    "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."},
297                    "description": {"type": "string", "description": "Free-text description shown on the time entry (e.g. 'pair debugging session'). Optional."},
298                    "billable": {"type": "boolean", "description": "true = mark this time entry as billable (shows as $ in reports); false or omitted = non-billable."}
299                },
300                "required": []
301            }
302        },
303        {
304            "name": "clickup_time_stop",
305            "description": "Stop the currently running time tracking entry",
306            "inputSchema": {
307                "type": "object",
308                "properties": {
309                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."}
310                },
311                "required": []
312            }
313        },
314        {
315            "name": "clickup_time_list",
316            "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).",
317            "inputSchema": {
318                "type": "object",
319                "properties": {
320                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
321                    "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."},
322                    "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."},
323                    "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."}
324                },
325                "required": []
326            }
327        },
328        {
329            "name": "clickup_checklist_create",
330            "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.",
331            "inputSchema": {
332                "type": "object",
333                "properties": {
334                    "task_id": {"type": "string", "description": "ID of the task to attach the checklist to. Obtain from clickup_task_list (field: id)."},
335                    "name": {"type": "string", "description": "Display name for the checklist (e.g. 'Launch prep', 'QA steps'). Shown as a heading above the items."}
336                },
337                "required": ["task_id", "name"]
338            }
339        },
340        {
341            "name": "clickup_checklist_delete",
342            "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.",
343            "inputSchema": {
344                "type": "object",
345                "properties": {
346                    "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."}
347                },
348                "required": ["checklist_id"]
349            }
350        },
351        {
352            "name": "clickup_goal_list",
353            "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.",
354            "inputSchema": {
355                "type": "object",
356                "properties": {
357                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
358                },
359                "required": []
360            }
361        },
362        {
363            "name": "clickup_goal_get",
364            "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.",
365            "inputSchema": {
366                "type": "object",
367                "properties": {
368                    "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."}
369                },
370                "required": ["goal_id"]
371            }
372        },
373        {
374            "name": "clickup_goal_create",
375            "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.",
376            "inputSchema": {
377                "type": "object",
378                "properties": {
379                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
380                    "name": {"type": "string", "description": "Goal title (e.g. 'Q1 revenue target'). Required and non-empty."},
381                    "due_date": {"type": "integer", "description": "Target completion date as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01)."},
382                    "description": {"type": "string", "description": "Goal description / rationale. Markdown supported. Omit for no description."},
383                    "owner_ids": {
384                        "type": "array",
385                        "items": {"type": "integer"},
386                        "description": "User IDs to assign as goal owners (they receive notifications about progress). Obtain from clickup_member_list."
387                    }
388                },
389                "required": ["name"]
390            }
391        },
392        {
393            "name": "clickup_goal_update",
394            "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.",
395            "inputSchema": {
396                "type": "object",
397                "properties": {
398                    "goal_id": {"type": "string", "description": "ID of the goal to update. Obtain from clickup_goal_list (field: id)."},
399                    "name": {"type": "string", "description": "New goal title. Omit to keep current name."},
400                    "due_date": {"type": "integer", "description": "New due date as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01)."},
401                    "description": {"type": "string", "description": "New goal description. Markdown supported."}
402                },
403                "required": ["goal_id"]
404            }
405        },
406        {
407            "name": "clickup_view_list",
408            "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).",
409            "inputSchema": {
410                "type": "object",
411                "properties": {
412                    "space_id": {"type": "string", "description": "Space ID whose views to list. Obtain from clickup_space_list. Mutually exclusive with folder_id/list_id."},
413                    "folder_id": {"type": "string", "description": "Folder ID whose views to list. Obtain from clickup_folder_list. Mutually exclusive with space_id/list_id."},
414                    "list_id": {"type": "string", "description": "List ID whose views to list. Obtain from clickup_list_list. Mutually exclusive with space_id/folder_id."},
415                    "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."}
416                },
417                "required": []
418            }
419        },
420        {
421            "name": "clickup_view_tasks",
422            "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.",
423            "inputSchema": {
424                "type": "object",
425                "properties": {
426                    "view_id": {"type": "string", "description": "ID of the view to read tasks from. Obtain from clickup_view_list (field: id)."},
427                    "page": {"type": "integer", "description": "Zero-indexed page number (default 0). Each page returns up to 30 tasks; increment to paginate."}
428                },
429                "required": ["view_id"]
430            }
431        },
432        {
433            "name": "clickup_doc_list",
434            "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.",
435            "inputSchema": {
436                "type": "object",
437                "properties": {
438                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
439                },
440                "required": []
441            }
442        },
443        {
444            "name": "clickup_doc_get",
445            "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.",
446            "inputSchema": {
447                "type": "object",
448                "properties": {
449                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
450                    "doc_id": {"type": "string", "description": "ID of the doc to fetch. Obtain from clickup_doc_list (field: id)."}
451                },
452                "required": ["doc_id"]
453            }
454        },
455        {
456            "name": "clickup_doc_pages",
457            "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.",
458            "inputSchema": {
459                "type": "object",
460                "properties": {
461                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
462                    "doc_id": {"type": "string", "description": "ID of the parent doc. Obtain from clickup_doc_list (field: id)."},
463                    "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)."}
464                },
465                "required": ["doc_id"]
466            }
467        },
468        {
469            "name": "clickup_tag_list",
470            "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).",
471            "inputSchema": {
472                "type": "object",
473                "properties": {
474                    "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."}
475                },
476                "required": ["space_id"]
477            }
478        },
479        {
480            "name": "clickup_task_add_tag",
481            "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.",
482            "inputSchema": {
483                "type": "object",
484                "properties": {
485                    "task_id": {"type": "string", "description": "ID of the task to tag. Obtain from clickup_task_list (field: id)."},
486                    "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."}
487                },
488                "required": ["task_id", "tag_name"]
489            }
490        },
491        {
492            "name": "clickup_task_remove_tag",
493            "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.",
494            "inputSchema": {
495                "type": "object",
496                "properties": {
497                    "task_id": {"type": "string", "description": "ID of the task to untag. Obtain from clickup_task_list (field: id) or clickup_task_get."},
498                    "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."}
499                },
500                "required": ["task_id", "tag_name"]
501            }
502        },
503        {
504            "name": "clickup_webhook_list",
505            "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.",
506            "inputSchema": {
507                "type": "object",
508                "properties": {
509                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
510                },
511                "required": []
512            }
513        },
514        {
515            "name": "clickup_member_list",
516            "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.",
517            "inputSchema": {
518                "type": "object",
519                "properties": {
520                    "task_id": {"type": "string", "description": "Task ID whose members to list. Obtain from clickup_task_list (field: id). Mutually exclusive with list_id."},
521                    "list_id": {"type": "string", "description": "List ID whose members to list. Obtain from clickup_list_list (field: id). Mutually exclusive with task_id."}
522                },
523                "required": []
524            }
525        },
526        {
527            "name": "clickup_template_list",
528            "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).",
529            "inputSchema": {
530                "type": "object",
531                "properties": {
532                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
533                    "page": {"type": "integer", "description": "Zero-indexed page number (default 0). Each page returns up to 100 templates; increment to paginate."}
534                },
535                "required": []
536            }
537        },
538        {
539            "name": "clickup_space_get",
540            "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.",
541            "inputSchema": {
542                "type": "object",
543                "properties": {
544                    "space_id": {"type": "string", "description": "ID of the space to fetch. Obtain from clickup_space_list (field: id)."}
545                },
546                "required": ["space_id"]
547            }
548        },
549        {
550            "name": "clickup_space_create",
551            "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.",
552            "inputSchema": {
553                "type": "object",
554                "properties": {
555                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
556                    "name": {"type": "string", "description": "Display name for the space (shown in the sidebar)."},
557                    "private": {"type": "boolean", "description": "true = private space (only explicit members see it); false or omitted = visible to the whole workspace."}
558                },
559                "required": ["name"]
560            }
561        },
562        {
563            "name": "clickup_space_update",
564            "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.",
565            "inputSchema": {
566                "type": "object",
567                "properties": {
568                    "space_id": {"type": "string", "description": "ID of the space to update. Obtain from clickup_space_list (field: id)."},
569                    "name": {"type": "string", "description": "New space name. Omit to keep current name."},
570                    "private": {"type": "boolean", "description": "true = space is private (visible only to explicit members); false = space is visible to the whole workspace."},
571                    "archived": {"type": "boolean", "description": "true = archive (hide but preserve); false = restore from archive."}
572                },
573                "required": ["space_id"]
574            }
575        },
576        {
577            "name": "clickup_space_delete",
578            "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.",
579            "inputSchema": {
580                "type": "object",
581                "properties": {
582                    "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."}
583                },
584                "required": ["space_id"]
585            }
586        },
587        {
588            "name": "clickup_folder_get",
589            "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.",
590            "inputSchema": {
591                "type": "object",
592                "properties": {
593                    "folder_id": {"type": "string", "description": "ID of the folder to fetch. Obtain from clickup_folder_list (field: id)."}
594                },
595                "required": ["folder_id"]
596            }
597        },
598        {
599            "name": "clickup_folder_create",
600            "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.",
601            "inputSchema": {
602                "type": "object",
603                "properties": {
604                    "space_id": {"type": "string", "description": "ID of the parent space. Obtain from clickup_space_list (field: id)."},
605                    "name": {"type": "string", "description": "Display name for the folder. Must be non-empty and unique within the space."}
606                },
607                "required": ["space_id", "name"]
608            }
609        },
610        {
611            "name": "clickup_folder_update",
612            "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.",
613            "inputSchema": {
614                "type": "object",
615                "properties": {
616                    "folder_id": {"type": "string", "description": "ID of the folder to rename. Obtain from clickup_folder_list (field: id) or clickup_folder_get."},
617                    "name": {"type": "string", "description": "New display name for the folder. Must be non-empty and unique within its parent space."}
618                },
619                "required": ["folder_id", "name"]
620            }
621        },
622        {
623            "name": "clickup_folder_delete",
624            "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.",
625            "inputSchema": {
626                "type": "object",
627                "properties": {
628                    "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."}
629                },
630                "required": ["folder_id"]
631            }
632        },
633        {
634            "name": "clickup_list_get",
635            "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.",
636            "inputSchema": {
637                "type": "object",
638                "properties": {
639                    "list_id": {"type": "string", "description": "ID of the list to fetch. Obtain from clickup_list_list (field: id)."}
640                },
641                "required": ["list_id"]
642            }
643        },
644        {
645            "name": "clickup_list_create",
646            "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.",
647            "inputSchema": {
648                "type": "object",
649                "properties": {
650                    "folder_id": {"type": "string", "description": "ID of the parent folder. Obtain from clickup_folder_list (field: id). Mutually exclusive with space_id."},
651                    "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."},
652                    "name": {"type": "string", "description": "Display name for the list. Required and non-empty."},
653                    "content": {"type": "string", "description": "List description shown at the top of the list. Markdown supported. Omit for no description."},
654                    "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."},
655                    "status": {"type": "string", "description": "Default status for tasks added to this list. Must match a status name from the parent space's status set."}
656                },
657                "required": ["name"]
658            }
659        },
660        {
661            "name": "clickup_list_update",
662            "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.",
663            "inputSchema": {
664                "type": "object",
665                "properties": {
666                    "list_id": {"type": "string", "description": "ID of the list to update. Obtain from clickup_list_list (field: id)."},
667                    "name": {"type": "string", "description": "New list name. Omit to keep current name."},
668                    "content": {"type": "string", "description": "New description for the list. Markdown supported."},
669                    "due_date": {"type": "integer", "description": "List-level due date as a Unix timestamp in milliseconds. Individual tasks retain their own due dates."},
670                    "status": {"type": "string", "description": "Default status for tasks added to this list (must match an existing status name in the list's status set)."}
671                },
672                "required": ["list_id"]
673            }
674        },
675        {
676            "name": "clickup_list_delete",
677            "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.",
678            "inputSchema": {
679                "type": "object",
680                "properties": {
681                    "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."}
682                },
683                "required": ["list_id"]
684            }
685        },
686        {
687            "name": "clickup_list_add_task",
688            "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.",
689            "inputSchema": {
690                "type": "object",
691                "properties": {
692                    "list_id": {"type": "string", "description": "ID of the secondary list the task should also appear in. Obtain from clickup_list_list (field: id)."},
693                    "task_id": {"type": "string", "description": "ID of the task to add. Obtain from clickup_task_list (field: id)."}
694                },
695                "required": ["list_id", "task_id"]
696            }
697        },
698        {
699            "name": "clickup_list_remove_task",
700            "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.",
701            "inputSchema": {
702                "type": "object",
703                "properties": {
704                    "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."},
705                    "task_id": {"type": "string", "description": "ID of the task to detach. Obtain from clickup_task_list (field: id)."}
706                },
707                "required": ["list_id", "task_id"]
708            }
709        },
710        {
711            "name": "clickup_comment_update",
712            "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.",
713            "inputSchema": {
714                "type": "object",
715                "properties": {
716                    "comment_id": {"type": "string", "description": "ID of the comment to edit. Obtain from clickup_comment_list (field: id)."},
717                    "text": {"type": "string", "description": "Replacement body for the comment. ClickUp accepts markdown plus @mentions (e.g. '@username'). The previous body is overwritten entirely."},
718                    "assignee": {"type": "integer", "description": "Reassign the comment to this user ID, who will receive a notification. Obtain from clickup_member_list."},
719                    "resolved": {"type": "boolean", "description": "true = mark the comment thread resolved/closed; false = reopen it."}
720                },
721                "required": ["comment_id", "text"]
722            }
723        },
724        {
725            "name": "clickup_comment_delete",
726            "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.",
727            "inputSchema": {
728                "type": "object",
729                "properties": {
730                    "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."}
731                },
732                "required": ["comment_id"]
733            }
734        },
735        {
736            "name": "clickup_task_add_dep",
737            "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.",
738            "inputSchema": {
739                "type": "object",
740                "properties": {
741                    "task_id": {"type": "string", "description": "ID of the primary task. Obtain from clickup_task_list (field: id)."},
742                    "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."},
743                    "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."}
744                },
745                "required": ["task_id"]
746            }
747        },
748        {
749            "name": "clickup_task_remove_dep",
750            "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.",
751            "inputSchema": {
752                "type": "object",
753                "properties": {
754                    "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[])."},
755                    "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."},
756                    "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."}
757                },
758                "required": ["task_id"]
759            }
760        },
761        {
762            "name": "clickup_task_link",
763            "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.",
764            "inputSchema": {
765                "type": "object",
766                "properties": {
767                    "task_id": {"type": "string", "description": "ID of the first task. Obtain from clickup_task_list (field: id)."},
768                    "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."}
769                },
770                "required": ["task_id", "links_to"]
771            }
772        },
773        {
774            "name": "clickup_task_unlink",
775            "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.",
776            "inputSchema": {
777                "type": "object",
778                "properties": {
779                    "task_id": {"type": "string", "description": "ID of the first task. Obtain from clickup_task_list (field: id) or clickup_task_get (field: linked_tasks[])."},
780                    "links_to": {"type": "string", "description": "ID of the linked task to unlink from task_id."}
781                },
782                "required": ["task_id", "links_to"]
783            }
784        },
785        {
786            "name": "clickup_goal_delete",
787            "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.",
788            "inputSchema": {
789                "type": "object",
790                "properties": {
791                    "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."}
792                },
793                "required": ["goal_id"]
794            }
795        },
796        {
797            "name": "clickup_goal_add_kr",
798            "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.",
799            "inputSchema": {
800                "type": "object",
801                "properties": {
802                    "goal_id": {"type": "string", "description": "ID of the parent goal. Obtain from clickup_goal_list (field: id)."},
803                    "name": {"type": "string", "description": "Display name of the key result (e.g. 'MRR reaches $50k')."},
804                    "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)."},
805                    "steps_start": {"type": "number", "description": "Starting value of the metric (e.g. 0 for a from-zero KR, current baseline otherwise). Ignored for 'boolean'."},
806                    "steps_end": {"type": "number", "description": "Target value the KR aims to reach. For 'percentage' KRs use 100; for 'boolean' use 1."},
807                    "unit": {"type": "string", "description": "Unit label shown next to numeric values (e.g. 'USD', 'users', 'signups'). Ignored for 'boolean' and 'automatic'."},
808                    "owner_ids": {"type": "array", "items": {"type": "integer"}, "description": "User IDs responsible for this KR. Obtain from clickup_member_list."},
809                    "task_ids": {"type": "array", "items": {"type": "string"}, "description": "Task IDs whose completion drives progress (only for type='automatic'). Obtain from clickup_task_list."},
810                    "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."}
811                },
812                "required": ["goal_id", "name", "type", "steps_start", "steps_end"]
813            }
814        },
815        {
816            "name": "clickup_goal_update_kr",
817            "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.",
818            "inputSchema": {
819                "type": "object",
820                "properties": {
821                    "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."},
822                    "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."},
823                    "name": {"type": "string", "description": "New display name for the key result. Omit to keep current name."},
824                    "unit": {"type": "string", "description": "Unit label shown next to numeric values (e.g. 'MRR', 'users'). Ignored for boolean and automatic types."}
825                },
826                "required": ["kr_id"]
827            }
828        },
829        {
830            "name": "clickup_goal_delete_kr",
831            "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.",
832            "inputSchema": {
833                "type": "object",
834                "properties": {
835                    "kr_id": {"type": "string", "description": "ID of the key result to delete. Obtain from clickup_goal_get (field: key_results[].id)."}
836                },
837                "required": ["kr_id"]
838            }
839        },
840        {
841            "name": "clickup_time_get",
842            "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.",
843            "inputSchema": {
844                "type": "object",
845                "properties": {
846                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
847                    "timer_id": {"type": "string", "description": "ID of the time entry. Obtain from clickup_time_list (field: id) or clickup_time_current."}
848                },
849                "required": ["timer_id"]
850            }
851        },
852        {
853            "name": "clickup_time_create",
854            "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.",
855            "inputSchema": {
856                "type": "object",
857                "properties": {
858                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
859                    "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."},
860                    "start": {"type": "integer", "description": "Entry start time as a Unix timestamp in milliseconds (e.g. 1735689600000 for 2025-01-01 00:00 UTC)."},
861                    "duration": {"type": "integer", "description": "Duration in milliseconds (e.g. 3600000 for one hour)."},
862                    "description": {"type": "string", "description": "Free-text description of the work logged. Optional."},
863                    "billable": {"type": "boolean", "description": "true = mark as billable (shows with $ in reports); false or omitted = non-billable."}
864                },
865                "required": ["start", "duration"]
866            }
867        },
868        {
869            "name": "clickup_time_update",
870            "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.",
871            "inputSchema": {
872                "type": "object",
873                "properties": {
874                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
875                    "timer_id": {"type": "string", "description": "ID of the time entry to update. Obtain from clickup_time_list (field: id)."},
876                    "start": {"type": "integer", "description": "New start time as a Unix timestamp in milliseconds. Omit to keep current start."},
877                    "duration": {"type": "integer", "description": "New duration in milliseconds (e.g. 3600000 for one hour). Omit to keep current duration."},
878                    "description": {"type": "string", "description": "New description for the entry. Omit to keep current description."},
879                    "billable": {"type": "boolean", "description": "true = billable, false = non-billable. Omit to keep current value."}
880                },
881                "required": ["timer_id"]
882            }
883        },
884        {
885            "name": "clickup_time_delete",
886            "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.",
887            "inputSchema": {
888                "type": "object",
889                "properties": {
890                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
891                    "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."}
892                },
893                "required": ["timer_id"]
894            }
895        },
896        {
897            "name": "clickup_view_get",
898            "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.",
899            "inputSchema": {
900                "type": "object",
901                "properties": {
902                    "view_id": {"type": "string", "description": "ID of the view to fetch. Obtain from clickup_view_list (field: id)."}
903                },
904                "required": ["view_id"]
905            }
906        },
907        {
908            "name": "clickup_view_create",
909            "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.",
910            "inputSchema": {
911                "type": "object",
912                "properties": {
913                    "scope": {"type": "string", "description": "Where to attach the view: 'space', 'folder', 'list', or 'team' (workspace-level 'Everything' view)."},
914                    "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)."},
915                    "name": {"type": "string", "description": "Display name for the view."},
916                    "type": {"type": "string", "description": "View type: 'list', 'board', 'calendar', 'table', 'timeline', 'gantt', 'map', 'workload', 'activity', 'chat', 'mind_map', 'doc', or 'form'."}
917                },
918                "required": ["scope", "scope_id", "name", "type"]
919            }
920        },
921        {
922            "name": "clickup_view_update",
923            "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.",
924            "inputSchema": {
925                "type": "object",
926                "properties": {
927                    "view_id": {"type": "string", "description": "ID of the view to update. Obtain from clickup_view_list (field: id)."},
928                    "name": {"type": "string", "description": "New display name for the view."},
929                    "type": {"type": "string", "description": "New view type: 'list', 'board', 'calendar', 'table', 'timeline', 'gantt', 'map', 'workload', 'activity', 'chat', 'mind_map', 'doc', or 'form'."}
930                },
931                "required": ["view_id", "name", "type"]
932            }
933        },
934        {
935            "name": "clickup_view_delete",
936            "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.",
937            "inputSchema": {
938                "type": "object",
939                "properties": {
940                    "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."}
941                },
942                "required": ["view_id"]
943            }
944        },
945        {
946            "name": "clickup_doc_create",
947            "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.",
948            "inputSchema": {
949                "type": "object",
950                "properties": {
951                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
952                    "name": {"type": "string", "description": "Display name for the doc (shown in the doc tree)."},
953                    "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=task. Omit to create at the workspace root."}
954                },
955                "required": ["name"]
956            }
957        },
958        {
959            "name": "clickup_doc_add_page",
960            "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.",
961            "inputSchema": {
962                "type": "object",
963                "properties": {
964                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
965                    "doc_id": {"type": "string", "description": "ID of the parent doc. Obtain from clickup_doc_list (field: id)."},
966                    "name": {"type": "string", "description": "Title shown in the doc's left-hand page navigator."},
967                    "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."},
968                    "sub_title": {"type": "string", "description": "Optional subtitle rendered under the page title."},
969                    "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)."}
970                },
971                "required": ["doc_id", "name"]
972            }
973        },
974        {
975            "name": "clickup_doc_edit_page",
976            "description": "Rename or rewrite an existing page inside a ClickUp doc. The supplied content replaces the current page body entirely (not an append). For a fresh page use clickup_doc_add_page instead. Returns the updated page object.",
977            "inputSchema": {
978                "type": "object",
979                "properties": {
980                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
981                    "doc_id": {"type": "string", "description": "ID of the parent doc. Obtain from clickup_doc_list (field: id)."},
982                    "page_id": {"type": "string", "description": "ID of the page to edit. Obtain from clickup_doc_pages (field: id)."},
983                    "name": {"type": "string", "description": "New page title. Omit to keep current title."},
984                    "content": {"type": "string", "description": "New page body in ClickUp-flavoured markdown. Replaces the existing body entirely. Omit to leave content unchanged."}
985                },
986                "required": ["doc_id", "page_id"]
987            }
988        },
989        {
990            "name": "clickup_chat_channel_create",
991            "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.",
992            "inputSchema": {
993                "type": "object",
994                "properties": {
995                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
996                    "name": {"type": "string", "description": "Channel name (e.g. 'product-launch'). Must be unique within the workspace."},
997                    "description": {"type": "string", "description": "Optional channel topic/description shown in the header."},
998                    "visibility": {"type": "string", "description": "Channel visibility: 'public' (any workspace member can join) or 'private' (invite only). Defaults to 'public'."}
999                },
1000                "required": ["name"]
1001            }
1002        },
1003        {
1004            "name": "clickup_chat_channel_get",
1005            "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.",
1006            "inputSchema": {
1007                "type": "object",
1008                "properties": {
1009                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1010                    "channel_id": {"type": "string", "description": "ID of the channel to fetch. Obtain from clickup_chat_channel_list (field: id)."}
1011                },
1012                "required": ["channel_id"]
1013            }
1014        },
1015        {
1016            "name": "clickup_chat_channel_update",
1017            "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.",
1018            "inputSchema": {
1019                "type": "object",
1020                "properties": {
1021                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1022                    "channel_id": {"type": "string", "description": "ID of the channel to update. Obtain from clickup_chat_channel_list (field: id)."},
1023                    "name": {"type": "string", "description": "New display name for the channel. Must be unique within the workspace."},
1024                    "description": {"type": "string", "description": "New channel description/topic shown in the channel header. Markdown supported."}
1025                },
1026                "required": ["channel_id"]
1027            }
1028        },
1029        {
1030            "name": "clickup_chat_channel_delete",
1031            "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.",
1032            "inputSchema": {
1033                "type": "object",
1034                "properties": {
1035                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1036                    "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."}
1037                },
1038                "required": ["channel_id"]
1039            }
1040        },
1041        {
1042            "name": "clickup_chat_message_list",
1043            "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.",
1044            "inputSchema": {
1045                "type": "object",
1046                "properties": {
1047                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1048                    "channel_id": {"type": "string", "description": "ID of the channel. Obtain from clickup_chat_channel_list (field: id)."},
1049                    "cursor": {"type": "string", "description": "Opaque pagination cursor from the previous response's next_cursor field. Omit for the first page (newest messages)."}
1050                },
1051                "required": ["channel_id"]
1052            }
1053        },
1054        {
1055            "name": "clickup_chat_message_send",
1056            "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.",
1057            "inputSchema": {
1058                "type": "object",
1059                "properties": {
1060                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1061                    "channel_id": {"type": "string", "description": "ID of the target channel. Obtain from clickup_chat_channel_list (field: id)."},
1062                    "content": {"type": "string", "description": "Message body. Supports markdown, @mentions (e.g. '@username'), and emoji."}
1063                },
1064                "required": ["channel_id", "content"]
1065            }
1066        },
1067        {
1068            "name": "clickup_chat_message_delete",
1069            "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.",
1070            "inputSchema": {
1071                "type": "object",
1072                "properties": {
1073                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1074                    "message_id": {"type": "string", "description": "ID of the message to delete. Obtain from clickup_chat_message_list (field: id) or clickup_chat_reply_list."}
1075                },
1076                "required": ["message_id"]
1077            }
1078        },
1079        {
1080            "name": "clickup_chat_dm",
1081            "description": "Send a direct message from the authenticated user to another workspace member. If no DM channel exists between the two users, one is created automatically. Returns the created message object. Use clickup_chat_message_send for channel messages.",
1082            "inputSchema": {
1083                "type": "object",
1084                "properties": {
1085                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1086                    "user_id": {"type": "integer", "description": "Numeric user ID of the recipient. Obtain from clickup_member_list or clickup_user_get (field: id)."},
1087                    "content": {"type": "string", "description": "Message body. Supports markdown, emoji, and @mentions."}
1088                },
1089                "required": ["user_id", "content"]
1090            }
1091        },
1092        {
1093            "name": "clickup_webhook_create",
1094            "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.",
1095            "inputSchema": {
1096                "type": "object",
1097                "properties": {
1098                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1099                    "endpoint": {"type": "string", "description": "Public HTTPS URL that will receive event POSTs. Must respond 2xx within 5 seconds or ClickUp will retry/suspend."},
1100                    "events": {
1101                        "type": "array",
1102                        "items": {"type": "string"},
1103                        "description": "Event names to subscribe to (e.g. ['taskCreated','taskUpdated','taskStatusUpdated','commentPosted']). Pass ['*'] to subscribe to every event ClickUp emits."
1104                    },
1105                    "space_id": {"type": "string", "description": "Scope events to this space only. Mutually exclusive with folder_id/list_id/task_id."},
1106                    "folder_id": {"type": "string", "description": "Scope events to this folder only. Mutually exclusive with space_id/list_id/task_id."},
1107                    "list_id": {"type": "string", "description": "Scope events to this list only. Mutually exclusive with space_id/folder_id/task_id."},
1108                    "task_id": {"type": "string", "description": "Scope events to this task only. Mutually exclusive with space_id/folder_id/list_id."}
1109                },
1110                "required": ["endpoint", "events"]
1111            }
1112        },
1113        {
1114            "name": "clickup_webhook_update",
1115            "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.",
1116            "inputSchema": {
1117                "type": "object",
1118                "properties": {
1119                    "webhook_id": {"type": "string", "description": "ID of the webhook to update. Obtain from clickup_webhook_list (field: id)."},
1120                    "endpoint": {"type": "string", "description": "New HTTPS URL that ClickUp will POST events to. Must be publicly reachable and respond with 2xx within 5 seconds."},
1121                    "events": {
1122                        "type": "array",
1123                        "items": {"type": "string"},
1124                        "description": "New list of event names to subscribe to (e.g. ['taskCreated','taskUpdated']). Pass ['*'] to subscribe to every event. Omit to leave subscriptions unchanged."
1125                    },
1126                    "status": {"type": "string", "description": "'active' to deliver events; 'suspended' to pause deliveries without deleting the webhook."}
1127                },
1128                "required": ["webhook_id"]
1129            }
1130        },
1131        {
1132            "name": "clickup_webhook_delete",
1133            "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='suspended' instead. Returns an empty object on success.",
1134            "inputSchema": {
1135                "type": "object",
1136                "properties": {
1137                    "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."}
1138                },
1139                "required": ["webhook_id"]
1140            }
1141        },
1142        {
1143            "name": "clickup_checklist_add_item",
1144            "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).",
1145            "inputSchema": {
1146                "type": "object",
1147                "properties": {
1148                    "checklist_id": {"type": "string", "description": "ID of the parent checklist. Obtain from clickup_task_get (field: checklists[].id)."},
1149                    "name": {"type": "string", "description": "Display text of the new checklist item (e.g. 'Send release notes')."},
1150                    "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."}
1151                },
1152                "required": ["checklist_id", "name"]
1153            }
1154        },
1155        {
1156            "name": "clickup_checklist_update_item",
1157            "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).",
1158            "inputSchema": {
1159                "type": "object",
1160                "properties": {
1161                    "checklist_id": {"type": "string", "description": "ID of the parent checklist. Obtain from clickup_task_get (field: checklists[].id)."},
1162                    "item_id": {"type": "string", "description": "ID of the item to update. Obtain from clickup_task_get (field: checklists[].items[].id)."},
1163                    "name": {"type": "string", "description": "New text for the item. Omit to keep current text."},
1164                    "resolved": {"type": "boolean", "description": "true = mark as done (strike-through); false = mark as open."},
1165                    "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."}
1166                },
1167                "required": ["checklist_id", "item_id"]
1168            }
1169        },
1170        {
1171            "name": "clickup_checklist_delete_item",
1172            "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).",
1173            "inputSchema": {
1174                "type": "object",
1175                "properties": {
1176                    "checklist_id": {"type": "string", "description": "ID of the parent checklist. Obtain from clickup_task_get (field: checklists[].id)."},
1177                    "item_id": {"type": "string", "description": "ID of the item to delete. Obtain from clickup_task_get (field: checklists[].items[].id)."}
1178                },
1179                "required": ["checklist_id", "item_id"]
1180            }
1181        },
1182        {
1183            "name": "clickup_user_get",
1184            "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.",
1185            "inputSchema": {
1186                "type": "object",
1187                "properties": {
1188                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1189                    "user_id": {"type": "integer", "description": "Numeric user ID. Obtain from clickup_member_list or clickup_workspace_list (field: members[].user.id)."}
1190                },
1191                "required": ["user_id"]
1192            }
1193        },
1194        {
1195            "name": "clickup_workspace_seats",
1196            "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.",
1197            "inputSchema": {
1198                "type": "object",
1199                "properties": {
1200                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1201                },
1202                "required": []
1203            }
1204        },
1205        {
1206            "name": "clickup_workspace_plan",
1207            "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.",
1208            "inputSchema": {
1209                "type": "object",
1210                "properties": {
1211                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1212                },
1213                "required": []
1214            }
1215        },
1216        {
1217            "name": "clickup_tag_create",
1218            "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.",
1219            "inputSchema": {
1220                "type": "object",
1221                "properties": {
1222                    "space_id": {"type": "string", "description": "ID of the space to create the tag in. Obtain from clickup_space_list (field: id)."},
1223                    "name": {"type": "string", "description": "Tag name (e.g. 'blocked', 'priority'). Must be unique within the space."},
1224                    "tag_fg": {"type": "string", "description": "Text (foreground) hex colour including leading '#' (e.g. '#FFFFFF'). Omit for default."},
1225                    "tag_bg": {"type": "string", "description": "Pill (background) hex colour including leading '#' (e.g. '#FF0000'). Omit for default."}
1226                },
1227                "required": ["space_id", "name"]
1228            }
1229        },
1230        {
1231            "name": "clickup_tag_update",
1232            "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.",
1233            "inputSchema": {
1234                "type": "object",
1235                "properties": {
1236                    "space_id": {"type": "string", "description": "ID of the space containing the tag. Obtain from clickup_space_list (field: id)."},
1237                    "tag_name": {"type": "string", "description": "Current name of the tag to update. Obtain from clickup_tag_list (field: name)."},
1238                    "name": {"type": "string", "description": "New tag name. Omit to keep current name."},
1239                    "tag_fg": {"type": "string", "description": "New text (foreground) hex colour with leading '#'. Note: forwarded as fg_color to the API."},
1240                    "tag_bg": {"type": "string", "description": "New pill (background) hex colour with leading '#'. Note: forwarded as bg_color to the API."}
1241                },
1242                "required": ["space_id", "tag_name"]
1243            }
1244        },
1245        {
1246            "name": "clickup_tag_delete",
1247            "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.",
1248            "inputSchema": {
1249                "type": "object",
1250                "properties": {
1251                    "space_id": {"type": "string", "description": "ID of the space containing the tag. Obtain from clickup_space_list (field: id)."},
1252                    "tag_name": {"type": "string", "description": "Name of the tag to delete. Obtain from clickup_tag_list (field: name)."}
1253                },
1254                "required": ["space_id", "tag_name"]
1255            }
1256        },
1257        {
1258            "name": "clickup_field_unset",
1259            "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.",
1260            "inputSchema": {
1261                "type": "object",
1262                "properties": {
1263                    "task_id": {"type": "string", "description": "ID of the task. Obtain from clickup_task_list (field: id)."},
1264                    "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)."}
1265                },
1266                "required": ["task_id", "field_id"]
1267            }
1268        },
1269        {
1270            "name": "clickup_attachment_list",
1271            "description": "List files attached to a ClickUp task — each attachment's id, title, size, mime type, url, and uploader. Uses the v3 attachments endpoint (cursor pagination). Use clickup_attachment_upload to add a new file. Returns an array of attachment objects.",
1272            "inputSchema": {
1273                "type": "object",
1274                "properties": {
1275                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1276                    "task_id": {"type": "string", "description": "ID of the task whose attachments to list. Obtain from clickup_task_list (field: id)."}
1277                },
1278                "required": ["task_id"]
1279            }
1280        },
1281        {
1282            "name": "clickup_shared_list",
1283            "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.",
1284            "inputSchema": {
1285                "type": "object",
1286                "properties": {
1287                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1288                },
1289                "required": []
1290            }
1291        },
1292        {
1293            "name": "clickup_group_list",
1294            "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).",
1295            "inputSchema": {
1296                "type": "object",
1297                "properties": {
1298                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1299                    "group_ids": {
1300                        "type": "array",
1301                        "items": {"type": "string"},
1302                        "description": "Optional filter to return only these group IDs. Omit to return all groups in the workspace."
1303                    }
1304                },
1305                "required": []
1306            }
1307        },
1308        {
1309            "name": "clickup_group_create",
1310            "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.",
1311            "inputSchema": {
1312                "type": "object",
1313                "properties": {
1314                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1315                    "name": {"type": "string", "description": "Display name for the group (e.g. 'Frontend Engineers')."},
1316                    "member_ids": {
1317                        "type": "array",
1318                        "items": {"type": "integer"},
1319                        "description": "User IDs to add as initial members. Obtain from clickup_member_list or clickup_user_get (field: id)."
1320                    }
1321                },
1322                "required": ["name"]
1323            }
1324        },
1325        {
1326            "name": "clickup_group_update",
1327            "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.",
1328            "inputSchema": {
1329                "type": "object",
1330                "properties": {
1331                    "group_id": {"type": "string", "description": "ID of the group to update. Obtain from clickup_group_list (field: id)."},
1332                    "name": {"type": "string", "description": "New display name. Omit to keep current name."},
1333                    "add_members": {
1334                        "type": "array",
1335                        "items": {"type": "integer"},
1336                        "description": "User IDs to add to the group (additive — does not replace current members)."
1337                    },
1338                    "rem_members": {
1339                        "type": "array",
1340                        "items": {"type": "integer"},
1341                        "description": "User IDs to remove from the group (no-op if not currently a member)."
1342                    }
1343                },
1344                "required": ["group_id"]
1345            }
1346        },
1347        {
1348            "name": "clickup_group_delete",
1349            "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.",
1350            "inputSchema": {
1351                "type": "object",
1352                "properties": {
1353                    "group_id": {"type": "string", "description": "ID of the group to delete. Obtain from clickup_group_list (field: id)."}
1354                },
1355                "required": ["group_id"]
1356            }
1357        },
1358        {
1359            "name": "clickup_role_list",
1360            "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).",
1361            "inputSchema": {
1362                "type": "object",
1363                "properties": {
1364                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1365                },
1366                "required": []
1367            }
1368        },
1369        {
1370            "name": "clickup_guest_get",
1371            "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.",
1372            "inputSchema": {
1373                "type": "object",
1374                "properties": {
1375                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1376                    "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."}
1377                },
1378                "required": ["guest_id"]
1379            }
1380        },
1381        {
1382            "name": "clickup_task_time_in_status",
1383            "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).",
1384            "inputSchema": {
1385                "type": "object",
1386                "properties": {
1387                    "task_id": {"type": "string", "description": "ID of the task. Obtain from clickup_task_list (field: id) or clickup_task_search."}
1388                },
1389                "required": ["task_id"]
1390            }
1391        },
1392        {
1393            "name": "clickup_task_move",
1394            "description": "Move a task to a different list (change home list)",
1395            "inputSchema": {
1396                "type": "object",
1397                "properties": {
1398                    "task_id": {"type": "string", "description": "Task ID"},
1399                    "list_id": {"type": "string", "description": "Destination list ID"},
1400                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."}
1401                },
1402                "required": ["task_id", "list_id"]
1403            }
1404        },
1405        {
1406            "name": "clickup_task_set_estimate",
1407            "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.",
1408            "inputSchema": {
1409                "type": "object",
1410                "properties": {
1411                    "task_id": {"type": "string", "description": "ID of the task. Obtain from clickup_task_list (field: id)."},
1412                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1413                    "user_id": {"type": "integer", "description": "Numeric ID of the user whose estimate to set. Obtain from clickup_member_list."},
1414                    "time_estimate": {"type": "integer", "description": "Estimated effort in milliseconds (e.g. 3600000 = 1 hour, 28800000 = 8 hours)."}
1415                },
1416                "required": ["task_id", "user_id", "time_estimate"]
1417            }
1418        },
1419        {
1420            "name": "clickup_task_replace_estimates",
1421            "description": "Replace all time estimates for a task (PUT replaces all user estimates)",
1422            "inputSchema": {
1423                "type": "object",
1424                "properties": {
1425                    "task_id": {"type": "string", "description": "Task ID"},
1426                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1427                    "user_id": {"type": "integer", "description": "User ID"},
1428                    "time_estimate": {"type": "integer", "description": "Time estimate in milliseconds"}
1429                },
1430                "required": ["task_id", "user_id", "time_estimate"]
1431            }
1432        },
1433        {
1434            "name": "clickup_auth_check",
1435            "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.",
1436            "inputSchema": {
1437                "type": "object",
1438                "properties": {},
1439                "required": []
1440            }
1441        },
1442        {
1443            "name": "clickup_checklist_update",
1444            "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.",
1445            "inputSchema": {
1446                "type": "object",
1447                "properties": {
1448                    "checklist_id": {"type": "string", "description": "ID of the checklist to update. Obtain from clickup_task_get (field: checklists[].id)."},
1449                    "name": {"type": "string", "description": "New display name for the checklist. Omit to keep current name."},
1450                    "position": {"type": "integer", "description": "Zero-indexed position among the task's checklists (0 = first). Omit to keep current position."}
1451                },
1452                "required": ["checklist_id"]
1453            }
1454        },
1455        {
1456            "name": "clickup_comment_replies",
1457            "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.",
1458            "inputSchema": {
1459                "type": "object",
1460                "properties": {
1461                    "comment_id": {"type": "string", "description": "ID of the parent comment. Obtain from clickup_comment_list (field: id)."}
1462                },
1463                "required": ["comment_id"]
1464            }
1465        },
1466        {
1467            "name": "clickup_comment_reply",
1468            "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.",
1469            "inputSchema": {
1470                "type": "object",
1471                "properties": {
1472                    "comment_id": {"type": "string", "description": "ID of the parent comment to reply to. Obtain from clickup_comment_list (field: id)."},
1473                    "text": {"type": "string", "description": "Reply body. Markdown and @mentions supported."},
1474                    "assignee": {"type": "integer", "description": "Optional user ID to assign the reply to — they receive a notification. Obtain from clickup_member_list."}
1475                },
1476                "required": ["comment_id", "text"]
1477            }
1478        },
1479        {
1480            "name": "clickup_chat_channel_list",
1481            "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.",
1482            "inputSchema": {
1483                "type": "object",
1484                "properties": {
1485                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1486                    "include_closed": {"type": "boolean", "description": "true = include archived/closed channels in the result; false or omitted = only active channels."}
1487                },
1488                "required": []
1489            }
1490        },
1491        {
1492            "name": "clickup_chat_channel_followers",
1493            "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.",
1494            "inputSchema": {
1495                "type": "object",
1496                "properties": {
1497                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1498                    "channel_id": {"type": "string", "description": "ID of the channel. Obtain from clickup_chat_channel_list (field: id)."}
1499                },
1500                "required": ["channel_id"]
1501            }
1502        },
1503        {
1504            "name": "clickup_chat_channel_members",
1505            "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).",
1506            "inputSchema": {
1507                "type": "object",
1508                "properties": {
1509                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1510                    "channel_id": {"type": "string", "description": "ID of the channel. Obtain from clickup_chat_channel_list (field: id)."}
1511                },
1512                "required": ["channel_id"]
1513            }
1514        },
1515        {
1516            "name": "clickup_chat_message_update",
1517            "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.",
1518            "inputSchema": {
1519                "type": "object",
1520                "properties": {
1521                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1522                    "message_id": {"type": "string", "description": "ID of the message to edit. Obtain from clickup_chat_message_list (field: id) or clickup_chat_reply_list."},
1523                    "text": {"type": "string", "description": "Replacement body for the message. Markdown, emoji, and @mentions supported. Overwrites the existing body entirely."}
1524                },
1525                "required": ["message_id", "text"]
1526            }
1527        },
1528        {
1529            "name": "clickup_chat_reaction_list",
1530            "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.",
1531            "inputSchema": {
1532                "type": "object",
1533                "properties": {
1534                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1535                    "message_id": {"type": "string", "description": "ID of the message whose reactions to list. Obtain from clickup_chat_message_list (field: id)."}
1536                },
1537                "required": ["message_id"]
1538            }
1539        },
1540        {
1541            "name": "clickup_chat_reaction_add",
1542            "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.",
1543            "inputSchema": {
1544                "type": "object",
1545                "properties": {
1546                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1547                    "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."},
1548                    "emoji": {"type": "string", "description": "Unicode emoji character to add (e.g. '👍', '🎉', '❤️'). Custom Slack-style shortcodes (':+1:') are not supported — use the raw emoji character."}
1549                },
1550                "required": ["message_id", "emoji"]
1551            }
1552        },
1553        {
1554            "name": "clickup_chat_reaction_remove",
1555            "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.",
1556            "inputSchema": {
1557                "type": "object",
1558                "properties": {
1559                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1560                    "message_id": {"type": "string", "description": "ID of the message. Obtain from clickup_chat_message_list (field: id)."},
1561                    "emoji": {"type": "string", "description": "The Unicode emoji character to remove (e.g. '👍'). Must match the exact emoji you reacted with."}
1562                },
1563                "required": ["message_id", "emoji"]
1564            }
1565        },
1566        {
1567            "name": "clickup_chat_reply_list",
1568            "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.",
1569            "inputSchema": {
1570                "type": "object",
1571                "properties": {
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                    "message_id": {"type": "string", "description": "ID of the parent message. Obtain from clickup_chat_message_list (field: id)."}
1574                },
1575                "required": ["message_id"]
1576            }
1577        },
1578        {
1579            "name": "clickup_chat_reply_send",
1580            "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.",
1581            "inputSchema": {
1582                "type": "object",
1583                "properties": {
1584                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1585                    "message_id": {"type": "string", "description": "ID of the parent message to reply to. Obtain from clickup_chat_message_list (field: id)."},
1586                    "text": {"type": "string", "description": "Reply body. Markdown, emoji, and @mentions supported."}
1587                },
1588                "required": ["message_id", "text"]
1589            }
1590        },
1591        {
1592            "name": "clickup_chat_tagged_users",
1593            "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.",
1594            "inputSchema": {
1595                "type": "object",
1596                "properties": {
1597                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1598                    "message_id": {"type": "string", "description": "ID of the message. Obtain from clickup_chat_message_list (field: id)."}
1599                },
1600                "required": ["message_id"]
1601            }
1602        },
1603        {
1604            "name": "clickup_time_current",
1605            "description": "Get the currently running time tracking entry",
1606            "inputSchema": {
1607                "type": "object",
1608                "properties": {
1609                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."}
1610                },
1611                "required": []
1612            }
1613        },
1614        {
1615            "name": "clickup_time_tags",
1616            "description": "List all time entry tags for a workspace",
1617            "inputSchema": {
1618                "type": "object",
1619                "properties": {
1620                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."}
1621                },
1622                "required": []
1623            }
1624        },
1625        {
1626            "name": "clickup_time_add_tags",
1627            "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.",
1628            "inputSchema": {
1629                "type": "object",
1630                "properties": {
1631                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1632                    "entry_ids": {
1633                        "type": "array",
1634                        "items": {"type": "string"},
1635                        "description": "IDs of the time entries to tag. Obtain from clickup_time_list (field: id)."
1636                    },
1637                    "tag_names": {
1638                        "type": "array",
1639                        "items": {"type": "string"},
1640                        "description": "Tag names to apply. Created if they don't exist in the workspace's tag set."
1641                    }
1642                },
1643                "required": ["entry_ids", "tag_names"]
1644            }
1645        },
1646        {
1647            "name": "clickup_time_remove_tags",
1648            "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.",
1649            "inputSchema": {
1650                "type": "object",
1651                "properties": {
1652                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1653                    "entry_ids": {
1654                        "type": "array",
1655                        "items": {"type": "string"},
1656                        "description": "IDs of the time entries to untag. Obtain from clickup_time_list (field: id)."
1657                    },
1658                    "tag_names": {
1659                        "type": "array",
1660                        "items": {"type": "string"},
1661                        "description": "Tag names to remove. Obtain from clickup_time_tags (field: name)."
1662                    }
1663                },
1664                "required": ["entry_ids", "tag_names"]
1665            }
1666        },
1667        {
1668            "name": "clickup_time_rename_tag",
1669            "description": "Rename a time-entry tag across the entire workspace. All historical time entries carrying the old name are updated. Cannot change colour via this endpoint. Returns an empty object on success.",
1670            "inputSchema": {
1671                "type": "object",
1672                "properties": {
1673                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1674                    "name": {"type": "string", "description": "Current name of the tag to rename. Obtain from clickup_time_tags (field: name)."},
1675                    "new_name": {"type": "string", "description": "Replacement name for the tag. Must not collide with an existing time-entry tag."}
1676                },
1677                "required": ["name", "new_name"]
1678            }
1679        },
1680        {
1681            "name": "clickup_time_history",
1682            "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.",
1683            "inputSchema": {
1684                "type": "object",
1685                "properties": {
1686                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1687                    "timer_id": {"type": "string", "description": "ID of the time entry. Obtain from clickup_time_list (field: id)."}
1688                },
1689                "required": ["timer_id"]
1690            }
1691        },
1692        {
1693            "name": "clickup_guest_invite",
1694            "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.",
1695            "inputSchema": {
1696                "type": "object",
1697                "properties": {
1698                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1699                    "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."},
1700                    "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."},
1701                    "can_see_time_spent": {"type": "boolean", "description": "true = allow the guest to see time-tracking data on shared tasks; false or omitted = hidden."},
1702                    "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."}
1703                },
1704                "required": ["email"]
1705            }
1706        },
1707        {
1708            "name": "clickup_guest_update",
1709            "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.",
1710            "inputSchema": {
1711                "type": "object",
1712                "properties": {
1713                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1714                    "guest_id": {"type": "integer", "description": "Numeric guest user ID. Obtain from clickup_guest_get or from clickup_guest_invite (response.id)."},
1715                    "can_edit_tags": {"type": "boolean", "description": "true = allow the guest to manage tags on shared items; false = deny. Omit to keep current value."},
1716                    "can_see_time_spent": {"type": "boolean", "description": "true = guest can see time-tracking on shared tasks; false = hidden. Omit to keep current value."},
1717                    "can_create_views": {"type": "boolean", "description": "true = guest can create saved views; false = cannot. Omit to keep current value."}
1718                },
1719                "required": ["guest_id"]
1720            }
1721        },
1722        {
1723            "name": "clickup_guest_remove",
1724            "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.",
1725            "inputSchema": {
1726                "type": "object",
1727                "properties": {
1728                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1729                    "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."}
1730                },
1731                "required": ["guest_id"]
1732            }
1733        },
1734        {
1735            "name": "clickup_guest_share_task",
1736            "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.",
1737            "inputSchema": {
1738                "type": "object",
1739                "properties": {
1740                    "task_id": {"type": "string", "description": "ID of the task to share. Obtain from clickup_task_list (field: id) or clickup_task_search."},
1741                    "guest_id": {"type": "integer", "description": "Numeric ID of the guest user. Obtain from clickup_guest_get or clickup_guest_invite (response.id)."},
1742                    "permission": {"type": "string", "description": "Access level: 'read' (view only), 'comment' (view + comment), 'create' (comment + create subtasks), 'edit' (full edit rights on this task)."}
1743                },
1744                "required": ["task_id", "guest_id", "permission"]
1745            }
1746        },
1747        {
1748            "name": "clickup_guest_unshare_task",
1749            "description": "Revoke a guest's access to a task",
1750            "inputSchema": {
1751                "type": "object",
1752                "properties": {
1753                    "task_id": {"type": "string", "description": "Task ID"},
1754                    "guest_id": {"type": "integer", "description": "Guest user ID"}
1755                },
1756                "required": ["task_id", "guest_id"]
1757            }
1758        },
1759        {
1760            "name": "clickup_guest_share_list",
1761            "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.",
1762            "inputSchema": {
1763                "type": "object",
1764                "properties": {
1765                    "list_id": {"type": "string", "description": "ID of the list to share. Obtain from clickup_list_list (field: id)."},
1766                    "guest_id": {"type": "integer", "description": "Numeric ID of the guest user. Obtain from clickup_guest_get or the response of clickup_guest_invite."},
1767                    "permission": {"type": "string", "description": "Access level: 'read' (view only), 'comment' (view + comment), 'create' (comment + create tasks), 'edit' (full edit rights on existing items)."}
1768                },
1769                "required": ["list_id", "guest_id", "permission"]
1770            }
1771        },
1772        {
1773            "name": "clickup_guest_unshare_list",
1774            "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.",
1775            "inputSchema": {
1776                "type": "object",
1777                "properties": {
1778                    "list_id": {"type": "string", "description": "ID of the list whose access to revoke. Obtain from clickup_list_list (field: id)."},
1779                    "guest_id": {"type": "integer", "description": "Numeric guest user ID. Obtain from clickup_guest_get or clickup_guest_invite."}
1780                },
1781                "required": ["list_id", "guest_id"]
1782            }
1783        },
1784        {
1785            "name": "clickup_guest_share_folder",
1786            "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.",
1787            "inputSchema": {
1788                "type": "object",
1789                "properties": {
1790                    "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."},
1791                    "guest_id": {"type": "integer", "description": "Numeric ID of the guest user. Obtain from clickup_guest_get or clickup_guest_invite (response.id)."},
1792                    "permission": {"type": "string", "description": "Access level applied to every descendant: 'read' (view only), 'comment' (view + comment), 'create' (comment + create tasks), 'edit' (full edit rights)."}
1793                },
1794                "required": ["folder_id", "guest_id", "permission"]
1795            }
1796        },
1797        {
1798            "name": "clickup_guest_unshare_folder",
1799            "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.",
1800            "inputSchema": {
1801                "type": "object",
1802                "properties": {
1803                    "folder_id": {"type": "string", "description": "ID of the folder whose access to revoke. Obtain from clickup_folder_list (field: id)."},
1804                    "guest_id": {"type": "integer", "description": "Numeric guest user ID. Obtain from clickup_guest_get or clickup_guest_invite."}
1805                },
1806                "required": ["folder_id", "guest_id"]
1807            }
1808        },
1809        {
1810            "name": "clickup_user_invite",
1811            "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.",
1812            "inputSchema": {
1813                "type": "object",
1814                "properties": {
1815                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1816                    "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."},
1817                    "admin": {"type": "boolean", "description": "true = grant the Admin role (can manage settings, billing, users); false or omitted = standard Member role."}
1818                },
1819                "required": ["email"]
1820            }
1821        },
1822        {
1823            "name": "clickup_user_update",
1824            "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.",
1825            "inputSchema": {
1826                "type": "object",
1827                "properties": {
1828                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1829                    "user_id": {"type": "integer", "description": "Numeric user ID to update. Obtain from clickup_member_list or clickup_user_get (field: id)."},
1830                    "username": {"type": "string", "description": "New display name. Omit to keep current username."},
1831                    "admin": {"type": "boolean", "description": "true = grant Admin role, false = revoke Admin (revert to Member). Omit to keep current role."}
1832                },
1833                "required": ["user_id"]
1834            }
1835        },
1836        {
1837            "name": "clickup_user_remove",
1838            "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.",
1839            "inputSchema": {
1840                "type": "object",
1841                "properties": {
1842                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1843                    "user_id": {"type": "integer", "description": "Numeric user ID to remove. Obtain from clickup_member_list (field: id). Cannot remove the workspace Owner."}
1844                },
1845                "required": ["user_id"]
1846            }
1847        },
1848        {
1849            "name": "clickup_template_apply_task",
1850            "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.",
1851            "inputSchema": {
1852                "type": "object",
1853                "properties": {
1854                    "list_id": {"type": "string", "description": "ID of the list to create the task in. Obtain from clickup_list_list (field: id)."},
1855                    "template_id": {"type": "string", "description": "ID of the task template to instantiate. Obtain from clickup_template_list (field: id)."},
1856                    "name": {"type": "string", "description": "Name for the newly-created task. Overrides the template's default name."}
1857                },
1858                "required": ["list_id", "template_id", "name"]
1859            }
1860        },
1861        {
1862            "name": "clickup_template_apply_list",
1863            "description": "Create a list from a list template in a folder or space",
1864            "inputSchema": {
1865                "type": "object",
1866                "properties": {
1867                    "template_id": {"type": "string", "description": "Template ID"},
1868                    "name": {"type": "string", "description": "New list name"},
1869                    "folder_id": {"type": "string", "description": "Folder ID (mutually exclusive with space_id)"},
1870                    "space_id": {"type": "string", "description": "Space ID (mutually exclusive with folder_id)"}
1871                },
1872                "required": ["template_id", "name"]
1873            }
1874        },
1875        {
1876            "name": "clickup_template_apply_folder",
1877            "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.",
1878            "inputSchema": {
1879                "type": "object",
1880                "properties": {
1881                    "space_id": {"type": "string", "description": "ID of the parent space. Obtain from clickup_space_list (field: id)."},
1882                    "template_id": {"type": "string", "description": "ID of the folder template to instantiate. Obtain from clickup_template_list (field: id)."},
1883                    "name": {"type": "string", "description": "Name for the newly-created folder. Must be unique within the parent space."}
1884                },
1885                "required": ["space_id", "template_id", "name"]
1886            }
1887        },
1888        {
1889            "name": "clickup_attachment_upload",
1890            "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).",
1891            "inputSchema": {
1892                "type": "object",
1893                "properties": {
1894                    "task_id": {"type": "string", "description": "ID of the task to attach the file to. Obtain from clickup_task_list (field: id)."},
1895                    "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."}
1896                },
1897                "required": ["task_id", "file_path"]
1898            }
1899        },
1900        {
1901            "name": "clickup_task_type_list",
1902            "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.",
1903            "inputSchema": {
1904                "type": "object",
1905                "properties": {
1906                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."}
1907                },
1908                "required": []
1909            }
1910        },
1911        {
1912            "name": "clickup_doc_get_page",
1913            "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.",
1914            "inputSchema": {
1915                "type": "object",
1916                "properties": {
1917                    "team_id": {"type": "string", "description": "Workspace (team) ID. Omit to use the default workspace from config."},
1918                    "doc_id": {"type": "string", "description": "ID of the parent doc. Obtain from clickup_doc_list (field: id)."},
1919                    "page_id": {"type": "string", "description": "ID of the page to fetch. Obtain from clickup_doc_pages (field: id)."}
1920                },
1921                "required": ["doc_id", "page_id"]
1922            }
1923        },
1924        {
1925            "name": "clickup_audit_log_query",
1926            "description": "Query the ClickUp audit log (who did what, when) for a workspace — filter by event type, acting user, and date range. Requires Enterprise plan. Uses v3 cursor pagination. Returns an array of audit event objects (actor, event, target, timestamp).",
1927            "inputSchema": {
1928                "type": "object",
1929                "properties": {
1930                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1931                    "type": {"type": "string", "description": "Audit event type filter (e.g. 'task_created', 'user_added', 'permission_changed'). Required. See ClickUp docs for the full list."},
1932                    "user_id": {"type": "integer", "description": "Restrict to events performed by this user ID. Obtain from clickup_member_list. Omit for all users."},
1933                    "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."},
1934                    "end_date": {"type": "integer", "description": "Inclusive upper bound as a Unix timestamp in milliseconds. Omit for no upper bound."}
1935                },
1936                "required": ["type"]
1937            }
1938        },
1939        {
1940            "name": "clickup_acl_update",
1941            "description": "Change the privacy (ACL) of a ClickUp hierarchy object — make a space/folder/list private (explicit members only) or public (whole workspace). Uses the v3 ACL endpoint. Requires Enterprise plan. Returns the updated object.",
1942            "inputSchema": {
1943                "type": "object",
1944                "properties": {
1945                    "team_id": {"type": "string", "description": "Workspace (team) ID. Obtain from clickup_workspace_list (field: id). Omit to use the default workspace from config."},
1946                    "object_type": {"type": "string", "description": "Type of object to change: 'space', 'folder', or 'list'."},
1947                    "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)."},
1948                    "private": {"type": "boolean", "description": "true = make the object private (only explicit members see it); false = make it public (visible to the whole workspace)."}
1949                },
1950                "required": ["object_type", "object_id"]
1951            }
1952        }
1953    ])
1954}
1955
1956/// Returns `tool_list()` with any tool the filter disallows removed.
1957pub fn filtered_tool_list(filter: &filter::Filter) -> serde_json::Value {
1958    let all = tool_list();
1959    let filtered: Vec<serde_json::Value> = all
1960        .as_array()
1961        .map(|arr| {
1962            arr.iter()
1963                .filter(|tool| {
1964                    tool.get("name")
1965                        .and_then(|v| v.as_str())
1966                        .map(|n| filter.allows(n))
1967                        .unwrap_or(false)
1968                })
1969                .cloned()
1970                .collect()
1971        })
1972        .unwrap_or_default();
1973    serde_json::Value::Array(filtered)
1974}
1975
1976// ── Tool execution ────────────────────────────────────────────────────────────
1977
1978async fn call_tool(
1979    name: &str,
1980    args: &Value,
1981    client: &ClickUpClient,
1982    workspace_id: &Option<String>,
1983) -> Value {
1984    let result = dispatch_tool(name, args, client, workspace_id).await;
1985    match result {
1986        Ok(v) => tool_result(v.to_string()),
1987        Err(e) => tool_error(format!("Error: {}", e)),
1988    }
1989}
1990
1991async fn dispatch_tool(
1992    name: &str,
1993    args: &Value,
1994    client: &ClickUpClient,
1995    workspace_id: &Option<String>,
1996) -> Result<Value, String> {
1997    let empty = json!({});
1998    let args = if args.is_null() { &empty } else { args };
1999
2000    // Resolve workspace ID from args or config
2001    let resolve_workspace = |args: &Value| -> Result<String, String> {
2002        if let Some(id) = args.get("team_id").and_then(|v| v.as_str()) {
2003            return Ok(id.to_string());
2004        }
2005        workspace_id
2006            .clone()
2007            .ok_or_else(|| "No workspace_id found in config. Please run `clickup setup` or provide team_id in the tool arguments.".to_string())
2008    };
2009
2010    match name {
2011        "clickup_whoami" => {
2012            let resp = client.get("/v2/user").await.map_err(|e| e.to_string())?;
2013            let user = resp.get("user").cloned().unwrap_or(resp);
2014            Ok(compact_items(&[user], &["id", "username", "email"]))
2015        }
2016
2017        "clickup_workspace_list" => {
2018            let resp = client.get("/v2/team").await.map_err(|e| e.to_string())?;
2019            let teams = resp.get("teams").and_then(|t| t.as_array()).cloned().unwrap_or_default();
2020            let items: Vec<Value> = teams.iter().map(|ws| {
2021                json!({
2022                    "id": ws.get("id"),
2023                    "name": ws.get("name"),
2024                    "members": ws.get("members").and_then(|m| m.as_array()).map(|a| a.len()).unwrap_or(0),
2025                })
2026            }).collect();
2027            Ok(compact_items(&items, &["id", "name", "members"]))
2028        }
2029
2030        "clickup_space_list" => {
2031            let team_id = resolve_workspace(args)?;
2032            let archived = args.get("archived").and_then(|v| v.as_bool()).unwrap_or(false);
2033            let path = format!("/v2/team/{}/space?archived={}", team_id, archived);
2034            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2035            let spaces = resp.get("spaces").and_then(|s| s.as_array()).cloned().unwrap_or_default();
2036            Ok(compact_items(&spaces, &["id", "name", "private", "archived"]))
2037        }
2038
2039        "clickup_folder_list" => {
2040            let space_id = args
2041                .get("space_id")
2042                .and_then(|v| v.as_str())
2043                .ok_or("Missing required parameter: space_id")?;
2044            let archived = args.get("archived").and_then(|v| v.as_bool()).unwrap_or(false);
2045            let path = format!("/v2/space/{}/folder?archived={}", space_id, archived);
2046            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2047            let folders = resp.get("folders").and_then(|f| f.as_array()).cloned().unwrap_or_default();
2048            let items: Vec<Value> = folders.iter().map(|f| {
2049                let list_count = f.get("lists").and_then(|l| l.as_array()).map(|a| a.len()).unwrap_or(0);
2050                json!({
2051                    "id": f.get("id"),
2052                    "name": f.get("name"),
2053                    "task_count": f.get("task_count"),
2054                    "list_count": list_count,
2055                })
2056            }).collect();
2057            Ok(compact_items(&items, &["id", "name", "task_count", "list_count"]))
2058        }
2059
2060        "clickup_list_list" => {
2061            let archived = args.get("archived").and_then(|v| v.as_bool()).unwrap_or(false);
2062            let path = if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
2063                format!("/v2/folder/{}/list?archived={}", folder_id, archived)
2064            } else if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
2065                format!("/v2/space/{}/list?archived={}", space_id, archived)
2066            } else {
2067                return Err("Provide either folder_id or space_id".to_string());
2068            };
2069            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2070            let lists = resp.get("lists").and_then(|l| l.as_array()).cloned().unwrap_or_default();
2071            Ok(compact_items(&lists, &["id", "name", "task_count", "status", "due_date"]))
2072        }
2073
2074        "clickup_task_list" => {
2075            let list_id = args
2076                .get("list_id")
2077                .and_then(|v| v.as_str())
2078                .ok_or("Missing required parameter: list_id")?;
2079            let mut qs = String::new();
2080            if let Some(include_closed) = args.get("include_closed").and_then(|v| v.as_bool()) {
2081                qs.push_str(&format!("&include_closed={}", include_closed));
2082            }
2083            if let Some(statuses) = args.get("statuses").and_then(|v| v.as_array()) {
2084                for s in statuses {
2085                    if let Some(s) = s.as_str() {
2086                        qs.push_str(&format!("&statuses[]={}", s));
2087                    }
2088                }
2089            }
2090            if let Some(assignees) = args.get("assignees").and_then(|v| v.as_array()) {
2091                for a in assignees {
2092                    if let Some(a) = a.as_str() {
2093                        qs.push_str(&format!("&assignees[]={}", a));
2094                    }
2095                }
2096            }
2097            let path = format!("/v2/list/{}/task?{}", list_id, qs.trim_start_matches('&'));
2098            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2099            let tasks = resp.get("tasks").and_then(|t| t.as_array()).cloned().unwrap_or_default();
2100            Ok(compact_items(&tasks, &["id", "name", "status", "priority", "assignees", "due_date"]))
2101        }
2102
2103        "clickup_task_get" => {
2104            let task_id = args
2105                .get("task_id")
2106                .and_then(|v| v.as_str())
2107                .ok_or("Missing required parameter: task_id")?;
2108            let include_subtasks = args
2109                .get("include_subtasks")
2110                .and_then(|v| v.as_bool())
2111                .unwrap_or(false);
2112            let path = format!(
2113                "/v2/task/{}?include_subtasks={}",
2114                task_id, include_subtasks
2115            );
2116            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2117            Ok(compact_items(&[resp], &["id", "name", "status", "priority", "assignees", "due_date", "description"]))
2118        }
2119
2120        "clickup_task_create" => {
2121            let list_id = args
2122                .get("list_id")
2123                .and_then(|v| v.as_str())
2124                .ok_or("Missing required parameter: list_id")?;
2125            let name = args
2126                .get("name")
2127                .and_then(|v| v.as_str())
2128                .ok_or("Missing required parameter: name")?;
2129            let mut body = json!({"name": name});
2130            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2131                body["description"] = json!(desc);
2132            }
2133            if let Some(status) = args.get("status").and_then(|v| v.as_str()) {
2134                body["status"] = json!(status);
2135            }
2136            if let Some(priority) = args.get("priority").and_then(|v| v.as_i64()) {
2137                body["priority"] = json!(priority);
2138            }
2139            if let Some(assignees) = args.get("assignees") {
2140                body["assignees"] = assignees.clone();
2141            }
2142            if let Some(tags) = args.get("tags") {
2143                body["tags"] = tags.clone();
2144            }
2145            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) {
2146                body["due_date"] = json!(due_date);
2147            }
2148            let path = format!("/v2/list/{}/task", list_id);
2149            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2150            Ok(compact_items(&[resp], &["id", "name", "status", "priority", "assignees", "due_date"]))
2151        }
2152
2153        "clickup_task_update" => {
2154            let task_id = args
2155                .get("task_id")
2156                .and_then(|v| v.as_str())
2157                .ok_or("Missing required parameter: task_id")?;
2158            let mut body = json!({});
2159            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
2160                body["name"] = json!(name);
2161            }
2162            if let Some(status) = args.get("status").and_then(|v| v.as_str()) {
2163                body["status"] = json!(status);
2164            }
2165            if let Some(priority) = args.get("priority").and_then(|v| v.as_i64()) {
2166                body["priority"] = json!(priority);
2167            }
2168            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2169                body["description"] = json!(desc);
2170            }
2171            if let Some(add) = args.get("add_assignees") {
2172                body["assignees"] = json!({"add": add, "rem": args.get("rem_assignees").cloned().unwrap_or(json!([]))});
2173            } else if let Some(rem) = args.get("rem_assignees") {
2174                body["assignees"] = json!({"add": [], "rem": rem});
2175            }
2176            let path = format!("/v2/task/{}", task_id);
2177            let resp = client.put(&path, &body).await.map_err(|e| e.to_string())?;
2178            Ok(compact_items(&[resp], &["id", "name", "status", "priority", "assignees", "due_date"]))
2179        }
2180
2181        "clickup_task_delete" => {
2182            let task_id = args
2183                .get("task_id")
2184                .and_then(|v| v.as_str())
2185                .ok_or("Missing required parameter: task_id")?;
2186            let path = format!("/v2/task/{}", task_id);
2187            client.delete(&path).await.map_err(|e| e.to_string())?;
2188            Ok(json!({"message": format!("Task {} deleted", task_id)}))
2189        }
2190
2191        "clickup_task_search" => {
2192            let team_id = resolve_workspace(args)?;
2193            let mut qs = String::new();
2194            if let Some(space_ids) = args.get("space_ids").and_then(|v| v.as_array()) {
2195                for id in space_ids {
2196                    if let Some(id) = id.as_str() {
2197                        qs.push_str(&format!("&space_ids[]={}", id));
2198                    }
2199                }
2200            }
2201            if let Some(list_ids) = args.get("list_ids").and_then(|v| v.as_array()) {
2202                for id in list_ids {
2203                    if let Some(id) = id.as_str() {
2204                        qs.push_str(&format!("&list_ids[]={}", id));
2205                    }
2206                }
2207            }
2208            if let Some(statuses) = args.get("statuses").and_then(|v| v.as_array()) {
2209                for s in statuses {
2210                    if let Some(s) = s.as_str() {
2211                        qs.push_str(&format!("&statuses[]={}", s));
2212                    }
2213                }
2214            }
2215            if let Some(assignees) = args.get("assignees").and_then(|v| v.as_array()) {
2216                for a in assignees {
2217                    if let Some(a) = a.as_str() {
2218                        qs.push_str(&format!("&assignees[]={}", a));
2219                    }
2220                }
2221            }
2222            let path = format!(
2223                "/v2/team/{}/task?{}",
2224                team_id,
2225                qs.trim_start_matches('&')
2226            );
2227            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2228            let tasks = resp.get("tasks").and_then(|t| t.as_array()).cloned().unwrap_or_default();
2229            Ok(compact_items(&tasks, &["id", "name", "status", "priority", "assignees", "due_date"]))
2230        }
2231
2232        "clickup_comment_list" => {
2233            let task_id = args
2234                .get("task_id")
2235                .and_then(|v| v.as_str())
2236                .ok_or("Missing required parameter: task_id")?;
2237            let path = format!("/v2/task/{}/comment", task_id);
2238            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2239            let comments = resp.get("comments").and_then(|c| c.as_array()).cloned().unwrap_or_default();
2240            Ok(compact_items(&comments, &["id", "user", "date", "comment_text"]))
2241        }
2242
2243        "clickup_comment_create" => {
2244            let task_id = args
2245                .get("task_id")
2246                .and_then(|v| v.as_str())
2247                .ok_or("Missing required parameter: task_id")?;
2248            let text = args
2249                .get("text")
2250                .and_then(|v| v.as_str())
2251                .ok_or("Missing required parameter: text")?;
2252            let mut body = json!({"comment_text": text});
2253            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) {
2254                body["assignee"] = json!(assignee);
2255            }
2256            if let Some(notify_all) = args.get("notify_all").and_then(|v| v.as_bool()) {
2257                body["notify_all"] = json!(notify_all);
2258            }
2259            let path = format!("/v2/task/{}/comment", task_id);
2260            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2261            Ok(json!({"message": "Comment created", "id": resp.get("id")}))
2262        }
2263
2264        "clickup_field_list" => {
2265            let list_id = args
2266                .get("list_id")
2267                .and_then(|v| v.as_str())
2268                .ok_or("Missing required parameter: list_id")?;
2269            let path = format!("/v2/list/{}/field", list_id);
2270            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2271            let fields = resp.get("fields").and_then(|f| f.as_array()).cloned().unwrap_or_default();
2272            Ok(compact_items(&fields, &["id", "name", "type", "required"]))
2273        }
2274
2275        "clickup_field_set" => {
2276            let task_id = args
2277                .get("task_id")
2278                .and_then(|v| v.as_str())
2279                .ok_or("Missing required parameter: task_id")?;
2280            let field_id = args
2281                .get("field_id")
2282                .and_then(|v| v.as_str())
2283                .ok_or("Missing required parameter: field_id")?;
2284            let value = args.get("value").ok_or("Missing required parameter: value")?;
2285            let body = json!({"value": value});
2286            let path = format!("/v2/task/{}/field/{}", task_id, field_id);
2287            client.post(&path, &body).await.map_err(|e| e.to_string())?;
2288            Ok(json!({"message": format!("Field {} set on task {}", field_id, task_id)}))
2289        }
2290
2291        "clickup_time_start" => {
2292            let team_id = resolve_workspace(args)?;
2293            let mut body = json!({});
2294            if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) {
2295                body["tid"] = json!(task_id);
2296            }
2297            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2298                body["description"] = json!(desc);
2299            }
2300            if let Some(billable) = args.get("billable").and_then(|v| v.as_bool()) {
2301                body["billable"] = json!(billable);
2302            }
2303            let path = format!("/v2/team/{}/time_entries/start", team_id);
2304            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2305            let data = resp.get("data").cloned().unwrap_or(resp);
2306            Ok(compact_items(&[data], &["id", "task", "duration", "start", "billable"]))
2307        }
2308
2309        "clickup_time_stop" => {
2310            let team_id = resolve_workspace(args)?;
2311            let path = format!("/v2/team/{}/time_entries/stop", team_id);
2312            let resp = client.post(&path, &json!({})).await.map_err(|e| e.to_string())?;
2313            let data = resp.get("data").cloned().unwrap_or(resp);
2314            Ok(compact_items(&[data], &["id", "task", "duration", "start", "end", "billable"]))
2315        }
2316
2317        "clickup_time_list" => {
2318            let team_id = resolve_workspace(args)?;
2319            let mut qs = String::new();
2320            if let Some(start_date) = args.get("start_date").and_then(|v| v.as_i64()) {
2321                qs.push_str(&format!("&start_date={}", start_date));
2322            }
2323            if let Some(end_date) = args.get("end_date").and_then(|v| v.as_i64()) {
2324                qs.push_str(&format!("&end_date={}", end_date));
2325            }
2326            if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) {
2327                qs.push_str(&format!("&task_id={}", task_id));
2328            }
2329            let path = format!(
2330                "/v2/team/{}/time_entries?{}",
2331                team_id,
2332                qs.trim_start_matches('&')
2333            );
2334            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2335            let entries = resp.get("data").and_then(|d| d.as_array()).cloned().unwrap_or_default();
2336            Ok(compact_items(&entries, &["id", "task", "duration", "start", "billable"]))
2337        }
2338
2339        "clickup_checklist_create" => {
2340            let task_id = args
2341                .get("task_id")
2342                .and_then(|v| v.as_str())
2343                .ok_or("Missing required parameter: task_id")?;
2344            let name = args
2345                .get("name")
2346                .and_then(|v| v.as_str())
2347                .ok_or("Missing required parameter: name")?;
2348            let path = format!("/v2/task/{}/checklist", task_id);
2349            let body = json!({"name": name});
2350            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2351            let checklist = resp.get("checklist").cloned().unwrap_or(resp);
2352            Ok(compact_items(&[checklist], &["id", "name"]))
2353        }
2354
2355        "clickup_checklist_delete" => {
2356            let checklist_id = args
2357                .get("checklist_id")
2358                .and_then(|v| v.as_str())
2359                .ok_or("Missing required parameter: checklist_id")?;
2360            let path = format!("/v2/checklist/{}", checklist_id);
2361            client.delete(&path).await.map_err(|e| e.to_string())?;
2362            Ok(json!({"message": format!("Checklist {} deleted", checklist_id)}))
2363        }
2364
2365        "clickup_goal_list" => {
2366            let team_id = resolve_workspace(args)?;
2367            let path = format!("/v2/team/{}/goal", team_id);
2368            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2369            let goals = resp.get("goals").and_then(|g| g.as_array()).cloned().unwrap_or_default();
2370            Ok(compact_items(&goals, &["id", "name", "percent_completed", "due_date"]))
2371        }
2372
2373        "clickup_goal_get" => {
2374            let goal_id = args
2375                .get("goal_id")
2376                .and_then(|v| v.as_str())
2377                .ok_or("Missing required parameter: goal_id")?;
2378            let path = format!("/v2/goal/{}", goal_id);
2379            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2380            let goal = resp.get("goal").cloned().unwrap_or(resp);
2381            Ok(compact_items(&[goal], &["id", "name", "percent_completed", "due_date", "description"]))
2382        }
2383
2384        "clickup_goal_create" => {
2385            let team_id = resolve_workspace(args)?;
2386            let name = args
2387                .get("name")
2388                .and_then(|v| v.as_str())
2389                .ok_or("Missing required parameter: name")?;
2390            let mut body = json!({"name": name});
2391            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) {
2392                body["due_date"] = json!(due_date);
2393            }
2394            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2395                body["description"] = json!(desc);
2396            }
2397            if let Some(owner_ids) = args.get("owner_ids") {
2398                body["owners"] = owner_ids.clone();
2399            }
2400            let path = format!("/v2/team/{}/goal", team_id);
2401            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2402            let goal = resp.get("goal").cloned().unwrap_or(resp);
2403            Ok(compact_items(&[goal], &["id", "name"]))
2404        }
2405
2406        "clickup_goal_update" => {
2407            let goal_id = args
2408                .get("goal_id")
2409                .and_then(|v| v.as_str())
2410                .ok_or("Missing required parameter: goal_id")?;
2411            let mut body = json!({});
2412            if let Some(name) = args.get("name").and_then(|v| v.as_str()) {
2413                body["name"] = json!(name);
2414            }
2415            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) {
2416                body["due_date"] = json!(due_date);
2417            }
2418            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) {
2419                body["description"] = json!(desc);
2420            }
2421            let path = format!("/v2/goal/{}", goal_id);
2422            let resp = client.put(&path, &body).await.map_err(|e| e.to_string())?;
2423            let goal = resp.get("goal").cloned().unwrap_or(resp);
2424            Ok(compact_items(&[goal], &["id", "name"]))
2425        }
2426
2427        "clickup_view_list" => {
2428            let path = if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
2429                format!("/v2/space/{}/view", space_id)
2430            } else if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
2431                format!("/v2/folder/{}/view", folder_id)
2432            } else if let Some(list_id) = args.get("list_id").and_then(|v| v.as_str()) {
2433                format!("/v2/list/{}/view", list_id)
2434            } else {
2435                let team_id = resolve_workspace(args)?;
2436                format!("/v2/team/{}/view", team_id)
2437            };
2438            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2439            let views = resp.get("views").and_then(|v| v.as_array()).cloned().unwrap_or_default();
2440            Ok(compact_items(&views, &["id", "name", "type"]))
2441        }
2442
2443        "clickup_view_tasks" => {
2444            let view_id = args
2445                .get("view_id")
2446                .and_then(|v| v.as_str())
2447                .ok_or("Missing required parameter: view_id")?;
2448            let page = args.get("page").and_then(|v| v.as_i64()).unwrap_or(0);
2449            let path = format!("/v2/view/{}/task?page={}", view_id, page);
2450            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2451            let tasks = resp.get("tasks").and_then(|t| t.as_array()).cloned().unwrap_or_default();
2452            Ok(compact_items(&tasks, &["id", "name", "status", "priority", "assignees", "due_date"]))
2453        }
2454
2455        "clickup_doc_list" => {
2456            let team_id = resolve_workspace(args)?;
2457            let path = format!("/v3/workspaces/{}/docs", team_id);
2458            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2459            let docs = resp.get("docs").and_then(|d| d.as_array()).cloned().unwrap_or_default();
2460            Ok(compact_items(&docs, &["id", "name", "date_created"]))
2461        }
2462
2463        "clickup_doc_get" => {
2464            let team_id = resolve_workspace(args)?;
2465            let doc_id = args
2466                .get("doc_id")
2467                .and_then(|v| v.as_str())
2468                .ok_or("Missing required parameter: doc_id")?;
2469            let path = format!("/v3/workspaces/{}/docs/{}", team_id, doc_id);
2470            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2471            Ok(compact_items(&[resp], &["id", "name", "date_created"]))
2472        }
2473
2474        "clickup_doc_pages" => {
2475            let team_id = resolve_workspace(args)?;
2476            let doc_id = args
2477                .get("doc_id")
2478                .and_then(|v| v.as_str())
2479                .ok_or("Missing required parameter: doc_id")?;
2480            let content = args.get("content").and_then(|v| v.as_bool()).unwrap_or(false);
2481            let path = format!("/v3/workspaces/{}/docs/{}/pages?content_format=text/md&max_page_depth=-1&include_content={}", team_id, doc_id, content);
2482            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2483            let pages = resp.get("pages").and_then(|p| p.as_array()).cloned().unwrap_or_default();
2484            Ok(compact_items(&pages, &["id", "name"]))
2485        }
2486
2487        "clickup_tag_list" => {
2488            let space_id = args
2489                .get("space_id")
2490                .and_then(|v| v.as_str())
2491                .ok_or("Missing required parameter: space_id")?;
2492            let path = format!("/v2/space/{}/tag", space_id);
2493            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2494            let tags = resp.get("tags").and_then(|t| t.as_array()).cloned().unwrap_or_default();
2495            Ok(compact_items(&tags, &["name", "tag_fg", "tag_bg"]))
2496        }
2497
2498        "clickup_task_add_tag" => {
2499            let task_id = args
2500                .get("task_id")
2501                .and_then(|v| v.as_str())
2502                .ok_or("Missing required parameter: task_id")?;
2503            let tag_name = args
2504                .get("tag_name")
2505                .and_then(|v| v.as_str())
2506                .ok_or("Missing required parameter: tag_name")?;
2507            let path = format!("/v2/task/{}/tag/{}", task_id, tag_name);
2508            client.post(&path, &json!({})).await.map_err(|e| e.to_string())?;
2509            Ok(json!({"message": format!("Tag '{}' added to task {}", tag_name, task_id)}))
2510        }
2511
2512        "clickup_task_remove_tag" => {
2513            let task_id = args
2514                .get("task_id")
2515                .and_then(|v| v.as_str())
2516                .ok_or("Missing required parameter: task_id")?;
2517            let tag_name = args
2518                .get("tag_name")
2519                .and_then(|v| v.as_str())
2520                .ok_or("Missing required parameter: tag_name")?;
2521            let path = format!("/v2/task/{}/tag/{}", task_id, tag_name);
2522            client.delete(&path).await.map_err(|e| e.to_string())?;
2523            Ok(json!({"message": format!("Tag '{}' removed from task {}", tag_name, task_id)}))
2524        }
2525
2526        "clickup_webhook_list" => {
2527            let team_id = resolve_workspace(args)?;
2528            let path = format!("/v2/team/{}/webhook", team_id);
2529            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2530            let webhooks = resp.get("webhooks").and_then(|w| w.as_array()).cloned().unwrap_or_default();
2531            Ok(compact_items(&webhooks, &["id", "endpoint", "events", "status"]))
2532        }
2533
2534        "clickup_member_list" => {
2535            let path = if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) {
2536                format!("/v2/task/{}/member", task_id)
2537            } else if let Some(list_id) = args.get("list_id").and_then(|v| v.as_str()) {
2538                format!("/v2/list/{}/member", list_id)
2539            } else {
2540                return Err("Provide either task_id or list_id".to_string());
2541            };
2542            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2543            let members = resp.get("members").and_then(|m| m.as_array()).cloned().unwrap_or_default();
2544            Ok(compact_items(&members, &["id", "username", "email"]))
2545        }
2546
2547        "clickup_template_list" => {
2548            let team_id = resolve_workspace(args)?;
2549            let page = args.get("page").and_then(|v| v.as_i64()).unwrap_or(0);
2550            let path = format!("/v2/team/{}/taskTemplate?page={}", team_id, page);
2551            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2552            let templates = resp.get("templates").and_then(|t| t.as_array()).cloned().unwrap_or_default();
2553            Ok(compact_items(&templates, &["id", "name"]))
2554        }
2555
2556        "clickup_space_get" => {
2557            let space_id = args.get("space_id").and_then(|v| v.as_str())
2558                .ok_or("Missing required parameter: space_id")?;
2559            let resp = client.get(&format!("/v2/space/{}", space_id)).await.map_err(|e| e.to_string())?;
2560            Ok(compact_items(&[resp], &["id", "name", "private", "archived"]))
2561        }
2562
2563        "clickup_space_create" => {
2564            let team_id = resolve_workspace(args)?;
2565            let name = args.get("name").and_then(|v| v.as_str())
2566                .ok_or("Missing required parameter: name")?;
2567            let mut body = json!({"name": name});
2568            if let Some(private) = args.get("private").and_then(|v| v.as_bool()) {
2569                body["private"] = json!(private);
2570            }
2571            let resp = client.post(&format!("/v2/team/{}/space", team_id), &body).await.map_err(|e| e.to_string())?;
2572            Ok(compact_items(&[resp], &["id", "name", "private"]))
2573        }
2574
2575        "clickup_space_update" => {
2576            let space_id = args.get("space_id").and_then(|v| v.as_str())
2577                .ok_or("Missing required parameter: space_id")?;
2578            let mut body = json!({});
2579            if let Some(name) = args.get("name").and_then(|v| v.as_str()) { body["name"] = json!(name); }
2580            if let Some(private) = args.get("private").and_then(|v| v.as_bool()) { body["private"] = json!(private); }
2581            if let Some(archived) = args.get("archived").and_then(|v| v.as_bool()) { body["archived"] = json!(archived); }
2582            let resp = client.put(&format!("/v2/space/{}", space_id), &body).await.map_err(|e| e.to_string())?;
2583            Ok(compact_items(&[resp], &["id", "name", "private", "archived"]))
2584        }
2585
2586        "clickup_space_delete" => {
2587            let space_id = args.get("space_id").and_then(|v| v.as_str())
2588                .ok_or("Missing required parameter: space_id")?;
2589            client.delete(&format!("/v2/space/{}", space_id)).await.map_err(|e| e.to_string())?;
2590            Ok(json!({"message": format!("Space {} deleted", space_id)}))
2591        }
2592
2593        "clickup_folder_get" => {
2594            let folder_id = args.get("folder_id").and_then(|v| v.as_str())
2595                .ok_or("Missing required parameter: folder_id")?;
2596            let resp = client.get(&format!("/v2/folder/{}", folder_id)).await.map_err(|e| e.to_string())?;
2597            Ok(compact_items(&[resp], &["id", "name", "task_count"]))
2598        }
2599
2600        "clickup_folder_create" => {
2601            let space_id = args.get("space_id").and_then(|v| v.as_str())
2602                .ok_or("Missing required parameter: space_id")?;
2603            let name = args.get("name").and_then(|v| v.as_str())
2604                .ok_or("Missing required parameter: name")?;
2605            let body = json!({"name": name});
2606            let resp = client.post(&format!("/v2/space/{}/folder", space_id), &body).await.map_err(|e| e.to_string())?;
2607            Ok(compact_items(&[resp], &["id", "name"]))
2608        }
2609
2610        "clickup_folder_update" => {
2611            let folder_id = args.get("folder_id").and_then(|v| v.as_str())
2612                .ok_or("Missing required parameter: folder_id")?;
2613            let name = args.get("name").and_then(|v| v.as_str())
2614                .ok_or("Missing required parameter: name")?;
2615            let body = json!({"name": name});
2616            let resp = client.put(&format!("/v2/folder/{}", folder_id), &body).await.map_err(|e| e.to_string())?;
2617            Ok(compact_items(&[resp], &["id", "name"]))
2618        }
2619
2620        "clickup_folder_delete" => {
2621            let folder_id = args.get("folder_id").and_then(|v| v.as_str())
2622                .ok_or("Missing required parameter: folder_id")?;
2623            client.delete(&format!("/v2/folder/{}", folder_id)).await.map_err(|e| e.to_string())?;
2624            Ok(json!({"message": format!("Folder {} deleted", folder_id)}))
2625        }
2626
2627        "clickup_list_get" => {
2628            let list_id = args.get("list_id").and_then(|v| v.as_str())
2629                .ok_or("Missing required parameter: list_id")?;
2630            let resp = client.get(&format!("/v2/list/{}", list_id)).await.map_err(|e| e.to_string())?;
2631            Ok(compact_items(&[resp], &["id", "name", "task_count", "status", "due_date"]))
2632        }
2633
2634        "clickup_list_create" => {
2635            let name = args.get("name").and_then(|v| v.as_str())
2636                .ok_or("Missing required parameter: name")?;
2637            let mut body = json!({"name": name});
2638            if let Some(content) = args.get("content").and_then(|v| v.as_str()) { body["content"] = json!(content); }
2639            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) { body["due_date"] = json!(due_date); }
2640            if let Some(status) = args.get("status").and_then(|v| v.as_str()) { body["status"] = json!(status); }
2641            let path = if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
2642                format!("/v2/folder/{}/list", folder_id)
2643            } else if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
2644                format!("/v2/space/{}/list", space_id)
2645            } else {
2646                return Err("Provide either folder_id or space_id".to_string());
2647            };
2648            let resp = client.post(&path, &body).await.map_err(|e| e.to_string())?;
2649            Ok(compact_items(&[resp], &["id", "name"]))
2650        }
2651
2652        "clickup_list_update" => {
2653            let list_id = args.get("list_id").and_then(|v| v.as_str())
2654                .ok_or("Missing required parameter: list_id")?;
2655            let mut body = json!({});
2656            if let Some(name) = args.get("name").and_then(|v| v.as_str()) { body["name"] = json!(name); }
2657            if let Some(content) = args.get("content").and_then(|v| v.as_str()) { body["content"] = json!(content); }
2658            if let Some(due_date) = args.get("due_date").and_then(|v| v.as_i64()) { body["due_date"] = json!(due_date); }
2659            if let Some(status) = args.get("status").and_then(|v| v.as_str()) { body["status"] = json!(status); }
2660            let resp = client.put(&format!("/v2/list/{}", list_id), &body).await.map_err(|e| e.to_string())?;
2661            Ok(compact_items(&[resp], &["id", "name", "task_count", "status"]))
2662        }
2663
2664        "clickup_list_delete" => {
2665            let list_id = args.get("list_id").and_then(|v| v.as_str())
2666                .ok_or("Missing required parameter: list_id")?;
2667            client.delete(&format!("/v2/list/{}", list_id)).await.map_err(|e| e.to_string())?;
2668            Ok(json!({"message": format!("List {} deleted", list_id)}))
2669        }
2670
2671        "clickup_list_add_task" => {
2672            let list_id = args.get("list_id").and_then(|v| v.as_str())
2673                .ok_or("Missing required parameter: list_id")?;
2674            let task_id = args.get("task_id").and_then(|v| v.as_str())
2675                .ok_or("Missing required parameter: task_id")?;
2676            client.post(&format!("/v2/list/{}/task/{}", list_id, task_id), &json!({})).await.map_err(|e| e.to_string())?;
2677            Ok(json!({"message": format!("Task {} added to list {}", task_id, list_id)}))
2678        }
2679
2680        "clickup_list_remove_task" => {
2681            let list_id = args.get("list_id").and_then(|v| v.as_str())
2682                .ok_or("Missing required parameter: list_id")?;
2683            let task_id = args.get("task_id").and_then(|v| v.as_str())
2684                .ok_or("Missing required parameter: task_id")?;
2685            client.delete(&format!("/v2/list/{}/task/{}", list_id, task_id)).await.map_err(|e| e.to_string())?;
2686            Ok(json!({"message": format!("Task {} removed from list {}", task_id, list_id)}))
2687        }
2688
2689        "clickup_comment_update" => {
2690            let comment_id = args.get("comment_id").and_then(|v| v.as_str())
2691                .ok_or("Missing required parameter: comment_id")?;
2692            let text = args.get("text").and_then(|v| v.as_str())
2693                .ok_or("Missing required parameter: text")?;
2694            let mut body = json!({"comment_text": text});
2695            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) { body["assignee"] = json!(assignee); }
2696            if let Some(resolved) = args.get("resolved").and_then(|v| v.as_bool()) { body["resolved"] = json!(resolved); }
2697            client.put(&format!("/v2/comment/{}", comment_id), &body).await.map_err(|e| e.to_string())?;
2698            Ok(json!({"message": format!("Comment {} updated", comment_id)}))
2699        }
2700
2701        "clickup_comment_delete" => {
2702            let comment_id = args.get("comment_id").and_then(|v| v.as_str())
2703                .ok_or("Missing required parameter: comment_id")?;
2704            client.delete(&format!("/v2/comment/{}", comment_id)).await.map_err(|e| e.to_string())?;
2705            Ok(json!({"message": format!("Comment {} deleted", comment_id)}))
2706        }
2707
2708        "clickup_task_add_dep" => {
2709            let task_id = args.get("task_id").and_then(|v| v.as_str())
2710                .ok_or("Missing required parameter: task_id")?;
2711            let mut body = json!({});
2712            if let Some(dep) = args.get("depends_on").and_then(|v| v.as_str()) { body["depends_on"] = json!(dep); }
2713            if let Some(dep) = args.get("dependency_of").and_then(|v| v.as_str()) { body["dependency_of"] = json!(dep); }
2714            client.post(&format!("/v2/task/{}/dependency", task_id), &body).await.map_err(|e| e.to_string())?;
2715            Ok(json!({"message": format!("Dependency added to task {}", task_id)}))
2716        }
2717
2718        "clickup_task_remove_dep" => {
2719            let task_id = args.get("task_id").and_then(|v| v.as_str())
2720                .ok_or("Missing required parameter: task_id")?;
2721            let mut body = json!({});
2722            if let Some(dep) = args.get("depends_on").and_then(|v| v.as_str()) { body["depends_on"] = json!(dep); }
2723            if let Some(dep) = args.get("dependency_of").and_then(|v| v.as_str()) { body["dependency_of"] = json!(dep); }
2724            client.delete_with_body(&format!("/v2/task/{}/dependency", task_id), &body).await.map_err(|e| e.to_string())?;
2725            Ok(json!({"message": format!("Dependency removed from task {}", task_id)}))
2726        }
2727
2728        "clickup_task_link" => {
2729            let task_id = args.get("task_id").and_then(|v| v.as_str())
2730                .ok_or("Missing required parameter: task_id")?;
2731            let links_to = args.get("links_to").and_then(|v| v.as_str())
2732                .ok_or("Missing required parameter: links_to")?;
2733            let resp = client.post(&format!("/v2/task/{}/link/{}", task_id, links_to), &json!({})).await.map_err(|e| e.to_string())?;
2734            Ok(json!({"message": format!("Task {} linked to {}", task_id, links_to), "data": resp}))
2735        }
2736
2737        "clickup_task_unlink" => {
2738            let task_id = args.get("task_id").and_then(|v| v.as_str())
2739                .ok_or("Missing required parameter: task_id")?;
2740            let links_to = args.get("links_to").and_then(|v| v.as_str())
2741                .ok_or("Missing required parameter: links_to")?;
2742            client.delete(&format!("/v2/task/{}/link/{}", task_id, links_to)).await.map_err(|e| e.to_string())?;
2743            Ok(json!({"message": format!("Task {} unlinked from {}", task_id, links_to)}))
2744        }
2745
2746        "clickup_goal_delete" => {
2747            let goal_id = args.get("goal_id").and_then(|v| v.as_str())
2748                .ok_or("Missing required parameter: goal_id")?;
2749            client.delete(&format!("/v2/goal/{}", goal_id)).await.map_err(|e| e.to_string())?;
2750            Ok(json!({"message": format!("Goal {} deleted", goal_id)}))
2751        }
2752
2753        "clickup_goal_add_kr" => {
2754            let goal_id = args.get("goal_id").and_then(|v| v.as_str())
2755                .ok_or("Missing required parameter: goal_id")?;
2756            let name = args.get("name").and_then(|v| v.as_str())
2757                .ok_or("Missing required parameter: name")?;
2758            let kr_type = args.get("type").and_then(|v| v.as_str())
2759                .ok_or("Missing required parameter: type")?;
2760            let steps_start = args.get("steps_start").and_then(|v| v.as_f64())
2761                .ok_or("Missing required parameter: steps_start")?;
2762            let steps_end = args.get("steps_end").and_then(|v| v.as_f64())
2763                .ok_or("Missing required parameter: steps_end")?;
2764            let mut body = json!({"name": name, "type": kr_type, "steps_start": steps_start, "steps_end": steps_end});
2765            if let Some(unit) = args.get("unit").and_then(|v| v.as_str()) { body["unit"] = json!(unit); }
2766            if let Some(owners) = args.get("owner_ids") { body["owners"] = owners.clone(); }
2767            if let Some(task_ids) = args.get("task_ids") { body["task_ids"] = task_ids.clone(); }
2768            if let Some(list_ids) = args.get("list_ids") { body["list_ids"] = list_ids.clone(); }
2769            let resp = client.post(&format!("/v2/goal/{}/key_result", goal_id), &body).await.map_err(|e| e.to_string())?;
2770            let kr = resp.get("key_result").cloned().unwrap_or(resp);
2771            Ok(compact_items(&[kr], &["id", "name", "type", "steps_start", "steps_end", "steps_current"]))
2772        }
2773
2774        "clickup_goal_update_kr" => {
2775            let kr_id = args.get("kr_id").and_then(|v| v.as_str())
2776                .ok_or("Missing required parameter: kr_id")?;
2777            let mut body = json!({});
2778            if let Some(v) = args.get("steps_current").and_then(|v| v.as_f64()) { body["steps_current"] = json!(v); }
2779            if let Some(v) = args.get("name").and_then(|v| v.as_str()) { body["name"] = json!(v); }
2780            if let Some(v) = args.get("unit").and_then(|v| v.as_str()) { body["unit"] = json!(v); }
2781            let resp = client.put(&format!("/v2/key_result/{}", kr_id), &body).await.map_err(|e| e.to_string())?;
2782            let kr = resp.get("key_result").cloned().unwrap_or(resp);
2783            Ok(compact_items(&[kr], &["id", "name", "steps_current", "steps_end"]))
2784        }
2785
2786        "clickup_goal_delete_kr" => {
2787            let kr_id = args.get("kr_id").and_then(|v| v.as_str())
2788                .ok_or("Missing required parameter: kr_id")?;
2789            client.delete(&format!("/v2/key_result/{}", kr_id)).await.map_err(|e| e.to_string())?;
2790            Ok(json!({"message": format!("Key result {} deleted", kr_id)}))
2791        }
2792
2793        "clickup_time_get" => {
2794            let team_id = resolve_workspace(args)?;
2795            let timer_id = args.get("timer_id").and_then(|v| v.as_str())
2796                .ok_or("Missing required parameter: timer_id")?;
2797            let resp = client.get(&format!("/v2/team/{}/time_entries/{}", team_id, timer_id)).await.map_err(|e| e.to_string())?;
2798            let data = resp.get("data").cloned().unwrap_or(resp);
2799            Ok(compact_items(&[data], &["id", "task", "duration", "start", "end", "billable"]))
2800        }
2801
2802        "clickup_time_create" => {
2803            let team_id = resolve_workspace(args)?;
2804            let start = args.get("start").and_then(|v| v.as_i64())
2805                .ok_or("Missing required parameter: start")?;
2806            let duration = args.get("duration").and_then(|v| v.as_i64())
2807                .ok_or("Missing required parameter: duration")?;
2808            let mut body = json!({"start": start, "duration": duration});
2809            if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) { body["tid"] = json!(task_id); }
2810            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) { body["description"] = json!(desc); }
2811            if let Some(billable) = args.get("billable").and_then(|v| v.as_bool()) { body["billable"] = json!(billable); }
2812            let resp = client.post(&format!("/v2/team/{}/time_entries", team_id), &body).await.map_err(|e| e.to_string())?;
2813            let data = resp.get("data").cloned().unwrap_or(resp);
2814            Ok(compact_items(&[data], &["id", "task", "duration", "start", "billable"]))
2815        }
2816
2817        "clickup_time_update" => {
2818            let team_id = resolve_workspace(args)?;
2819            let timer_id = args.get("timer_id").and_then(|v| v.as_str())
2820                .ok_or("Missing required parameter: timer_id")?;
2821            let mut body = json!({});
2822            if let Some(start) = args.get("start").and_then(|v| v.as_i64()) { body["start"] = json!(start); }
2823            if let Some(duration) = args.get("duration").and_then(|v| v.as_i64()) { body["duration"] = json!(duration); }
2824            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) { body["description"] = json!(desc); }
2825            if let Some(billable) = args.get("billable").and_then(|v| v.as_bool()) { body["billable"] = json!(billable); }
2826            let resp = client.put(&format!("/v2/team/{}/time_entries/{}", team_id, timer_id), &body).await.map_err(|e| e.to_string())?;
2827            let data = resp.get("data").cloned().unwrap_or(resp);
2828            Ok(compact_items(&[data], &["id", "task", "duration", "start", "billable"]))
2829        }
2830
2831        "clickup_time_delete" => {
2832            let team_id = resolve_workspace(args)?;
2833            let timer_id = args.get("timer_id").and_then(|v| v.as_str())
2834                .ok_or("Missing required parameter: timer_id")?;
2835            client.delete(&format!("/v2/team/{}/time_entries/{}", team_id, timer_id)).await.map_err(|e| e.to_string())?;
2836            Ok(json!({"message": format!("Time entry {} deleted", timer_id)}))
2837        }
2838
2839        "clickup_view_get" => {
2840            let view_id = args.get("view_id").and_then(|v| v.as_str())
2841                .ok_or("Missing required parameter: view_id")?;
2842            let resp = client.get(&format!("/v2/view/{}", view_id)).await.map_err(|e| e.to_string())?;
2843            let view = resp.get("view").cloned().unwrap_or(resp);
2844            Ok(compact_items(&[view], &["id", "name", "type"]))
2845        }
2846
2847        "clickup_view_create" => {
2848            let scope = args.get("scope").and_then(|v| v.as_str())
2849                .ok_or("Missing required parameter: scope")?;
2850            let scope_id = args.get("scope_id").and_then(|v| v.as_str())
2851                .ok_or("Missing required parameter: scope_id")?;
2852            let name = args.get("name").and_then(|v| v.as_str())
2853                .ok_or("Missing required parameter: name")?;
2854            let view_type = args.get("type").and_then(|v| v.as_str())
2855                .ok_or("Missing required parameter: type")?;
2856            let body = json!({"name": name, "type": view_type});
2857            let resp = client.post(&format!("/v2/{}/{}/view", scope, scope_id), &body).await.map_err(|e| e.to_string())?;
2858            let view = resp.get("view").cloned().unwrap_or(resp);
2859            Ok(compact_items(&[view], &["id", "name", "type"]))
2860        }
2861
2862        "clickup_view_update" => {
2863            let view_id = args.get("view_id").and_then(|v| v.as_str())
2864                .ok_or("Missing required parameter: view_id")?;
2865            let name = args.get("name").and_then(|v| v.as_str())
2866                .ok_or("Missing required parameter: name")?;
2867            let view_type = args.get("type").and_then(|v| v.as_str())
2868                .ok_or("Missing required parameter: type")?;
2869            let body = json!({"name": name, "type": view_type});
2870            let resp = client.put(&format!("/v2/view/{}", view_id), &body).await.map_err(|e| e.to_string())?;
2871            let view = resp.get("view").cloned().unwrap_or(resp);
2872            Ok(compact_items(&[view], &["id", "name", "type"]))
2873        }
2874
2875        "clickup_view_delete" => {
2876            let view_id = args.get("view_id").and_then(|v| v.as_str())
2877                .ok_or("Missing required parameter: view_id")?;
2878            client.delete(&format!("/v2/view/{}", view_id)).await.map_err(|e| e.to_string())?;
2879            Ok(json!({"message": format!("View {} deleted", view_id)}))
2880        }
2881
2882        "clickup_doc_create" => {
2883            let team_id = resolve_workspace(args)?;
2884            let name = args.get("name").and_then(|v| v.as_str())
2885                .ok_or("Missing required parameter: name")?;
2886            let mut body = json!({"name": name});
2887            if let Some(parent) = args.get("parent") { body["parent"] = parent.clone(); }
2888            let resp = client.post(&format!("/v3/workspaces/{}/docs", team_id), &body).await.map_err(|e| e.to_string())?;
2889            Ok(compact_items(&[resp], &["id", "name"]))
2890        }
2891
2892        "clickup_doc_add_page" => {
2893            let team_id = resolve_workspace(args)?;
2894            let doc_id = args.get("doc_id").and_then(|v| v.as_str())
2895                .ok_or("Missing required parameter: doc_id")?;
2896            let name = args.get("name").and_then(|v| v.as_str())
2897                .ok_or("Missing required parameter: name")?;
2898            let mut body = json!({"name": name});
2899            if let Some(content) = args.get("content").and_then(|v| v.as_str()) { body["content"] = json!(content); }
2900            if let Some(subtitle) = args.get("sub_title").and_then(|v| v.as_str()) { body["sub_title"] = json!(subtitle); }
2901            if let Some(parent_page_id) = args.get("parent_page_id").and_then(|v| v.as_str()) { body["parent_page_id"] = json!(parent_page_id); }
2902            let resp = client.post(&format!("/v3/workspaces/{}/docs/{}/pages", team_id, doc_id), &body).await.map_err(|e| e.to_string())?;
2903            Ok(compact_items(&[resp], &["id", "name"]))
2904        }
2905
2906        "clickup_doc_edit_page" => {
2907            let team_id = resolve_workspace(args)?;
2908            let doc_id = args.get("doc_id").and_then(|v| v.as_str())
2909                .ok_or("Missing required parameter: doc_id")?;
2910            let page_id = args.get("page_id").and_then(|v| v.as_str())
2911                .ok_or("Missing required parameter: page_id")?;
2912            let mut body = json!({});
2913            if let Some(name) = args.get("name").and_then(|v| v.as_str()) { body["name"] = json!(name); }
2914            if let Some(content) = args.get("content").and_then(|v| v.as_str()) { body["content"] = json!(content); }
2915            let resp = client.put(&format!("/v3/workspaces/{}/docs/{}/pages/{}", team_id, doc_id, page_id), &body).await.map_err(|e| e.to_string())?;
2916            Ok(compact_items(&[resp], &["id", "name"]))
2917        }
2918
2919        "clickup_chat_channel_create" => {
2920            let team_id = resolve_workspace(args)?;
2921            let name = args.get("name").and_then(|v| v.as_str())
2922                .ok_or("Missing required parameter: name")?;
2923            let mut body = json!({"name": name});
2924            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) { body["description"] = json!(desc); }
2925            if let Some(vis) = args.get("visibility").and_then(|v| v.as_str()) { body["visibility"] = json!(vis); }
2926            let resp = client.post(&format!("/v3/workspaces/{}/chat/channels", team_id), &body).await.map_err(|e| e.to_string())?;
2927            Ok(compact_items(&[resp], &["id", "name", "visibility"]))
2928        }
2929
2930        "clickup_chat_channel_get" => {
2931            let team_id = resolve_workspace(args)?;
2932            let channel_id = args.get("channel_id").and_then(|v| v.as_str())
2933                .ok_or("Missing required parameter: channel_id")?;
2934            let resp = client.get(&format!("/v3/workspaces/{}/chat/channels/{}", team_id, channel_id)).await.map_err(|e| e.to_string())?;
2935            Ok(compact_items(&[resp], &["id", "name", "visibility"]))
2936        }
2937
2938        "clickup_chat_channel_update" => {
2939            let team_id = resolve_workspace(args)?;
2940            let channel_id = args.get("channel_id").and_then(|v| v.as_str())
2941                .ok_or("Missing required parameter: channel_id")?;
2942            let mut body = json!({});
2943            if let Some(name) = args.get("name").and_then(|v| v.as_str()) { body["name"] = json!(name); }
2944            if let Some(desc) = args.get("description").and_then(|v| v.as_str()) { body["description"] = json!(desc); }
2945            let resp = client.patch(&format!("/v3/workspaces/{}/chat/channels/{}", team_id, channel_id), &body).await.map_err(|e| e.to_string())?;
2946            Ok(compact_items(&[resp], &["id", "name"]))
2947        }
2948
2949        "clickup_chat_channel_delete" => {
2950            let team_id = resolve_workspace(args)?;
2951            let channel_id = args.get("channel_id").and_then(|v| v.as_str())
2952                .ok_or("Missing required parameter: channel_id")?;
2953            client.delete(&format!("/v3/workspaces/{}/chat/channels/{}", team_id, channel_id)).await.map_err(|e| e.to_string())?;
2954            Ok(json!({"message": format!("Channel {} deleted", channel_id)}))
2955        }
2956
2957        "clickup_chat_message_list" => {
2958            let team_id = resolve_workspace(args)?;
2959            let channel_id = args.get("channel_id").and_then(|v| v.as_str())
2960                .ok_or("Missing required parameter: channel_id")?;
2961            let mut path = format!("/v3/workspaces/{}/chat/channels/{}/messages", team_id, channel_id);
2962            if let Some(cursor) = args.get("cursor").and_then(|v| v.as_str()) {
2963                path.push_str(&format!("?cursor={}", cursor));
2964            }
2965            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
2966            let messages = resp.get("messages").and_then(|m| m.as_array()).cloned().unwrap_or_default();
2967            Ok(compact_items(&messages, &["id", "content", "date"]))
2968        }
2969
2970        "clickup_chat_message_send" => {
2971            let team_id = resolve_workspace(args)?;
2972            let channel_id = args.get("channel_id").and_then(|v| v.as_str())
2973                .ok_or("Missing required parameter: channel_id")?;
2974            let content = args.get("content").and_then(|v| v.as_str())
2975                .ok_or("Missing required parameter: content")?;
2976            let body = json!({"content": content});
2977            let resp = client.post(&format!("/v3/workspaces/{}/chat/channels/{}/messages", team_id, channel_id), &body).await.map_err(|e| e.to_string())?;
2978            Ok(json!({"message": "Message sent", "id": resp.get("id")}))
2979        }
2980
2981        "clickup_chat_message_delete" => {
2982            let team_id = resolve_workspace(args)?;
2983            let message_id = args.get("message_id").and_then(|v| v.as_str())
2984                .ok_or("Missing required parameter: message_id")?;
2985            client.delete(&format!("/v3/workspaces/{}/chat/messages/{}", team_id, message_id)).await.map_err(|e| e.to_string())?;
2986            Ok(json!({"message": format!("Message {} deleted", message_id)}))
2987        }
2988
2989        "clickup_chat_dm" => {
2990            let team_id = resolve_workspace(args)?;
2991            let user_id = args.get("user_id").and_then(|v| v.as_i64())
2992                .ok_or("Missing required parameter: user_id")?;
2993            let content = args.get("content").and_then(|v| v.as_str())
2994                .ok_or("Missing required parameter: content")?;
2995            let body = json!({"user_id": user_id, "content": content});
2996            let resp = client.post(&format!("/v3/workspaces/{}/chat/channels/direct_message", team_id), &body).await.map_err(|e| e.to_string())?;
2997            Ok(json!({"message": "DM sent", "id": resp.get("id")}))
2998        }
2999
3000        "clickup_webhook_create" => {
3001            let team_id = resolve_workspace(args)?;
3002            let endpoint = args.get("endpoint").and_then(|v| v.as_str())
3003                .ok_or("Missing required parameter: endpoint")?;
3004            let events = args.get("events").ok_or("Missing required parameter: events")?;
3005            let mut body = json!({"endpoint": endpoint, "events": events});
3006            if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) { body["space_id"] = json!(space_id); }
3007            if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) { body["folder_id"] = json!(folder_id); }
3008            if let Some(list_id) = args.get("list_id").and_then(|v| v.as_str()) { body["list_id"] = json!(list_id); }
3009            if let Some(task_id) = args.get("task_id").and_then(|v| v.as_str()) { body["task_id"] = json!(task_id); }
3010            let resp = client.post(&format!("/v2/team/{}/webhook", team_id), &body).await.map_err(|e| e.to_string())?;
3011            let webhook = resp.get("webhook").cloned().unwrap_or(resp);
3012            Ok(compact_items(&[webhook], &["id", "endpoint", "events", "status"]))
3013        }
3014
3015        "clickup_webhook_update" => {
3016            let webhook_id = args.get("webhook_id").and_then(|v| v.as_str())
3017                .ok_or("Missing required parameter: webhook_id")?;
3018            let mut body = json!({});
3019            if let Some(endpoint) = args.get("endpoint").and_then(|v| v.as_str()) { body["endpoint"] = json!(endpoint); }
3020            if let Some(events) = args.get("events") { body["events"] = events.clone(); }
3021            if let Some(status) = args.get("status").and_then(|v| v.as_str()) { body["status"] = json!(status); }
3022            let resp = client.put(&format!("/v2/webhook/{}", webhook_id), &body).await.map_err(|e| e.to_string())?;
3023            let webhook = resp.get("webhook").cloned().unwrap_or(resp);
3024            Ok(compact_items(&[webhook], &["id", "endpoint", "events", "status"]))
3025        }
3026
3027        "clickup_webhook_delete" => {
3028            let webhook_id = args.get("webhook_id").and_then(|v| v.as_str())
3029                .ok_or("Missing required parameter: webhook_id")?;
3030            client.delete(&format!("/v2/webhook/{}", webhook_id)).await.map_err(|e| e.to_string())?;
3031            Ok(json!({"message": format!("Webhook {} deleted", webhook_id)}))
3032        }
3033
3034        "clickup_checklist_add_item" => {
3035            let checklist_id = args.get("checklist_id").and_then(|v| v.as_str())
3036                .ok_or("Missing required parameter: checklist_id")?;
3037            let name = args.get("name").and_then(|v| v.as_str())
3038                .ok_or("Missing required parameter: name")?;
3039            let mut body = json!({"name": name});
3040            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) { body["assignee"] = json!(assignee); }
3041            let resp = client.post(&format!("/v2/checklist/{}/checklist_item", checklist_id), &body).await.map_err(|e| e.to_string())?;
3042            let item = resp.get("checklist").cloned().unwrap_or(resp);
3043            Ok(compact_items(&[item], &["id", "name"]))
3044        }
3045
3046        "clickup_checklist_update_item" => {
3047            let checklist_id = args.get("checklist_id").and_then(|v| v.as_str())
3048                .ok_or("Missing required parameter: checklist_id")?;
3049            let item_id = args.get("item_id").and_then(|v| v.as_str())
3050                .ok_or("Missing required parameter: item_id")?;
3051            let mut body = json!({});
3052            if let Some(name) = args.get("name").and_then(|v| v.as_str()) { body["name"] = json!(name); }
3053            if let Some(resolved) = args.get("resolved").and_then(|v| v.as_bool()) { body["resolved"] = json!(resolved); }
3054            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) { body["assignee"] = json!(assignee); }
3055            client.put(&format!("/v2/checklist/{}/checklist_item/{}", checklist_id, item_id), &body).await.map_err(|e| e.to_string())?;
3056            Ok(json!({"message": format!("Checklist item {} updated", item_id)}))
3057        }
3058
3059        "clickup_checklist_delete_item" => {
3060            let checklist_id = args.get("checklist_id").and_then(|v| v.as_str())
3061                .ok_or("Missing required parameter: checklist_id")?;
3062            let item_id = args.get("item_id").and_then(|v| v.as_str())
3063                .ok_or("Missing required parameter: item_id")?;
3064            client.delete(&format!("/v2/checklist/{}/checklist_item/{}", checklist_id, item_id)).await.map_err(|e| e.to_string())?;
3065            Ok(json!({"message": format!("Checklist item {} deleted", item_id)}))
3066        }
3067
3068        "clickup_user_get" => {
3069            let team_id = resolve_workspace(args)?;
3070            let user_id = args.get("user_id").and_then(|v| v.as_i64())
3071                .ok_or("Missing required parameter: user_id")?;
3072            let resp = client.get(&format!("/v2/team/{}/user/{}", team_id, user_id)).await.map_err(|e| e.to_string())?;
3073            let member = resp.get("member").cloned().unwrap_or(resp);
3074            Ok(compact_items(&[member], &["user", "role"]))
3075        }
3076
3077        "clickup_workspace_seats" => {
3078            let team_id = resolve_workspace(args)?;
3079            let resp = client.get(&format!("/v2/team/{}/seats", team_id)).await.map_err(|e| e.to_string())?;
3080            Ok(json!(resp))
3081        }
3082
3083        "clickup_workspace_plan" => {
3084            let team_id = resolve_workspace(args)?;
3085            let resp = client.get(&format!("/v2/team/{}/plan", team_id)).await.map_err(|e| e.to_string())?;
3086            Ok(json!(resp))
3087        }
3088
3089        "clickup_tag_create" => {
3090            let space_id = args.get("space_id").and_then(|v| v.as_str())
3091                .ok_or("Missing required parameter: space_id")?;
3092            let name = args.get("name").and_then(|v| v.as_str())
3093                .ok_or("Missing required parameter: name")?;
3094            let mut tag = json!({"name": name});
3095            if let Some(fg) = args.get("tag_fg").and_then(|v| v.as_str()) { tag["tag_fg"] = json!(fg); }
3096            if let Some(bg) = args.get("tag_bg").and_then(|v| v.as_str()) { tag["tag_bg"] = json!(bg); }
3097            let body = json!({"tag": tag});
3098            client.post(&format!("/v2/space/{}/tag", space_id), &body).await.map_err(|e| e.to_string())?;
3099            Ok(json!({"message": format!("Tag '{}' created in space {}", name, space_id)}))
3100        }
3101
3102        "clickup_tag_update" => {
3103            let space_id = args.get("space_id").and_then(|v| v.as_str())
3104                .ok_or("Missing required parameter: space_id")?;
3105            let tag_name = args.get("tag_name").and_then(|v| v.as_str())
3106                .ok_or("Missing required parameter: tag_name")?;
3107            let mut tag = json!({});
3108            if let Some(name) = args.get("name").and_then(|v| v.as_str()) { tag["name"] = json!(name); }
3109            if let Some(fg) = args.get("tag_fg").and_then(|v| v.as_str()) { tag["tag_fg"] = json!(fg); }
3110            if let Some(bg) = args.get("tag_bg").and_then(|v| v.as_str()) { tag["tag_bg"] = json!(bg); }
3111            let body = json!({"tag": tag});
3112            client.put(&format!("/v2/space/{}/tag/{}", space_id, tag_name), &body).await.map_err(|e| e.to_string())?;
3113            Ok(json!({"message": format!("Tag '{}' updated", tag_name)}))
3114        }
3115
3116        "clickup_tag_delete" => {
3117            let space_id = args.get("space_id").and_then(|v| v.as_str())
3118                .ok_or("Missing required parameter: space_id")?;
3119            let tag_name = args.get("tag_name").and_then(|v| v.as_str())
3120                .ok_or("Missing required parameter: tag_name")?;
3121            client.delete(&format!("/v2/space/{}/tag/{}", space_id, tag_name)).await.map_err(|e| e.to_string())?;
3122            Ok(json!({"message": format!("Tag '{}' deleted from space {}", tag_name, space_id)}))
3123        }
3124
3125        "clickup_field_unset" => {
3126            let task_id = args.get("task_id").and_then(|v| v.as_str())
3127                .ok_or("Missing required parameter: task_id")?;
3128            let field_id = args.get("field_id").and_then(|v| v.as_str())
3129                .ok_or("Missing required parameter: field_id")?;
3130            client.delete(&format!("/v2/task/{}/field/{}", task_id, field_id)).await.map_err(|e| e.to_string())?;
3131            Ok(json!({"message": format!("Field {} unset on task {}", field_id, task_id)}))
3132        }
3133
3134        "clickup_attachment_list" => {
3135            let team_id = resolve_workspace(args)?;
3136            let task_id = args.get("task_id").and_then(|v| v.as_str())
3137                .ok_or("Missing required parameter: task_id")?;
3138            let resp = client.get(&format!("/v3/workspaces/{}/task/{}/attachments", team_id, task_id)).await.map_err(|e| e.to_string())?;
3139            let attachments = resp.get("attachments").and_then(|a| a.as_array()).cloned().unwrap_or_default();
3140            Ok(compact_items(&attachments, &["id", "title", "url", "date"]))
3141        }
3142
3143        "clickup_shared_list" => {
3144            let team_id = resolve_workspace(args)?;
3145            let resp = client.get(&format!("/v2/team/{}/shared", team_id)).await.map_err(|e| e.to_string())?;
3146            Ok(json!(resp))
3147        }
3148
3149        "clickup_group_list" => {
3150            let team_id = resolve_workspace(args)?;
3151            let mut qs = format!("team_id={}", team_id);
3152            if let Some(group_ids) = args.get("group_ids").and_then(|v| v.as_array()) {
3153                for id in group_ids {
3154                    if let Some(id) = id.as_str() {
3155                        qs.push_str(&format!("&group_ids[]={}", id));
3156                    }
3157                }
3158            }
3159            let resp = client.get(&format!("/v2/group?{}", qs)).await.map_err(|e| e.to_string())?;
3160            let groups = resp.get("groups").and_then(|g| g.as_array()).cloned().unwrap_or_default();
3161            Ok(compact_items(&groups, &["id", "name", "members"]))
3162        }
3163
3164        "clickup_group_create" => {
3165            let team_id = resolve_workspace(args)?;
3166            let name = args.get("name").and_then(|v| v.as_str())
3167                .ok_or("Missing required parameter: name")?;
3168            let mut body = json!({"name": name});
3169            if let Some(members) = args.get("member_ids") { body["members"] = members.clone(); }
3170            let resp = client.post(&format!("/v2/team/{}/group", team_id), &body).await.map_err(|e| e.to_string())?;
3171            Ok(compact_items(&[resp], &["id", "name"]))
3172        }
3173
3174        "clickup_group_update" => {
3175            let group_id = args.get("group_id").and_then(|v| v.as_str())
3176                .ok_or("Missing required parameter: group_id")?;
3177            let mut body = json!({});
3178            if let Some(name) = args.get("name").and_then(|v| v.as_str()) { body["name"] = json!(name); }
3179            if let Some(add) = args.get("add_members") {
3180                body["members"] = json!({"add": add, "rem": args.get("rem_members").cloned().unwrap_or(json!([]))});
3181            } else if let Some(rem) = args.get("rem_members") {
3182                body["members"] = json!({"add": [], "rem": rem});
3183            }
3184            let resp = client.put(&format!("/v2/group/{}", group_id), &body).await.map_err(|e| e.to_string())?;
3185            Ok(compact_items(&[resp], &["id", "name"]))
3186        }
3187
3188        "clickup_group_delete" => {
3189            let group_id = args.get("group_id").and_then(|v| v.as_str())
3190                .ok_or("Missing required parameter: group_id")?;
3191            client.delete(&format!("/v2/group/{}", group_id)).await.map_err(|e| e.to_string())?;
3192            Ok(json!({"message": format!("Group {} deleted", group_id)}))
3193        }
3194
3195        "clickup_role_list" => {
3196            let team_id = resolve_workspace(args)?;
3197            let resp = client.get(&format!("/v2/team/{}/customroles", team_id)).await.map_err(|e| e.to_string())?;
3198            let roles = resp.get("roles").and_then(|r| r.as_array()).cloned().unwrap_or_default();
3199            Ok(compact_items(&roles, &["id", "name"]))
3200        }
3201
3202        "clickup_guest_get" => {
3203            let team_id = resolve_workspace(args)?;
3204            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3205                .ok_or("Missing required parameter: guest_id")?;
3206            let resp = client.get(&format!("/v2/team/{}/guest/{}", team_id, guest_id)).await.map_err(|e| e.to_string())?;
3207            let guest = resp.get("guest").cloned().unwrap_or(resp);
3208            Ok(compact_items(&[guest], &["user", "role"]))
3209        }
3210
3211        "clickup_task_time_in_status" => {
3212            let task_id = args.get("task_id").and_then(|v| v.as_str())
3213                .ok_or("Missing required parameter: task_id")?;
3214            let resp = client.get(&format!("/v2/task/{}/time_in_status", task_id)).await.map_err(|e| e.to_string())?;
3215            Ok(resp)
3216        }
3217
3218        "clickup_task_move" => {
3219            let team_id = resolve_workspace(args)?;
3220            let task_id = args.get("task_id").and_then(|v| v.as_str())
3221                .ok_or("Missing required parameter: task_id")?;
3222            let list_id = args.get("list_id").and_then(|v| v.as_str())
3223                .ok_or("Missing required parameter: list_id")?;
3224            client.put(&format!("/v3/workspaces/{}/tasks/{}/home_list/{}", team_id, task_id, list_id), &json!({})).await.map_err(|e| e.to_string())?;
3225            Ok(json!({"message": format!("Task {} moved to list {}", task_id, list_id)}))
3226        }
3227
3228        "clickup_task_set_estimate" => {
3229            let team_id = resolve_workspace(args)?;
3230            let task_id = args.get("task_id").and_then(|v| v.as_str())
3231                .ok_or("Missing required parameter: task_id")?;
3232            let user_id = args.get("user_id").and_then(|v| v.as_i64())
3233                .ok_or("Missing required parameter: user_id")?;
3234            let time_estimate = args.get("time_estimate").and_then(|v| v.as_i64())
3235                .ok_or("Missing required parameter: time_estimate")?;
3236            let body = json!({"time_estimates": [{"user_id": user_id, "time_estimate": time_estimate}]});
3237            client.patch(&format!("/v3/workspaces/{}/tasks/{}/time_estimates_by_user", team_id, task_id), &body).await.map_err(|e| e.to_string())?;
3238            Ok(json!({"message": format!("Time estimate set for task {}", task_id)}))
3239        }
3240
3241        "clickup_task_replace_estimates" => {
3242            let team_id = resolve_workspace(args)?;
3243            let task_id = args.get("task_id").and_then(|v| v.as_str())
3244                .ok_or("Missing required parameter: task_id")?;
3245            let user_id = args.get("user_id").and_then(|v| v.as_i64())
3246                .ok_or("Missing required parameter: user_id")?;
3247            let time_estimate = args.get("time_estimate").and_then(|v| v.as_i64())
3248                .ok_or("Missing required parameter: time_estimate")?;
3249            let body = json!({"time_estimates": [{"user_id": user_id, "time_estimate": time_estimate}]});
3250            client.put(&format!("/v3/workspaces/{}/tasks/{}/time_estimates_by_user", team_id, task_id), &body).await.map_err(|e| e.to_string())?;
3251            Ok(json!({"message": format!("Time estimates replaced for task {}", task_id)}))
3252        }
3253
3254        "clickup_auth_check" => {
3255            client.get("/v2/user").await.map_err(|e| e.to_string())?;
3256            Ok(json!({"message": "Token valid"}))
3257        }
3258
3259        "clickup_checklist_update" => {
3260            let checklist_id = args.get("checklist_id").and_then(|v| v.as_str())
3261                .ok_or("Missing required parameter: checklist_id")?;
3262            let mut body = json!({});
3263            if let Some(name) = args.get("name").and_then(|v| v.as_str()) { body["name"] = json!(name); }
3264            if let Some(position) = args.get("position").and_then(|v| v.as_i64()) { body["position"] = json!(position); }
3265            let resp = client.put(&format!("/v2/checklist/{}", checklist_id), &body).await.map_err(|e| e.to_string())?;
3266            let checklist = resp.get("checklist").cloned().unwrap_or(resp);
3267            Ok(compact_items(&[checklist], &["id", "name"]))
3268        }
3269
3270        "clickup_comment_replies" => {
3271            let comment_id = args.get("comment_id").and_then(|v| v.as_str())
3272                .ok_or("Missing required parameter: comment_id")?;
3273            let resp = client.get(&format!("/v2/comment/{}/reply", comment_id)).await.map_err(|e| e.to_string())?;
3274            let comments = resp.get("comments")
3275                .or_else(|| resp.get("replies"))
3276                .and_then(|c| c.as_array())
3277                .cloned()
3278                .unwrap_or_default();
3279            Ok(compact_items(&comments, &["id", "user", "date", "comment_text"]))
3280        }
3281
3282        "clickup_comment_reply" => {
3283            let comment_id = args.get("comment_id").and_then(|v| v.as_str())
3284                .ok_or("Missing required parameter: comment_id")?;
3285            let text = args.get("text").and_then(|v| v.as_str())
3286                .ok_or("Missing required parameter: text")?;
3287            let mut body = json!({"comment_text": text});
3288            if let Some(assignee) = args.get("assignee").and_then(|v| v.as_i64()) { body["assignee"] = json!(assignee); }
3289            let resp = client.post(&format!("/v2/comment/{}/reply", comment_id), &body).await.map_err(|e| e.to_string())?;
3290            Ok(json!({"message": "Reply posted", "id": resp.get("id")}))
3291        }
3292
3293        "clickup_chat_channel_list" => {
3294            let team_id = resolve_workspace(args)?;
3295            let mut path = format!("/v3/workspaces/{}/chat/channels", team_id);
3296            if let Some(include_closed) = args.get("include_closed").and_then(|v| v.as_bool()) {
3297                path.push_str(&format!("?include_closed={}", include_closed));
3298            }
3299            let resp = client.get(&path).await.map_err(|e| e.to_string())?;
3300            let channels = resp.get("channels").and_then(|c| c.as_array()).cloned().unwrap_or_default();
3301            Ok(compact_items(&channels, &["id", "name", "type"]))
3302        }
3303
3304        "clickup_chat_channel_followers" => {
3305            let team_id = resolve_workspace(args)?;
3306            let channel_id = args.get("channel_id").and_then(|v| v.as_str())
3307                .ok_or("Missing required parameter: channel_id")?;
3308            let resp = client.get(&format!("/v3/workspaces/{}/chat/channels/{}/followers", team_id, channel_id)).await.map_err(|e| e.to_string())?;
3309            Ok(resp)
3310        }
3311
3312        "clickup_chat_channel_members" => {
3313            let team_id = resolve_workspace(args)?;
3314            let channel_id = args.get("channel_id").and_then(|v| v.as_str())
3315                .ok_or("Missing required parameter: channel_id")?;
3316            let resp = client.get(&format!("/v3/workspaces/{}/chat/channels/{}/members", team_id, channel_id)).await.map_err(|e| e.to_string())?;
3317            Ok(resp)
3318        }
3319
3320        "clickup_chat_message_update" => {
3321            let team_id = resolve_workspace(args)?;
3322            let message_id = args.get("message_id").and_then(|v| v.as_str())
3323                .ok_or("Missing required parameter: message_id")?;
3324            let text = args.get("text").and_then(|v| v.as_str())
3325                .ok_or("Missing required parameter: text")?;
3326            let body = json!({"content": text});
3327            client.patch(&format!("/v3/workspaces/{}/chat/messages/{}", team_id, message_id), &body).await.map_err(|e| e.to_string())?;
3328            Ok(json!({"message": format!("Message {} updated", message_id)}))
3329        }
3330
3331        "clickup_chat_reaction_list" => {
3332            let team_id = resolve_workspace(args)?;
3333            let message_id = args.get("message_id").and_then(|v| v.as_str())
3334                .ok_or("Missing required parameter: message_id")?;
3335            let resp = client.get(&format!("/v3/workspaces/{}/chat/messages/{}/reactions", team_id, message_id)).await.map_err(|e| e.to_string())?;
3336            Ok(resp)
3337        }
3338
3339        "clickup_chat_reaction_add" => {
3340            let team_id = resolve_workspace(args)?;
3341            let message_id = args.get("message_id").and_then(|v| v.as_str())
3342                .ok_or("Missing required parameter: message_id")?;
3343            let emoji = args.get("emoji").and_then(|v| v.as_str())
3344                .ok_or("Missing required parameter: emoji")?;
3345            let body = json!({"emoji": emoji});
3346            client.post(&format!("/v3/workspaces/{}/chat/messages/{}/reactions", team_id, message_id), &body).await.map_err(|e| e.to_string())?;
3347            Ok(json!({"message": format!("Reaction '{}' added to message {}", emoji, message_id)}))
3348        }
3349
3350        "clickup_chat_reaction_remove" => {
3351            let team_id = resolve_workspace(args)?;
3352            let message_id = args.get("message_id").and_then(|v| v.as_str())
3353                .ok_or("Missing required parameter: message_id")?;
3354            let emoji = args.get("emoji").and_then(|v| v.as_str())
3355                .ok_or("Missing required parameter: emoji")?;
3356            client.delete(&format!("/v3/workspaces/{}/chat/messages/{}/reactions/{}", team_id, message_id, emoji)).await.map_err(|e| e.to_string())?;
3357            Ok(json!({"message": format!("Reaction '{}' removed from message {}", emoji, message_id)}))
3358        }
3359
3360        "clickup_chat_reply_list" => {
3361            let team_id = resolve_workspace(args)?;
3362            let message_id = args.get("message_id").and_then(|v| v.as_str())
3363                .ok_or("Missing required parameter: message_id")?;
3364            let resp = client.get(&format!("/v3/workspaces/{}/chat/messages/{}/replies", team_id, message_id)).await.map_err(|e| e.to_string())?;
3365            Ok(resp)
3366        }
3367
3368        "clickup_chat_reply_send" => {
3369            let team_id = resolve_workspace(args)?;
3370            let message_id = args.get("message_id").and_then(|v| v.as_str())
3371                .ok_or("Missing required parameter: message_id")?;
3372            let text = args.get("text").and_then(|v| v.as_str())
3373                .ok_or("Missing required parameter: text")?;
3374            let body = json!({"content": text});
3375            let resp = client.post(&format!("/v3/workspaces/{}/chat/messages/{}/replies", team_id, message_id), &body).await.map_err(|e| e.to_string())?;
3376            Ok(json!({"message": "Reply sent", "id": resp.get("id")}))
3377        }
3378
3379        "clickup_chat_tagged_users" => {
3380            let team_id = resolve_workspace(args)?;
3381            let message_id = args.get("message_id").and_then(|v| v.as_str())
3382                .ok_or("Missing required parameter: message_id")?;
3383            let resp = client.get(&format!("/v3/workspaces/{}/chat/messages/{}/tagged_users", team_id, message_id)).await.map_err(|e| e.to_string())?;
3384            Ok(resp)
3385        }
3386
3387        "clickup_time_current" => {
3388            let team_id = resolve_workspace(args)?;
3389            let resp = client.get(&format!("/v2/team/{}/time_entries/current", team_id)).await.map_err(|e| e.to_string())?;
3390            let data = resp.get("data").cloned().unwrap_or(resp);
3391            Ok(compact_items(&[data], &["id", "task", "duration", "start", "billable"]))
3392        }
3393
3394        "clickup_time_tags" => {
3395            let team_id = resolve_workspace(args)?;
3396            let resp = client.get(&format!("/v2/team/{}/time_entries/tags", team_id)).await.map_err(|e| e.to_string())?;
3397            let tags = resp.get("data").and_then(|d| d.as_array()).cloned().unwrap_or_default();
3398            Ok(compact_items(&tags, &["name"]))
3399        }
3400
3401        "clickup_time_add_tags" => {
3402            let team_id = resolve_workspace(args)?;
3403            let entry_ids = args.get("entry_ids").and_then(|v| v.as_array())
3404                .ok_or("Missing required parameter: entry_ids")?;
3405            let tag_names = args.get("tag_names").and_then(|v| v.as_array())
3406                .ok_or("Missing required parameter: tag_names")?;
3407            let tags: Vec<Value> = tag_names.iter()
3408                .filter_map(|n| n.as_str())
3409                .map(|n| json!({"name": n}))
3410                .collect();
3411            let body = json!({"time_entry_ids": entry_ids, "tags": tags});
3412            client.post(&format!("/v2/team/{}/time_entries/tags", team_id), &body).await.map_err(|e| e.to_string())?;
3413            Ok(json!({"message": "Tags added to time entries"}))
3414        }
3415
3416        "clickup_time_remove_tags" => {
3417            let team_id = resolve_workspace(args)?;
3418            let entry_ids = args.get("entry_ids").and_then(|v| v.as_array())
3419                .ok_or("Missing required parameter: entry_ids")?;
3420            let tag_names = args.get("tag_names").and_then(|v| v.as_array())
3421                .ok_or("Missing required parameter: tag_names")?;
3422            let tags: Vec<Value> = tag_names.iter()
3423                .filter_map(|n| n.as_str())
3424                .map(|n| json!({"name": n}))
3425                .collect();
3426            let body = json!({"time_entry_ids": entry_ids, "tags": tags});
3427            client.delete_with_body(&format!("/v2/team/{}/time_entries/tags", team_id), &body).await.map_err(|e| e.to_string())?;
3428            Ok(json!({"message": "Tags removed from time entries"}))
3429        }
3430
3431        "clickup_time_rename_tag" => {
3432            let team_id = resolve_workspace(args)?;
3433            let name = args.get("name").and_then(|v| v.as_str())
3434                .ok_or("Missing required parameter: name")?;
3435            let new_name = args.get("new_name").and_then(|v| v.as_str())
3436                .ok_or("Missing required parameter: new_name")?;
3437            let body = json!({"name": name, "new_name": new_name});
3438            client.put(&format!("/v2/team/{}/time_entries/tags", team_id), &body).await.map_err(|e| e.to_string())?;
3439            Ok(json!({"message": format!("Tag '{}' renamed to '{}'", name, new_name)}))
3440        }
3441
3442        "clickup_time_history" => {
3443            let team_id = resolve_workspace(args)?;
3444            let timer_id = args.get("timer_id").and_then(|v| v.as_str())
3445                .ok_or("Missing required parameter: timer_id")?;
3446            let resp = client.get(&format!("/v2/team/{}/time_entries/{}/history", team_id, timer_id)).await.map_err(|e| e.to_string())?;
3447            Ok(resp)
3448        }
3449
3450        "clickup_guest_invite" => {
3451            let team_id = resolve_workspace(args)?;
3452            let email = args.get("email").and_then(|v| v.as_str())
3453                .ok_or("Missing required parameter: email")?;
3454            let mut body = json!({"email": email});
3455            if let Some(v) = args.get("can_edit_tags").and_then(|v| v.as_bool()) { body["can_edit_tags"] = json!(v); }
3456            if let Some(v) = args.get("can_see_time_spent").and_then(|v| v.as_bool()) { body["can_see_time_spent"] = json!(v); }
3457            if let Some(v) = args.get("can_create_views").and_then(|v| v.as_bool()) { body["can_create_views"] = json!(v); }
3458            let resp = client.post(&format!("/v2/team/{}/guest", team_id), &body).await.map_err(|e| e.to_string())?;
3459            let guest = resp.get("guest").cloned().unwrap_or(resp);
3460            let user = guest.get("user").cloned().unwrap_or(guest);
3461            Ok(compact_items(&[user], &["id", "email"]))
3462        }
3463
3464        "clickup_guest_update" => {
3465            let team_id = resolve_workspace(args)?;
3466            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3467                .ok_or("Missing required parameter: guest_id")?;
3468            let mut body = json!({});
3469            if let Some(v) = args.get("can_edit_tags").and_then(|v| v.as_bool()) { body["can_edit_tags"] = json!(v); }
3470            if let Some(v) = args.get("can_see_time_spent").and_then(|v| v.as_bool()) { body["can_see_time_spent"] = json!(v); }
3471            if let Some(v) = args.get("can_create_views").and_then(|v| v.as_bool()) { body["can_create_views"] = json!(v); }
3472            client.put(&format!("/v2/team/{}/guest/{}", team_id, guest_id), &body).await.map_err(|e| e.to_string())?;
3473            Ok(json!({"message": format!("Guest {} updated", guest_id)}))
3474        }
3475
3476        "clickup_guest_remove" => {
3477            let team_id = resolve_workspace(args)?;
3478            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3479                .ok_or("Missing required parameter: guest_id")?;
3480            client.delete(&format!("/v2/team/{}/guest/{}", team_id, guest_id)).await.map_err(|e| e.to_string())?;
3481            Ok(json!({"message": format!("Guest {} removed", guest_id)}))
3482        }
3483
3484        "clickup_guest_share_task" => {
3485            let task_id = args.get("task_id").and_then(|v| v.as_str())
3486                .ok_or("Missing required parameter: task_id")?;
3487            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3488                .ok_or("Missing required parameter: guest_id")?;
3489            let permission = args.get("permission").and_then(|v| v.as_str())
3490                .ok_or("Missing required parameter: permission")?;
3491            let body = json!({"permission_level": permission});
3492            client.post(&format!("/v2/task/{}/guest/{}", task_id, guest_id), &body).await.map_err(|e| e.to_string())?;
3493            Ok(json!({"message": format!("Task {} shared with guest {}", task_id, guest_id)}))
3494        }
3495
3496        "clickup_guest_unshare_task" => {
3497            let task_id = args.get("task_id").and_then(|v| v.as_str())
3498                .ok_or("Missing required parameter: task_id")?;
3499            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3500                .ok_or("Missing required parameter: guest_id")?;
3501            client.delete(&format!("/v2/task/{}/guest/{}", task_id, guest_id)).await.map_err(|e| e.to_string())?;
3502            Ok(json!({"message": format!("Guest {} unshared from task {}", guest_id, task_id)}))
3503        }
3504
3505        "clickup_guest_share_list" => {
3506            let list_id = args.get("list_id").and_then(|v| v.as_str())
3507                .ok_or("Missing required parameter: list_id")?;
3508            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3509                .ok_or("Missing required parameter: guest_id")?;
3510            let permission = args.get("permission").and_then(|v| v.as_str())
3511                .ok_or("Missing required parameter: permission")?;
3512            let body = json!({"permission_level": permission});
3513            client.post(&format!("/v2/list/{}/guest/{}", list_id, guest_id), &body).await.map_err(|e| e.to_string())?;
3514            Ok(json!({"message": format!("List {} shared with guest {}", list_id, guest_id)}))
3515        }
3516
3517        "clickup_guest_unshare_list" => {
3518            let list_id = args.get("list_id").and_then(|v| v.as_str())
3519                .ok_or("Missing required parameter: list_id")?;
3520            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3521                .ok_or("Missing required parameter: guest_id")?;
3522            client.delete(&format!("/v2/list/{}/guest/{}", list_id, guest_id)).await.map_err(|e| e.to_string())?;
3523            Ok(json!({"message": format!("Guest {} unshared from list {}", guest_id, list_id)}))
3524        }
3525
3526        "clickup_guest_share_folder" => {
3527            let folder_id = args.get("folder_id").and_then(|v| v.as_str())
3528                .ok_or("Missing required parameter: folder_id")?;
3529            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3530                .ok_or("Missing required parameter: guest_id")?;
3531            let permission = args.get("permission").and_then(|v| v.as_str())
3532                .ok_or("Missing required parameter: permission")?;
3533            let body = json!({"permission_level": permission});
3534            client.post(&format!("/v2/folder/{}/guest/{}", folder_id, guest_id), &body).await.map_err(|e| e.to_string())?;
3535            Ok(json!({"message": format!("Folder {} shared with guest {}", folder_id, guest_id)}))
3536        }
3537
3538        "clickup_guest_unshare_folder" => {
3539            let folder_id = args.get("folder_id").and_then(|v| v.as_str())
3540                .ok_or("Missing required parameter: folder_id")?;
3541            let guest_id = args.get("guest_id").and_then(|v| v.as_i64())
3542                .ok_or("Missing required parameter: guest_id")?;
3543            client.delete(&format!("/v2/folder/{}/guest/{}", folder_id, guest_id)).await.map_err(|e| e.to_string())?;
3544            Ok(json!({"message": format!("Guest {} unshared from folder {}", guest_id, folder_id)}))
3545        }
3546
3547        "clickup_user_invite" => {
3548            let team_id = resolve_workspace(args)?;
3549            let email = args.get("email").and_then(|v| v.as_str())
3550                .ok_or("Missing required parameter: email")?;
3551            let mut body = json!({"email": email});
3552            if let Some(admin) = args.get("admin").and_then(|v| v.as_bool()) { body["admin"] = json!(admin); }
3553            let resp = client.post(&format!("/v2/team/{}/user", team_id), &body).await.map_err(|e| e.to_string())?;
3554            let member = resp.get("member").cloned().unwrap_or(resp);
3555            let user = member.get("user").cloned().unwrap_or(member);
3556            Ok(compact_items(&[user], &["id", "username", "email"]))
3557        }
3558
3559        "clickup_user_update" => {
3560            let team_id = resolve_workspace(args)?;
3561            let user_id = args.get("user_id").and_then(|v| v.as_i64())
3562                .ok_or("Missing required parameter: user_id")?;
3563            let mut body = json!({});
3564            if let Some(username) = args.get("username").and_then(|v| v.as_str()) { body["username"] = json!(username); }
3565            if let Some(admin) = args.get("admin").and_then(|v| v.as_bool()) { body["admin"] = json!(admin); }
3566            client.put(&format!("/v2/team/{}/user/{}", team_id, user_id), &body).await.map_err(|e| e.to_string())?;
3567            Ok(json!({"message": format!("User {} updated", user_id)}))
3568        }
3569
3570        "clickup_user_remove" => {
3571            let team_id = resolve_workspace(args)?;
3572            let user_id = args.get("user_id").and_then(|v| v.as_i64())
3573                .ok_or("Missing required parameter: user_id")?;
3574            client.delete(&format!("/v2/team/{}/user/{}", team_id, user_id)).await.map_err(|e| e.to_string())?;
3575            Ok(json!({"message": format!("User {} removed from workspace", user_id)}))
3576        }
3577
3578        "clickup_template_apply_task" => {
3579            let list_id = args.get("list_id").and_then(|v| v.as_str())
3580                .ok_or("Missing required parameter: list_id")?;
3581            let template_id = args.get("template_id").and_then(|v| v.as_str())
3582                .ok_or("Missing required parameter: template_id")?;
3583            let name = args.get("name").and_then(|v| v.as_str())
3584                .ok_or("Missing required parameter: name")?;
3585            let body = json!({"name": name});
3586            let resp = client.post(&format!("/v2/list/{}/taskTemplate/{}", list_id, template_id), &body).await.map_err(|e| e.to_string())?;
3587            Ok(compact_items(&[resp], &["id", "name"]))
3588        }
3589
3590        "clickup_template_apply_list" => {
3591            let template_id = args.get("template_id").and_then(|v| v.as_str())
3592                .ok_or("Missing required parameter: template_id")?;
3593            let name = args.get("name").and_then(|v| v.as_str())
3594                .ok_or("Missing required parameter: name")?;
3595            let body = json!({"name": name});
3596            let path = if let Some(folder_id) = args.get("folder_id").and_then(|v| v.as_str()) {
3597                format!("/v2/folder/{}/list_template/{}", folder_id, template_id)
3598            } else if let Some(space_id) = args.get("space_id").and_then(|v| v.as_str()) {
3599                format!("/v2/space/{}/list_template/{}", space_id, template_id)
3600            } else {
3601                return Err("Provide either folder_id or space_id".to_string());
3602            };
3603            client.post(&path, &body).await.map_err(|e| e.to_string())?;
3604            Ok(json!({"message": format!("List '{}' created from template {}", name, template_id)}))
3605        }
3606
3607        "clickup_template_apply_folder" => {
3608            let space_id = args.get("space_id").and_then(|v| v.as_str())
3609                .ok_or("Missing required parameter: space_id")?;
3610            let template_id = args.get("template_id").and_then(|v| v.as_str())
3611                .ok_or("Missing required parameter: template_id")?;
3612            let name = args.get("name").and_then(|v| v.as_str())
3613                .ok_or("Missing required parameter: name")?;
3614            let body = json!({"name": name});
3615            client.post(&format!("/v2/space/{}/folder_template/{}", space_id, template_id), &body).await.map_err(|e| e.to_string())?;
3616            Ok(json!({"message": format!("Folder '{}' created from template {}", name, template_id)}))
3617        }
3618
3619        "clickup_attachment_upload" => {
3620            let task_id = args.get("task_id").and_then(|v| v.as_str())
3621                .ok_or("Missing required parameter: task_id")?;
3622            let file_path = args.get("file_path").and_then(|v| v.as_str())
3623                .ok_or("Missing required parameter: file_path")?;
3624            let path = format!("/v2/task/{}/attachment", task_id);
3625            let resp = client.upload_file(&path, std::path::Path::new(file_path)).await.map_err(|e| e.to_string())?;
3626            Ok(json!({"message": "File uploaded", "id": resp.get("id"), "url": resp.get("url")}))
3627        }
3628
3629        "clickup_task_type_list" => {
3630            let team_id = resolve_workspace(args)?;
3631            let resp = client.get(&format!("/v2/team/{}/custom_item", team_id)).await.map_err(|e| e.to_string())?;
3632            let items = resp.get("custom_items").and_then(|i| i.as_array()).cloned().unwrap_or_default();
3633            Ok(compact_items(&items, &["id", "name", "name_plural"]))
3634        }
3635
3636        "clickup_doc_get_page" => {
3637            let team_id = resolve_workspace(args)?;
3638            let doc_id = args.get("doc_id").and_then(|v| v.as_str())
3639                .ok_or("Missing required parameter: doc_id")?;
3640            let page_id = args.get("page_id").and_then(|v| v.as_str())
3641                .ok_or("Missing required parameter: page_id")?;
3642            let resp = client.get(&format!("/v3/workspaces/{}/docs/{}/pages/{}", team_id, doc_id, page_id)).await.map_err(|e| e.to_string())?;
3643            Ok(resp)
3644        }
3645
3646        "clickup_audit_log_query" => {
3647            let team_id = resolve_workspace(args)?;
3648            let event_type = args.get("type").and_then(|v| v.as_str())
3649                .ok_or("Missing required parameter: type")?;
3650            let mut body = json!({"type": event_type});
3651            if let Some(user_id) = args.get("user_id").and_then(|v| v.as_i64()) {
3652                body["user_id"] = json!(user_id);
3653            }
3654            if let Some(start_date) = args.get("start_date").and_then(|v| v.as_i64()) {
3655                body["date_filter"] = json!({"start_date": start_date, "end_date": args.get("end_date").and_then(|v| v.as_i64()).unwrap_or(i64::MAX)});
3656            } else if let Some(end_date) = args.get("end_date").and_then(|v| v.as_i64()) {
3657                body["date_filter"] = json!({"end_date": end_date});
3658            }
3659            let resp = client.post(&format!("/v3/workspaces/{}/auditlogs", team_id), &body).await.map_err(|e| e.to_string())?;
3660            Ok(resp)
3661        }
3662
3663        "clickup_acl_update" => {
3664            let team_id = resolve_workspace(args)?;
3665            let object_type = args.get("object_type").and_then(|v| v.as_str())
3666                .ok_or("Missing required parameter: object_type")?;
3667            let object_id = args.get("object_id").and_then(|v| v.as_str())
3668                .ok_or("Missing required parameter: object_id")?;
3669            let mut body = json!({});
3670            if let Some(private) = args.get("private").and_then(|v| v.as_bool()) { body["private"] = json!(private); }
3671            client.patch(&format!("/v3/workspaces/{}/{}/{}/acls", team_id, object_type, object_id), &body).await.map_err(|e| e.to_string())?;
3672            Ok(json!({"message": format!("ACL updated for {} {}", object_type, object_id)}))
3673        }
3674
3675        unknown => Err(format!("Unknown tool: {}", unknown)),
3676    }
3677}
3678
3679// ── Main server loop ──────────────────────────────────────────────────────────
3680
3681pub async fn serve(filter: filter::Filter) -> Result<(), Box<dyn std::error::Error>> {
3682    // Resolve token: CLICKUP_TOKEN env > config file
3683    let token = std::env::var("CLICKUP_TOKEN")
3684        .ok()
3685        .filter(|t| !t.is_empty())
3686        .or_else(|| Config::load().ok().map(|c| c.auth.token).filter(|t| !t.is_empty()))
3687        .ok_or("No API token. Set CLICKUP_TOKEN env var or run `clickup setup`.")?;
3688
3689    // Resolve workspace: CLICKUP_WORKSPACE env > config file
3690    let workspace_id = std::env::var("CLICKUP_WORKSPACE")
3691        .ok()
3692        .filter(|w| !w.is_empty())
3693        .or_else(|| Config::load().ok().and_then(|c| c.defaults.workspace_id));
3694
3695    let client = ClickUpClient::new(&token, 30)
3696        .map_err(|e| format!("Failed to create HTTP client: {}", e))?;
3697
3698    let stdin = tokio::io::stdin();
3699    let reader = BufReader::new(stdin);
3700    let mut lines = reader.lines();
3701
3702    let groups_str = filter
3703        .groups
3704        .as_ref()
3705        .map(|g| format!(", groups=[{}]", g.join(",")))
3706        .unwrap_or_default();
3707    let excluded_groups_str = filter
3708        .exclude_groups
3709        .as_ref()
3710        .map(|g| format!(", exclude-groups=[{}]", g.join(",")))
3711        .unwrap_or_default();
3712    eprintln!(
3713        "MCP: profile={}{}{}, exposing {}/{} tools",
3714        filter.profile.as_str(),
3715        groups_str,
3716        excluded_groups_str,
3717        filter.allowed_count(),
3718        tool_list().as_array().map(Vec::len).unwrap_or(0),
3719    );
3720
3721    while let Some(line) = lines.next_line().await? {
3722        let line = line.trim().to_string();
3723        if line.is_empty() {
3724            continue;
3725        }
3726
3727        let msg: Value = match serde_json::from_str(&line) {
3728            Ok(v) => v,
3729            Err(e) => {
3730                // Parse error — send error response with null id
3731                let resp = error_response(&Value::Null, -32700, &format!("Parse error: {}", e));
3732                println!("{}", resp);
3733                continue;
3734            }
3735        };
3736
3737        // Notifications have no id — don't respond
3738        let id = msg.get("id").cloned().unwrap_or(Value::Null);
3739        let method = msg.get("method").and_then(|v| v.as_str()).unwrap_or("");
3740
3741        if id.is_null() && method.starts_with("notifications/") {
3742            // Notification — no response needed
3743            continue;
3744        }
3745
3746        let resp = match method {
3747            "initialize" => {
3748                let version = msg
3749                    .get("params")
3750                    .and_then(|p| p.get("protocolVersion"))
3751                    .and_then(|v| v.as_str())
3752                    .unwrap_or("2024-11-05");
3753                ok_response(
3754                    &id,
3755                    json!({
3756                        "protocolVersion": version,
3757                        "capabilities": {"tools": {}},
3758                        "serverInfo": {
3759                            "name": "clickup-cli",
3760                            "version": env!("CARGO_PKG_VERSION")
3761                        }
3762                    }),
3763                )
3764            }
3765
3766            "tools/list" => ok_response(&id, json!({"tools": filtered_tool_list(&filter)})),
3767
3768            "tools/call" => {
3769                let params = msg.get("params").cloned().unwrap_or(json!({}));
3770                if let Some(response) = handle_tools_call_early(&id, &params, &filter) {
3771                    response
3772                } else {
3773                    let tool_name = params
3774                        .get("name")
3775                        .and_then(|v| v.as_str())
3776                        .unwrap_or("");
3777                    let arguments = params.get("arguments").cloned().unwrap_or(json!({}));
3778                    let result = call_tool(tool_name, &arguments, &client, &workspace_id).await;
3779                    ok_response(&id, result)
3780                }
3781            }
3782
3783            other => {
3784                // Unknown method
3785                eprintln!("Unknown method: {}", other);
3786                error_response(&id, -32601, &format!("Method not found: {}", other))
3787            }
3788        };
3789
3790        println!("{}", resp);
3791    }
3792
3793    Ok(())
3794}