diff --git a/main/MCP.md b/main/MCP.md
new file mode 100644
index 0000000..4c55980
--- /dev/null
+++ b/main/MCP.md
@@ -0,0 +1,58 @@
+# TaskNest MCP server
+
+The Streamable HTTP MCP endpoint exposes the Food and Kitchen API to an AI assistant. The server in `mcp_server.server` is an HTTP adapter: every user operation goes through `/api/v1/` with the connected user's bearer token. It does not read Django models directly.
+
+## Local development
+
+Install `main/requirements.txt` in the project virtual environment and run Django migrations. Start Django using the project's normal development command on port 1234, then start MCP from `main/`:
+
+```sh
+python -m uvicorn mcp_server.server:app --host 127.0.0.1 --port 8002
+```
+
+The endpoint is `http://127.0.0.1:8002/mcp`. Its protected resource metadata is at `/.well-known/oauth-protected-resource/mcp`. Django serves OAuth authorization server metadata at `/.well-known/oauth-authorization-server` and OAuth endpoints under `/o/`.
+
+Set these variables in the MCP process for deployment:
+
+| Variable | Purpose |
+| --- | --- |
+| `TASKNEST_API_BASE_URL` | Internal Django API URL ending in `/api/v1` |
+| `TASKNEST_MCP_PUBLIC_URL` | Public HTTPS MCP URL ending in `/mcp` |
+| `TASKNEST_OAUTH_ISSUER_URL` | Public HTTPS Django origin used in OAuth metadata |
+| `TASKNEST_MCP_FILE_HOSTS` | Comma-separated HTTPS host allowlist for client-supplied file downloads |
+
+Set `TASKNEST_MCP_PUBLIC_URL` and `TASKNEST_OAUTH_ISSUER_URL` in Django as well. Keep the issuer URL consistent between both processes. The checked-in defaults use `https://tasksnest.jorendegraaf.eu/`; override both variables with local URLs when testing local OAuth. Do not place personal access tokens in URLs or environment variables. Bind MCP to loopback only when Caddy runs on the **same host**. When Caddy runs on another host and proxies to the app host's Tailnet address, bind MCP to that Tailnet address instead. The MCP process should have the same restart and logging policy as the Django service.
+
+The public `/mcp` path **must** reach the MCP process, not Django. For the site's Caddy proxy, route the exact MCP path and protected-resource metadata to the MCP listener, and let the existing Django route handle OAuth metadata and `/o/`:
+
+```caddyfile
+tasksnest.jorendegraaf.eu {
+ handle /mcp {
+ reverse_proxy 100.91.62.59:8002
+ }
+ handle /.well-known/oauth-protected-resource/mcp {
+ reverse_proxy 100.91.62.59:8002
+ }
+ handle {
+ reverse_proxy 100.91.62.59:1234
+ }
+}
+```
+
+Integrate these `handle` routes into the existing site block rather than replacing unrelated proxy settings. Preserve HTTPS and the `Authorization` header. The provided `deploy/systemd/tasknest-mcp.service` starts MCP on the app host's Tailnet address; adjust its address and virtualenv path if they differ, install it on the **app host**, and start it before reloading Caddy. If Caddy and Django are on the same host, replace the Caddy upstreams with `127.0.0.1` and bind MCP to `127.0.0.1`.
+
+Before reconnecting ChatGPT, verify the public endpoints: `/.well-known/oauth-protected-resource/mcp` must advertise `https://tasksnest.jorendegraaf.eu/` as its authorization server; `/.well-known/oauth-authorization-server` must advertise public HTTPS authorization and token endpoints; and an unauthenticated POST to `/mcp` should return an MCP authentication response, not a Django 404. Restart the Django and MCP processes after changing their environment variables.
+
+## Connect a client
+
+Open **Settings → API tokens → Connect an AI assistant**. For ChatGPT, use the public MCP URL and OAuth sign-in. ChatGPT must be able to reach the HTTPS URL and its OAuth metadata. For Open WebUI or another bearer-token client, create a personal token with only the scopes needed, choose Streamable HTTP, and enter the same MCP URL and token as a bearer credential. The helper's password field is local to the browser and clears when the page is left; it does not submit the token to the helper. Revoke a token from Settings when it is no longer needed.
+
+The server exposes 12 tools for food diary and inventory reads and changes. `food_attach_image` and `food_log_with_image` accept a ChatGPT file object via `image_file` or base64 data via `image_base64`. Images must be JPEG, PNG, or WebP and at most 5 MiB. A client-supplied file URL must use HTTPS and an allowed host. The API performs image validation and ownership checks. Creation tools accept an `idempotency_key`; reuse the same key and arguments when retrying a request. `food_log_with_image` reports whether the entry was created even if its later attachment upload fails.
+
+`food_get_today` accepts an optional `date` in `YYYY-MM-DD` format. Omit it for the user's local today; pass a calendar date to read another day, such as yesterday. The HTTP API supports the same parameter on `GET /api/v1/food/today/?date=YYYY-MM-DD`.
+
+The OAuth consent page displays the requested scopes. OAuth access tokens are user-specific API tokens, and token revocation also revokes the matching OAuth grant. For production, use HTTPS and set the issuer and MCP URLs to the actual public hosts before connecting a client. Dynamic client registration is disabled; clients use OAuth Client ID Metadata Documents (CIMD). ChatGPT's document offers both `none` and `private_key_jwt`; this server selects `none` with PKCE because the installed Django OAuth Toolkit supports public CIMD clients only. Clients that do not explicitly offer `none` are rejected.
+
+## 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.
diff --git a/main/README.md b/main/README.md
index 685bdbb..d5ab131 100644
--- a/main/README.md
+++ b/main/README.md
@@ -1,5 +1,9 @@
# Tasknest development notes
+## AI assistant connection
+
+The Food and Kitchen API has a Streamable HTTP MCP adapter with per-user token and OAuth authentication. See [MCP.md](MCP.md) for local startup, deployment routing, client setup, and verification.
+
## Weather scheduling
The server gets a finite 16-day daily forecast from Open-Meteo and caches each user's normalized forecast for twelve hours. No browser code, template, or model calls Open-Meteo directly.
diff --git a/main/deploy/systemd/tasknest-mcp.service b/main/deploy/systemd/tasknest-mcp.service
new file mode 100644
index 0000000..2f7cc5b
--- /dev/null
+++ b/main/deploy/systemd/tasknest-mcp.service
@@ -0,0 +1,18 @@
+[Unit]
+Description=Tasknest MCP Streamable HTTP server
+Wants=network-online.target
+After=network-online.target tailscaled.service
+
+[Service]
+Type=simple
+User=jorenmartijn
+WorkingDirectory=/home/jorenmartijn/django/main
+Environment=TASKNEST_API_BASE_URL=http://127.0.0.1:1234/api/v1
+Environment=TASKNEST_MCP_PUBLIC_URL=https://tasksnest.jorendegraaf.eu/mcp
+Environment=TASKNEST_OAUTH_ISSUER_URL=https://tasksnest.jorendegraaf.eu/
+ExecStart=/home/jorenmartijn/django/tasksnest-host/bin/python -m uvicorn mcp_server.server:app --host 100.91.62.59 --port 8002
+Restart=on-failure
+RestartSec=3
+
+[Install]
+WantedBy=multi-user.target
diff --git a/main/food/api.py b/main/food/api.py
index aab2863..1a10611 100644
--- a/main/food/api.py
+++ b/main/food/api.py
@@ -222,7 +222,13 @@ def _idempotent(request, payload, action, digest_override=None):
@api_view('food:read', ('GET',))
def today(request):
- day = localdate_for_user(request.api_user)
+ requested_date = request.GET.get('date')
+ if requested_date is None:
+ day = localdate_for_user(request.api_user)
+ else:
+ day = parse_date(requested_date)
+ if day is None or day.isoformat() != requested_date:
+ return error('invalid_date', 'Use a date in YYYY-MM-DD format.')
entries = list(FoodLogEntry.objects.filter(user=request.api_user, date=day)
.select_related('product').prefetch_related('attachments'))
meals = {meal: [_entry_data(e) for e in entries if e.meal == meal] for meal in MealType.values}
diff --git a/main/food/api_schema.py b/main/food/api_schema.py
index 18bb4db..819a98f 100644
--- a/main/food/api_schema.py
+++ b/main/food/api_schema.py
@@ -49,7 +49,7 @@ def schema(request):
'servers': [{'url': '/api/v1'}],
'components': {'securitySchemes': {'bearerToken': {'type': 'http', 'scheme': 'bearer'}}},
'paths': {
- '/food/today/': {'get': operation('Current local day food log, meal groups, totals, and goals', 'food:read')},
+ '/food/today/': {'get': operation('Food log for an optional local calendar date, defaulting to today', 'food:read')},
'/food/products/': {'get': operation('Search own food products', 'food:read')},
'/food/log/': {'post': operation('Create food log entry', 'food:write', ENTRY)},
'/food/log/{id}/': {
@@ -77,6 +77,11 @@ def schema(request):
'schema': {'type': 'string', 'format': 'uuid'}}]
if 'post' in methods:
methods['post']['responses']['201'] = methods['post']['responses'].pop('200')
+ document['paths']['/food/today/']['get']['parameters'] = [{
+ 'name': 'date', 'in': 'query', 'required': False,
+ 'description': 'Local calendar date; defaults to today in the user time zone.',
+ 'schema': {'type': 'string', 'format': 'date'},
+ }]
document['paths']['/food/attachments/{id}/file/']['get']['responses']['200'] = {
'description': 'Owned image bytes',
'content': {mime: {'schema': {'type': 'string', 'format': 'binary'}}
diff --git a/main/food/cimd.py b/main/food/cimd.py
new file mode 100644
index 0000000..35e5033
--- /dev/null
+++ b/main/food/cimd.py
@@ -0,0 +1,21 @@
+"""Adapt CIMD method negotiation for DOT's public-client-only implementation."""
+
+from oauth2_provider.cimd import SafeMetadataFetcher
+from oauth2_provider.settings import oauth2_settings
+
+
+class CompatibleCIMDFetcher(SafeMetadataFetcher):
+ def fetch(self, client_id):
+ metadata, max_age = super().fetch(client_id)
+ methods = metadata.get('token_endpoint_auth_methods_supported')
+ if (
+ metadata.get('token_endpoint_auth_method') != 'none'
+ and isinstance(methods, list)
+ and 'none' in methods
+ and 'none' in oauth2_settings.OAUTH2_TOKEN_ENDPOINT_AUTH_METHODS_SUPPORTED
+ ):
+ # DOT 3.4 accepts only public CIMD clients. The plural metadata
+ # field explicitly allows this method even when the legacy singular
+ # field prefers private_key_jwt, which this server does not offer.
+ metadata = {**metadata, 'token_endpoint_auth_method': 'none'}
+ return metadata, max_age
diff --git a/main/food/services/diary.py b/main/food/services/diary.py
index 3983e3d..3be01f0 100644
--- a/main/food/services/diary.py
+++ b/main/food/services/diary.py
@@ -24,7 +24,8 @@ def selected_date(request):
def diary_context(user, day):
goals, _ = UserSettings.objects.get_or_create(user=user)
- entries = list(FoodLogEntry.objects.filter(user=user, date=day).select_related('product').defer('product__raw_data'))
+ entries = list(FoodLogEntry.objects.filter(user=user, date=day).select_related('product')
+ .prefetch_related('attachments').defer('product__raw_data'))
totals = {name: sum((getattr(entry, name) or ZERO for entry in entries), ZERO) for name in
('calories_kcal', 'carbohydrates_g', 'protein_g', 'fat_g')}
meals = []
diff --git a/main/food/static/food/food.css b/main/food/static/food/food.css
index 2821e6a..40bcd86 100644
--- a/main/food/static/food/food.css
+++ b/main/food/static/food/food.css
@@ -15,6 +15,9 @@ body[data-theme="dark"]{--food-surface:#202923;--food-border:#3b473f;--food-ink:
.food-progress span{background:var(--food-green)}
.food-entry-main span,.food-entry-main small,.food-card>p:not(.food-remaining),.food-attribution{color:var(--food-muted);opacity:1}
.food-entry-main strong,.food-card h2,.food-card h3,.food-remaining{color:var(--food-ink)}
+.food-entry-images{display:flex;gap:.35rem;flex:none;max-width:min(40vw,220px);overflow-x:auto;padding:.15rem}
+.food-entry-images a{display:block;flex:none;border-radius:.6rem}
+.food-entry-images a:focus-visible{outline:2px solid currentColor;outline-offset:2px}
.inventory-page .inventory-group{margin:1.5rem 0 .5rem}.inventory-filters{display:flex;flex-wrap:wrap;gap:.75rem;align-items:end}.inventory-filters label{display:grid;gap:.25rem;min-width:130px;flex:1}.inventory-filters .inventory-check{display:flex;align-items:center;min-width:auto}.inventory-row{display:flex;align-items:center;gap:1rem}.inventory-row>img,.inventory-product>img{width:68px;height:68px;object-fit:contain;background:#fff;border-radius:.6rem}.inventory-row-main{flex:1;min-width:0}.inventory-row-main p{margin:.2rem 0}.inventory-row-actions{display:flex;align-items:center;gap:.5rem;flex-wrap:wrap}.inventory-row-actions form{display:flex;gap:.4rem}.inventory-row-actions button,.inventory-row-actions a{min-height:44px;padding:.5rem .75rem}.inventory-tag{display:inline-block;padding:.2rem .45rem;margin:.2rem .2rem 0 0;border-radius:.5rem;background:#eef1ed;color:#263828}.inventory-soon{background:#fff0c2;color:#533c00}.inventory-expired{background:#f9d9d9;color:#6b1717}.inventory-product{display:flex;gap:1rem;align-items:center}.inventory-existing{display:flex;justify-content:space-between;align-items:center;gap:.7rem;margin:.7rem 0}.inventory-form{display:grid;gap:.8rem}.inventory-form .form-field{display:grid;gap:.25rem}.inventory-form input:not([type=checkbox]),.inventory-form textarea{width:100%}@media(max-width:650px){.inventory-row{align-items:flex-start;flex-wrap:wrap}.inventory-row-actions{width:100%}.inventory-existing{align-items:flex-start;flex-direction:column}}
.inventory-quantity{display:flex;align-items:center;gap:.5rem}.inventory-quantity input{text-align:center;max-width:6rem}.inventory-quantity button{min-width:44px;min-height:44px;border:1px solid currentColor;border-radius:.5rem;background:transparent;color:inherit;font-size:1.3rem}
.food-tabs a[aria-current=page]{background:var(--food-green);border-color:var(--food-green);color:#fff}
diff --git a/main/food/templates/food/partials/diary_content.html b/main/food/templates/food/partials/diary_content.html
index efdf029..d5fa076 100644
--- a/main/food/templates/food/partials/diary_content.html
+++ b/main/food/templates/food/partials/diary_content.html
@@ -5,7 +5,18 @@
{% for meal in meals %}