workspace-mcp 1.1.3__py3-none-any.whl → 1.1.5__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- auth/google_auth.py +6 -8
- auth/oauth_callback_server.py +22 -8
- auth/scopes.py +10 -1
- auth/service_decorator.py +8 -2
- core/server.py +4 -1
- gcalendar/calendar_tools.py +1 -1
- gdocs/docs_tools.py +0 -1
- gforms/forms_tools.py +17 -18
- gmail/gmail_tools.py +0 -1
- gtasks/__init__.py +5 -0
- gtasks/tasks_tools.py +732 -0
- main.py +6 -4
- {workspace_mcp-1.1.3.dist-info → workspace_mcp-1.1.5.dist-info}/METADATA +79 -17
- {workspace_mcp-1.1.3.dist-info → workspace_mcp-1.1.5.dist-info}/RECORD +18 -16
- {workspace_mcp-1.1.3.dist-info → workspace_mcp-1.1.5.dist-info}/top_level.txt +1 -0
- {workspace_mcp-1.1.3.dist-info → workspace_mcp-1.1.5.dist-info}/WHEEL +0 -0
- {workspace_mcp-1.1.3.dist-info → workspace_mcp-1.1.5.dist-info}/entry_points.txt +0 -0
- {workspace_mcp-1.1.3.dist-info → workspace_mcp-1.1.5.dist-info}/licenses/LICENSE +0 -0
gtasks/tasks_tools.py
ADDED
@@ -0,0 +1,732 @@
|
|
1
|
+
"""
|
2
|
+
Google Tasks MCP Tools
|
3
|
+
|
4
|
+
This module provides MCP tools for interacting with Google Tasks API.
|
5
|
+
"""
|
6
|
+
|
7
|
+
import logging
|
8
|
+
import asyncio
|
9
|
+
from typing import List, Optional, Dict, Any
|
10
|
+
|
11
|
+
from mcp import types
|
12
|
+
from googleapiclient.errors import HttpError
|
13
|
+
|
14
|
+
from auth.service_decorator import require_google_service
|
15
|
+
from core.server import server
|
16
|
+
|
17
|
+
logger = logging.getLogger(__name__)
|
18
|
+
|
19
|
+
|
20
|
+
@server.tool()
|
21
|
+
@require_google_service("tasks", "tasks_read")
|
22
|
+
async def list_task_lists(
|
23
|
+
service,
|
24
|
+
user_google_email: str,
|
25
|
+
max_results: Optional[int] = None,
|
26
|
+
page_token: Optional[str] = None
|
27
|
+
) -> str:
|
28
|
+
"""
|
29
|
+
List all task lists for the user.
|
30
|
+
|
31
|
+
Args:
|
32
|
+
user_google_email (str): The user's Google email address. Required.
|
33
|
+
max_results (Optional[int]): Maximum number of task lists to return (default: 1000, max: 1000).
|
34
|
+
page_token (Optional[str]): Token for pagination.
|
35
|
+
|
36
|
+
Returns:
|
37
|
+
str: List of task lists with their IDs, titles, and details.
|
38
|
+
"""
|
39
|
+
logger.info(f"[list_task_lists] Invoked. Email: '{user_google_email}'")
|
40
|
+
|
41
|
+
try:
|
42
|
+
params = {}
|
43
|
+
if max_results is not None:
|
44
|
+
params["maxResults"] = max_results
|
45
|
+
if page_token:
|
46
|
+
params["pageToken"] = page_token
|
47
|
+
|
48
|
+
result = await asyncio.to_thread(
|
49
|
+
service.tasklists().list(**params).execute
|
50
|
+
)
|
51
|
+
|
52
|
+
task_lists = result.get("items", [])
|
53
|
+
next_page_token = result.get("nextPageToken")
|
54
|
+
|
55
|
+
if not task_lists:
|
56
|
+
return f"No task lists found for {user_google_email}."
|
57
|
+
|
58
|
+
response = f"Task Lists for {user_google_email}:\n"
|
59
|
+
for task_list in task_lists:
|
60
|
+
response += f"- {task_list['title']} (ID: {task_list['id']})\n"
|
61
|
+
response += f" Updated: {task_list.get('updated', 'N/A')}\n"
|
62
|
+
|
63
|
+
if next_page_token:
|
64
|
+
response += f"\nNext page token: {next_page_token}"
|
65
|
+
|
66
|
+
logger.info(f"Found {len(task_lists)} task lists for {user_google_email}")
|
67
|
+
return response
|
68
|
+
|
69
|
+
except HttpError as error:
|
70
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
71
|
+
logger.error(message, exc_info=True)
|
72
|
+
raise Exception(message)
|
73
|
+
except Exception as e:
|
74
|
+
message = f"Unexpected error: {e}."
|
75
|
+
logger.exception(message)
|
76
|
+
raise Exception(message)
|
77
|
+
|
78
|
+
|
79
|
+
@server.tool()
|
80
|
+
@require_google_service("tasks", "tasks_read")
|
81
|
+
async def get_task_list(
|
82
|
+
service,
|
83
|
+
user_google_email: str,
|
84
|
+
task_list_id: str
|
85
|
+
) -> str:
|
86
|
+
"""
|
87
|
+
Get details of a specific task list.
|
88
|
+
|
89
|
+
Args:
|
90
|
+
user_google_email (str): The user's Google email address. Required.
|
91
|
+
task_list_id (str): The ID of the task list to retrieve.
|
92
|
+
|
93
|
+
Returns:
|
94
|
+
str: Task list details including title, ID, and last updated time.
|
95
|
+
"""
|
96
|
+
logger.info(f"[get_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}")
|
97
|
+
|
98
|
+
try:
|
99
|
+
task_list = await asyncio.to_thread(
|
100
|
+
service.tasklists().get(tasklist=task_list_id).execute
|
101
|
+
)
|
102
|
+
|
103
|
+
response = f"""Task List Details for {user_google_email}:
|
104
|
+
- Title: {task_list['title']}
|
105
|
+
- ID: {task_list['id']}
|
106
|
+
- Updated: {task_list.get('updated', 'N/A')}
|
107
|
+
- Self Link: {task_list.get('selfLink', 'N/A')}"""
|
108
|
+
|
109
|
+
logger.info(f"Retrieved task list '{task_list['title']}' for {user_google_email}")
|
110
|
+
return response
|
111
|
+
|
112
|
+
except HttpError as error:
|
113
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
114
|
+
logger.error(message, exc_info=True)
|
115
|
+
raise Exception(message)
|
116
|
+
except Exception as e:
|
117
|
+
message = f"Unexpected error: {e}."
|
118
|
+
logger.exception(message)
|
119
|
+
raise Exception(message)
|
120
|
+
|
121
|
+
|
122
|
+
@server.tool()
|
123
|
+
@require_google_service("tasks", "tasks")
|
124
|
+
async def create_task_list(
|
125
|
+
service,
|
126
|
+
user_google_email: str,
|
127
|
+
title: str
|
128
|
+
) -> str:
|
129
|
+
"""
|
130
|
+
Create a new task list.
|
131
|
+
|
132
|
+
Args:
|
133
|
+
user_google_email (str): The user's Google email address. Required.
|
134
|
+
title (str): The title of the new task list.
|
135
|
+
|
136
|
+
Returns:
|
137
|
+
str: Confirmation message with the new task list ID and details.
|
138
|
+
"""
|
139
|
+
logger.info(f"[create_task_list] Invoked. Email: '{user_google_email}', Title: '{title}'")
|
140
|
+
|
141
|
+
try:
|
142
|
+
body = {
|
143
|
+
"title": title
|
144
|
+
}
|
145
|
+
|
146
|
+
result = await asyncio.to_thread(
|
147
|
+
service.tasklists().insert(body=body).execute
|
148
|
+
)
|
149
|
+
|
150
|
+
response = f"""Task List Created for {user_google_email}:
|
151
|
+
- Title: {result['title']}
|
152
|
+
- ID: {result['id']}
|
153
|
+
- Created: {result.get('updated', 'N/A')}
|
154
|
+
- Self Link: {result.get('selfLink', 'N/A')}"""
|
155
|
+
|
156
|
+
logger.info(f"Created task list '{title}' with ID {result['id']} for {user_google_email}")
|
157
|
+
return response
|
158
|
+
|
159
|
+
except HttpError as error:
|
160
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
161
|
+
logger.error(message, exc_info=True)
|
162
|
+
raise Exception(message)
|
163
|
+
except Exception as e:
|
164
|
+
message = f"Unexpected error: {e}."
|
165
|
+
logger.exception(message)
|
166
|
+
raise Exception(message)
|
167
|
+
|
168
|
+
|
169
|
+
@server.tool()
|
170
|
+
@require_google_service("tasks", "tasks")
|
171
|
+
async def update_task_list(
|
172
|
+
service,
|
173
|
+
user_google_email: str,
|
174
|
+
task_list_id: str,
|
175
|
+
title: str
|
176
|
+
) -> str:
|
177
|
+
"""
|
178
|
+
Update an existing task list.
|
179
|
+
|
180
|
+
Args:
|
181
|
+
user_google_email (str): The user's Google email address. Required.
|
182
|
+
task_list_id (str): The ID of the task list to update.
|
183
|
+
title (str): The new title for the task list.
|
184
|
+
|
185
|
+
Returns:
|
186
|
+
str: Confirmation message with updated task list details.
|
187
|
+
"""
|
188
|
+
logger.info(f"[update_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, New Title: '{title}'")
|
189
|
+
|
190
|
+
try:
|
191
|
+
body = {
|
192
|
+
"id": task_list_id,
|
193
|
+
"title": title
|
194
|
+
}
|
195
|
+
|
196
|
+
result = await asyncio.to_thread(
|
197
|
+
service.tasklists().update(tasklist=task_list_id, body=body).execute
|
198
|
+
)
|
199
|
+
|
200
|
+
response = f"""Task List Updated for {user_google_email}:
|
201
|
+
- Title: {result['title']}
|
202
|
+
- ID: {result['id']}
|
203
|
+
- Updated: {result.get('updated', 'N/A')}"""
|
204
|
+
|
205
|
+
logger.info(f"Updated task list {task_list_id} with new title '{title}' for {user_google_email}")
|
206
|
+
return response
|
207
|
+
|
208
|
+
except HttpError as error:
|
209
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
210
|
+
logger.error(message, exc_info=True)
|
211
|
+
raise Exception(message)
|
212
|
+
except Exception as e:
|
213
|
+
message = f"Unexpected error: {e}."
|
214
|
+
logger.exception(message)
|
215
|
+
raise Exception(message)
|
216
|
+
|
217
|
+
|
218
|
+
@server.tool()
|
219
|
+
@require_google_service("tasks", "tasks")
|
220
|
+
async def delete_task_list(
|
221
|
+
service,
|
222
|
+
user_google_email: str,
|
223
|
+
task_list_id: str
|
224
|
+
) -> str:
|
225
|
+
"""
|
226
|
+
Delete a task list. Note: This will also delete all tasks in the list.
|
227
|
+
|
228
|
+
Args:
|
229
|
+
user_google_email (str): The user's Google email address. Required.
|
230
|
+
task_list_id (str): The ID of the task list to delete.
|
231
|
+
|
232
|
+
Returns:
|
233
|
+
str: Confirmation message.
|
234
|
+
"""
|
235
|
+
logger.info(f"[delete_task_list] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}")
|
236
|
+
|
237
|
+
try:
|
238
|
+
await asyncio.to_thread(
|
239
|
+
service.tasklists().delete(tasklist=task_list_id).execute
|
240
|
+
)
|
241
|
+
|
242
|
+
response = f"Task list {task_list_id} has been deleted for {user_google_email}. All tasks in this list have also been deleted."
|
243
|
+
|
244
|
+
logger.info(f"Deleted task list {task_list_id} for {user_google_email}")
|
245
|
+
return response
|
246
|
+
|
247
|
+
except HttpError as error:
|
248
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
249
|
+
logger.error(message, exc_info=True)
|
250
|
+
raise Exception(message)
|
251
|
+
except Exception as e:
|
252
|
+
message = f"Unexpected error: {e}."
|
253
|
+
logger.exception(message)
|
254
|
+
raise Exception(message)
|
255
|
+
|
256
|
+
|
257
|
+
@server.tool()
|
258
|
+
@require_google_service("tasks", "tasks_read")
|
259
|
+
async def list_tasks(
|
260
|
+
service,
|
261
|
+
user_google_email: str,
|
262
|
+
task_list_id: str,
|
263
|
+
max_results: Optional[int] = None,
|
264
|
+
page_token: Optional[str] = None,
|
265
|
+
show_completed: Optional[bool] = None,
|
266
|
+
show_deleted: Optional[bool] = None,
|
267
|
+
show_hidden: Optional[bool] = None,
|
268
|
+
show_assigned: Optional[bool] = None,
|
269
|
+
completed_max: Optional[str] = None,
|
270
|
+
completed_min: Optional[str] = None,
|
271
|
+
due_max: Optional[str] = None,
|
272
|
+
due_min: Optional[str] = None,
|
273
|
+
updated_min: Optional[str] = None
|
274
|
+
) -> str:
|
275
|
+
"""
|
276
|
+
List all tasks in a specific task list.
|
277
|
+
|
278
|
+
Args:
|
279
|
+
user_google_email (str): The user's Google email address. Required.
|
280
|
+
task_list_id (str): The ID of the task list to retrieve tasks from.
|
281
|
+
max_results (Optional[int]): Maximum number of tasks to return (default: 20, max: 100).
|
282
|
+
page_token (Optional[str]): Token for pagination.
|
283
|
+
show_completed (Optional[bool]): Whether to include completed tasks (default: True).
|
284
|
+
show_deleted (Optional[bool]): Whether to include deleted tasks (default: False).
|
285
|
+
show_hidden (Optional[bool]): Whether to include hidden tasks (default: False).
|
286
|
+
show_assigned (Optional[bool]): Whether to include assigned tasks (default: False).
|
287
|
+
completed_max (Optional[str]): Upper bound for completion date (RFC 3339 timestamp).
|
288
|
+
completed_min (Optional[str]): Lower bound for completion date (RFC 3339 timestamp).
|
289
|
+
due_max (Optional[str]): Upper bound for due date (RFC 3339 timestamp).
|
290
|
+
due_min (Optional[str]): Lower bound for due date (RFC 3339 timestamp).
|
291
|
+
updated_min (Optional[str]): Lower bound for last modification time (RFC 3339 timestamp).
|
292
|
+
|
293
|
+
Returns:
|
294
|
+
str: List of tasks with their details.
|
295
|
+
"""
|
296
|
+
logger.info(f"[list_tasks] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}")
|
297
|
+
|
298
|
+
try:
|
299
|
+
params = {"tasklist": task_list_id}
|
300
|
+
if max_results is not None:
|
301
|
+
params["maxResults"] = max_results
|
302
|
+
if page_token:
|
303
|
+
params["pageToken"] = page_token
|
304
|
+
if show_completed is not None:
|
305
|
+
params["showCompleted"] = show_completed
|
306
|
+
if show_deleted is not None:
|
307
|
+
params["showDeleted"] = show_deleted
|
308
|
+
if show_hidden is not None:
|
309
|
+
params["showHidden"] = show_hidden
|
310
|
+
if show_assigned is not None:
|
311
|
+
params["showAssigned"] = show_assigned
|
312
|
+
if completed_max:
|
313
|
+
params["completedMax"] = completed_max
|
314
|
+
if completed_min:
|
315
|
+
params["completedMin"] = completed_min
|
316
|
+
if due_max:
|
317
|
+
params["dueMax"] = due_max
|
318
|
+
if due_min:
|
319
|
+
params["dueMin"] = due_min
|
320
|
+
if updated_min:
|
321
|
+
params["updatedMin"] = updated_min
|
322
|
+
|
323
|
+
result = await asyncio.to_thread(
|
324
|
+
service.tasks().list(**params).execute
|
325
|
+
)
|
326
|
+
|
327
|
+
tasks = result.get("items", [])
|
328
|
+
next_page_token = result.get("nextPageToken")
|
329
|
+
|
330
|
+
if not tasks:
|
331
|
+
return f"No tasks found in task list {task_list_id} for {user_google_email}."
|
332
|
+
|
333
|
+
response = f"Tasks in list {task_list_id} for {user_google_email}:\n"
|
334
|
+
for task in tasks:
|
335
|
+
response += f"- {task.get('title', 'Untitled')} (ID: {task['id']})\n"
|
336
|
+
response += f" Status: {task.get('status', 'N/A')}\n"
|
337
|
+
if task.get('due'):
|
338
|
+
response += f" Due: {task['due']}\n"
|
339
|
+
if task.get('notes'):
|
340
|
+
response += f" Notes: {task['notes'][:100]}{'...' if len(task['notes']) > 100 else ''}\n"
|
341
|
+
if task.get('completed'):
|
342
|
+
response += f" Completed: {task['completed']}\n"
|
343
|
+
response += f" Updated: {task.get('updated', 'N/A')}\n"
|
344
|
+
response += "\n"
|
345
|
+
|
346
|
+
if next_page_token:
|
347
|
+
response += f"Next page token: {next_page_token}"
|
348
|
+
|
349
|
+
logger.info(f"Found {len(tasks)} tasks in list {task_list_id} for {user_google_email}")
|
350
|
+
return response
|
351
|
+
|
352
|
+
except HttpError as error:
|
353
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
354
|
+
logger.error(message, exc_info=True)
|
355
|
+
raise Exception(message)
|
356
|
+
except Exception as e:
|
357
|
+
message = f"Unexpected error: {e}."
|
358
|
+
logger.exception(message)
|
359
|
+
raise Exception(message)
|
360
|
+
|
361
|
+
|
362
|
+
@server.tool()
|
363
|
+
@require_google_service("tasks", "tasks_read")
|
364
|
+
async def get_task(
|
365
|
+
service,
|
366
|
+
user_google_email: str,
|
367
|
+
task_list_id: str,
|
368
|
+
task_id: str
|
369
|
+
) -> str:
|
370
|
+
"""
|
371
|
+
Get details of a specific task.
|
372
|
+
|
373
|
+
Args:
|
374
|
+
user_google_email (str): The user's Google email address. Required.
|
375
|
+
task_list_id (str): The ID of the task list containing the task.
|
376
|
+
task_id (str): The ID of the task to retrieve.
|
377
|
+
|
378
|
+
Returns:
|
379
|
+
str: Task details including title, notes, status, due date, etc.
|
380
|
+
"""
|
381
|
+
logger.info(f"[get_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}")
|
382
|
+
|
383
|
+
try:
|
384
|
+
task = await asyncio.to_thread(
|
385
|
+
service.tasks().get(tasklist=task_list_id, task=task_id).execute
|
386
|
+
)
|
387
|
+
|
388
|
+
response = f"""Task Details for {user_google_email}:
|
389
|
+
- Title: {task.get('title', 'Untitled')}
|
390
|
+
- ID: {task['id']}
|
391
|
+
- Status: {task.get('status', 'N/A')}
|
392
|
+
- Updated: {task.get('updated', 'N/A')}"""
|
393
|
+
|
394
|
+
if task.get('due'):
|
395
|
+
response += f"\n- Due Date: {task['due']}"
|
396
|
+
if task.get('completed'):
|
397
|
+
response += f"\n- Completed: {task['completed']}"
|
398
|
+
if task.get('notes'):
|
399
|
+
response += f"\n- Notes: {task['notes']}"
|
400
|
+
if task.get('parent'):
|
401
|
+
response += f"\n- Parent Task ID: {task['parent']}"
|
402
|
+
if task.get('position'):
|
403
|
+
response += f"\n- Position: {task['position']}"
|
404
|
+
if task.get('selfLink'):
|
405
|
+
response += f"\n- Self Link: {task['selfLink']}"
|
406
|
+
if task.get('webViewLink'):
|
407
|
+
response += f"\n- Web View Link: {task['webViewLink']}"
|
408
|
+
|
409
|
+
logger.info(f"Retrieved task '{task.get('title', 'Untitled')}' for {user_google_email}")
|
410
|
+
return response
|
411
|
+
|
412
|
+
except HttpError as error:
|
413
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
414
|
+
logger.error(message, exc_info=True)
|
415
|
+
raise Exception(message)
|
416
|
+
except Exception as e:
|
417
|
+
message = f"Unexpected error: {e}."
|
418
|
+
logger.exception(message)
|
419
|
+
raise Exception(message)
|
420
|
+
|
421
|
+
|
422
|
+
@server.tool()
|
423
|
+
@require_google_service("tasks", "tasks")
|
424
|
+
async def create_task(
|
425
|
+
service,
|
426
|
+
user_google_email: str,
|
427
|
+
task_list_id: str,
|
428
|
+
title: str,
|
429
|
+
notes: Optional[str] = None,
|
430
|
+
due: Optional[str] = None,
|
431
|
+
parent: Optional[str] = None,
|
432
|
+
previous: Optional[str] = None
|
433
|
+
) -> str:
|
434
|
+
"""
|
435
|
+
Create a new task in a task list.
|
436
|
+
|
437
|
+
Args:
|
438
|
+
user_google_email (str): The user's Google email address. Required.
|
439
|
+
task_list_id (str): The ID of the task list to create the task in.
|
440
|
+
title (str): The title of the task.
|
441
|
+
notes (Optional[str]): Notes/description for the task.
|
442
|
+
due (Optional[str]): Due date in RFC 3339 format (e.g., "2024-12-31T23:59:59Z").
|
443
|
+
parent (Optional[str]): Parent task ID (for subtasks).
|
444
|
+
previous (Optional[str]): Previous sibling task ID (for positioning).
|
445
|
+
|
446
|
+
Returns:
|
447
|
+
str: Confirmation message with the new task ID and details.
|
448
|
+
"""
|
449
|
+
logger.info(f"[create_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Title: '{title}'")
|
450
|
+
|
451
|
+
try:
|
452
|
+
body = {
|
453
|
+
"title": title
|
454
|
+
}
|
455
|
+
if notes:
|
456
|
+
body["notes"] = notes
|
457
|
+
if due:
|
458
|
+
body["due"] = due
|
459
|
+
|
460
|
+
params = {"tasklist": task_list_id, "body": body}
|
461
|
+
if parent:
|
462
|
+
params["parent"] = parent
|
463
|
+
if previous:
|
464
|
+
params["previous"] = previous
|
465
|
+
|
466
|
+
result = await asyncio.to_thread(
|
467
|
+
service.tasks().insert(**params).execute
|
468
|
+
)
|
469
|
+
|
470
|
+
response = f"""Task Created for {user_google_email}:
|
471
|
+
- Title: {result['title']}
|
472
|
+
- ID: {result['id']}
|
473
|
+
- Status: {result.get('status', 'N/A')}
|
474
|
+
- Updated: {result.get('updated', 'N/A')}"""
|
475
|
+
|
476
|
+
if result.get('due'):
|
477
|
+
response += f"\n- Due Date: {result['due']}"
|
478
|
+
if result.get('notes'):
|
479
|
+
response += f"\n- Notes: {result['notes']}"
|
480
|
+
if result.get('webViewLink'):
|
481
|
+
response += f"\n- Web View Link: {result['webViewLink']}"
|
482
|
+
|
483
|
+
logger.info(f"Created task '{title}' with ID {result['id']} for {user_google_email}")
|
484
|
+
return response
|
485
|
+
|
486
|
+
except HttpError as error:
|
487
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
488
|
+
logger.error(message, exc_info=True)
|
489
|
+
raise Exception(message)
|
490
|
+
except Exception as e:
|
491
|
+
message = f"Unexpected error: {e}."
|
492
|
+
logger.exception(message)
|
493
|
+
raise Exception(message)
|
494
|
+
|
495
|
+
|
496
|
+
@server.tool()
|
497
|
+
@require_google_service("tasks", "tasks")
|
498
|
+
async def update_task(
|
499
|
+
service,
|
500
|
+
user_google_email: str,
|
501
|
+
task_list_id: str,
|
502
|
+
task_id: str,
|
503
|
+
title: Optional[str] = None,
|
504
|
+
notes: Optional[str] = None,
|
505
|
+
status: Optional[str] = None,
|
506
|
+
due: Optional[str] = None
|
507
|
+
) -> str:
|
508
|
+
"""
|
509
|
+
Update an existing task.
|
510
|
+
|
511
|
+
Args:
|
512
|
+
user_google_email (str): The user's Google email address. Required.
|
513
|
+
task_list_id (str): The ID of the task list containing the task.
|
514
|
+
task_id (str): The ID of the task to update.
|
515
|
+
title (Optional[str]): New title for the task.
|
516
|
+
notes (Optional[str]): New notes/description for the task.
|
517
|
+
status (Optional[str]): New status ("needsAction" or "completed").
|
518
|
+
due (Optional[str]): New due date in RFC 3339 format.
|
519
|
+
|
520
|
+
Returns:
|
521
|
+
str: Confirmation message with updated task details.
|
522
|
+
"""
|
523
|
+
logger.info(f"[update_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}")
|
524
|
+
|
525
|
+
try:
|
526
|
+
# First get the current task to build the update body
|
527
|
+
current_task = await asyncio.to_thread(
|
528
|
+
service.tasks().get(tasklist=task_list_id, task=task_id).execute
|
529
|
+
)
|
530
|
+
|
531
|
+
body = {
|
532
|
+
"id": task_id,
|
533
|
+
"title": title if title is not None else current_task.get("title", ""),
|
534
|
+
"status": status if status is not None else current_task.get("status", "needsAction")
|
535
|
+
}
|
536
|
+
|
537
|
+
if notes is not None:
|
538
|
+
body["notes"] = notes
|
539
|
+
elif current_task.get("notes"):
|
540
|
+
body["notes"] = current_task["notes"]
|
541
|
+
|
542
|
+
if due is not None:
|
543
|
+
body["due"] = due
|
544
|
+
elif current_task.get("due"):
|
545
|
+
body["due"] = current_task["due"]
|
546
|
+
|
547
|
+
result = await asyncio.to_thread(
|
548
|
+
service.tasks().update(tasklist=task_list_id, task=task_id, body=body).execute
|
549
|
+
)
|
550
|
+
|
551
|
+
response = f"""Task Updated for {user_google_email}:
|
552
|
+
- Title: {result['title']}
|
553
|
+
- ID: {result['id']}
|
554
|
+
- Status: {result.get('status', 'N/A')}
|
555
|
+
- Updated: {result.get('updated', 'N/A')}"""
|
556
|
+
|
557
|
+
if result.get('due'):
|
558
|
+
response += f"\n- Due Date: {result['due']}"
|
559
|
+
if result.get('notes'):
|
560
|
+
response += f"\n- Notes: {result['notes']}"
|
561
|
+
if result.get('completed'):
|
562
|
+
response += f"\n- Completed: {result['completed']}"
|
563
|
+
|
564
|
+
logger.info(f"Updated task {task_id} for {user_google_email}")
|
565
|
+
return response
|
566
|
+
|
567
|
+
except HttpError as error:
|
568
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
569
|
+
logger.error(message, exc_info=True)
|
570
|
+
raise Exception(message)
|
571
|
+
except Exception as e:
|
572
|
+
message = f"Unexpected error: {e}."
|
573
|
+
logger.exception(message)
|
574
|
+
raise Exception(message)
|
575
|
+
|
576
|
+
|
577
|
+
@server.tool()
|
578
|
+
@require_google_service("tasks", "tasks")
|
579
|
+
async def delete_task(
|
580
|
+
service,
|
581
|
+
user_google_email: str,
|
582
|
+
task_list_id: str,
|
583
|
+
task_id: str
|
584
|
+
) -> str:
|
585
|
+
"""
|
586
|
+
Delete a task from a task list.
|
587
|
+
|
588
|
+
Args:
|
589
|
+
user_google_email (str): The user's Google email address. Required.
|
590
|
+
task_list_id (str): The ID of the task list containing the task.
|
591
|
+
task_id (str): The ID of the task to delete.
|
592
|
+
|
593
|
+
Returns:
|
594
|
+
str: Confirmation message.
|
595
|
+
"""
|
596
|
+
logger.info(f"[delete_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}")
|
597
|
+
|
598
|
+
try:
|
599
|
+
await asyncio.to_thread(
|
600
|
+
service.tasks().delete(tasklist=task_list_id, task=task_id).execute
|
601
|
+
)
|
602
|
+
|
603
|
+
response = f"Task {task_id} has been deleted from task list {task_list_id} for {user_google_email}."
|
604
|
+
|
605
|
+
logger.info(f"Deleted task {task_id} for {user_google_email}")
|
606
|
+
return response
|
607
|
+
|
608
|
+
except HttpError as error:
|
609
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
610
|
+
logger.error(message, exc_info=True)
|
611
|
+
raise Exception(message)
|
612
|
+
except Exception as e:
|
613
|
+
message = f"Unexpected error: {e}."
|
614
|
+
logger.exception(message)
|
615
|
+
raise Exception(message)
|
616
|
+
|
617
|
+
|
618
|
+
@server.tool()
|
619
|
+
@require_google_service("tasks", "tasks")
|
620
|
+
async def move_task(
|
621
|
+
service,
|
622
|
+
user_google_email: str,
|
623
|
+
task_list_id: str,
|
624
|
+
task_id: str,
|
625
|
+
parent: Optional[str] = None,
|
626
|
+
previous: Optional[str] = None,
|
627
|
+
destination_task_list: Optional[str] = None
|
628
|
+
) -> str:
|
629
|
+
"""
|
630
|
+
Move a task to a different position or parent within the same list, or to a different list.
|
631
|
+
|
632
|
+
Args:
|
633
|
+
user_google_email (str): The user's Google email address. Required.
|
634
|
+
task_list_id (str): The ID of the current task list containing the task.
|
635
|
+
task_id (str): The ID of the task to move.
|
636
|
+
parent (Optional[str]): New parent task ID (for making it a subtask).
|
637
|
+
previous (Optional[str]): Previous sibling task ID (for positioning).
|
638
|
+
destination_task_list (Optional[str]): Destination task list ID (for moving between lists).
|
639
|
+
|
640
|
+
Returns:
|
641
|
+
str: Confirmation message with updated task details.
|
642
|
+
"""
|
643
|
+
logger.info(f"[move_task] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}, Task ID: {task_id}")
|
644
|
+
|
645
|
+
try:
|
646
|
+
params = {
|
647
|
+
"tasklist": task_list_id,
|
648
|
+
"task": task_id
|
649
|
+
}
|
650
|
+
if parent:
|
651
|
+
params["parent"] = parent
|
652
|
+
if previous:
|
653
|
+
params["previous"] = previous
|
654
|
+
if destination_task_list:
|
655
|
+
params["destinationTasklist"] = destination_task_list
|
656
|
+
|
657
|
+
result = await asyncio.to_thread(
|
658
|
+
service.tasks().move(**params).execute
|
659
|
+
)
|
660
|
+
|
661
|
+
response = f"""Task Moved for {user_google_email}:
|
662
|
+
- Title: {result['title']}
|
663
|
+
- ID: {result['id']}
|
664
|
+
- Status: {result.get('status', 'N/A')}
|
665
|
+
- Updated: {result.get('updated', 'N/A')}"""
|
666
|
+
|
667
|
+
if result.get('parent'):
|
668
|
+
response += f"\n- Parent Task ID: {result['parent']}"
|
669
|
+
if result.get('position'):
|
670
|
+
response += f"\n- Position: {result['position']}"
|
671
|
+
|
672
|
+
move_details = []
|
673
|
+
if destination_task_list:
|
674
|
+
move_details.append(f"moved to task list {destination_task_list}")
|
675
|
+
if parent:
|
676
|
+
move_details.append(f"made a subtask of {parent}")
|
677
|
+
if previous:
|
678
|
+
move_details.append(f"positioned after {previous}")
|
679
|
+
|
680
|
+
if move_details:
|
681
|
+
response += f"\n- Move Details: {', '.join(move_details)}"
|
682
|
+
|
683
|
+
logger.info(f"Moved task {task_id} for {user_google_email}")
|
684
|
+
return response
|
685
|
+
|
686
|
+
except HttpError as error:
|
687
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
688
|
+
logger.error(message, exc_info=True)
|
689
|
+
raise Exception(message)
|
690
|
+
except Exception as e:
|
691
|
+
message = f"Unexpected error: {e}."
|
692
|
+
logger.exception(message)
|
693
|
+
raise Exception(message)
|
694
|
+
|
695
|
+
|
696
|
+
@server.tool()
|
697
|
+
@require_google_service("tasks", "tasks")
|
698
|
+
async def clear_completed_tasks(
|
699
|
+
service,
|
700
|
+
user_google_email: str,
|
701
|
+
task_list_id: str
|
702
|
+
) -> str:
|
703
|
+
"""
|
704
|
+
Clear all completed tasks from a task list. The tasks will be marked as hidden.
|
705
|
+
|
706
|
+
Args:
|
707
|
+
user_google_email (str): The user's Google email address. Required.
|
708
|
+
task_list_id (str): The ID of the task list to clear completed tasks from.
|
709
|
+
|
710
|
+
Returns:
|
711
|
+
str: Confirmation message.
|
712
|
+
"""
|
713
|
+
logger.info(f"[clear_completed_tasks] Invoked. Email: '{user_google_email}', Task List ID: {task_list_id}")
|
714
|
+
|
715
|
+
try:
|
716
|
+
await asyncio.to_thread(
|
717
|
+
service.tasks().clear(tasklist=task_list_id).execute
|
718
|
+
)
|
719
|
+
|
720
|
+
response = f"All completed tasks have been cleared from task list {task_list_id} for {user_google_email}. The tasks are now hidden and won't appear in default task list views."
|
721
|
+
|
722
|
+
logger.info(f"Cleared completed tasks from list {task_list_id} for {user_google_email}")
|
723
|
+
return response
|
724
|
+
|
725
|
+
except HttpError as error:
|
726
|
+
message = f"API error: {error}. You might need to re-authenticate. LLM: Try 'start_google_auth' with the user's email ({user_google_email}) and service_name='Google Tasks'."
|
727
|
+
logger.error(message, exc_info=True)
|
728
|
+
raise Exception(message)
|
729
|
+
except Exception as e:
|
730
|
+
message = f"Unexpected error: {e}."
|
731
|
+
logger.exception(message)
|
732
|
+
raise Exception(message)
|