feat(tasks): add clear_list tool (v0.11.6)
Deletes all tasks in a list within a single authenticated session, avoiding N×(login+logout) overhead — Login once, N×delete, logout once. Supports only_open=True to keep completed tasks. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1041,6 +1041,71 @@ def delete_task(task_id: str) -> str:
|
||||
return json.dumps({"deleted": True, "id": task_id}, ensure_ascii=False, indent=2)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tool: clear_list
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
|
||||
@mcp.tool()
|
||||
def clear_list(list_id: str, only_open: bool = False) -> str:
|
||||
"""Delete all tasks in a list within a single authenticated session.
|
||||
|
||||
IMPORTANT: Ask the user for confirmation before calling this tool.
|
||||
|
||||
Significantly faster than deleting tasks one by one because all
|
||||
delete calls share a single login/logout session.
|
||||
|
||||
Args:
|
||||
list_id: List metaId from get_lists
|
||||
(e.g. ``"taskList/16282169_29775360"``).
|
||||
only_open: When ``True`` only incomplete tasks are deleted;
|
||||
completed tasks are kept. Default ``False`` deletes all.
|
||||
|
||||
Returns:
|
||||
JSON with ``deleted_count`` and ``list_id`` on success,
|
||||
or an error message.
|
||||
"""
|
||||
if not list_id.startswith("taskList/"):
|
||||
return "Error: list_id must start with 'taskList/'"
|
||||
|
||||
try:
|
||||
email, password = get_credentials()
|
||||
except RuntimeError as exc:
|
||||
return f"Error: {exc}"
|
||||
|
||||
try:
|
||||
with FamilyWallClient() as client:
|
||||
client.login(email, password)
|
||||
|
||||
data = client.call(
|
||||
"accgetallfamily",
|
||||
{"a01call": "taskcategorysync", "a02call": "tasksync"},
|
||||
)
|
||||
raw_tasks = _extract_tasks(data)
|
||||
|
||||
tasks_to_delete = [
|
||||
t
|
||||
for t in raw_tasks
|
||||
if t.get("taskListId") == list_id
|
||||
and (not only_open or str(t.get("complete", "false")).lower() != "true")
|
||||
]
|
||||
|
||||
for task in tasks_to_delete:
|
||||
client.call("metadelete", {"id": task["metaId"]})
|
||||
|
||||
client.logout()
|
||||
except FamilyWallError as exc:
|
||||
return f"Error: Family Wall API error: {exc}"
|
||||
except Exception as exc:
|
||||
return f"Error: Connection error: {exc}"
|
||||
|
||||
return json.dumps(
|
||||
{"deleted_count": len(tasks_to_delete), "list_id": list_id},
|
||||
ensure_ascii=False,
|
||||
indent=2,
|
||||
)
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Tool: create_list
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user