Specify MCP delete results and accept hydration decimal precision
This commit is contained in:
@@ -110,3 +110,12 @@ implicitly evaluate a recipe against private preferences.
|
||||
These are endpoint-source observations, not yet evidence that every client
|
||||
receives accurate machine-readable output schemas. The adapter still advertises
|
||||
generic object outputs for most tools.
|
||||
|
||||
## Output schema pass
|
||||
|
||||
The registered catalog initially advertised 93 generic object output schemas.
|
||||
Three simple deletion results now have explicit required fields: `food_delete_entry`
|
||||
returns `success` and `deleted_entry_id`; `inventory_remove` returns `success`
|
||||
and `removed_item_id`; `hydration_delete` returns `deleted`. These shapes match
|
||||
the adapter's returned objects or the routed Django response. The other tools
|
||||
still need individual response review before narrowing their schemas.
|
||||
|
||||
@@ -18,6 +18,21 @@ from mcp.server.mcpserver import MCPServer
|
||||
from mcp.server.mcpserver.exceptions import ToolError
|
||||
from mcp.server.transport_security import TransportSecuritySettings
|
||||
from pydantic import AnyHttpUrl, BaseModel, ConfigDict, Field
|
||||
from typing_extensions import TypedDict
|
||||
|
||||
|
||||
class FoodDeleteResult(TypedDict):
|
||||
success: bool
|
||||
deleted_entry_id: str
|
||||
|
||||
|
||||
class InventoryRemoveResult(TypedDict):
|
||||
success: bool
|
||||
removed_item_id: str
|
||||
|
||||
|
||||
class HydrationDeleteResult(TypedDict):
|
||||
deleted: bool
|
||||
|
||||
API_BASE = os.environ.get('TASKNEST_API_BASE_URL', 'http://127.0.0.1:1234/api/v1').rstrip('/')
|
||||
MCP_PUBLIC_URL = os.environ.get('TASKNEST_MCP_PUBLIC_URL', 'https://tasksnest.jorendegraaf.eu/mcp')
|
||||
@@ -519,7 +534,7 @@ def create_server() -> MCPServer:
|
||||
return {'success': True, 'entry': _entry(data)}
|
||||
|
||||
@server.tool(structured_output=True, description='Permanently delete one food log entry belonging to the authenticated user. This is destructive and also removes its image attachments. Require the user’s clear intent.')
|
||||
async def food_delete_entry(entry_id: str) -> dict[str, Any]:
|
||||
async def food_delete_entry(entry_id: str) -> FoodDeleteResult:
|
||||
await api_request('DELETE', f'food/log/{entry_id}/')
|
||||
return {'success': True, 'deleted_entry_id': entry_id}
|
||||
|
||||
@@ -642,7 +657,7 @@ def create_server() -> MCPServer:
|
||||
return {**data, 'idempotency_key': idempotency_key}
|
||||
|
||||
@server.tool(structured_output=True, description='Permanently remove one kitchen inventory item belonging to the authenticated user. This is destructive; require the user’s clear intent.')
|
||||
async def inventory_remove(item_id: str) -> dict[str, Any]:
|
||||
async def inventory_remove(item_id: str) -> InventoryRemoveResult:
|
||||
await api_request('DELETE', f'kitchen/items/{item_id}/')
|
||||
return {'success': True, 'removed_item_id': item_id}
|
||||
|
||||
@@ -695,7 +710,7 @@ def create_server() -> MCPServer:
|
||||
payload={k: v for k, v in changes.items() if v is not None})
|
||||
|
||||
@server.tool(structured_output=True, description='Delete an owned standalone manual hydration entry by ID. Requires food:write and the user’s clear intent. Does not affect Food Diary entries. Use hydration_update to correct an entry instead of deleting it.')
|
||||
async def hydration_delete(entry_id: str) -> dict[str, Any]:
|
||||
async def hydration_delete(entry_id: str) -> HydrationDeleteResult:
|
||||
return await api_request('DELETE', f'hydration/manual/{entry_id}/')
|
||||
|
||||
@server.tool(structured_output=True, description='Read hydration goal and automatic drink counting settings for the authenticated user.')
|
||||
|
||||
@@ -38,3 +38,15 @@ class ToolCatalogDiscoveryTests(SimpleTestCase):
|
||||
self.assertIn('food:read', tools['recipe_composition_preview'].description)
|
||||
self.assertIn('inventory:read', tools['grocery_add_recipe'].description)
|
||||
self.assertIn('inventory:write', tools['grocery_add_recipe'].description)
|
||||
|
||||
def test_delete_results_expose_actual_response_fields(self):
|
||||
tools = {tool.name: tool for tool in create_server()._tool_manager.list_tools()}
|
||||
for name, fields in {
|
||||
'food_delete_entry': {'success', 'deleted_entry_id'},
|
||||
'inventory_remove': {'success', 'removed_item_id'},
|
||||
'hydration_delete': {'deleted'},
|
||||
}.items():
|
||||
with self.subTest(tool=name):
|
||||
schema = tools[name].output_schema
|
||||
self.assertEqual(set(schema['required']), fields)
|
||||
self.assertEqual(set(schema['properties']), fields)
|
||||
|
||||
@@ -167,7 +167,7 @@ class McpHttpTests(LiveServerTestCase):
|
||||
'unit': 'ml', 'product_id': str(drink.api_id)}})
|
||||
self.assertFalse(food.is_error, food)
|
||||
daily = (await client.call_tool('hydration_get_daily')).structured_content
|
||||
self.assertEqual(daily['food_ml'], '200.000')
|
||||
self.assertEqual(Decimal(daily['food_ml']), Decimal('200'))
|
||||
manual = (await client.call_tool('hydration_log', {'amount_ml': '125',
|
||||
'idempotency_key': 'mcp-hydration-1'})).structured_content
|
||||
self.assertEqual(manual['amount_ml'], '125')
|
||||
|
||||
Reference in New Issue
Block a user