Skip to main content
Glama
THEMIGHTYBULL

FreshKeep MCP Server

README.md
# ๐Ÿฅฌ FreshKeep โ€” your kitchen's memory, built for Alexa+

> **FreshKeep gives Alexa+ persistent, structured memory of your kitchen โ€” it knows
> what you bought, warns you before food spoils, and turns expiring ingredients
> into tonight's dinner.**

Built for **Build, Ship, Shape: The Amazon Developer Hackathon 2026**.

- **Primary track:** Alexa+ โ€” self-hosted **MCP server** (Streamable HTTP,
  MCP spec 2026-07-28 via the official SDK; requirement was 2025-11-25+),
  an **Agent Skill** definition, and a **simulated Alexa+ experience** web app
  that acts as a real MCP client.
- **Mini-challenges:** AWS Builder (Bedrock router + DynamoDB adapter seams) ยท Open Source (MIT).

---

## The problem

The average household throws away roughly **$1,500 of food per year**
(USDA estimates 30โ€“40% of the food supply is wasted). The reason is not lack
of caring โ€” it's lack of *memory*: nobody maintains a pantry app when their
hands are full of groceries. Voice is the natural fix, but before MCP, Alexa
had no persistent, structured kitchen memory to reason over.

## The 60-second wow

1. *"We just bought spinach, 500 g of yogurt, and chicken that expires in 2 days"* โ†’ FreshKeep tracks them with structured MCP tool calls (visible in judge mode).
2. *"What needs rescuing?"* โ†’ 4 at-risk items, most urgent first, with money-at-risk.
3. *"Plan a rescue meal"* โ†’ **Everything-Left Veggie Omelette**, rescuing 3 items, โ‰ˆ$9.60 saved (estimate), and it notices you're missing bread.
4. *"Add bread to the shopping list"* โ†’ write-back action completes the loop.
5. *"Waste report"* โ†’ rescued vs wasted, in dollars.
6. **๐Ÿงพ Bonus:** paste a receipt โ†’ FreshKeep proposes the items (noise like totals/tax filtered) โ†’ confirm โ†’ tracked via the same MCP path. With `FRESHKEEP_TEXTRACT=1`, receipt *photos* are read by **Amazon Textract**.

Everything runs **deterministically** โ€” the demo never depends on an LLM
behaving. Optional Bedrock mode enhances natural-language routing with strict
schema validation and automatic fallback.

## Quickstart (2 terminals, no cloud account needed)

```bash
git clone <this-repo> && cd freshkeep
pip install -r requirements.txt          # add pytest via requirements-dev.txt for tests

# Terminal 1 โ€” the MCP server (Streamable HTTP on :8811)
python -m freshkeep.mcpserver

# Terminal 2 โ€” the simulated Alexa+ experience (:8800)
python -m freshkeep.simulator.app
```

Open **http://localhost:8800**, accept the consent prompt, press
**Seed demo kitchen**, then use the quick-action chips (โ‘ โ€“โ‘ค) or type/speak:

- *"What needs rescuing?"*
- *"Plan a rescue meal"*
- *"Add soy sauce to the shopping list"*
- *"Waste report"*
- *"Delete my data"* (two-step confirmation)
- **๐Ÿงพ button** next to the mic: paste a receipt โ†’ review parsed items โ†’ track

**Judge mode** (right panel) shows every live MCP tool call with arguments,
structured JSON results, latency, and which router answered.

### Verify the MCP endpoint directly

```bash
curl -s -X POST http://127.0.0.1:8811/mcp \
  -H 'Content-Type: application/json' -H 'Accept: application/json, text/event-stream' \
  -d '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-11-25","capabilities":{},"clientInfo":{"name":"probe","version":"0"}}}'
```

### Tests

```bash
pip install -r requirements-dev.txt
pytest -q          # 34 tests: tools, router, receipts, API, and a real MCP wire loop
```

## Architecture (summary)

```
Browser (simulated Alexa+ experience, judge mode)
        โ”‚  /api/utterance
        โ–ผ
FastAPI simulator โ”€โ”€ deterministic router (default)
        โ”‚              โ””โ”€โ”€ optional Bedrock Converse router (schema-validated, fallback-safe)
        โ”‚  MCP: initialize โ†’ tools/call  (Streamable HTTP)
        โ–ผ
FreshKeep MCP server (official Python SDK, spec 2026-07-28)
        โ”‚
        โ”œโ”€โ”€ tool layer (validation, unit-aware merge, waste ledger)
        โ”œโ”€โ”€ deterministic rescue-meal engine (curated templates, zero hallucination)
        โ””โ”€โ”€ storage: JsonFileStore (default) | DynamoStore (FRESHKEEP_STORE=dynamodb)
```

Full diagram + AWS service justification: [`docs/ARCHITECTURE.md`](docs/ARCHITECTURE.md).

