get_statistic
Retrieve dataset details and resource links from Swiss open data using an opendata.swiss identifier. First use search_statistics to find dataset IDs.
Instructions
Fetch details and resource links for a specific BFS/OFS dataset by its opendata.swiss identifier. Use search_statistics first to find dataset IDs.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| dataset_id | Yes | Dataset identifier from opendata.swiss (e.g. 'bevolkerungsstatistik-einwohner') |
Implementation Reference
- src/modules/statistics.ts:331-364 (handler)The handler function 'handleGetStatistic' that implements the 'get_statistic' tool logic by fetching dataset details from the CKAN API.
async function handleGetStatistic(args: Record<string, unknown>): Promise<string> { const datasetId = typeof args.dataset_id === "string" ? args.dataset_id.trim() : ""; if (!datasetId) throw new Error("dataset_id is required"); const url = buildUrl(`${CKAN_BASE}/package_show`, { id: datasetId }); const data = await fetchJSON<CkanPackageResult>(url); if (!data.success) throw new Error(`Dataset not found: ${datasetId}`); const pkg = data.result; const resources = (pkg.resources ?? []).slice(0, 10).map((r) => ({ name: resolveText(r.name), format: r.format, url: r.url, })); const contact = pkg.contact_points?.[0]; const org = resolveText(pkg.organization?.title); return JSON.stringify({ id: pkg.name, title: resolveText(pkg.title), description: truncate(resolveText(pkg.notes || pkg.description), 500), keywords: pkg.keywords?.en ?? pkg.keywords?.de ?? [], issued: pkg.issued?.slice(0, 10) ?? "", modified: pkg.metadata_modified?.slice(0, 10) ?? "", organization: org, contact: contact ? { name: contact.name, email: contact.email } : undefined, resources, source: "opendata.swiss", source_url: `https://opendata.swiss/en/dataset/${pkg.name}`, }); } - src/modules/statistics.ts:163-177 (schema)The tool definition and input schema for 'get_statistic'.
name: "get_statistic", description: "Fetch details and resource links for a specific BFS/OFS dataset by its opendata.swiss identifier. " + "Use search_statistics first to find dataset IDs.", inputSchema: { type: "object", required: ["dataset_id"], properties: { dataset_id: { type: "string", description: "Dataset identifier from opendata.swiss (e.g. 'bevolkerungsstatistik-einwohner')", }, }, }, }, - src/modules/statistics.ts:377-378 (registration)The registration/dispatch logic for 'get_statistic' within the 'handleStatistics' function.
case "get_statistic": return handleGetStatistic(args);