get_rent_index
Retrieve Swiss Consumer Price Index data to track residential rent costs and cost of living trends, using monthly BFS publications with historical data from 1983 onward.
Instructions
Get the Swiss Consumer Price Index (CPI/LIK), which tracks cost of living including residential rents. Baseline December 1982 = 100. Published monthly by BFS. For property purchase prices, use get_property_price_index instead.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| year | No | Filter to a specific year (1983–2025). Omit for latest 24 months. | |
| limit | No | Number of recent monthly data points to return (1–60, default 24). Ignored if year is set. |
Implementation Reference
- src/modules/realestate.ts:314-394 (handler)The handleGetRentIndex function performs the logic of fetching and formatting the Swiss Consumer Price Index data.
async function handleGetRentIndex(args: Record<string, unknown>): Promise<string> { const rawYear = typeof args.year === "number" ? args.year : undefined; const rawLimit = Math.min(60, Math.max(1, typeof args.limit === "number" ? args.limit : 24)); // Fetch CPI (LIK) data from Canton Zug open data - monthly index (base Dec 1982 = 100) // This is the Swiss national CPI (Landesindex der Konsumentenpreise) which includes // the residential rent component const totalRecords = 515; // approximate total let url: string; if (rawYear !== undefined) { // Fetch specific year - estimate offset // Data starts from Dec 1982 (record 0) ~ month 0 // Each year has 12 records. 1982 has 1 record (Dec only). const yearsFromStart = rawYear - 1982; const estOffset = Math.max(0, 1 + (yearsFromStart - 1) * 12); url = buildUrl(CPI_RENT_URL, { _limit: 12, _offset: estOffset }); } else { // Latest data - fetch last N months const offset = Math.max(0, totalRecords - rawLimit); url = buildUrl(CPI_RENT_URL, { _limit: rawLimit, _offset: offset }); } const data = await fetchJSON<ZgCpiResponse>(url, { headers: { "User-Agent": "mcp-swiss" }, }); // Filter by year if specified let rows = data.results; if (rawYear !== undefined) { rows = rows.filter((r) => r.jahr === String(rawYear)); } if (rows.length === 0 && rawYear !== undefined) { throw new Error( `No CPI data found for year ${rawYear}. Available data: 1982–2025.` ); } const series = rows.map((r) => ({ year: parseInt(r.jahr, 10), month: r.monat, index: parseFloat(r.index), })); const latestRow = series[series.length - 1]; const firstRow = series[0]; // YoY change (if we have 12+ months) let yoyChange: number | null = null; if (series.length >= 13) { const prev = series[series.length - 13]; if (prev) { yoyChange = parseFloat( (((latestRow.index - prev.index) / prev.index) * 100).toFixed(2) ); } } const period = series.length > 0 ? `${firstRow.month} ${firstRow.year} – ${latestRow.month} ${latestRow.year}` : "N/A"; return JSON.stringify({ index_name: "Swiss Consumer Price Index (LIK / IPC)", baseline: "December 1982 = 100", note: "The Swiss CPI (Landesindex der Konsumentenpreise) tracks the cost of living including residential rents. " + "This is the official Swiss national index published by BFS/FSO. " + "For the residential property price index (buying/ownership), use get_property_price_index.", period, latest: latestRow ?? null, data_points: series.length, series, yoy_change_percent: yoyChange, source: "Federal Statistical Office (BFS) via Canton Zug Open Data", source_url: "https://data.zg.ch/store/1/resource/334", ckan_dataset: "https://opendata.swiss/en/dataset/landesindex-der-konsumentenpreise", }); } - src/modules/realestate.ts:453-473 (schema)The definition of get_rent_index containing the name, description, and inputSchema.
name: "get_rent_index", description: "Get the Swiss Consumer Price Index (CPI/LIK), which tracks cost of living including " + "residential rents. Baseline December 1982 = 100. Published monthly by BFS. " + "For property purchase prices, use get_property_price_index instead.", inputSchema: { type: "object", properties: { year: { type: "number", description: "Filter to a specific year (1983–2025). Omit for latest 24 months.", }, limit: { type: "number", description: "Number of recent monthly data points to return (1–60, default 24). Ignored if year is set.", }, }, }, }, - src/modules/realestate.ts:487-488 (registration)Registration of the get_rent_index tool in the main dispatcher within handleRealEstate function.
case "get_rent_index": return handleGetRentIndex(args);