## Environment

Copy `.env.example` โ†’ `.env` (or export vars). Everything has a safe local
default; **no AWS account is required** for the core experience.

| Variable | Default | Purpose |
|---|---|---|
| `FRESHKEEP_MCP_HOST/PORT` | `0.0.0.0:8811` | MCP server bind |
| `FRESHKEEP_SIM_HOST/PORT` | `0.0.0.0:8800` | simulator bind |
| `FRESHKEEP_STORE` | `json` | `json` or `dynamodb` |
| `FRESHKEEP_JSON_PATH` | `data/household.json` | local store file |
| `FRESHKEEP_DYNAMO_TABLE` | `FreshKeepHousehold` | DynamoDB table |
| `FRESHKEEP_BEDROCK` | `0` | `1` enables the Bedrock NL router |
| `FRESHKEEP_BEDROCK_MODEL` | `amazon.nova-lite-v1:0` | router model |
| `FRESHKEEP_RATE_LIMIT` | `30` | utterances/min per client |
| `FRESHKEEP_REQUIRE_CONSENT` | `1` | consent gate before any storage |
| `FRESHKEEP_TEXTRACT` | `0` | `1` enables receipt-photo extraction via Amazon Textract |
| `FRESHKEEP_TEXTRACT_REGION` | `AWS_REGION` | Textract region |

## Privacy & safety (short version)

- **Consent before storage** โ€” nothing persists until granted; withdrawal supported.
- **Two-step deletion** โ€” "delete my data" then explicit confirmation; nothing is model-callable.
- **Prompt-injection hardening** โ€” user text is data only; router can only emit schema-validated calls to known tools; destructive tools unreachable from the model path.
- **Audit log excludes utterance text** โ€” tool names and counts only.
- **Deterministic core** โ€” AI never controls actions; savings figures are always labeled estimates.

Details + full threat model: [`docs/SECURITY.md`](docs/SECURITY.md).

## Honest status (what is verified)

| Capability | Status |
|---|---|
| MCP server over Streamable HTTP (spec โ‰ฅ 2025-11-25) | โœ… tested end-to-end (`tests/test_mcp_wire.py`) |
| Simulated Alexa+ experience as real MCP client | โœ… tested incl. rate-limit, consent, 2-step delete |
| Deterministic router + rescue engine | โœ… unit-tested |
| JSON file storage | โœ… exercised by all tests |
| DynamoDB adapter (`DynamoStore`) | ๐Ÿ”ง implemented behind the same interface; live-verify with `python scripts/verify_aws.py` (setup: [`docs/AWS_SETUP.md`](docs/AWS_SETUP.md)) |
| Bedrock NL router (`bedrock.py`) | ๐Ÿ”ง implemented with strict validation + fallback; live-verify with the same script |
| Receipt ingestion (`receipts.py`) | โœ… text path tested end-to-end; Textract photo adapter implemented, live-verifiable with the same script |
| Agent Skill definition | ๐Ÿ“„ follows public Agent Skills conventions; final format to be re-verified against Alexa+ docs before submission |

## Repository map

```
freshkeep/               Python package
โ”œโ”€โ”€ mcpserver.py         MCP server entry (Streamable HTTP) โ€” 13 tools
โ”œโ”€โ”€ mcpclient.py         Real MCP client used by the simulator + test harness
โ”œโ”€โ”€ tools.py             Tool logic + shared JSON schemas (single source of truth)
โ”œโ”€โ”€ router.py            Deterministic utterance โ†’ tool router
โ”œโ”€โ”€ bedrock.py           Optional Bedrock Converse router (guarded)
โ”œโ”€โ”€ rescue.py            Deterministic rescue-meal engine
โ”œโ”€โ”€ receipts.py          Receipt parsing (deterministic) + Amazon Textract adapter
โ”œโ”€โ”€ storage.py           JsonFileStore | DynamoStore
โ”œโ”€โ”€ models.py            Freshness math, validation helpers
โ”œโ”€โ”€ safety.py            Validation, rate limiter, PII-light audit log
โ”œโ”€โ”€ seed.py              Seeded demo kitchen (relative dates โ†’ always demo-ready)
โ””โ”€โ”€ simulator/           FastAPI simulated Alexa+ experience + single-file UI
skill/SKILL.md           Agent Skill definition for Alexa+
tests/                   29 tests incl. real MCP wire loop
docs/                    Architecture, security, demo script, judge guide,
                         submission draft, product feedback, friction log,
                         rules compliance
```

## Deadline (verified against the official page)

**Oct 23, 2026 โ€” 12:00 PM Pacific (PDT) ยท 3:00 PM EDT ยท = Oct 24, 2026, 00:30 IST (Asia/Kolkata).**
Re-check before submitting: https://amazonappdev2026.devpost.com/

## License

MIT โ€” see [LICENSE](LICENSE).