CartWeave MCP Server
README.md
<div align="center">
# π CartWeave
### Alexa+ Multi-Brand Pantry, Meal-Plan & Grocery Arbitrage Concierge
A self-hosted **Model Context Protocol (MCP `2025-11-25` Streamable HTTP)** server and **Amazon Echo Show 15 Multimodal Alexa+ Simulator** powered by **Amazon Bedrock Converse API**. Automates expiring pantry rescue, high-protein meal planning, and multi-retailer grocery arbitrage across Amazon Fresh, Whole Foods Market, and Local Neighborhood Co-op.
[](./LICENSE)
[](https://modelcontextprotocol.io/specification/2025-11-25/basic/transports)
[](https://aws.amazon.com/bedrock/)
[](https://developer.amazon.com/docs/alexaplus/add-ons/mcp-toolkit-overview.html)
[](https://nextjs.org/)
[](https://nodejs.org/)
<br>
<p align="center">
<a href="#-overview"><b>Overview</b></a> β’
<a href="#-key-features"><b>Key Features</b></a> β’
<a href="#-hackathon-prize-alignment"><b>Prize Tracks</b></a> β’
<a href="#-system-architecture"><b>Architecture</b></a> β’
<a href="#-the-5-stateful-mcp-tools"><b>MCP Tools</b></a> β’
<a href="#-quick-start"><b>Quick Start</b></a> β’
<a href="#-project-structure"><b>Structure</b></a> β’
<a href="#-connect--author"><b>Connect</b></a>
</p>
</div>
---
## π Overview
Instead of static shopping lists or isolated timers, imagine a household member speaking naturally to their kitchen Echo Show 15:
> *"Alexa, my baby spinach, paneer, and Greek yogurt expire tomorrowβplan 3 high-protein dinners under $38 and compare Amazon Fresh vs. Whole Foods for the missing ingredients."*
**CartWeave** orchestrates **5 stateful MCP tools** over a single `Mcp-Session-Id` session, prioritizes expiring fridge inventory to prevent food waste, computes per-serving protein and calorie macros, performs real-time price and substitution arbitrage across **Amazon Fresh**, **Whole Foods Market**, and a **Local Co-op**, and returns interactive **MCP Apps UI** cards where users can swap meals, filter dietary constraints, or check out in a single tap.
---
## β¨ Key Features
| Capability | Technical Implementation & User Benefit |
| :--- | :--- |
| **π MCP `2025-11-25` Streamable HTTP** | Full implementation of `POST /mcp`, `GET /mcp` (Server-Sent Events), and `DELETE /mcp` with stateful `Mcp-Session-Id` header tracking and `Access-Control-Expose-Headers` configuration. |
| **π§ Amazon Bedrock Converse Orchestration** | Chained multi-tool reasoning via `@aws-sdk/client-bedrock-runtime` supporting Anthropic Claude 3.5 Sonnet and Amazon Nova Pro, with an automated fallback to a zero-cost deterministic mock (`USE_MOCK_BEDROCK=true`). |
| **π₯ Expiry-First Pantry Optimization** | `scan_pantry_inventory` scans refrigerated items, computes hours until spoilage, and calculates total food waste dollars saved upon completing a meal plan. |
| **βοΈ Multi-Retailer Grocery Arbitrage** | `compare_grocery_carts` contrasts itemized carts across **Amazon Fresh**, **Whole Foods Market**, and **Local Co-op**, surfacing brand substitutions, Prime member savings, and hybrid split orders. |
| **π In-Session Constraint Mutation** | `swap_ingredient_constraint` enables mid-conversation modifications (e.g. *"Swap Day 2 to dairy-free under 520 kcal"*) without resetting the session context or re-prompting. |
| **πΊ Echo Show 15 Multimodal Simulator** | Next.js 14 split-screen simulator integrating Web Speech API STT/TTS, conversation timeline with 4 one-click Judge Demo chips, interactive MCP Apps cards, and a live Protocol Inspector. |
| **π‘οΈ Built-In Protocol Inspector & Test Runner** | Real-time JSON-RPC 2.0 frame monitor with a one-click automated MCP compliance test runner validating all 5 tools, resources, and prompts. |
---
## π Hackathon Prize Alignment
Built for the **Build, Ship, Shape: Amazon Developer Hackathon**:
| Prize Track | Implementation in CartWeave |
| :--- | :--- |
| **π₯ Primary Track β Alexa+** | Implements the official **MCP `2025-11-25` Streamable HTTP** specification (`POST`, `GET` SSE, `DELETE`), exposes `Mcp-Session-Id` session headers, and renders 4 rich multimodal **MCP Apps UI** widgets (`PANTRY_EXPIRY_GRID`, `MEAL_PLAN_MACRO_CARDS`, `STORE_ARBITRAGE_TABLE`, `ORDER_CONFIRMATION_CARD`) inside an Echo Show 15 simulator. |
| **π οΈ Mini Challenge β AWS Builder** | Integrates `@aws-sdk/client-bedrock-runtime` (`ConverseCommand`) with live Claude 3.5 Sonnet and Amazon Nova Pro support, includes an automated zero-cost deterministic mock planner, and packages a complete AWS SAM infrastructure-as-code template ([`template.yaml`](./template.yaml)). |
| **π Mini Challenge β Open Source** | Clean MIT-licensed monorepo ([`LICENSE`](./LICENSE)), automated specification compliance test suite (`npm run test:mcp`), system architecture diagrams, a 3-minute judge script, and a detailed 5-point Developer Friction Log ([`FRICTION_LOG.md`](./FRICTION_LOG.md)). |
---
## ποΈ System Architecture
The following diagram illustrates CartWeave's client-server architecture, MCP `2025-11-25` Streamable HTTP transport, stateful session handling, and Bedrock orchestrator:
```mermaid
flowchart TD
subgraph SIMULATOR ["πΊ Echo Show 15 Alexa+ Simulator (Next.js :3000)"]
VoiceOrb["Alexa+ Voice Orb (Web Speech API STT/TTS)"]
ConvPane["Conversation Pane & 4 Judge Demo Chips"]
McpClient["Browser MCP Client (mcpHttpClient.ts)"]
AppsCanvas["MCP Apps UI Canvas (4 Interactive Cards)"]
Inspector["Judge MCP Protocol Inspector (Live JSON-RPC 2.0 & Compliance Runner)"]
end
subgraph SERVER ["β‘ CartWeave MCP Server (Express :3001)"]
StreamHttp["MCP 2025-11-25 Transport (POST / GET SSE / DELETE /mcp)"]
SessionMgr["McpSessionManager (Stateful Mcp-Session-Id Store)"]
BedrockOrch["BedrockOrchestrator (Converse API + Deterministic Mock)"]
subgraph TOOLS ["π οΈ 5 Stateful MCP Tools"]
T1["1. scan_pantry_inventory"]
T2["2. generate_meal_plan"]
T3["3. compare_grocery_carts"]
T4["4. swap_ingredient_constraint"]
T5["5. checkout_smart_basket"]
end
Resources["MCP Resources & Prompts (mcp://pantry/expiring-soon, mcp://cart/active-comparison)"]
end
VoiceOrb --> ConvPane
ConvPane -->|POST /agent/chat| BedrockOrch
AppsCanvas -->|Interactive Card Actions / POST tools/call| McpClient
McpClient <-->|JSON-RPC 2.0 + Mcp-Session-Id| StreamHttp
StreamHttp <--> SessionMgr
BedrockOrch --> TOOLS
StreamHttp --> TOOLS
StreamHttp --> Resources
McpClient --> Inspector
```
---
## π οΈ The 5 Stateful MCP Tools
CartWeave exposes 5 stateful MCP tools over the `2025-11-25` transport, returning both token-efficient text for LLM chaining and structured `mcp_app_ui` cards for the display:
```
+---------------------------------------------------------------------------------------------------------+
| CartWeave Tool Execution Flow |
+---------------------------------------------------------------------------------------------------------+
| |
| 1. scan_pantry_inventory --> Finds items expiring soon (Spinach: 18h, Yogurt: 24h, Paneer: 36h) |
| | |
| 2. generate_meal_plan --> Generates 3 dinners under budget (39g avg protein, $31.40 cost) |
| | |
| 3. compare_grocery_carts --> Evaluates missing ingredients across Amazon Fresh vs Whole Foods vs Co-op |
| | |
| 4. swap_ingredient_constraint -> Mutates Day 2 dish (Dairy-Free <520 kcal) without resetting session |
| | |
| 5. checkout_smart_basket --> Locks delivery slot, generates tracking code, saves $18.45 in waste |
| |
+---------------------------------------------------------------------------------------------------------+
```
| Tool Name | Parameters | Core Responsibility & Return Payload |
| :--- | :--- | :--- |
| **`scan_pantry_inventory`** | `filter_category?`, `max_hours_to_spoil?` | Inspects stored pantry inventory, flags high-urgency items, computes hours to spoil, and returns the `PANTRY_EXPIRY_GRID` widget. |
| **`generate_meal_plan`** | `days`, `target_protein_per_day_g?`, `max_budget_dollars?`, `dietary_tags?` | Creates a multi-day culinary plan utilizing expiring items, calculates per-serving macros, and renders `MEAL_PLAN_MACRO_CARDS`. |
| **`compare_grocery_carts`** | `target_stores?`, `enable_substitutions?` | Analyzes missing ingredients across Amazon Fresh, Whole Foods, and Local Co-op, presenting the `STORE_ARBITRAGE_TABLE`. |
| **`swap_ingredient_constraint`** | `day_number`, `avoid_ingredient?`, `max_calories?`, `preferred_protein_source?` | Replaces a specific meal in place while preserving session context and recalculating store totals. |
| **`checkout_smart_basket`** | `store_id`, `delivery_window`, `confirm_order` | Finalizes the order, deducts used inventory from the pantry, and outputs the `ORDER_CONFIRMATION_CARD`. |
---
## π± Interactive Multimodal Cards (`mcp_app_ui`)
CartWeave's Echo Show 15 simulator renders 4 interactive visual cards paired with spoken voice responses:
1. **`PANTRY_EXPIRY_GRID`**: Color-coded urgency badges (red: <24h, amber: <48h, green: fresh), item quantities, and estimated discard values.
2. **`MEAL_PLAN_MACRO_CARDS`**: 3-day meal breakdown highlighting used pantry items, missing grocery items, calorie counts, and protein macros. Includes an inline **"Swap Dish"** action button.
3. **`STORE_ARBITRAGE_TABLE`**: Side-by-side comparison of Amazon Fresh vs. Whole Foods Market vs. Local Co-op, including brand substitutions, Prime member discounts, and delivery speed.
4. **`ORDER_CONFIRMATION_CARD`**: Receipt showing delivery window, one-tap tracking link, itemized total, and total food waste dollars saved ($18.45).
---
## π Quick Start (Zero-Config Local Run)
### Prerequisites
* **Node.js** `>= 20.x` and **npm** `>= 10.x`
* No AWS credentials required by default (`USE_MOCK_BEDROCK=true` is enabled out of the box; set `USE_MOCK_BEDROCK=false` and provide AWS credentials to connect to live Amazon Bedrock).
### 1. Clone the Repository
```bash
git clone https://github.com/harinarayana1457-cmyk/CartWeave.git
cd CartWeave
```
### 2. Install Workspace Dependencies
```bash
npm install
```
### 3. Run Automated MCP 2025-11-25 Compliance Suite
```bash
npm run test:mcp
```
*Validates the `initialize` handshake (`protocolVersion === "2025-11-25"`), asserts `Mcp-Session-Id` header persistence, tests `tools/list`, `resources/list`, `resources/read`, `prompts/list`, `prompts/get`, and executes all 5 stateful `tools/call` operations while verifying non-empty `mcp_app_ui` structured payloads.*
### 4. Launch Development Servers (MCP Server + Simulator)
```bash
npm run dev
```
* **Echo Show 15 Alexa+ Simulator**: [`http://localhost:3000`](http://localhost:3000)
* **MCP 2025-11-25 Streamable HTTP Endpoint**: [`http://localhost:3001/mcp`](http://localhost:3001/mcp)
* **Health & Diagnostics**: [`http://localhost:3001/health`](http://localhost:3001/health)
---
## π Project Structure
```
CartWeave/
βββ packages/
β βββ mcp-server/ # Self-hosted MCP 2025-11-25 Streamable HTTP Server
β β βββ src/
β β β βββ aws/
β β β β βββ bedrockAgent.ts # Amazon Bedrock Converse API + Mock Planner
β β β βββ data/
β β β β βββ seedData.ts # Seed pantry items, store catalog & recipe DB
β β β βββ prompts/
β β β β βββ mcpPrompts.ts # MCP Prompts handler (mcp://prompts/pantry-rescue)
β β β βββ resources/
β β β β βββ mcpResources.ts # MCP Resources handler (mcp://pantry/expiring-soon)
β β β βββ test/
β β β β βββ verifyMcpSpec.ts # Automated MCP 2025-11-25 Compliance Test Suite
β β β βββ tools/ # 5 Stateful MCP Tool Implementations
β β β β βββ scanPantry.ts
β β β β βββ generateMealPlan.ts
β β β β βββ compareCarts.ts
β β β β βββ swapConstraint.ts
β β β β βββ checkoutBasket.ts
β β β βββ index.ts # Express HTTP transport (POST/GET/DELETE /mcp)
β β β βββ mcpSessionManager.ts # Mcp-Session-Id state tracking & SSE streams
β β βββ package.json
β β βββ tsconfig.json
β β
β βββ alexa-plus-simulator/ # Echo Show 15 Multimodal Alexa+ Simulator
β βββ src/
β β βββ app/
β β β βββ layout.tsx
β β β βββ page.tsx # Split-screen Echo Show 15 layout
β β β βββ globals.css
β β βββ components/
β β β βββ AlexaVoiceOrb.tsx # Animated Voice Orb with Web Speech API
β β β βββ ConversationPane.tsx # Chat transcript & 4 Judge Demo chips
β β β βββ EchoShowFrame.tsx # Echo Show 15 hardware bezel & status bar
β β β βββ McpAppsCanvas.tsx # Multimodal cards container
β β β βββ McpProtocolInspector.tsx # JSON-RPC 2.0 inspector drawer & test runner
β β β βββ cards/ # 4 Interactive MCP Apps UI Cards
β β β βββ PantryExpiryCard.tsx
β β β βββ MealPlanMacroCard.tsx
β β β βββ StoreArbitrageCard.tsx
β β β βββ OrderConfirmationCard.tsx
β β βββ lib/
β β βββ mcpHttpClient.ts # Browser MCP Streamable HTTP Client
β βββ package.json
β βββ tailwind.config.ts
β
βββ FRICTION_LOG.md # Detailed 5-point Developer Friction Log
βββ template.yaml # Production AWS SAM template (Lambda + DynamoDB)
βββ package.json # Root workspace scripts (npm run dev, test:mcp)
βββ README.md # Project documentation
```
---
## π οΈ Tech Stack
| Layer | Technology | Version | Purpose |
| :--- | :--- | :--- | :--- |
| **Protocol Transport** | [Model Context Protocol](https://modelcontextprotocol.io/) | `2025-11-25` | Stateful Streamable HTTP transport (`POST /mcp`, `GET /mcp` SSE, `DELETE /mcp`) |
| **Cloud AI Orchestration** | [Amazon Bedrock](https://aws.amazon.com/bedrock/) | SDK `v3.700` | Multi-turn tool calling via `ConverseCommand` (Claude 3.5 Sonnet / Nova Pro) |
| **Backend Runtime** | [Node.js](https://nodejs.org/) & [Express](https://expressjs.com/) | Node 20+, Express 4 | High-throughput HTTP & SSE server with custom CORS session headers |
| **Type Validation** | [Zod](https://zod.dev/) & [TypeScript](https://www.typescriptlang.org/) | Zod 3.24, TS 5.7 | Strict runtime input/output schemas for all 5 MCP tools and JSON-RPC payloads |
| **Frontend Framework** | [Next.js](https://nextjs.org/) & [React](https://react.dev/) | Next 14.2, React 18 | SSR/Client split-screen Echo Show 15 simulator application |
| **Styling & Icons** | [Tailwind CSS](https://tailwindcss.com/) & [Lucide](https://lucide.dev/) | Tailwind 3.4, Lucide | Echo Show 15 device styling, responsive cards, and clean visual indicators |
| **Voice Interface** | [Web Speech API](https://developer.mozilla.org/en-US/docs/Web/API/Web_Speech_API) | Native Browser | In-browser Speech-to-Text (`SpeechRecognition`) and Alexa TTS synthesis |
| **Cloud Deployment** | [AWS SAM](https://aws.amazon.com/serverless/sam/) | SAM CLI / CloudFormation | Serverless packaging for AWS Lambda, API Gateway HTTP API, and DynamoDB |
---
## π License
Distributed under the **[MIT License](https://opensource.org/licenses/MIT)**. See [`LICENSE`](./LICENSE) for full details.
---
## π Connect & Author
[](https://www.linkedin.com/in/hari-narayana-035ba1389/)
[](https://github.com/harinarayana1457-cmyk)
<div align="center">
<sub>Built for the Build, Ship, Shape: Amazon Developer Hackathon. Empowering smart, zero-waste kitchen economies with Alexa+ and Model Context Protocol.</sub>
</div>
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo issues