Add MCP nutrition ingredient import and classification
This commit is contained in:
+12
@@ -139,3 +139,15 @@ The OAuth consent page displays the requested scopes. OAuth access tokens are us
|
||||
## Verify
|
||||
|
||||
Run `python manage.py test food.test_oauth_mcp mcp_server.tests` from `main/`. These tests exercise OAuth issuance and revocation, the live HTTP MCP protocol, scopes, user isolation, image upload, idempotency, and tool results. A real external ChatGPT connection still requires a public HTTPS deployment and a client sign-in test.
|
||||
|
||||
## Structured nutrition import (v1 working slice)
|
||||
|
||||
A standard MCP client can submit PDF-extracted JSON to `nutrition_import_preview(payload)` and then, after user review, `nutrition_import_commit(payload, confirmation, idempotency_key)`. The payload is provider independent. The client must calculate the SHA-256 of the original PDF bytes; the server stores its hash and filename, not a public file URL. The server currently accepts up to 100 rows per document.
|
||||
|
||||
```json
|
||||
{"source":{"programme":"Body Support","document_name":"shopping.pdf","sha256":"<64 hex digits>"},"ingredients":[{"row_key":"page1-broccoli","original_label":"Broccoli vers","canonical_name":"broccoli","quantity":"250","unit":"g","page":1,"preparation":"raw","category":"vegetable","subcategory":"cruciferous","confidence":"0.9"}]}
|
||||
```
|
||||
|
||||
Each row may also include `form`, `aliases`, `nutrition` (energy_kcal, protein_g, carbohydrates_g, fat_g, fibre_g), and `uncertainty`. Omitted nutrition stays unknown. Supported culinary categories are vegetable, fruit, herb, spice, bread, grain, meat, fish, dairy, legume, nuts_seeds, oil_fat, sauce, beverage, other and unresolved. Preparation is raw, cooked, dry, prepared or unknown. Preview flags unresolved category or preparation and unsupported units. Commit rejects unresolved rows, requires a confirmation no older than ten minutes and an idempotency key, and preserves original wording and source page. A repeated key returns the prior result; a different key for the same PDF is rejected for review as a possible amendment.
|
||||
|
||||
`nutrition_ingredients_search` returns canonical IDs, classifications, source labels/pages and read-only exact-name stock candidates. Filter by category, subcategory, programme, form, verification, query, or inventory status, with bounded pagination. An exact name candidate does not establish equivalent nutrition or sufficient stock. `nutrition_ingredient_correct` lets the owner manually correct category, subcategory or aliases while leaving source rows unchanged. All operations use existing food read/write scopes and per-user ownership. Import never writes inventory, groceries, recipes or diary. Recipe review, planned meals, source revisions, richer matching and optional search enrichment remain later card scope.
|
||||
|
||||
Reference in New Issue
Block a user