search_organizational_units
Search for Swedish organizational units like schools, preschools, and care facilities. Filter by name, municipality, or type to find specific public sector entities.
Instructions
Sök efter organisationsenheter som skolor, förskolor, äldreboenden etc. Filtrera efter namn, kommun eller typ. OBS: Resultat trunkeras till limit (max 100). Kontrollera "truncated" i svaret för att veta om det finns fler träffar.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | No | Sökterm för att filtrera enheter efter namn | |
| municipality | No | Filtrera efter kommun-ID (4-siffrig kod) | |
| ou_type | No | Filtrera efter OU-typ (t.ex. "V11" för förskola, "V15" för grundskola) | |
| limit | No | Max antal resultat (standard: 20, max: 100) |
Implementation Reference
- src/tools/ou-tools.ts:42-96 (handler)The async handler function that implements the core logic: fetches organizational units from Kolada API, applies client-side filtering for ou_type, limits results, handles truncation, logs execution, and returns structured JSON response.handler: async (args: z.infer<typeof searchOuSchema>): Promise<ToolResult> => { const startTime = Date.now(); const { query, municipality, ou_type, limit } = args; logger.toolCall('search_organizational_units', { query, municipality, ou_type, limit }); try { const params: Record<string, string> = {}; if (query) params.title = query; if (municipality) params.municipality = municipality; let units = await koladaClient.fetchAllData<OrganizationalUnit>('/ou', params); // Client-side filtering for ou_type if (ou_type) { units = units.filter((u) => u.id.startsWith(ou_type)); } // Limit results const totalMatches = units.length; units = units.slice(0, limit); logger.toolResult('search_organizational_units', true, Date.now() - startTime); const isTruncated = totalMatches > limit; return { content: [ { type: 'text', text: JSON.stringify( { count: units.length, total_matches: totalMatches, truncated: isTruncated, truncation_note: isTruncated ? `Visar ${units.length} av ${totalMatches} träffar. Öka limit (max 100) eller lägg till fler filter för att få fler resultat.` : undefined, organizational_units: units.map((u) => ({ id: u.id, title: u.title, municipality: u.municipality, ou_type: u.ou_type, })), }, null, 2 ), }, ], }; } catch (error) { logger.toolResult('search_organizational_units', false, Date.now() - startTime); throw error; } },
- src/tools/ou-tools.ts:20-25 (schema)Zod schema defining input parameters for the search_organizational_units tool: query, municipality, ou_type, and limit.const searchOuSchema = z.object({ query: z.string().optional().describe('Sökterm för att filtrera enheter efter namn'), municipality: z.string().optional().describe('Filtrera efter kommun-ID (4-siffrig kod)'), ou_type: z.string().optional().describe('Filtrera efter OU-typ (t.ex. "V11" för förskola, "V15" för grundskola)'), limit: z.number().min(1).max(100).default(20).describe('Max antal resultat (standard: 20, max: 100)'), });
- src/server/handlers.ts:32-38 (registration)The ouTools object (containing search_organizational_units) is spread into the allTools registry, which is used by the MCP server handlers for listing tools (lines 129-137) and executing tool calls (lines 140-156).export const allTools = { ...kpiTools, ...municipalityTools, ...ouTools, ...dataTools, ...analysisTools, };