walmart-ca-mcp
# walmart-ca-mcp
An [MCP](https://modelcontextprotocol.io) server for **Walmart.ca** (Canada). It lets an AI assistant search
products and read product details through a real Chrome browser with a persistent profile.
> Unofficial. Not affiliated with or endorsed by Walmart. It drives the public website the way a browser does;
> use it for personal, low-volume use and respect Walmart.ca's terms.
## Tools
| Tool | What it does |
|---|---|
| `search_products` | Search Walmart.ca. Returns id, name, brand, price and was-price (CAD), stock, rating, seller (Walmart or marketplace), badges, delivery estimate, URL and image. Sponsored listings are excluded unless `includeSponsored` is true. Supports `page` and `limit`. |
| `get_product_details` | One product by id or walmart.ca URL: price, stock, seller, category, highlights, description, specifications, variants and images. |
| `get_my_items` | The account's **My Items** (previously bought products, up to 300): current price, unit price, stock and how often bought ("Bought 5+ times"). Filter by `category` (case-insensitive; the list comes back in `categories`), name `search`, `inStockOnly`; page with `limit`/`offset`. Reorder by passing an id to `add_to_cart`. |
| `get_orders` | Purchase history, newest first: order id, date, total, item count, and per delivery/pickup group the status and item names with quantities. Filters: `last-3-months`, `last-6-months`, `year-0` (this year), `year-1`, ..., `returned`, `in-store` (valid ids come back in `filters`); item-name `search`; `limit` up to 100 (pages through the site's 5-per-page history). |
| `get_order_details` | One order: each item with product id, quantity, price and what happened to it (Received, Received with weight-adjusted price, Substitute received, Refunded, Unavailable and not charged), a per-shipment summary ("7 items received", "1 unavailable item"), plus subtotal, savings, fees, tax, tip and total. Payment and address details are left out. |
| `track_order` | Live status of an order: status message, step tracker (Placed / Preparing / On the way / Delivered), window, delay flags, the live header Walmart shows while a driver is on the way, carrier tracking for shipped items, and whether the slot can still be changed or the order cancelled. Without `orderId` it tracks every order not yet delivered among the 10 most recent. |
| `get_cart` | Items in the signed-in cart: id, name, quantity, price, line total, seller, plus item count, subtotal and fees, and the current pickup/delivery mode, store and reserved time slot. Saved-for-later items are not included. |
| `add_to_cart` | Add a product (by id or URL) to the cart, `quantity` 1-12, added to any quantity already there. Returns the cart line and new subtotal. |
| `set_cart_quantity` | Set an item already in the cart to an exact quantity (0-12; 0 removes it), using the cart's own - / + buttons. |
| `remove_from_cart` | Remove a product (all units) from the cart. Saved-for-later items are never touched. |
| `get_flyer` | Current flyer items for the profile's store (main weekly flyer by default; Private Brands, Holiday Gifting, ... via `flyer`): name, brand, flyer price ("$2.44", "$3.97/lb", "From $9.97"), regular price, deal (e.g. Rollback), category, details, valid-to date. `id` is the Walmart product id, so items go straight into `add_to_cart`. Filter by `search` words or `category`. Cached for an hour. |
| `get_my_deals` | Which of **My Items** are in any current flyer. `onSale`: exact matches by product id (flyer price, regular price, deal, how often bought), most-bought first. `possibleMatches`: flyer items that look like one of your items (same brand and product word, e.g. "Sealtest 5% or 10% cream"), to check. |
| `get_delivery_slots` | Pickup or delivery time slots: window, price (Walmart+ prices as $0 with the regular price), kind (scheduled, or express / "now" options when offered, usually same day) and `slotId`; plus the current mode and reservation. Filter with `date` (YYYY-MM-DD, `today`, `tomorrow`), `earliest` / `latest` ("10am", "14:00"); without a date, `days` (default 3) from the first bookable day. Viewing the other mode does not change the cart. |
| `reserve_slot` | Reserve a slot by `slotId` (pass `mode` if it was listed under the other method; that also switches the cart). Walmart holds it until `heldUntil`. |
| `set_fulfillment_mode` | Switch the cart between `pickup` and `delivery`. |
| `session_status` | Whether the site is reachable, whether the bot check is blocking, whether the profile is signed in, and which store prices are shown for. Returns no account details. |
`get_my_items`, the order tools and the cart tools need a signed-in profile (see [Signing in](#signing-in-optional)). There is **no checkout or order tool**:
the server can fill a cart, but placing the order stays with you. Other tools are read-only. Prices depend on the store / postal code selected in the profile (`store` in each result).
## Why a real browser, and why rebrowser
Walmart.ca is protected by HUMAN (PerimeterX) bot detection, which answers suspicious traffic with a
"Press & Hold" page. In testing:
- **Stock puppeteer** loaded the home page, then got "Press & Hold" on the first search, with a new or a used profile.
- **[rebrowser-puppeteer-core](https://github.com/rebrowser/rebrowser-patches)**, with the same browser and network,
completed 40 back-to-back searches without a challenge. It removes the Chrome DevTools Protocol `Runtime.enable`
leak that bot checks use to spot automation.
The server also:
- runs Chrome **headed** (on a virtual display in Docker), since headless Chrome is easier to flag;
- keeps **one browser on a persistent profile**, so cookies, including the bot check's own, carry over between calls;
- uses a **pinned Chrome build** and no fake user agent, so the browser identity stays consistent;
- **closes Chrome after 10 idle minutes** (~500 MB freed) and relaunches it on the next call.
If a challenge does appear, tools return a clear error instead of empty results. Open the profile in a visible
browser (see [Signing in](#signing-in-optional)), complete the check once and retry.
## Run with Docker (recommended)
```sh
docker build -t walmart-ca-mcp .
docker volume create walmart-profile
```
**stdio** (for MCP clients that start the server themselves):
```json
{
"mcpServers": {
"walmart-ca": {
"command": "docker",
"args": ["run", "-i", "--rm", "--shm-size=512m", "-v", "walmart-profile:/profile", "walmart-ca-mcp"]
}
}
}
```
**HTTP** (streamable HTTP at `/mcp`, SSE at `/sse`, via [mcp-proxy](https://github.com/sparfenyuk/mcp-proxy)):
```sh
docker run -d --name walmart-ca-mcp --init --shm-size=512m -p 127.0.0.1:3000:3000 \
-v walmart-profile:/profile walmart-ca-mcp http
```
There is no authentication on the HTTP endpoint. Keep it on localhost or put it behind your own auth.
Quick check without an MCP client: `docker run --rm --shm-size=512m -v walmart-profile:/profile walmart-ca-mcp smoke "coffee"`
## Run with Node
Needs Node 20+ and Chrome or Chromium.
```sh
npm install
npm run build
CHROME_PATH="/path/to/chrome" node build/index.js # stdio MCP server
npm run smoke -- "coffee" # quick live check
```
On a machine without a display, run it under `xvfb-run`, or set `HEADLESS=true` (more likely to be challenged).
## Signing in (optional)
Search and product details work without an account. The cart tools need one, and signing in can also lower the
chance of challenges.
Stop the server first (Chrome locks the profile), then:
```sh
docker run --rm --shm-size=512m -p 127.0.0.1:6080:6080 -v walmart-profile:/profile walmart-ca-mcp login
```
Open `http://localhost:6080/vnc.html`, sign in, and complete any "Press & Hold" yourself. The container exits when
the account menu shows you are signed in, and the session stays in the profile. Without Docker: `npm run login`.
## Configuration
| Variable | Default | Purpose |
|---|---|---|
| `WALMART_PROFILE_DIR` | `./profile` (`/profile` in Docker) | Chrome profile. Holds the session: keep it private. |
| `CHROME_PATH` | auto-detect (`/usr/local/bin/chrome` in Docker) | Chrome binary. Use one build for the profile. |
| `HEADLESS` | `false` | Headless Chrome. Not recommended. |
| `BROWSER_IDLE_CLOSE_MS` | `600000` | Close Chrome after this long without calls. `0` keeps it open. |
| `WALMART_LANG` | `en` | `en` or `fr`. |
| `WALMART_NAV_TIMEOUT_MS` | `45000` | Page load timeout. |
| `WALMART_DEBUG_DIR` | unset | Save a screenshot and HTML of failed pages here (they can include account details), and the raw slot data of each `get_delivery_slots` call (customer details removed, newest 20 kept). |
| `LOGIN_TIMEOUT_MS` | `1800000` | How long `login` waits for you to sign in. |
## How it works
Purchase history: the orders page makes its own history request; further pages and filters repeat that request from
inside the page with a new cursor or filter, the same way the site's "Next page" does.
The flyer is Walmart's embedded Flipp flyer: the flyer page lists the store's current flyers, and items come from
the same flyer service with the public token the page uses (cached for an hour, so repeat searches skip the browser).
Time slots come from the cart's "Reserve a time" panel; reserving clicks the slot and the panel's Reserve button.
The cart must have items for pickup/delivery options to show.
Cart changes click the site's own buttons ("Add to cart", "Increase quantity", "Remove") and wait for the
cart update Walmart.ca sends in response, then re-read the cart to confirm. The cart itself is read from the data
the cart page loads, so results are the same as what you see on walmart.ca.
Product data comes from the JSON that Walmart.ca embeds in each page (`__NEXT_DATA__`), not from scraping the
layout, so small visual changes do not break it. Each tool call opens a tab in the shared browser, reads the page
and closes the tab.
```
src/
index.ts MCP server and tool definitions
walmart.ts search, product details and session status
browser.ts shared persistent Chrome, idle close, bot-check detection
config.ts environment settings
login.ts visible sign-in helper
smoke.ts command-line live check
```
## Limitations
- A browser per server: about 500 MB of RAM while active, and a few seconds on the first call after an idle close.
- Walmart.ca can change its pages or bot checks at any time. A layout change shows up as a "page layout may have
changed" error.
- Keep the request rate low. Bursts are what bot checks look for.
## License
MIT
TDQS
Scored across 16 tools
Each tool targets a distinct resource+action pair, and the descriptions actively draw the boundaries (get_orders = ordered items, get_order_details = what was actually received, track_order = live shipment status; get_flyer = browse current flyers, get_my_deals = cross-reference against purchase history). Cart tools are cleanly split into read/add/set-quantity/remove with explicit cross-references. No two tools appear to do the same thing.
Nearly everything follows a snake_case verb_noun pattern (search_products, get_cart, add_to_cart, set_cart_quantity, remove_from_cart, reserve_slot, track_order). The only deviation is session_status, which drops the verb, and get_my_items / get_my_deals use possessive phrasing, but the overall convention is highly predictable.
16 tools is at the upper end of the comfortable band, but each one maps to a real step in the shopping lifecycle (discover, inspect, cart, fulfillment, order history). Nothing looks redundant or padded, though it sits just past the typically-scoped 3-15 range.
Search, product, cart CRUD, flyer/deals, delivery slots and order history/tracking are all well covered, so the browse-to-cart-to-slot flow is complete. However, there is no checkout/place-order tool (the descriptions explicitly stop at the cart), no order cancellation despite track_order reporting eligibility, and no way to change the store used for pricing — real dead ends for the assistant's stated workflow.