fix: add trash/delete collective tools and address review feedback (round 4)

Add collectives_trash_collective and collectives_delete_collective MCP
tools with proper destructiveHint annotations. Refactor integration test
fixture to use MCP tools for cleanup instead of direct httpx/OCS calls.
Optimize _get_ocs_headers() to class-level constant.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Chris Coutinho
2026-03-26 07:36:40 +01:00
co-authored by Claude Opus 4.6
parent f3caad122d
commit 95edd9ba8e
6 changed files with 178 additions and 29 deletions
@@ -115,6 +115,37 @@ async def test_create_collective(mocker):
assert call_args[1]["json"]["emoji"] == "📚"
async def test_trash_collective(mocker):
"""Test trashing a collective sends DELETE to correct endpoint."""
mock_response = create_mock_response(status_code=200, json_data={})
mock_request = mocker.patch.object(
CollectivesClient, "_make_request", return_value=mock_response
)
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
await client.trash_collective(collective_id=5)
call_args = mock_request.call_args
assert call_args[0][0] == "DELETE"
assert "/collectives/5" in call_args[0][1]
assert "/trash" not in call_args[0][1]
async def test_delete_collective(mocker):
"""Test permanently deleting a collective sends DELETE to trash endpoint."""
mock_response = create_mock_response(status_code=200, json_data={})
mock_request = mocker.patch.object(
CollectivesClient, "_make_request", return_value=mock_response
)
client = CollectivesClient(mocker.AsyncMock(spec=httpx.AsyncClient), "testuser")
await client.delete_collective(collective_id=5)
call_args = mock_request.call_args
assert call_args[0][0] == "DELETE"
assert "/collectives/trash/5" in call_args[0][1]
# --- Pages ---
+11 -24
View File
@@ -2,25 +2,14 @@
import json
import logging
import os
import uuid
import httpx
import pytest
from mcp import ClientSession
logger = logging.getLogger(__name__)
pytestmark = pytest.mark.integration
# Nextcloud credentials from environment (matches .envrc / docker-compose.yml defaults)
_NC_BASE = os.environ.get("NEXTCLOUD_HOST", "http://localhost:8080")
_NC_USER = os.environ.get("NEXTCLOUD_USERNAME", "admin")
_NC_PASS = os.environ.get("NEXTCLOUD_PASSWORD", "admin")
_OCS_HEADERS = {
"OCS-APIRequest": "true",
"Accept": "application/json",
}
# --- Fixtures ---
@@ -56,20 +45,16 @@ async def temporary_collective(nc_mcp_client: ClientSession):
"landing_page_id": landing_page_id,
}
# Cleanup: trash and permanently delete the collective via direct OCS API
# Cleanup: trash and permanently delete the collective via MCP tools
try:
async with httpx.AsyncClient(
base_url=_NC_BASE, auth=(_NC_USER, _NC_PASS)
) as client:
api = "/ocs/v2.php/apps/collectives/api/v1.0"
await client.delete(
f"{api}/collectives/{collective_id}",
headers=_OCS_HEADERS,
)
await client.delete(
f"{api}/collectives/trash/{collective_id}",
headers=_OCS_HEADERS,
)
await nc_mcp_client.call_tool(
"collectives_trash_collective",
{"collective_id": collective_id},
)
await nc_mcp_client.call_tool(
"collectives_delete_collective",
{"collective_id": collective_id},
)
logger.info(f"Cleaned up collective: {collective_id}")
except Exception as e:
logger.warning(f"Cleanup of collective {collective_id} failed: {e}")
@@ -87,6 +72,8 @@ async def test_collectives_tools_available(nc_mcp_client: ClientSession):
"collectives_get_collectives",
"collectives_create_collective",
"collectives_update_collective",
"collectives_trash_collective",
"collectives_delete_collective",
"collectives_get_pages",
"collectives_get_page",
"collectives_create_page",