iherb-mcp
# iherb-mcp
Read the [permissions model](docs/PERMISSIONS.md) and [design record](docs/DESIGN.md).
An [MCP](https://modelcontextprotocol.io) server for [iHerb](https://www.iherb.com). It lets an AI assistant (Claude,
ChatGPT, Cursor, ...) search iHerb for a shopping list in one call, read full supplement facts, ingredients,
suggested use, warnings, and rating distributions, browse categories and top sellers, and display visual product
cards. **You buy yourself, on iHerb:** this server never places, pays for, or modifies orders.
> Unofficial. Not affiliated with or endorsed by iHerb, LLC. iHerb has no official public API; this server reads the
> same public web pages iHerb serves to browsers, gently, paced at human speed, and only when you ask. iHerb's terms
> of use apply to you.
## Requirements
- [uv](https://docs.astral.sh/uv/) (fetches Python 3.12+ automatically), or Docker for HTTP serving.
- Optional: Google Chrome (or `patchright install chromium`) if you use `iherb-mcp login` to save a browser session
when Cloudflare challenges plain HTTP requests.
## Quick start
1. **Optional: save a browser session** (recommended if your network receives Cloudflare challenges):
```sh
uvx --from "iherb-mcp[login]" iherb-mcp login
```
A browser window opens on iHerb; complete any sign-in or verification yourself. Nothing is clicked or typed for you.
2. **Add the server to your MCP client** (runs over stdio by default):
- Claude Code:
```sh
claude mcp add iherb -- uvx iherb-mcp
```
- Claude Desktop / Cursor / generic MCP client:
```json
{
"mcpServers": {
"iherb": {
"command": "uvx",
"args": ["iherb-mcp"],
"env": {
"IHERB_COUNTRY": "US",
"IHERB_CURRENCY": "USD",
"IHERB_LANGUAGE": "en-US"
}
}
}
}
```
For Hong Kong pricing and availability, set `IHERB_COUNTRY=HK` and `IHERB_CURRENCY=HKD`.
3. **Streamable HTTP (Docker / multi-user server):**
```sh
MCP_BEARER_TOKEN="replace-with-32-char-random-token" iherb-mcp serve --host 127.0.0.1 --port 8000
```
## Tools
| Tool | Class | What it does |
|---|---|---|
| `iherb_search(queries[1..10], sort, category, max_price_cents, per_query)` | R0 read | Batched search returning lean candidates (`id`, `title`, `brand`, `price`, `original_price`, `price_per_unit`, `rating`, `review_count`, `in_stock`, `image`, canonical `url`). |
| `iherb_get_products(ids[1..10])` | R0 read | Full product details by numeric id: pricing, unit price, stock, product code, UPC, shipping weight, description, ingredients, suggested use, warnings, structured `supplement_facts`, `review_distribution`, `photos`, and `url`. |
| `iherb_show_products(items[{id, note}] 1..12, title)` | R0 read | Visual product cards via MCP Apps (`ui://iherb/products.html`) with a concise text fallback for non-Apps clients. |
| `iherb_category(category, sort, page, limit)` | R0 read | Browse an iHerb category slug (e.g. `vitamin-c`, `omega-3-fish-oil`). |
| `iherb_top_sellers(limit)` | R0 read | Current iHerb top-selling products (with price, unit price, rating, review count). |
| `iherb_reviews(id, limit 1..10, rating)` | R0 read | Public review star breakdown and recent comments (sent anonymously without session cookies; reviewer identities stripped). |
| `iherb_status(check)` | R0 read | Session state, region/currency, UTC daily budget, active pause, and last error. `check=true` runs one budgeted canary read. |
| `iherb_connect()` | R0 read | Instructions or Connections URL for browser sign-in. Starts nothing. |
Money is `{"cents": 2399, "currency": "USD", "display": "$23.99"}`.
Errors are tool results with `isError: true` and `{"error": {code, next_step, retryable, action}}`.
## Configuration
| Environment variable | Default | Description |
|---|---|---|
| `IHERB_COUNTRY` | `US` | 2-letter ISO country code (`US`, `HK`, `GB`, `DE`, `FR`, `JP`, `KR`, `AU`, `CA`, `SG`, `TW`, `CN`, `EU`). |
| `IHERB_CURRENCY` | `USD` | 3-letter ISO currency code (`USD`, `HKD`, `EUR`, `GBP`, ...). |
| `IHERB_LANGUAGE` | `en-US` | Locale tag (`en-US`, `zh-HK`, `de-DE`, ...). |
| `IHERB_STATE_DIR` | OS user state dir | State directory for budgets, pause state, and saved sessions (`/state` in Docker). |
| `IHERB_DAILY_BUDGET` | `1000` | Daily UTC request budget for the default account. |
| `IHERB_ACCOUNT_DAILY_BUDGET` | `400` | Per-person daily UTC request budget in people mode. |
| `IHERB_TOTAL_DAILY_BUDGET` | `2000` | Shared server-wide daily UTC request budget. |
| `IHERB_SESSION_KEY` | unset | 32-byte AES-256 key (base64 or 64 hex chars) to seal sessions at rest; required for people mode. |
| `IHERB_TRUSTED_PERSON_HEADER` | unset | HTTP header set by an authenticated gateway (e.g. `X-Fleet-Person`) to isolate state per person. |
| `IHERB_PUBLIC_URL` | unset | Base URL of a hosted Connections page returned by `iherb_connect`. |
| `MCP_BEARER_TOKEN` | unset | Required for `iherb-mcp serve` (16+ chars; comma-separated for rotation). |
## Safety & privacy
Enforced in code and pinned by `tests/test_safety.py`:
- **Read-only boundary:** No checkout, payment, order-placement, address, or profile-mutation endpoints exist in the
codebase.
- **Allowlisted network boundary:** Only `src/iherb_mcp/site.py` makes network requests to iHerb, restricted to
allowlisted `*.iherb.com` hosts and read-only catalog paths. Off-allowlist redirects are refused.
- **Polite by construction:** Serialized requests (~1 req/s), UTC daily budgets, and a persisted pause breaker
(5 minutes on first 429/403/Cloudflare challenge, 30 minutes on repeat within 2 hours). Serving code never solves
or bypasses anti-bot challenges.
- **Untrusted content:** Merchant and customer text is sanitized and treated as data, never instructions.
## Troubleshooting
- **`blocked`**: iHerb or Cloudflare returned a challenge or rate limit. Wait until `paused_until` in `iherb_status`
clears, or run `iherb-mcp login` to refresh a real browser session.
- **`budget_exhausted`**: Today's UTC request budget is spent; it resets at `00:00 UTC`.
- **`schema_changed`**: iHerb updated its page markup; open an issue with the affected tool name (never include
cookies or personal data).
TDQS
Scored across 8 tools
Each tool targets a distinct operation: search (multi-query discovery), get_products (full detail by id), show_products (visual rendering), category, top_sellers, reviews, status, and connect. The only mild overlap is iherb_search vs iherb_get_products vs iherb_show_products, which all touch product data, but the descriptions clearly separate lean candidates, full detail, and card display.
All names are snake_case with a uniform iherb_ prefix, giving a predictable pattern. The suffix style mixes verbs (search, get_products, show_products, connect) with bare nouns (category, top_sellers, reviews, status), a minor deviation from a strict verb_noun convention.
Eight tools is well-scoped for a read-only product research server, with each tool covering a clear slice of the workflow (discovery, detail, display, reviews, session state). Nothing appears redundant or padded.
The read-only research lifecycle is well covered: discovery via search/category/top sellers, enrichment via product details and reviews, plus session status and sign-in guidance. Gaps are minor (e.g., no brand-scoped browsing, pagination controls, or compare/favorites), and ordering is explicitly out of scope.