Skip to main content
Glama

compare_municipalities

Compare specific performance indicators across multiple Swedish municipalities for selected years, enabling benchmarking analysis with gender filtering options.

Instructions

Jämför ett specifikt nyckeltal över flera kommuner för angivna år. Utmärkt för benchmarking. Stöder könsfiltrering (T/M/K).

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
kpi_idYesKPI-ID att jämföra
municipality_idsYesLista med kommun-ID:n att jämföra (2-10 kommuner)
yearsNoSpecifika år att inkludera i jämförelsen
genderNoKönsfilter: T=Totalt, M=Män, K=Kvinnor, all=visa allaall

Implementation Reference

  • Handler function that fetches KPI data from Kolada API for multiple municipalities in parallel, applies gender filtering, and returns structured comparison data.
    handler: async (args: z.infer<typeof compareMunicipalitiesSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { kpi_id, municipality_ids, years, gender } = args; logger.toolCall('compare_municipalities', { kpi_id, municipality_ids, years, gender }); try { interface ComparisonEntry { municipality_id: string; data: KPIData[]; } const comparison: { kpi_id: string; municipalities: ComparisonEntry[]; } = { kpi_id, municipalities: [], }; // Fetch data for all municipalities in parallel for better performance const promises = municipality_ids.map(async (municipality_id) => { // Kolada API v3 uses path-based URLs let endpoint = `/data/kpi/${kpi_id}/municipality/${municipality_id}`; if (years && years.length > 0) { endpoint += `/year/${years.join(',')}`; } let data = await koladaClient.fetchAllData<KPIData>(endpoint); // Apply gender filter data = filterByGender(data, gender); return { municipality_id, data, }; }); comparison.municipalities = await Promise.all(promises); logger.toolResult('compare_municipalities', true, Date.now() - startTime); return { content: [ { type: 'text', text: JSON.stringify( { ...comparison, gender_filter: gender, source: 'Kolada - Källa: Kolada', }, null, 2 ), }, ], }; } catch (error) { logger.toolResult('compare_municipalities', false, Date.now() - startTime); throw error; } },
  • Zod schema defining input parameters: kpi_id, municipality_ids (2-10), optional years, and gender filter.
    const compareMunicipalitiesSchema = z.object({ kpi_id: z.string().describe('KPI-ID att jämföra'), municipality_ids: z .array(z.string()) .min(2) .max(10) .describe('Lista med kommun-ID:n att jämföra (2-10 kommuner)'), years: z.array(z.number()).optional().describe('Specifika år att inkludera i jämförelsen'), gender: z.enum(['T', 'M', 'K', 'all']).default('all').describe('Könsfilter: T=Totalt, M=Män, K=Kvinnor, all=visa alla'), });
  • Tool registration as 'compare_municipalities' within the dataTools export object, including description, schema, annotations, and handler reference.
    compare_municipalities: { description: 'Jämför ett specifikt nyckeltal över flera kommuner för angivna år. Utmärkt för benchmarking. Stöder könsfiltrering (T/M/K).', inputSchema: compareMunicipalitiesSchema, annotations: READ_ONLY_ANNOTATIONS, handler: async (args: z.infer<typeof compareMunicipalitiesSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { kpi_id, municipality_ids, years, gender } = args; logger.toolCall('compare_municipalities', { kpi_id, municipality_ids, years, gender }); try { interface ComparisonEntry { municipality_id: string; data: KPIData[]; } const comparison: { kpi_id: string; municipalities: ComparisonEntry[]; } = { kpi_id, municipalities: [], }; // Fetch data for all municipalities in parallel for better performance const promises = municipality_ids.map(async (municipality_id) => { // Kolada API v3 uses path-based URLs let endpoint = `/data/kpi/${kpi_id}/municipality/${municipality_id}`; if (years && years.length > 0) { endpoint += `/year/${years.join(',')}`; } let data = await koladaClient.fetchAllData<KPIData>(endpoint); // Apply gender filter data = filterByGender(data, gender); return { municipality_id, data, }; }); comparison.municipalities = await Promise.all(promises); logger.toolResult('compare_municipalities', true, Date.now() - startTime); return { content: [ { type: 'text', text: JSON.stringify( { ...comparison, gender_filter: gender, source: 'Kolada - Källa: Kolada', }, null, 2 ), }, ], }; } catch (error) { logger.toolResult('compare_municipalities', false, Date.now() - startTime); throw error; } }, },
  • Helper function to filter KPI data points by gender (T=Totalt, M=Män, K=Kvinnor, all=unfiltered), used by the handler.
    function filterByGender(data: KPIData[], gender: 'T' | 'M' | 'K' | 'all'): KPIData[] { if (gender === 'all') return data; return data.map(d => ({ ...d, values: d.values.filter(v => v.gender === gender || (!v.gender && gender === 'T')) })).filter(d => d.values.length > 0); }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/isakskogstad/Kolada-MCP'

If you have feedback or need assistance with the MCP directory API, please join our Discord server