dk_municipality_lookup
Find Danish municipalities by code or name to retrieve official details including region, geographic boundaries, and administrative codes for data verification and location analysis.
Instructions
Look up a Danish municipality (kommune) by code or search by name. Returns name, code, region, and geographic bounds.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | No | 4-digit municipality code (e.g. '0101' for Copenhagen) | |
| name | No | Municipality name to search (e.g. 'Solrød') |
Implementation Reference
- src/servers/danish-addresses.js:111-142 (handler)The 'dk_municipality_lookup' tool registration and handler implementation. It uses a helper function 'dawaFetch' to query the municipal API and formats the result as markdown.
// Tool 4: Municipality info server.tool( "dk_municipality_lookup", "Look up a Danish municipality (kommune) by code or search by name. Returns name, code, region, and geographic bounds.", { code: z.string().optional().describe("4-digit municipality code (e.g. '0101' for Copenhagen)"), name: z.string().optional().describe("Municipality name to search (e.g. 'Solrød')"), }, async ({ code, name }) => { try { let data; if (code) { data = [await dawaFetch(`/kommuner/${code}`)]; } else if (name) { data = await dawaFetch("/kommuner", { q: name }); } else { return { content: [{ type: "text", text: "Provide either code or name." }], isError: true }; } if (!data.length) return { content: [{ type: "text", text: "No municipality found." }] }; const lines = data.map(k => { const parts = [`## ${k.navn} (${k.kode})`]; if (k.regionskode) parts.push(`**Region code:** ${k.regionskode}`); if (k.bbox) parts.push(`**Bounds:** ${k.bbox[1].toFixed(4)}°N to ${k.bbox[3].toFixed(4)}°N`); if (k.href) parts.push(`**API:** ${k.href}`); return parts.join("\n"); }); return { content: [{ type: "text", text: lines.join("\n\n") }] }; } catch (err) { return { content: [{ type: "text", text: `Error: ${err.message}` }], isError: true }; } } );