From b3548ea49d581359bd76b9ee5166cf742821214e Mon Sep 17 00:00:00 2001 From: Isaac Johnson Date: Tue, 14 Oct 2025 11:58:30 -0500 Subject: [PATCH] 0.24 - try and create labels before use --- Dockerfile | 2 +- gemini-extension.json | 4 ++-- main.py | 30 ++++++++++++++++++++++++++++-- 3 files changed, 31 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index 7edbf03..bb01760 100644 --- a/Dockerfile +++ b/Dockerfile @@ -20,4 +20,4 @@ RUN pip install --no-cache-dir -r requirements.txt COPY . . CMD ["python", "main.py"] -#harbor.freshbrewed.science/library/vikunjamcp:0.23 +#harbor.freshbrewed.science/library/vikunjamcp:0.24 diff --git a/gemini-extension.json b/gemini-extension.json index 89ddd0f..4b68893 100644 --- a/gemini-extension.json +++ b/gemini-extension.json @@ -1,6 +1,6 @@ { "name": "vikunja", - "version": "1.0.23", + "version": "1.0.24", "mcpServers": { "nodeServer": { "command": "docker", @@ -14,7 +14,7 @@ "VIKUNJA_USERNAME", "-e", "VIKUNJA_PASSWORD", - "harbor.freshbrewed.science/library/vikunjamcp:0.23" + "harbor.freshbrewed.science/library/vikunjamcp:0.24" ], "env": { "VIKUNJA_URL": "$VIKUNJA_URL", diff --git a/main.py b/main.py index 5a9a982..7a4901b 100644 --- a/main.py +++ b/main.py @@ -657,8 +657,34 @@ def update_task_details( if existing_id: final_labels.append({'id': existing_id}) else: - # Create new labels via the bulk endpoint by providing title+description - final_labels.append({'title': title, 'description': title}) + # Try to create the label first via the /labels endpoint so we have a real id + try: + logger.info("update_task_details: creating missing label '%s' via %s/labels", title, VIKUNJA_URL) + create_resp = session.put(f"{VIKUNJA_URL}/api/v1/labels", json={"title": title, "description": title}) + # If creation failed with 4xx/5xx this will raise and be caught below + create_resp.raise_for_status() + created = create_resp.json() or {} + created_id = created.get('id') + if created_id: + title_to_id[title.lower()] = created_id + final_labels.append({'id': created_id}) + logger.info("update_task_details: created label '%s' id=%s", title, created_id) + else: + # Fallback: include title/description in payload if no id returned + logger.warning("update_task_details: label created but no id returned for title='%s' - including title in bulk payload", title) + final_labels.append({'title': title, 'description': title}) + except requests.exceptions.RequestException as ce: + # Creation failed; log more details and include title in payload as a fallback + resp = getattr(ce, 'response', None) + if resp is not None: + try: + logger.error("update_task_details: label creation returned status=%s body=%s for title=%s", resp.status_code, resp.text, title) + except Exception: + logger.exception("update_task_details: failed to read create label response body for title=%s", title) + else: + logger.exception("update_task_details: label creation request failed for title=%s", title) + # As a last resort try to send title in bulk payload (some servers may accept this) + final_labels.append({'title': title, 'description': title}) final_payload = {'labels': final_labels}