search_real_estate_data
Search Swiss open data for real estate and housing datasets including property prices, rents, construction data, and vacancy rates to support market analysis and research.
Instructions
Search opendata.swiss for Swiss real estate and housing datasets. Finds datasets about property prices, rents, housing construction, vacancy rates, and more. Returns dataset names, descriptions, and resource download URLs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search terms in German, French, or English (e.g. "Immobilien", "Miete", "rent", "logement", "Wohnungspreise", "Leerwohnungen"). | |
| limit | No | Max results to return (1–20, default 10). |
Implementation Reference
- src/modules/realestate.ts:248-310 (handler)The function handleSearchRealEstateData executes the tool logic, including searching the opendata.swiss CKAN API with relevant keywords for real estate datasets and formatting the output.
async function handleSearchRealEstateData( args: Record<string, unknown> ): Promise<string> { const query = typeof args.query === "string" ? args.query.trim() : ""; if (!query) throw new Error("query is required"); const limit = Math.min(20, Math.max(1, typeof args.limit === "number" ? args.limit : 10)); const url = buildUrl(`${CKAN_BASE}/package_search`, { q: query, rows: limit, fq: "groups:territoire-et-environnement OR groups:construction-et-logement OR tags:immobilien OR tags:wohnen OR tags:miete OR tags:logement", }); const data = await fetchJSON<CkanSearchResult>(url, { headers: { "User-Agent": "mcp-swiss" }, }); if (!data.success) throw new Error("opendata.swiss search failed"); // Also do a fallback search without group filter if we get 0 results let results = data.result.results; let totalCount = data.result.count; if (results.length === 0) { const url2 = buildUrl(`${CKAN_BASE}/package_search`, { q: query, rows: limit }); const data2 = await fetchJSON<CkanSearchResult>(url2, { headers: { "User-Agent": "mcp-swiss" }, }); if (data2.success) { results = data2.result.results; totalCount = data2.result.count; } } const mapped = results.map((pkg) => { const resources = (pkg.resources ?? []).slice(0, 5).map((r) => ({ name: resolveText(r.name) || r.format, format: r.format, url: r.url, })); return { id: pkg.name, title: resolveText(pkg.title), description: truncate(resolveText(pkg.notes || pkg.description), 200), keywords: pkg.keywords?.en ?? pkg.keywords?.de ?? [], modified: pkg.metadata_modified?.slice(0, 10) ?? "", organization: resolveText(pkg.organization?.title), resources, dataset_url: `https://opendata.swiss/en/dataset/${pkg.name}`, }; }); return JSON.stringify({ query, total_matches: totalCount, returned: mapped.length, results: mapped, source: "opendata.swiss CKAN", source_url: `https://opendata.swiss/en/dataset?q=${encodeURIComponent(query)}`, }); } - src/modules/realestate.ts:430-444 (schema)Tool registration for search_real_estate_data, including its name, description, and input schema.
name: "search_real_estate_data", description: "Search opendata.swiss for Swiss real estate and housing datasets. " + "Finds datasets about property prices, rents, housing construction, vacancy rates, and more. " + "Returns dataset names, descriptions, and resource download URLs.", inputSchema: { type: "object", required: ["query"], properties: { query: { type: "string", description: 'Search terms in German, French, or English (e.g. "Immobilien", "Miete", ' + '"rent", "logement", "Wohnungspreise", "Leerwohnungen").', },