fix(server): Replace ErrorResponses with standard McpErrors
This commit is contained in:
@@ -20,23 +20,15 @@ async def test_missing_note_resource_error(nc_mcp_client: ClientSession):
|
||||
@pytest.mark.integration
|
||||
async def test_delete_missing_note_tool_error(nc_mcp_client: ClientSession):
|
||||
"""Test that deleting a non-existent note returns proper error."""
|
||||
# Try to delete a non-existent note
|
||||
# Try to delete a non-existent note - should return error response
|
||||
response = await nc_mcp_client.call_tool(
|
||||
"nc_notes_delete_note", {"note_id": 999999}
|
||||
)
|
||||
|
||||
logger.info(f"Delete missing note response: {response}")
|
||||
|
||||
# Should return structured error response with improved message
|
||||
# Should return error response (not raise exception) for tools
|
||||
assert response is not None
|
||||
assert (
|
||||
response.isError is False
|
||||
) # Tools now return structured responses, not MCP errors
|
||||
|
||||
# Check structured content for error
|
||||
assert "success" in response.structuredContent["result"]
|
||||
assert response.structuredContent["result"]["success"] is False
|
||||
assert "Note 999999 not found" in response.structuredContent["result"]["error"]
|
||||
assert response.isError is True
|
||||
assert "Note 999999 not found" in response.content[0].text
|
||||
|
||||
|
||||
@pytest.mark.integration
|
||||
@@ -81,7 +73,7 @@ async def test_update_note_with_invalid_etag(nc_mcp_client: ClientSession, nc_cl
|
||||
note_id = note_data["id"]
|
||||
|
||||
try:
|
||||
# Try to update with invalid ETag
|
||||
# Try to update with invalid ETag - should return error response
|
||||
response = await nc_mcp_client.call_tool(
|
||||
"nc_notes_update_note",
|
||||
{
|
||||
@@ -93,16 +85,10 @@ async def test_update_note_with_invalid_etag(nc_mcp_client: ClientSession, nc_cl
|
||||
},
|
||||
)
|
||||
|
||||
logger.info(f"Invalid ETag response: {response}")
|
||||
|
||||
# Should return structured error response with improved message
|
||||
# Should return error response (not raise exception) for tools
|
||||
assert response is not None
|
||||
assert response.isError is False # Tools now return structured responses
|
||||
assert "success" in response.structuredContent["result"]
|
||||
assert response.structuredContent["result"]["success"] is False
|
||||
assert (
|
||||
"modified by someone else" in response.structuredContent["result"]["error"]
|
||||
)
|
||||
assert response.isError is True
|
||||
assert "modified by someone else" in response.content[0].text
|
||||
|
||||
finally:
|
||||
# Clean up
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
"""Unit tests for Pydantic models and serialization."""
|
||||
|
||||
import json
|
||||
import re
|
||||
from datetime import datetime, timezone
|
||||
|
||||
import json
|
||||
import logging
|
||||
import re
|
||||
|
||||
from nextcloud_mcp_server.models.base import BaseResponse, SuccessResponse
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def test_timestamp_format_validation():
|
||||
"""Test that timestamps in BaseResponse are RFC3339 compliant for MCP validation.
|
||||
@@ -76,7 +78,7 @@ def test_current_broken_format():
|
||||
assert "+" not in current_format
|
||||
assert "-" not in current_format[-6:] # Check last 6 chars for timezone
|
||||
|
||||
print(f"Current broken format: {current_format}")
|
||||
print(
|
||||
logger.info(f"Current broken format: {current_format}")
|
||||
logger.info(
|
||||
"This format causes MCP validation errors because it lacks timezone information"
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user