get_kpi
Retrieve detailed metadata for specific Swedish public sector KPIs using their unique identifiers. Access publication dates, gender breakdowns, and comprehensive statistical information for analysis and comparison.
Instructions
Hämta detaljerad information om ett specifikt nyckeltal (KPI) via dess ID. Returnerar fullständig metadata inklusive publiceringsdatum och könsuppdelning.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| kpi_id | Yes | KPI-ID (t.ex. "N15033") |
Implementation Reference
- src/tools/kpi-tools.ts:138-168 (handler)The async handler function that implements the core logic of the get_kpi tool: validates kpi_id, fetches KPI details from Kolada API, handles errors, and returns formatted JSON response.handler: async (args: z.infer<typeof getKpiSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { kpi_id } = args; logger.toolCall('get_kpi', { kpi_id }); try { validateKpiId(kpi_id); const response = await koladaClient.request<KPI>(`/kpi/${kpi_id}`); if (response.values.length === 0) { const error = ERROR_MESSAGES.KPI_NOT_FOUND(kpi_id); throw createMcpError(KoladaErrorType.NOT_FOUND, error.message, { suggestion: error.suggestion, }); } logger.toolResult('get_kpi', true, Date.now() - startTime); return { content: [ { type: 'text', text: JSON.stringify(response.values[0], null, 2), }, ], }; } catch (error) { logger.toolResult('get_kpi', false, Date.now() - startTime); handleApiError(error, `get_kpi(${kpi_id})`); }
- src/tools/kpi-tools.ts:37-39 (schema)Zod input schema for the get_kpi tool, defining the required kpi_id parameter as a string.const getKpiSchema = z.object({ kpi_id: z.string().describe('KPI-ID (t.ex. "N15033")'), });
- src/server/handlers.ts:32-38 (registration)Registration of all tools including get_kpi (via spread of kpiTools) into the central allTools object used by MCP server handlers for tool listing and execution.export const allTools = { ...kpiTools, ...municipalityTools, ...ouTools, ...dataTools, ...analysisTools, };
- src/tools/kpi-tools.ts:134-169 (registration)Tool definition and local registration within kpiTools export, including description, schema reference, annotations, and handler.get_kpi: { description: 'Hämta detaljerad information om ett specifikt nyckeltal (KPI) via dess ID. Returnerar fullständig metadata inklusive publiceringsdatum och könsuppdelning.', inputSchema: getKpiSchema, annotations: READ_ONLY_ANNOTATIONS, handler: async (args: z.infer<typeof getKpiSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { kpi_id } = args; logger.toolCall('get_kpi', { kpi_id }); try { validateKpiId(kpi_id); const response = await koladaClient.request<KPI>(`/kpi/${kpi_id}`); if (response.values.length === 0) { const error = ERROR_MESSAGES.KPI_NOT_FOUND(kpi_id); throw createMcpError(KoladaErrorType.NOT_FOUND, error.message, { suggestion: error.suggestion, }); } logger.toolResult('get_kpi', true, Date.now() - startTime); return { content: [ { type: 'text', text: JSON.stringify(response.values[0], null, 2), }, ], }; } catch (error) { logger.toolResult('get_kpi', false, Date.now() - startTime); handleApiError(error, `get_kpi(${kpi_id})`); } },