cbs-mcp
by Shtibel1
README.md
<div align="center">
<img src=".github/banner.svg" alt="cbs-mcp" width="100%"/>
[](https://github.com/Shtibel1/cbs-mcp/actions/workflows/ci.yml)
[](package.json)
[](LICENSE)

[](https://modelcontextprotocol.io)

**Israel's Consumer Price Index, housing and construction-input indices — and a correct הצמדה למדד calculator — for any MCP client.**
</div>
<p align="center"><a href="#quick-start">Quick start</a> · <a href="#tools">Tools</a> · <a href="#live-example">Live example</a> · <a href="#index-linkage-done-right">Index linkage</a> · <a href="#architecture">Architecture</a> · <a href="#roadmap">Roadmap</a></p>
A [Model Context Protocol](https://modelcontextprotocol.io) server that gives AI agents the official price indices of the **Israel Central Bureau of Statistics** (הלשכה המרכזית לסטטיסטיקה): the CPI (מדד המחירים לצרכן) and its ~350 components, dwelling prices, residential/commercial building inputs (מדד תשומות הבנייה), road construction, agriculture, producer prices and more — about **1,350 indices** with bilingual search, chain-linked history across base changes, multi-index comparison, a one-call CPI summary and an **index-linkage calculator** that matches the official CBS calculator to the agora.
It talks directly to the CBS's free, public price-index API (published by the [CBS](https://www.cbs.gov.il)) at `api.cbs.gov.il`: no API key, no scraping.
Part of a small family of Israeli MCP servers: [boi-mcp](https://github.com/Shtibel1/boi-mcp) (Bank of Israel exchange rates and interest rate), [il-opendata-mcp](https://github.com/Shtibel1/il-opendata-mcp) (data.gov.il datasets) and [hebrew-il-mcp](https://github.com/Shtibel1/hebrew-il-mcp) (ID, phone, VAT, IBAN validators and the Hebrew calendar).
## Tools
| Tool | What it does |
| --- | --- |
| `list_chapters` | The catalog's chapters (consumer prices, housing, producer prices, building/road/agriculture/bus inputs...) in English and Hebrew, each with its main index code and subjects with index counts. |
| `search_indices` | Search ~1,350 indices by English or Hebrew text (`rent`, `שכר דירה`, `electricity`, `תשומות בנייה`, `cpi`) or by code. Returns code, both names, chapter/subject, `frequency`, `available_from` and `active`. Optional `chapter`, `limit`, `include_inactive`. |
| `get_latest_index` | Latest value of an index (default: headline CPI `120010`) with its base, the published monthly and 12-month change, `published_on` and the last N observations. `change_over_window_pct` is chain-linked. |
| `get_index_history` | History between `start_month` and `end_month`: every observation as published **plus `rebased_value` on the latest base**, the chain-linked `change_pct`, `annualized_pct`, min/max and the `base_changes` (with coefficients) inside the range. |
| `compare_indices` | Rank up to 12 indices by their chain-linked change between two months (default: the CPI and its main groups), with annualized rates and a `missing` list explaining any gaps. One API request. |
| `get_cpi_summary` | The latest CPI in one call: headline value, monthly and 12-month inflation, four `core` measures (ex. fruit/vegetables/housing, ex. energy...) and the 10 main consumption `groups`, plus the `fastest_rising_yoy` and `falling_yoy` groups. One API request. |
| `calculate_linked_amount` | **הצמדה למדד.** Adjust an `amount` by any monthly index, either by **index months** (`from_month`/`to_month`, the actual index — מדד בגין — computed locally, both directions) or by **dates** (`from_date`/`to_date`, the index *known* on each date — המדד הידוע — via the official CBS calculator). `no_decrease` applies a contract-style index floor. |
### Resources
| URI | Content |
| --- | --- |
| `cbs://chapters` | Catalog chapters and subjects (same as `list_chapters`) |
| `cbs://featured` | Hand-picked indices (CPI, core CPI, housing, construction inputs...) and what each is used for — no network |
| `cbs://cpi/latest` | The latest CPI summary |
| `cbs://index/{code}` | Latest value and last 13 observations of any index; the template lists and auto-completes the featured codes |
Every tool returns human-readable JSON text and `structuredContent`. Bad input (unknown code, malformed month, a month that isn't published yet, a future date) produces an MCP `isError` result with a clear message instead of crashing the session.
## Index linkage, done right
Index-linked amounts are everywhere in Israel — rent, alimony, salaries, apartment purchase contracts (linked to the building-inputs index), tenders and loans — and they are easy to get subtly wrong:
- **Base changes.** The CBS moves indices to a new base every few years (CPI: "Average 2022" → "Average 2024" in January 2025, coefficient **1.074**). Dividing a 2019 value (100.8, base 2018) by a 2025 value (103.6, base 2024) gives +2.8% instead of the real **+17.25%**. cbs-mcp requests the API's chaining data (`coef=true`), which carries each observation's value on every older base, and always compares on a common base.
- **Known index vs. index month.** Contracts usually link to the index *known* on the payment date. CBS publishes month M on the 15th of M+1 at 18:30, so on 1–15 of a month the known index is two months back and from the 16th it is last month's. The `from_date`/`to_date` mode delegates to the official CBS calculator, which applies this rule; `from_month`/`to_month` uses exactly the months you name.
- **Both agree.** `100 ₪` from the November 2019 CPI to the November 2025 CPI computed locally (chaining coefficient 1.140778) gives **117.25 ₪** — the same result the official calculator returns for 2020-01-01 → 2026-01-01. This exact case is a regression test.
- **Calculator quirks handled.** The CBS calculator parses dates as `MM-DD-YYYY` (so `01-06-2023` is 6 January), answers HTTP 500 for future dates or reversed ranges, and the API drops a share of connections. cbs-mcp sends US-ordered dates, validates input up front, retries transient failures with backoff and turns validation errors into readable messages.
## Quick start
### Claude Desktop / Cursor / any MCP client
```json
{
"mcpServers": {
"cbs": {
"command": "npx",
"args": ["-y", "github:Shtibel1/cbs-mcp"]
}
}
}
```
Claude Desktop: put this in `claude_desktop_config.json`. Cursor: `~/.cursor/mcp.json` (or `.cursor/mcp.json` in a project).
Or from a local clone:
```bash
npm install && npm run build
node dist/cli.js # speaks MCP over stdio
```
Then ask your agent things like:
- "My rent is 4,500 ₪ linked to the CPI from March 2025. What should I pay now?"
- "What was inflation last month, and which CPI groups rose the most over the past year?"
- "חוזה דירה מקבלן צמוד למדד תשומות הבנייה מיוני 2023 — בכמה עלה הסכום של מיליון ש״ח?"
- "Chart the CPI since 2015 on a single base."
### Hosted: Streamable HTTP
```bash
npx -y github:Shtibel1/cbs-mcp --http --port 3000
# → cbs-mcp listening on http://127.0.0.1:3000/mcp
curl http://127.0.0.1:3000/healthz # {"status":"ok","name":"cbs-mcp","version":"0.1.0"}
```
```json
{ "mcpServers": { "cbs": { "url": "http://127.0.0.1:3000/mcp" } } }
```
| Flag | Env | Default | Notes |
| --- | --- | --- | --- |
| `--http` | | off | Serve [Streamable HTTP](https://modelcontextprotocol.io/specification/2025-06-18/basic/transports#streamable-http) instead of stdio |
| `--port` | `PORT` | `3000` | |
| `--host` | `HOST` | `127.0.0.1` | Binds to loopback by default; use `0.0.0.0` inside a container |
| `--allowed-origin` | `ALLOWED_ORIGINS` | none | Repeatable flag, or a comma-separated env var. Browser requests from any other `Origin` get `403` (DNS-rebinding protection); non-browser clients without `Origin` are always allowed |
| `--cache-ttl` | `CBS_CACHE_TTL` | `300` | Seconds to cache index data; the catalog is kept 12 hours. `0` disables caching |
| `--version` | | | Print the version and exit |
The HTTP mode is **stateless**: every `POST /mcp` gets a fresh server and transport (sharing one cached client), there are no session ids, and `GET`/`DELETE /mcp` return `405`, so instances can sit behind any load balancer. Bodies over 1 MB get `413`, malformed JSON gets `400`.
### Docker
```bash
docker build -t cbs-mcp .
docker run --rm -p 3000:3000 -e ALLOWED_ORIGINS=https://app.example cbs-mcp
```
The image runs the HTTP mode as the unprivileged `node` user on `0.0.0.0:3000` with a `HEALTHCHECK` against `/healthz`. CI builds it on every push and smoke-tests the health check, a real `tools/list` call, the origin guard and the non-root user.
### As a library
```ts
import { CbsClient } from "cbs-mcp";
const cbs = new CbsClient();
const cpi = await cbs.getLatestIndex(120010); // latest CPI, base, monthly / 12-month change
const hits = await cbs.searchIndices("שכר דירה"); // → 120460 Rent
const history = await cbs.getHistory(120010, "2015-01"); // chain-linked, rebased to the latest base
const rent = await cbs.calculateLinkedAmount({ amount: 4500, from_date: "2025-03-10" });
const contract = await cbs.calculateLinkedAmount({ amount: 1_000_000, code: 200010, from_month: "2023-04", no_decrease: true });
```
## Live example
Real output from the built server against the live CBS API, run on **2026-11-22** (Asia/Jerusalem; the latest CPI is October 2026, published 2026-11-15):
| Call | Result |
| --- | --- |
| `get_cpi_summary` | CPI October 2026: **105.2** (Average 2024 = 100), **−0.1%** on the month, **+1.1%** year over year; core ex. fruit/vegetables/housing **−0.2%**; housing **+4.2%** YoY leads, clothing & footwear **−4.7%** and furniture **−4.2%** fall |
| `get_index_history { 120010, 2023-01 → 2026-10 }` | 46 months, one base change (2025-01, ×1.074), chain-linked **+10.44%** (**2.68%/yr**) — a naive comparison of published values would show +2.8% |
| `compare_indices { 8 CPI groups, 2025-10 → 2026-10 }` | Housing **+4.19%** · CPI +1.06% · Health +1.06% · ex-energy +0.96% · Food −0.10% · Transport & communication −1.64% · Clothing & footwear **−4.70%** |
| `calculate_linked_amount { 100, from_month 2019-11, to_month 2025-11 }` | **117.25 ₪** (100.8 on base 2018 → 103.6 on base 2024, chaining coefficient 1.140778) |
| `calculate_linked_amount { 100, from_date 2020-01-01, to_date 2026-01-01 }` | **117.25 ₪** from the official calculator (known indices 2019-11 → 2025-11) |
| `calculate_linked_amount { 1,000,000, code 200010, from_date 2023-06-01, to_date 2026-11-01 }` | **1,115,607.12 ₪** — residential building inputs, known index 2023-04 → 2026-09, coefficient 1.387 |
| `calculate_linked_amount { 5000, from_month 2026-08, to_month 2026-10, no_decrease }` | CPI fell 0.57% → floor applied, **5,000 ₪** |
| `search_indices { "שכר דירה" }` | `120460` Rent (שכר דירה פרטי, ציבורי ושכירות ארוכת טווח בפיקוח ממשלתי) |
The first call loads the bilingual catalog (~1.4 s); later searches are served from memory in ~20 ms.
<details>
<summary>Raw <code>calculate_linked_amount</code> response</summary>
```json
{
"amount": 100,
"code": 120010,
"name": "Consumer Price Index - General",
"method": "index_months",
"from": { "period": "2019-11", "value": 100.8, "base": "Average 2018" },
"to": { "period": "2025-11", "value": 103.6, "base": "Average 2024" },
"chaining_coefficient": 1.140778,
"factor": 1.172466,
"change_pct": 17.247,
"linked_amount": 117.25,
"difference": 17.25,
"no_decrease": false,
"floor_applied": false,
"computed_by": "cbs-mcp (published index values linked with CBS chaining coefficients)",
"source": "Israel Central Bureau of Statistics (הלשכה המרכזית לסטטיסטיקה), api.cbs.gov.il"
}
```
</details>
## Architecture
```mermaid
flowchart LR
C["MCP client<br/>(Claude Desktop, Cursor, agents)"] -- stdio --> CLI[cli.ts]
R["Remote agents"] -- "POST /mcp" --> H["http.ts<br/>stateless Streamable HTTP<br/>origin check · /healthz"]
CLI --> S["server.ts<br/>7 tools · 4 resources<br/>zod schemas · isError results"]
CLI -- "--http" --> H
H -- "new server per request<br/>shared CbsClient" --> S
S --> CBS
subgraph L["src/lib — no MCP imports"]
CBS["cbs.ts<br/>injectable fetch · retries · paging<br/>history · compare · calculator"]
CACHE["cache.ts<br/>TTL · in-flight dedupe"]
LINK["linkage.ts<br/>chain-linking · rebasing · index floor"]
CAT["catalog.ts<br/>EN+HE tree merge · search"]
MON["months.ts<br/>known index · MM-DD-YYYY · Asia/Jerusalem"]
CBS --> CACHE
CBS --> LINK
CBS --> CAT
CBS --> MON
end
CBS -- "HTTPS · JSON" --> API["api.cbs.gov.il/index<br/>catalog/tree · data/price · data/calculator"]
APP["Your TS app"] -- import --> L
```
### How the data is fetched
| Need | CBS API request |
| --- | --- |
| Catalog (chapters → subjects → codes) | `catalog/tree?lang=en` + `lang=he`, cached 12 h |
| Latest values | `data/price?id=120010&last=13&coef=true` |
| History / comparison | `data/price?id=120010,120450,…&startPeriod=01-2023&endPeriod=10-2026&coef=true&PageSize=1000` (paging followed) |
| CPI summary | `data/price?id=<15 codes>&last=1` — one request |
| Known-index linkage | `data/calculator/120010?value=100&date=01-01-2020&toDate=01-01-2026` (dates are `MM-DD-YYYY`) |
### Layout
```
src/
lib/cbs.ts injectable-fetch client: retries, paging, series parsing, history, compare, CPI summary, calculator
lib/linkage.ts chain-linking across base changes, rebasing to the latest base, base-change detection, index floor
lib/catalog.ts merges the English and Hebrew catalog trees; bilingual search with aliases and niqqud-insensitive matching
lib/months.ts YYYY-MM / MM-YYYY / MM-DD-YYYY formats, known-index rule, publication dates, Israeli "today"
lib/featured.ts hand-picked index codes and the CPI summary basket
lib/cache.ts promise-based TTL cache with in-flight de-duplication
server.ts MCP tools, resources and the resource template (zod schemas)
http.ts stateless Streamable HTTP transport (node:http, no framework)
cli.ts entry: stdio by default, --http for hosted mode
version.ts single source of the version
scripts/
record-fixtures.mjs re-records every fixture from the live API and prints a live check of each tool
test/
scenarios.mjs the live calls whose responses are recorded (shared by the recorder and the tests)
fixtures/ real CBS API responses recorded on 2026-11-22
*.test.ts 75 vitest tests; fetch replays the fixtures, so CI never hits the network
```
## Development
```bash
npm test # vitest, replaying recorded CBS responses (no network)
npm run typecheck
npm run build
npm run record-fixtures # refresh fixtures from the live API (then update expected numbers)
```
## Attribution
This is an unofficial client. All index data comes from the [Israel Central Bureau of Statistics](https://www.cbs.gov.il) and is subject to its terms of use. Linkage results are informational; for legal or financial disputes rely on the official CBS publications and calculator. This project has no affiliation with the CBS.
## Roadmap
- [ ] Publish to npm so `npx cbs-mcp` works without the GitHub shorthand
- [ ] Average dwelling prices by district and number of rooms
- [ ] Quarterly producer-price and services indices in `compare_indices`
- [ ] Linked-payment schedules (monthly rent or instalments linked over a period)
- [ ] Exact publication calendar for the known-index rule when the 15th falls on a weekend or holiday
- [x] Chain-linked history and comparison across base changes (v0.1.0)
- [x] Official-calculator cross-check for known-index linkage (v0.1.0)
## Contributing
Issues and PRs are welcome. Keep API logic in `src/lib` with unit tests and add an end-to-end case in `test/server.test.ts` for new tools. New fixtures must be real recorded responses (`npm run record-fixtures`) — never hand-written API data.
## License
[MIT](LICENSE) © Nadav Shtibel
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues