Inspiration
Online shopping is still a pile of tabs, filters, and checkout forms, while AI agents can already search and reason. The missing piece is trust: would you let an AI spend your money? I wanted to build an agent that can shop and pay for you, while making overspending or a wrong charge hard by design.
What it does
AI Shop is a conversational shopping agent and an MCP server. You ask for something like "gaming laptop under $1,200", and it:
- searches real retail products through the Channel3 API
- compares them in cards or an AG Grid comparison table
- charges a vaulted PayPal Sandbox account with no checkout form
- handles order history, refunds, and disputes by chat
It works in the built-in web chat and in Claude.ai or Claude Desktop through 14 shared tools.
How I built it
- Backend: TypeScript, Node 20, Express, Supabase (PostgreSQL)
- Payments: PayPal Vault v3 (setup tokens and payment tokens) and the Orders API, with webhooks for captures, refunds, and disputes
- AI integration: a Model Context Protocol server with a built-in OAuth 2.1 + PKCE (S256) authorization server
- Hosting: Render, using a
render.yamlblueprint
The purchase flow has two steps. prepare_purchase reads prices from the database and freezes them in a single-use quote that expires in 10 minutes. confirm_purchase then checks the quote, the user's consent, and the spending limits before charging.
With the total $T$ in cents, a charge goes through only if:
$$T \le L_{\text{order}} \quad \text{and} \quad S_{\text{today}} + T \le L_{\text{daily}}$$
where $L_{\text{order}}$ and $L_{\text{daily}}$ are the user's limits (capped by a server-side MAX_LIMIT) and $S_{\text{today}}$ is what they have already spent today. All money is handled as integer cents, so there is no floating-point drift.
What I learned
- An AI agent should never be the source of truth for prices. The model only passes product IDs, and the server decides the amounts.
- Safety rules must live on the server, not in the prompt.
- Idempotency matters. The quote UUID doubles as the
PayPal-Request-Id, so a retry can never double-charge. - OAuth 2.1 for MCP clients (PKCE, token rotation, replay defense) takes real care to get right.
- Webhooks are essential, because the state in PayPal and the state in your database can drift apart.
Challenges I faced
- Preventing double charges: the quote is marked as used before the charge, using a conditional update so two simultaneous confirmations can't both win.
- Stale quotes: prices and stock are re-checked at confirmation time, so a quote can't be used after the catalog changes.
- Keeping the AI honest: consent, quote matching, and limits are all enforced in code rather than trusted to the model.
- Real catalog data: live products change constantly, so I cache them and always charge from the verified database record.
- Staying in sandbox: the server refuses to start unless
PAYPAL_ENV=sandbox, so no real money can move.
What's next
- A server-issued confirmation step, so consent doesn't depend on the model alone
- Atomic enforcement of the daily limit under concurrent purchases
- Stock reservation before the charge to prevent overselling
- Multi-merchant carts and order tracking
Built With
- ag-grid
- channel3
- claude
- css3
- express.js
- gpt-oss
- groq
- html5
- javascript
- model-context-protocol
- node.js
- oauth-2.1
- paypal
- paypal-orders-api
- paypal-vault
- paypal-webhooks
- pkce
- postgresql
- render
- rest-api
- sql
- supabase
- typescript
- zod