wp-woo-mcp
# wp-woo-mcp
An [MCP](https://modelcontextprotocol.io) server that lets AI assistants (Claude Code, Claude Desktop, Cursor and other MCP clients) work with a WooCommerce store: find products, check and change prices with guardrails, read orders and get sales summaries.
```
You: Which demo products cost more than 500 UAH? Raise the primer by 3%.
Claude: → search_products → update_product_price (dry run) → shows 375 → 386.25 (+3%)
You: OK, apply.
Claude: → update_product_price (dry_run: false) → done, re-read confirms 386.25
```
## Tools
| Tool | What it does | Writes |
|---|---|---|
| `search_products` | Search by text, SKU (one or several) or status; compact rows with prices and stock | — |
| `get_product` | One product by id or SKU: categories, stock, variations, description | — |
| `update_product_price` | Change regular / sale price of a simple product | ✅ guarded |
| `list_orders` | Orders with status and date filters | — |
| `get_order` | One order: items, total, payment | — |
| `sales_summary` | Orders count, revenue, average order, statuses, top products for a period | — |
## Safety by design
An AI agent with write access to a live store needs more than a prompt saying "be careful":
- **Writes are off by default.** `update_product_price` refuses until the server runs with `WOO_ALLOW_WRITES=true`.
- **Dry run by default.** The tool shows *before → after* and the change in %. It applies only with `dry_run: false`, which the agent is told to send only after the user agrees.
- **Change limit.** Changes above `WOO_MAX_PRICE_CHANGE_PCT` (default 30%) are refused unless `allow_large_change: true`, a separate explicit confirmation.
- **Validation.** Prices must look like `1250` or `389.50`; sale price must be lower than regular; variable products are refused because their prices live on variations.
- **Tool annotations.** Read-only tools are marked `readOnlyHint`, the price tool `destructiveHint`, so clients can ask for confirmation.
- **Personal data.** Orders show only the customer's first name and city unless `WOO_EXPOSE_CUSTOMER_CONTACTS=true`.
- **Least privilege.** Use an application password of a *Shop manager* user, not an administrator.
- **Readable errors.** API errors come back as tool errors with a hint (401 → how to fix the application password), so the agent can explain the problem instead of guessing.
## Setup
1. In WordPress: **Users → Profile → Application Passwords**, add a password named `wp-woo-mcp`.
Application passwords require HTTPS, except on sites with `WP_ENVIRONMENT_TYPE` set to `local`.
2. Build:
```bash
npm install
npm run build
```
3. Add the server to your MCP client.
**Claude Code:**
```bash
claude mcp add woo \
-e WP_URL=https://shop.example \
-e WP_USER=shop-manager \
-e WP_APP_PASSWORD="xxxx xxxx xxxx xxxx xxxx xxxx" \
-- node /path/to/wp-woo-mcp/dist/index.js
```
**Claude Desktop / Cursor** (`mcpServers` in the client config):
```json
{
"mcpServers": {
"woo": {
"command": "node",
"args": ["/path/to/wp-woo-mcp/dist/index.js"],
"env": {
"WP_URL": "https://shop.example",
"WP_USER": "shop-manager",
"WP_APP_PASSWORD": "xxxx xxxx xxxx xxxx xxxx xxxx",
"WOO_ALLOW_WRITES": "false"
}
}
}
}
```
### Environment variables
| Variable | Default | Meaning |
|---|---|---|
| `WP_URL` | required | Store URL |
| `WP_USER` | required | WordPress user login |
| `WP_APP_PASSWORD` | required | Application password (spaces are fine) |
| `WOO_ALLOW_WRITES` | `false` | Enables `update_product_price` |
| `WOO_MAX_PRICE_CHANGE_PCT` | `30` | Max price change without `allow_large_change` |
| `WOO_EXPOSE_CUSTOMER_CONTACTS` | `false` | Adds customer names and emails to orders |
## Development
```
src/
woo-client.ts WooCommerce REST client: Basic auth, retries on 429/5xx (Retry-After), timeouts, typed errors
logic.ts pure functions: price guard, compact product/order views, sales aggregation
server.ts MCP tools (zod input schemas, annotations, error handling)
index.ts stdio entry point, config from env
test/ node:test: logic, HTTP client with a fake fetch, MCP protocol via in-memory transport
scripts/smoke.ts end-to-end check against a real store over stdio
```
```bash
npm test # 23 tests, no network
npm run build
npm run smoke # against the store in .env; SMOKE_WRITE_SKU=<test SKU> also checks writes (changes the price and restores it)
```
Verified end to end against a local store (WooCommerce 11.3, WordPress 7.1, PHP 8.4): 11/11 smoke checks, including a real price update, re-read and restore.
## Limitations
- Price updates for simple products only (variations are refused, not silently skipped).
- `sales_summary` reads up to `max_orders` orders (default 500) through the REST API; for large stores, WooCommerce Analytics would be faster.
- stdio transport only (local use by one person). A shared remote server would need HTTP transport and per-user auth.
## License
MIT
TDQS
Scored across 6 tools
Each tool targets a distinct resource+action pair: product search vs. single product fetch vs. price mutation, and order listing vs. single order fetch vs. aggregate reporting. The one plausible overlap (list_orders vs. sales_summary) is resolved by the descriptions making one an enumerator and the other an aggregator.
Five of six tools follow a clean verb_noun pattern (search_products, get_product, update_product_price, list_orders, get_order) in consistent snake_case. The lone outlier is sales_summary, a noun-only name that breaks the verb convention.
Six tools is a tight, well-scoped surface for a store-admin server, with no redundant endpoints. Every tool covers a distinct read or write need an agent would actually reach for.
Read coverage is solid (search/get for products, list/get for orders, plus aggregation), but the write surface is thin: only price can be modified. There is no stock update, no product field update, and no order status update or refund, which are core WooCommerce operations agents will likely need.