Add MCP nutrition ingredient import and classification
This commit is contained in:
@@ -547,6 +547,25 @@ def create_server() -> MCPServer:
|
||||
result['attachment_error'] = str(exc)
|
||||
return result
|
||||
|
||||
@server.tool(structured_output=True, description='Preview 1–100 structured PDF-extracted ingredient rows. Requires source programme, filename and PDF SHA-256 plus original labels, quantities, pages, preparation and reviewable culinary categories. Read only; returns blockers and a short-lived confirmation. Unknown nutrition stays unknown.')
|
||||
async def nutrition_import_preview(payload: dict[str, Any]) -> dict[str, Any]:
|
||||
return await api_request('POST', 'nutrition/preview/', payload=payload)
|
||||
|
||||
@server.tool(structured_output=True, description='Commit exactly the previously previewed structured PDF extraction after explicit user approval. Requires the preview confirmation and an idempotency key. Writes suggestions and canonical ingredients only; never changes inventory, shopping or Food Diary.')
|
||||
async def nutrition_import_commit(payload: dict[str, Any], confirmation: str, idempotency_key: str) -> dict[str, Any]:
|
||||
return await api_request('POST', 'nutrition/commit/', payload={'payload': payload, 'confirmation': confirmation}, idempotency_key=idempotency_key)
|
||||
|
||||
@server.tool(structured_output=True, description='Search your source suggested canonical ingredients by culinary category, subcategory, programme, form, verification and actual inventory name candidates. For vegetables suggested by Body Support set category=vegetable and programme=Body Support. Stock matches are candidates only; no nutrition equivalence is inferred.')
|
||||
async def nutrition_ingredients_search(category: str = '', subcategory: str = '', programme: str = '', query: str = '', form: str = '', verified: bool | None = None, inventory_status: str = '', limit: int = 20, offset: int = 0) -> dict[str, Any]:
|
||||
params = {'category': category, 'subcategory': subcategory, 'programme': programme, 'query': query, 'form': form, 'inventory_status': inventory_status, 'limit': limit, 'offset': offset}
|
||||
if verified is not None:
|
||||
params['verified'] = str(verified).lower()
|
||||
return await api_request('GET', 'nutrition/ingredients/', params=params)
|
||||
|
||||
@server.tool(structured_output=True, description='Manually correct the category, subcategory or aliases of one owned canonical ingredient after review. Preserves the source PDF wording and marks the classification as verified.')
|
||||
async def nutrition_ingredient_correct(ingredient_id: str, changes: dict[str, Any]) -> dict[str, Any]:
|
||||
return await api_request('PATCH', f'nutrition/ingredients/{ingredient_id}/', payload=changes)
|
||||
|
||||
@server.tool(structured_output=True, description='List a bounded page of the authenticated user’s current kitchen inventory. Does not change data.')
|
||||
async def inventory_list(limit: int = 30, offset: int = 0) -> dict[str, Any]:
|
||||
data = await api_request('GET', 'kitchen/items/', params={'limit': min(max(limit, 1), 100), 'offset': max(offset, 0)})
|
||||
|
||||
Reference in New Issue
Block a user