mercadona-mcp
<p align="center"><img src="assets/logo.svg" width="96" alt=""></p>
# mercadona-mcp
> **Unofficial.** Not made, endorsed or supported by Mercadona. It uses the web shop's undocumented API, which can change or stop working at any time. Use it with your own account, at your own pace.
An MCP server that lets Claude (or any MCP-capable agent) use **tienda.mercadona.es**: search the catalog, read your orders and purchase history, and fill your cart. **It never checks out or pays.** You place the order yourself on the website.
## How it works (and why not "browser automation")
People often build these marketplace servers by driving a headless browser: click, read the DOM, click again. That approach is slow, breaks whenever the UI changes, and burns tokens. It's mostly unnecessary, because nearly every modern shop is a single-page app talking to its own JSON API. This server takes that route:
| Layer | What it does |
|---|---|
| **Site's internal JSON API** (`tienda.mercadona.es/api/...`) | All data and cart operations. Endpoints were found by reading the site's public JS bundle. Fast, structured, and stable for longer than the HTML. |
| **Real browser, for login only** | Mercadona's login needs reCAPTCHA, so `login` opens a normal Chrome window and **you** sign in. The server then copies the session token from the page's `localStorage["MO-user"]`. Your password never passes through this code. Tokens refresh automatically. |
| **Local catalog index** | The site's search backend blocks non-browser clients, so the server crawls the ~150 public category pages (≈4,400 products) and searches them locally with accent-insensitive matching. The first search takes about 20 s; results are cached for 12 h in `~/.mercadona-mcp/`. |
This is unofficial and uses undocumented endpoints, so Mercadona can change them at any time. Request volume is small and paced (≥120 ms between calls).
## Tools
**Setup:** `mercadona_status`, `mercadona_login`, `mercadona_import_session`, `mercadona_logout`, `set_postal_code`
**Catalog (no login):** `search_products`, `list_categories`, `browse_category`, `get_product` (ingredients, allergens, origin, similar products), `refresh_catalog`
**Cart:** `get_cart`, `update_cart` (add or set quantities, many items in one call), `remove_from_cart`, `clear_cart` (needs `confirm: true`), `add_order_to_cart` (re-order), `add_shopping_list_to_cart`, `add_regulars_to_cart`
**History:** `list_orders`, `get_order` (every line: ordered vs. prepared quantity, price paid), `purchase_history` (what you buy, how often, typical quantities), `my_regulars` (Mercadona's "Mis habituales"), `list_store_tickets` (in-store digital receipts, if enabled)
**Lists and delivery:** `list_shopping_lists`, `get_shopping_list`, `create_shopping_list`, `update_shopping_list`, `delete_shopping_list` (needs `confirm: true`), `list_addresses`, `delivery_slots`
**Prompt:** `weekly_basket` rebuilds your usual shop from history, asks for your OK, then fills the cart.
**Product cards:** chat apps don't show outside images in the agent's replies, so the server attaches a small display-only view to product, cart and order results ([MCP Apps](https://modelcontextprotocol.io/extensions/apps), rendered inline by Claude and ChatGPT). It shows:
- **Search results, categories, regulars and history:** photo cards with price, size and price per kilo.
- **The cart and orders:** a two-column list grouped by shop section, with a highlight on what the last request changed and the total.
- **A product page:** photos, price, allergens and similar products.
The view has no buttons that change anything: you still ask the agent, and the agent still does the talking. Its text results carry the same data without image links, which keeps them short. In clients without MCP Apps you get the text only. `test/cards-harness.mjs` previews the cards locally.
Apps download the view once and may keep that copy for a long time. In remote mode the view therefore loads its current styles and code from the server (`/cards/live.js`) every time it's shown, so design changes reach every app right away; if that fails, it uses the copy built into the view. Locally (stdio) the built-in copy is always used.
## Tested
All 29 tools were run against a live account (December 2026): reading orders, history, regulars, lists, addresses and slots; adding, setting, removing and clearing cart items; re-ordering a 38-item order; creating, editing and deleting a list. `test/smoke.mjs` and `test/lists.mjs` are the scripts used. `lists.mjs` changes your real cart and lists, then cleans up.
## Setup
```bash
npm install
node src/cli.js postal-code 28001 # your delivery postal code (sets the warehouse and prices)
node src/cli.js login # opens Chrome; sign in, and the window closes by itself
node src/cli.js status
```
Register with Claude Code:
```bash
claude mcp add --scope user mercadona -- node /ABSOLUTE/PATH/mercadona-mcp/src/cli.js
```
Claude Desktop or other clients (`claude_desktop_config.json` and similar):
```json
{ "mcpServers": { "mercadona": { "command": "node", "args": ["/ABSOLUTE/PATH/mercadona-mcp/src/cli.js"] } } }
```
You can also log in from chat: ask the agent to call `mercadona_login`.
**Fallback login:** if the automated Chrome window gives you trouble (Google sign-in sometimes refuses automated browsers), log in to tienda.mercadona.es in your normal browser. Then run `localStorage.getItem('MO-user')` in the DevTools console and pass the result to `node src/cli.js import-session '<json>'` (or the `mercadona_import_session` tool).
## Remote mode (Claude on iPad/web, ChatGPT)
The Claude apps and ChatGPT can't start a program on your computer. They connect to MCP servers by URL instead, so `http` mode serves the same tools over Streamable HTTP at `/mcp`, with a built-in single-owner OAuth server in front:
- **Discovery and registration are automatic.** The apps find the OAuth endpoints and register themselves (dynamic client registration). Only redirect URIs on `claude.ai`, `claude.com`, `chatgpt.com`, `chat.openai.com` and localhost are accepted; override with `MCP_ALLOWED_REDIRECT_HOSTS`.
- **The owner approves each app once** by typing the passphrase on the sign-in page. Five wrong tries lock the page for 15 minutes.
- **Tokens:** access tokens last 24 h, refresh tokens 90 days and rotate on use. Both are stored only as SHA-256 hashes in `oauth.json`.
- **Not available remotely:** `mercadona_login` (it needs a desktop). Log in on the server with `import-session`.
```bash
node src/cli.js set-passphrase # generates one and prints it; or pass your own (12+ chars)
MCP_PUBLIC_URL=https://mcp.example.com PORT=8787 node src/cli.js http # listens on 127.0.0.1 only
node src/cli.js revoke-tokens # sign every connected app out
```
`deploy/remote.sh` sets this up on a Debian server that already runs Caddy: a sandboxed systemd service, a dedicated system user, and the Caddy site. It reads `MCP_HOST` and `SSH_HOST` from `deploy/remote.env` (gitignored); run it without `--apply` first to see what it would change.
Put a TLS reverse proxy in front (Caddy: `mcp.example.com { reverse_proxy 127.0.0.1:8787 }`). Then add `https://mcp.example.com/mcp` as a custom connector in Claude (Settings → Connectors) or ChatGPT (custom MCP server). `test/http-flow.mjs` checks the whole OAuth and MCP flow against a running instance.
## Using it yourself (or sharing with a friend)
Each running server belongs to **one Mercadona account**: it holds that account's session, and everyone who connects to it shares the same cart and orders. So don't hand out access to yours. Instead, each person runs their own copy:
| Setup | Works with | Effort | Notes |
|---|---|---|---|
| **On your computer** (`npm install`, `login`, add to the app) | Claude Desktop, Claude Code, other local MCP clients | Low | No server, no domain. Only while that computer is on. |
| **Your computer + a tunnel** (e.g. Cloudflare Tunnel or ngrok) to `http` mode | ChatGPT, Claude on the web or phone | Medium | Set a passphrase and `MCP_PUBLIC_URL` to the tunnel's https URL. Only while that computer is awake. |
| **Your own small server** (`http` mode behind Caddy, see `deploy/remote.sh`) | Everything, from any device | Higher | Needs a Linux box and a domain. Always on. Log in on your computer, then copy the session over (`--with-session`). |
ChatGPT only connects to servers at a public https URL, so it needs one of the last two.
## Files
`~/.mercadona-mcp/` holds:
- `config.json`: postal code and warehouse.
- `session.json`: the Mercadona token (mode 600).
- `catalog-*.json`: the search index.
- `chrome-profile/`: the login browser profile.
- `owner.json` and `oauth.json`: remote mode only (passphrase hash, app registrations, token hashes).
Override the location with `MERCADONA_MCP_HOME`.
## Ideas for more
- Price tracking: diff the catalog index daily and alert when a usual product drops in price.
- Meal planning: recipe → ingredients → `search_products` → `update_cart`.
- Nutrition and allergen filters over `get_product`.
- "Running low" predictions from `purchase_history` intervals.
- The same pattern (read the SPA bundle, call its JSON API, log in through a real browser) works for most shops, e.g. Carrefour, DIA, Alcampo or Amazon. Only the endpoint map changes.
## License
MIT, see [LICENSE](LICENSE). Mercadona is a trademark of Mercadona S.A.; this project is not affiliated with it.
TDQS
Scored across 29 tools
Most tools target clearly distinct resources (catalog browsing vs. cart vs. orders vs. shopping lists), and the three 'add X to cart' variants are differentiated by their source (past order, 'my regulars', saved list). Minor overlap exists between update_cart with mode 'set'/0, remove_from_cart, and clear_cart, which could cause misselection for removal tasks.
The dominant convention is snake_case verb_noun (list_categories, get_product, update_cart), which is readable, but four auth tools carry a mercadona_ prefix while the rest do not, and several tools are bare nouns (delivery_slots, purchase_history, my_regulars, list_store_tickets). The mix is workable but not predictable.
29 tools is heavy, but the surface spans genuinely separate sub-domains (auth, catalog, cart, orders, physical tickets, regulars, shopping lists, addresses/delivery), so most tools earn their place. Still, marginal value tools like refresh_catalog and the four separate auth tools push it past a comfortable size.
Coverage is broad across browsing, cart building, history and list management, but the lifecycle dead-ends at checkout: update_cart explicitly 'does NOT check out' and there is no place_order or delivery-slot booking tool, so an agent can assemble a basket but never complete a purchase. Address management is read-only and there is no order tracking beyond past orders.