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