get_cities
Retrieve cities and municipalities for a specific Colombian department, including names, populations, and postal codes, to access detailed geographical information.
Instructions
Obtiene todas las ciudades/municipios de un departamento específico.
Args:
department_id (number): ID del departamento
Returns: Lista de ciudades con nombre, población y código postal.
Ejemplo de uso:
"¿Qué ciudades hay en Antioquia?"
"Lista los municipios del Valle del Cauca"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| department_id | Yes | ID del departamento |
Implementation Reference
- src/index.ts:383-417 (handler)The handler function for the 'get_cities' tool. It takes a department_id, fetches the list of cities/municipalities from the API endpoint `/Department/${department_id}/cities`, formats the data (including id, name, population, surface, postal code), and returns it as a JSON string in the MCP response format. Handles errors gracefully.async ({ department_id }) => { try { const cities = await apiRequest<City[]>(`/Department/${department_id}/cities`); const resultado = { departamento_id: department_id, total_ciudades: cities.length, ciudades: cities.map(c => ({ id: c.id, nombre: c.name, poblacion: c.population, superficie_km2: c.surface, codigo_postal: c.postalCode, })), }; return { content: [ { type: "text", text: JSON.stringify(resultado, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error al obtener ciudades: ${error instanceof Error ? error.message : "Error desconocido"}`, }, ], }; } }
- src/index.ts:373-375 (schema)Input schema for the 'get_cities' tool using Zod validation. Requires a single parameter 'department_id' as a positive integer (minimum 1).inputSchema: { department_id: z.number().int().min(1).describe("ID del departamento"), },
- src/index.ts:358-418 (registration)Registration of the 'get_cities' tool using server.registerTool. Includes title, detailed description, input schema, annotations (read-only, idempotent, etc.), and references the handler function.server.registerTool( "get_cities", { title: "Obtener Ciudades de un Departamento", description: `Obtiene todas las ciudades/municipios de un departamento específico. Args: - department_id (number): ID del departamento Returns: Lista de ciudades con nombre, población y código postal. Ejemplo de uso: - "¿Qué ciudades hay en Antioquia?" - "Lista los municipios del Valle del Cauca"`, inputSchema: { department_id: z.number().int().min(1).describe("ID del departamento"), }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, }, async ({ department_id }) => { try { const cities = await apiRequest<City[]>(`/Department/${department_id}/cities`); const resultado = { departamento_id: department_id, total_ciudades: cities.length, ciudades: cities.map(c => ({ id: c.id, nombre: c.name, poblacion: c.population, superficie_km2: c.surface, codigo_postal: c.postalCode, })), }; return { content: [ { type: "text", text: JSON.stringify(resultado, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error al obtener ciudades: ${error instanceof Error ? error.message : "Error desconocido"}`, }, ], }; } } );
- src/index.ts:67-75 (schema)TypeScript interface defining the structure of a City object, used in the get_cities handler for typing the API response.interface City { id: number; name: string; description: string; surface: number | null; population: number | null; postalCode: string | null; departmentId: number; }