fix: address PR review feedback (round 3)

Bugs:
- assign_tag/remove_tag now call _unwrap_ocs to surface OCS-level errors
- trash_page changed to idempotentHint=False (trashing twice errors)
- WebDAV path parts stripped of slashes to prevent double-slash paths

Robustness:
- _unwrap_ocs uses ocs.get("data", {}) instead of ocs["data"]
- Unit test added for missing data key in OCS envelope

Minor:
- MCP error codes use -1 (project convention) instead of HTTP status codes
- update_collective docstring notes that emoji is required
- CollectiveTag.color validated as hex format via field_validator

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-03-25 13:25:09 +01:00
co-authored by Claude Opus 4.6
parent 44a27bd9e9
commit f3caad122d
4 changed files with 45 additions and 13 deletions
+8 -6
View File
@@ -34,8 +34,8 @@ logger = logging.getLogger(__name__)
def _handle_collectives_error(e: OCSError | HTTPStatusError) -> McpError:
"""Convert OCS or HTTP errors to McpError."""
if isinstance(e, OCSError):
return McpError(ErrorData(code=e.status_code, message=e.message))
return McpError(ErrorData(code=e.response.status_code, message=str(e)))
return McpError(ErrorData(code=-1, message=e.message))
return McpError(ErrorData(code=-1, message=str(e)))
def configure_collectives_tools(mcp: FastMCP):
@@ -120,7 +120,7 @@ def configure_collectives_tools(mcp: FastMCP):
if page.filePath:
parts.append(page.filePath)
parts.append(page.fileName)
webdav_path = "/".join(parts)
webdav_path = "/".join(p.strip("/") for p in parts)
try:
file_bytes, _ = await client.webdav.read_file(webdav_path)
content = file_bytes.decode("utf-8")
@@ -243,11 +243,13 @@ def configure_collectives_tools(mcp: FastMCP):
async def collectives_update_collective(
ctx: Context, collective_id: int, emoji: str | None = None
) -> CollectiveOperationResponse:
"""Update a Nextcloud Collective (emoji)
"""Update a Nextcloud Collective (emoji).
At least one field must be provided.
Args:
collective_id: ID of the collective
emoji: New emoji for the collective
emoji: New emoji for the collective (required)
"""
client = await get_client(ctx)
try:
@@ -340,7 +342,7 @@ def configure_collectives_tools(mcp: FastMCP):
@mcp.tool(
title="Trash Collective Page",
annotations=ToolAnnotations(
destructiveHint=True, idempotentHint=True, openWorldHint=True
destructiveHint=True, idempotentHint=False, openWorldHint=True
),
)
@require_scopes("collectives:write")