Odoo MCP
README.md
# Odoo MCP
A token-efficient MCP server for **Odoo 19+** (with **17/18** fallback). It gives any MCP client
access to inventory, manufacturing, sales, purchasing, POS, quality, dashboards, finance, custom
modules, and developer gap analysis — plus generic tools that work on **any** Odoo model.
---
## Setup — start here
You need **Bun**, an **Odoo URL**, a **database name**, and an **API key**. That is the whole
required configuration.
### 1. Install Bun
```bash
# Windows PowerShell
powershell -c "irm bun.sh/install.ps1 | iex"
# macOS / Linux
curl -fsSL https://bun.sh/install | bash
```
Verify:
```bash
bun --version
```
### 2. Collect your Odoo values
| Value | Where to get it | Example |
| --- | --- | --- |
| `ODOO_URL` | The address you use in the browser, without a trailing slash | `https://mycompany.odoo.com` |
| `ODOO_DB` | Database name (on Odoo.sh this is usually the subdomain) | `mycompany` |
| `ODOO_API_KEY` | Odoo 19+: **Preferences → Account Security → New API Key** | `a1b2c3…` |
For **Odoo 17/18**, also set `ODOO_LOGIN` to the user login; the API key is used as the password.
### 3. Install this server
```bash
git clone <this-repo-url> odoo-mcp
cd odoo-mcp
bun install
```
### 4. Configure it
The easiest path is the interactive setup:
```bash
bun run init
```
It asks for the URL, database, API key, and optionally your addons repo, then writes `.env`.
Non-interactive version (one line is safest in PowerShell):
```powershell
bun run init --non-interactive --url https://mycompany.odoo.com --db my_database --api-key "paste-the-key-here" --repo C:\dev\Woocommerce
```
If `.env` already exists, add `--force` to overwrite it.
Resulting `.env`:
```dotenv
ODOO_URL=https://mycompany.odoo.com
ODOO_DB=my_database
ODOO_API_KEY=paste-the-key-here
ODOO_REPO=C:\dev\Woocommerce
```
> `ODOO_REPO` is optional. Set it to your custom/third-party addons folder to enable
> `odoo_dev` (repo vs database gap analysis), `odoo_repo` (source search/read), and
> `odoo_custom` (custom module discovery).
### 5. Check the connection
```bash
bun run doctor
```
Expected result:
```text
Odoo MCP doctor — https://mycompany.odoo.com / my_database
✓ connection Odoo 19.0 via json2
✓ url https://mycompany.odoo.com
✓ database my_database
✓ user you@example.com
✓ Inventory quants stock.quant · 44 fields
✓ Stock moves stock.move · 126 fields
✓ Lots/serials stock.lot · 59 fields
✓ Sales sale.order · 166 fields
✓ Purchases purchase.order · 111 fields
✓ Manufacturing mrp.production · 139 fields
✓ Point of sale pos.order · 104 fields
✓ Products product.product · 251 fields
✓ source repo 36 modules · 1151 files · 174 models
✓ toolsets core, inventory, … (20 tools)
```
If connection fails, the doctor prints the exact error. Fix that before continuing.
### 6. Build once
```bash
bun run build
```
This creates `dist/cli.js`. You can also run the server directly with Bun without building:
`bun src/cli.ts serve`.
### 7. Add it to your MCP client
Use the built server and pass the three values in the client's `env` block. That way the client
does not depend on which folder it was launched from. Replace `C:\dev\odoo-mcp` with the folder
where you cloned this repository. If your client cannot find `bun`, run `where.exe bun` and use
that full executable path as `command`.
#### OpenCode
CLI:
```bash
opencode mcp add odoo --env ODOO_URL=https://mycompany.odoo.com --env ODOO_DB=my_database --env ODOO_API_KEY=paste-the-key-here --env ODOO_REPO=C:\dev\Woocommerce -- bun C:\dev\odoo-mcp\dist\cli.js serve
```
Or in `opencode.jsonc`:
```jsonc
{
"$schema": "https://opencode.ai/config.json",
"mcp": {
"servers": {
"odoo": {
"type": "local",
"command": ["bun", "C:\\dev\\odoo-mcp\\dist\\cli.js", "serve"],
"cwd": "C:\\dev\\odoo-mcp",
"environment": {
"ODOO_URL": "https://mycompany.odoo.com",
"ODOO_DB": "my_database",
"ODOO_API_KEY": "{env:ODOO_API_KEY}",
"ODOO_REPO": "C:\\dev\\Woocommerce"
}
}
}
}
}
```
OpenCode prefixes MCP tools with the server name. If you name the server `odoo`, `odoo_health`
appears as `odoo_odoo_health`; name the server `erp` if you prefer `erp_odoo_health`.
#### Claude Desktop
Edit `%APPDATA%\Claude\claude_desktop_config.json` on Windows (or
`~/Library/Application Support/Claude/claude_desktop_config.json` on macOS):
```json
{
"mcpServers": {
"odoo": {
"command": "bun",
"args": ["C:\\dev\\odoo-mcp\\dist\\cli.js", "serve"],
"env": {
"ODOO_URL": "https://mycompany.odoo.com",
"ODOO_DB": "my_database",
"ODOO_API_KEY": "paste-the-key-here",
"ODOO_REPO": "C:\\dev\\Woocommerce"
}
}
}
}
```
#### Cursor
Edit `~/.cursor/mcp.json` (or `.cursor/mcp.json` in a project) using the same
`mcpServers` shape as Claude Desktop.
#### Any other MCP client
Use this generic stdio configuration:
```json
{
"command": "bun",
"args": ["C:\\dev\\odoo-mcp\\dist\\cli.js", "serve"],
"env": {
"ODOO_URL": "https://mycompany.odoo.com",
"ODOO_DB": "my_database",
"ODOO_API_KEY": "paste-the-key-here",
"ODOO_REPO": "C:\\dev\\Woocommerce"
}
}
```
### 8. Verify inside the client
Ask your client:
```text
Use odoo_health to check the Odoo connection.
```
Then try:
```text
Use odoo_suggest with question="what is below its reorder point?"
```
That returns ready-to-run tool calls. If `odoo_health` works, setup is complete.
---
## Everyday use
You do not need to memorize models or fields. Start with `odoo_suggest`:
```json
{ "question": "which manufacturing orders are late?" }
{ "question": "which sales lines are delivered but not invoiced?" }
{ "question": "what is in our custom loyalty module?" }
```
It returns 1–3 matched playbooks with copy-ready arguments, plus matching custom models and
modules from your repo. Omit `question` to browse the playbook catalog by area.
MCP prompts are also included, so clients that support prompts get ready-made investigations:
`business_health_check`, `sales_mismatch_review`, `inventory_exception_review`,
`manufacturing_delay_review`, `pos_reconciliation`, `custom_module_review`,
`repo_database_gap_review`, `lot_recall`, `slow_moving_stock_review`, `anything_explore`.
Examples that work out of the box:
- “Which sales lines are delivered but not invoiced in the last 30 days?”
- “Which purchase receipts are short, by vendor?”
- “Trace lot ABC123 and tell me which customers received it.”
- “Which MOs are overdue, and are they short on components?”
- “What is running on the shop floor right now?”
- “How much did each POS config sell today, and is any order unpaid?”
- “Which customer invoices are overdue, and who owes the most?”
- “What is in the CRM pipeline, and where are deals stuck?”
- “Which project tasks or maintenance requests are overdue?”
- “Which quality checks failed?”
- “Which custom modules are not installed, and which models are missing?”
- “Why is this custom field missing after deployment?”
- “Where is this model/field overridden in our addons repo?”
- “Show me stock, sales, purchasing, production, POS, and finance in one board.”
---
## What is included
### Tool groups
Every group is optional. Removing groups reduces tool-definition tokens sent to the model.
| Toolset | Tools | What it answers |
| --- | --- | --- |
| `core` | `odoo_health`, `odoo_models`, `odoo_describe_model`, `odoo_search`, `odoo_read`, `odoo_aggregate`, `odoo_call`, `odoo_suggest` | Orientation, schema discovery, any-model querying, recommendations |
| `inventory` | `odoo_inventory`, `odoo_lot_trace`, `odoo_reorder` | On-hand, reservations, lots/serials, reorder points |
| `manufacturing` | `odoo_manufacturing` | MOs, components, work orders, BOMs, consumption mismatches |
| `sales` | `odoo_sales` | Orders, lines, delivery/invoice mismatches |
| `purchases` | `odoo_purchases` | Orders, lines, receipt/invoice mismatches |
| `pos` | `odoo_pos` | POS orders, lines, sessions, payments, unpaid orders |
| `quality` | `odoo_data_quality` | Negative stock, missing lots, stale pickings, duplicates, expiry |
| `dashboards` | `odoo_dashboard` | Preset or custom KPI boards across every area |
| `dev` | `odoo_dev` | Repo ↔ database gap analysis, type drift, missing columns, Studio fields |
| `repo` | `odoo_repo` | Module list/detail, source search/read, overrides, views, dependents |
| `custom` | `odoo_custom` | Custom/third-party modules, custom models, overview, grouped queries |
`odoo_search`, `odoo_read`, `odoo_aggregate`, and `odoo_call` work on **any** model — including
models from modules you install next month. The specialized tools are conveniences, not limits.
### Inventory and lots
```json
{ "product": "SKU-123", "warehouse": "MSA", "summary": true }
```
`odoo_inventory` resolves SKU/barcode/name, filters to internal/transit locations by default,
and returns quantity, reserved, available, lot, location, and in-date. `odoo_lot_trace` adds
current quants plus recent moves with source/destination/reference/state.
### Sales and purchase mismatch
```json
{ "mode": "mismatch", "problem": "both", "date_from": "2026-01-01", "date_to": "2026-01-31" }
```
`odoo_sales` and `odoo_purchases` compute `qty_undelivered`, `qty_uninvoiced`, `qty_unreceived`
per line. They scan a bounded window, state how many rows were scanned, and tell you when to
narrow the filter.
### Manufacturing
`odoo_manufacturing` supports `orders`, `components`, `workorders`, `boms`, `bom_lines`,
`overview`, and `mismatch`. It works with standard Odoo fields and surfaces custom
manufacturing fields automatically when they exist.
### Point of sale
`odoo_pos` supports `orders`, `lines`, `sessions`, `payments`, `summary`, and `mismatch`.
Custom fields such as loyalty or alert fields are included when present.
### Dashboards
```json
{ "preset": "business", "days": 30 }
```
Presets: `business`, `inventory`, `sales`, `purchases`, `manufacturing`, `pos`, `quality`,
`finance`, `custom`. Or pass custom cards:
```json
{
"cards": [
{ "title": "Open MOs", "model": "mrp.production", "domain": { "state": { "in": ["confirmed", "progress"] } }, "aggregate": "count" },
{ "title": "Revenue", "model": "sale.order", "measure": "amount_total", "aggregate": "sum", "groupby": "partner_id" }
]
}
```
### Custom modules
```json
{ "action": "modules" }
{ "action": "models", "module": "jani_stock" }
{ "action": "overview", "model": "jani.stock.forecast.demand" }
{ "action": "query", "model": "qrbase.loyalty.member", "groupby": "state" }
```
`odoo_custom` compares repo manifests with `ir.module.module`, checks custom models against
`ir.model`, and summarizes record counts, state distribution, and sample rows.
### Developer gap analysis
```json
{ "action": "gap", "model": "stock.lot" }
```
`odoo_dev` reports:
- fields declared in Python but missing from the database (module not installed/upgraded);
- fields that `fields_get` reports but whose database column is gone (a failed upgrade or removed module);
- field type drift between code and DB;
- DB-only fields (manual/Studio fields and custom module prefixes);
- local classes, file:line locations, and XML views for the model.
`verify_columns=false` skips the stored-field read test when you want a pure metadata comparison.
When the database has a stale column, queries automatically fall back to raw many2one ids instead
of failing, and the result includes a note pointing back to gap analysis.
`odoo_repo` then lets you search and read the source:
```json
{ "action": "search", "query": "returned_qty", "include": "**/models/*.py" }
{ "action": "read", "path": "custom/jani_stock/models/stock_move_line.py", "start_line": 1, "end_line": 120 }
```
---
## Configuration reference
Precedence, highest first:
1. environment variables;
2. `.env` in the current working directory;
3. `odoo-mcp.config.json` (explicit path via `ODOO_MCP_CONFIG` / `--config`, else cwd, else `~/.odoo-mcp/config.json`);
4. built-in defaults.
### All environment variables
| Variable | Default | Purpose |
| --- | --- | --- |
| `ODOO_URL` | — | Odoo base URL (required) |
| `ODOO_DB` | — | Database name (required) |
| `ODOO_API_KEY` | — | API key (required for Odoo 19+) |
| `ODOO_LOGIN` | — | Odoo 17/18 login (legacy fallback) |
| `ODOO_PASSWORD` | — | Odoo 17/18 password if not using an API key |
| `ODOO_REPO` | — | Addons path(s), separated by `;` on Windows or `:` elsewhere |
| `ODOO_COMPANY` | — | Company name or id (`allowed_company_ids`) |
| `ODOO_MCP_TOOLSETS` | all | Comma-separated tool groups |
| `ODOO_MCP_FORMAT` | `md` | `md`, `json`, or `csv` |
| `ODOO_MCP_DEFAULT_ROWS` | `20` | Default rows per query |
| `ODOO_MCP_MAX_ROWS` | `200` | Hard row cap |
| `ODOO_MCP_MAX_BYTES` | `120000` | Hard result-size cap |
| `ODOO_MCP_MAX_CELL_CHARS` | `180` | Cell truncation |
| `ODOO_MCP_MAX_COLUMNS` | `12` | Columns before summarising |
| `ODOO_MCP_TIMEOUT_MS` | `30000` | Odoo HTTP timeout |
| `ODOO_MCP_CONCURRENCY` | `4` | Max concurrent Odoo requests |
| `ODOO_MCP_SCHEMA_TTL_MS` | `600000` | Schema cache lifetime |
| `ODOO_MCP_ALLOW_WRITE` | `false` | Enable write methods via `odoo_call` |
| `ODOO_MCP_ALLOW_RAW_METHODS` | `false` | Allow non-allowlisted methods |
| `ODOO_MCP_ALLOW_SENSITIVE` | `false` | Allow binary/secret-like fields |
| `ODOO_MCP_AUDIT_LOG` | — | JSONL audit log path |
| `ODOO_MCP_LOG_LEVEL` | `info` | `debug`, `info`, `warn`, `error` |
| `ODOO_MCP_PROFILE` | `default` | Profile name in the JSON config |
| `ODOO_MCP_CONFIG` | — | Path to `odoo-mcp.config.json` |
See [`.env.example`](.env.example) for a commented copy.
### Profiles (`odoo-mcp.config.json`)
Keep prod and a dev copy side by side:
```json
{
"defaultProfile": "prod",
"profiles": {
"prod": {
"url": "https://mycompany.odoo.com",
"db": "mycompany",
"apiKeyEnv": "ODOO_PROD_API_KEY",
"repoPaths": ["C:\\dev\\Woocommerce"],
"toolsets": ["core", "inventory", "manufacturing", "sales", "purchases", "pos", "quality", "dashboards", "finance"]
},
"dev": {
"url": "http://localhost:8079",
"db": "mycompany_dev",
"apiKeyEnv": "ODOO_DEV_API_KEY",
"repoPaths": ["C:\\dev\\Woocommerce"],
"toolsets": ["core", "dev", "repo", "custom"],
"allowRawMethods": true
}
}
}
```
Select with `--profile dev` or `ODOO_MCP_PROFILE=dev`.
---
## CLI reference
```text
odoo-mcp [serve] [--profile name] [--config path]
odoo-mcp init [--url URL --db DB --api-key KEY] [--repo PATH] [--force] [--non-interactive]
odoo-mcp doctor [--json] [--profile name]
odoo-mcp tools [--json] [--profile name]
odoo-mcp config [--json] [--profile name]
odoo-mcp help | version
```
`doctor` checks connectivity, auth mode, version, user, key models, source repo, write/sensitive
flags, and tool count. `tools` lists the enabled catalog without connecting.
---
## Token and safety model
- Rows: `ODOO_MCP_DEFAULT_ROWS` (20) and `ODOO_MCP_MAX_ROWS` (200).
- Output: `ODOO_MCP_MAX_BYTES` (120k) with row, cell, and column caps.
- Empty columns are dropped; many2one values render as `Label (#id)`.
- Schema is cached and only requested fields are fetched.
- Binary/password-like fields are blocked by default.
- `res.users.apikeys` and `ir.config_parameter` are blocked; model denylists are configurable.
- **Read-only by default.** `odoo_call` write methods require `ODOO_MCP_ALLOW_WRITE=true` and
`confirm=true`. Arbitrary methods require the method allowlist or `ODOO_MCP_ALLOW_RAW_METHODS`.
- Optional JSONL audit log via `ODOO_MCP_AUDIT_LOG`.
---
## Troubleshooting
**`Missing ODOO_API_KEY`** — run `bun run init`, or set the env var. Odoo 19 API keys are in
Preferences → Account Security.
**401/403** — the key user lacks access to the model, the database name is wrong, or the key
was revoked. `odoo_health` reports the auth mode and user.
**404 on a model** — use `odoo_models` to find the technical name. Custom models only exist
after the module is installed.
**`/web/version` fails** — the client falls back to JSON-RPC `common.version`. If both fail,
check `ODOO_URL` and the network.
**“column … does not exist”** — the database references a stale module column. Run
`odoo_dev` with `action=gap` on the affected model, then upgrade or clean up the module.
Queries automatically fall back to raw ids where possible.
**Gap analysis says everything is missing** — the model may not be installed in that database,
or the repo path is wrong. Run `odoo_custom action=models` and `bun run doctor`.
**Odoo 17/18** — set `ODOO_LOGIN` as well as `ODOO_API_KEY`; the key is used as the password.
---
## Development
```bash
bun install
bun run typecheck
bun test
bun run build
bun scripts/smoke.ts # stdio handshake, tool/prompt list, odoo_suggest call
```
Layout:
```text
src/
config.ts env / .env / profiles / limits
context.ts shared client + schema + repo + tool catalog
cli.ts serve / init / doctor / tools / config
index.ts MCP server assembly
prompts.ts recommended investigation prompts
odoo/ JSON-2 + legacy client, schema cache, domains, fields, resolvers
repo/ manifest parser, module/source index, Python/XML heuristics
format/ bounded Markdown/JSON/CSV rendering
tools/ core, inventory, manufacturing, sales, purchases, pos, quality,
dashboards, dev, repo, custom, suggest
tests/ config, domain, format, manifest/repo, client, tool registration
```
## License
MIT