0.21 - fix label update with details. updating lables was not working
CICD / Explore-Gitea-Actions (push) Successful in 35s Details

This commit is contained in:
Isaac Johnson 2025-10-14 07:16:53 -05:00
parent a6626a0959
commit 572cc4dd3c
3 changed files with 55 additions and 8 deletions

View File

@ -20,4 +20,4 @@ RUN pip install --no-cache-dir -r requirements.txt
COPY . . COPY . .
CMD ["python", "main.py"] CMD ["python", "main.py"]
#harbor.freshbrewed.science/library/vikunjamcp:0.20 #harbor.freshbrewed.science/library/vikunjamcp:0.21

View File

@ -1,6 +1,6 @@
{ {
"name": "vikunja", "name": "vikunja",
"version": "1.0.20", "version": "1.0.21",
"mcpServers": { "mcpServers": {
"nodeServer": { "nodeServer": {
"command": "docker", "command": "docker",
@ -14,7 +14,7 @@
"VIKUNJA_USERNAME", "VIKUNJA_USERNAME",
"-e", "-e",
"VIKUNJA_PASSWORD", "VIKUNJA_PASSWORD",
"harbor.freshbrewed.science/library/vikunjamcp:0.20" "harbor.freshbrewed.science/library/vikunjamcp:0.21"
], ],
"env": { "env": {
"VIKUNJA_URL": "$VIKUNJA_URL", "VIKUNJA_URL": "$VIKUNJA_URL",

57
main.py
View File

@ -579,14 +579,43 @@ def update_task_details(
set_if(is_favorite, "is_favorite") set_if(is_favorite, "is_favorite")
set_if(hex_color, "hex_color") set_if(hex_color, "hex_color")
# Replace labels if provided as comma-separated string # Prepare labels payload separately because Vikunja's task update endpoint
# does not accept label updates; labels are managed via the labels bulk API.
labels_payload = None
if labels is not None: if labels is not None:
# normalize into array of strings (label titles) or ids
if isinstance(labels, str): if isinstance(labels, str):
parsed = [s.strip() for s in labels.split(",") if s.strip()] parsed = [s.strip() for s in labels.split(",") if s.strip()]
payload["labels"] = parsed labels_payload = {"labels": parsed}
elif isinstance(labels, list):
# If list contains dicts with id/title, pass through; otherwise coerce
normalized = []
for item in labels:
if isinstance(item, dict):
# prefer 'title' or 'name' or 'id'
if 'title' in item:
normalized.append(item['title'])
elif 'name' in item:
normalized.append(item['name'])
elif 'id' in item:
normalized.append(item['id'])
else:
normalized.append(str(item))
else:
normalized.append(item)
labels_payload = {"labels": normalized}
elif isinstance(labels, dict):
# single dict -> try to extract title or id
if 'title' in labels:
labels_payload = {"labels": [labels['title']]}
elif 'name' in labels:
labels_payload = {"labels": [labels['name']]}
elif 'id' in labels:
labels_payload = {"labels": [labels['id']]}
else:
labels_payload = {"labels": [str(labels)]}
else: else:
# Allow callers to pass list directly labels_payload = {"labels": [str(labels)]}
payload["labels"] = labels
if not payload: if not payload:
return "No fields provided to update." return "No fields provided to update."
@ -595,7 +624,25 @@ def update_task_details(
logger.info("update_task_details: updating task_id=%s with payload keys=%s", task_id, list(payload.keys())) logger.info("update_task_details: updating task_id=%s with payload keys=%s", task_id, list(payload.keys()))
response = session.post(f"{VIKUNJA_URL}/api/v1/tasks/{task_id}", json=payload) response = session.post(f"{VIKUNJA_URL}/api/v1/tasks/{task_id}", json=payload)
response.raise_for_status() response.raise_for_status()
return response.json() task_update_resp = response.json()
# If labels were provided, send them to the labels bulk endpoint
if labels_payload is not None:
try:
logger.info("update_task_details: updating labels for task_id=%s labels=%s", task_id, labels_payload)
lab_resp = session.post(f"{VIKUNJA_URL}/api/v1/tasks/{task_id}/labels/bulk", json=labels_payload)
lab_resp.raise_for_status()
logger.info("update_task_details: labels updated successfully for task_id=%s", task_id)
except requests.exceptions.RequestException as le:
resp = getattr(le, 'response', None)
if resp is not None:
try:
logger.error("update_task_details: labels update returned status=%s body=%s", resp.status_code, resp.text)
except Exception:
logger.exception("update_task_details: failed to read labels response body for task_id=%s", task_id)
logger.exception("update_task_details: labels update request failed for task_id=%s", task_id)
return task_update_resp
except requests.exceptions.RequestException as e: except requests.exceptions.RequestException as e:
logger.exception("update_task_details: request failed for task_id=%s", task_id) logger.exception("update_task_details: request failed for task_id=%s", task_id)
return f"Error updating task details: {e}" return f"Error updating task details: {e}"