get_municipality_groups
Retrieve municipality groups like metropolitan regions or coastal municipalities to compare similar Swedish municipalities for statistical analysis and benchmarking.
Instructions
Lista kommungrupper som storstadsregioner, kustkommuner etc. Grupper hjälper till att jämföra liknande kommuner.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | Sökterm för att filtrera grupper efter titel |
Implementation Reference
- src/tools/municipality-tools.ts:161-197 (handler)Handler function that executes the tool logic: fetches municipality groups from Kolada API using koladaClient.fetchAllData, optionally filters by 'title' param if query provided, formats response as JSON with count and summaries (id, title, member_count), includes logging and error handling.handler: async (args: z.infer<typeof getMunicipalityGroupsSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { query } = args; logger.toolCall('get_municipality_groups', { query }); try { const params: Record<string, string> = {}; if (query) params.title = query; const groups = await koladaClient.fetchAllData<MunicipalityGroup>('/municipality_groups', params); logger.toolResult('get_municipality_groups', true, Date.now() - startTime); return { content: [ { type: 'text', text: JSON.stringify( { count: groups.length, groups: groups.map((g) => ({ id: g.id, title: g.title, member_count: g.members?.length || 0, })), }, null, 2 ), }, ], }; } catch (error) { logger.toolResult('get_municipality_groups', false, Date.now() - startTime); throw error; } },
- Zod input schema for the tool defining an optional 'query' string parameter to filter municipality groups by title.const getMunicipalityGroupsSchema = z.object({ query: z.string().optional().describe('Sökterm för att filtrera grupper efter titel'), });
- src/tools/municipality-tools.ts:157-197 (registration)Registration of the get_municipality_groups tool as a property in the exported municipalityTools object, which is later spread into the top-level allTools used by MCP server handlers.get_municipality_groups: { description: 'Lista kommungrupper som storstadsregioner, kustkommuner etc. Grupper hjälper till att jämföra liknande kommuner.', inputSchema: getMunicipalityGroupsSchema, annotations: READ_ONLY_ANNOTATIONS, handler: async (args: z.infer<typeof getMunicipalityGroupsSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { query } = args; logger.toolCall('get_municipality_groups', { query }); try { const params: Record<string, string> = {}; if (query) params.title = query; const groups = await koladaClient.fetchAllData<MunicipalityGroup>('/municipality_groups', params); logger.toolResult('get_municipality_groups', true, Date.now() - startTime); return { content: [ { type: 'text', text: JSON.stringify( { count: groups.length, groups: groups.map((g) => ({ id: g.id, title: g.title, member_count: g.members?.length || 0, })), }, null, 2 ), }, ], }; } catch (error) { logger.toolResult('get_municipality_groups', false, Date.now() - startTime); throw error; } },