get_kpis
Retrieve multiple Swedish municipal KPIs by their IDs in a single request, enabling efficient access to public sector performance data for analysis and comparison.
Instructions
Hämta flera nyckeltal (KPIs) via deras ID:n i en enda förfrågan. Accepterar upp till 25 KPI-ID:n per anrop.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kpi_ids | Yes | Lista med KPI-ID:n (max 25) |
Implementation Reference
- src/tools/kpi-tools.ts:179-212 (handler)The main handler function for the get_kpis tool. Fetches multiple KPIs by their IDs using batch request to Kolada API, with validation and error handling.handler: async (args: z.infer<typeof getKpisSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { kpi_ids } = args; logger.toolCall('get_kpis', { kpi_ids, count: kpi_ids.length }); try { validateBatchSize(kpi_ids, 25); kpi_ids.forEach((id: string) => validateKpiId(id)); const kpis = await koladaClient.batchRequest<KPI>('/kpi', kpi_ids); logger.toolResult('get_kpis', true, Date.now() - startTime); return { content: [ { type: 'text', text: JSON.stringify( { requested: kpi_ids.length, found: kpis.length, kpis, }, null, 2 ), }, ], }; } catch (error) { logger.toolResult('get_kpis', false, Date.now() - startTime); handleApiError(error, 'get_kpis'); } },
- src/tools/kpi-tools.ts:41-43 (schema)Zod input schema for get_kpis tool, validating an array of 1-25 KPI IDs.const getKpisSchema = z.object({ kpi_ids: z.array(z.string()).min(1).max(25).describe('Lista med KPI-ID:n (max 25)'), });
- src/tools/kpi-tools.ts:175-213 (registration)Local registration of the get_kpis tool within the kpiTools object.get_kpis: { description: 'Hämta flera nyckeltal (KPIs) via deras ID:n i en enda förfrågan. Accepterar upp till 25 KPI-ID:n per anrop.', inputSchema: getKpisSchema, annotations: READ_ONLY_ANNOTATIONS, handler: async (args: z.infer<typeof getKpisSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { kpi_ids } = args; logger.toolCall('get_kpis', { kpi_ids, count: kpi_ids.length }); try { validateBatchSize(kpi_ids, 25); kpi_ids.forEach((id: string) => validateKpiId(id)); const kpis = await koladaClient.batchRequest<KPI>('/kpi', kpi_ids); logger.toolResult('get_kpis', true, Date.now() - startTime); return { content: [ { type: 'text', text: JSON.stringify( { requested: kpi_ids.length, found: kpis.length, kpis, }, null, 2 ), }, ], }; } catch (error) { logger.toolResult('get_kpis', false, Date.now() - startTime); handleApiError(error, 'get_kpis'); } }, },
- src/server/handlers.ts:32-38 (registration)Global tool registry where kpiTools (containing get_kpis) is spread into allTools used by the MCP server handlers.export const allTools = { ...kpiTools, ...municipalityTools, ...ouTools, ...dataTools, ...analysisTools, };
- src/server/handlers.ts:11-11 (registration)Import of kpiTools into the server handlers module.import { kpiTools } from '../tools/kpi-tools.js';