get_president
Retrieve detailed information about a specific Colombian president by providing their ID number.
Instructions
Obtiene información detallada de un presidente específico.
Args:
id (number): ID del presidente
Returns: Información detallada del presidente.
Ejemplo de uso:
"Dame información sobre el presidente con ID 5"
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| id | Yes | ID del presidente |
Implementation Reference
- src/index.ts:646-680 (handler)The handler function for the 'get_president' tool. It takes an 'id' parameter, fetches the president's data from the API endpoint `/President/${id}`, formats it into a structured object including full name, period dates, political party, description, and image, and returns it as text content. Handles errors gracefully.async ({ id }) => { try { const president = await apiRequest<any>(`/President/${id}`); const resultado = { id: president.id, nombre: president.name, apellido: president.lastName, nombre_completo: `${president.name} ${president.lastName}`, inicio_periodo: president.startPeriodDate, fin_periodo: president.endPeriodDate, partido_politico: president.politicalParty, descripcion: president.description, imagen: president.image, }; return { content: [ { type: "text", text: JSON.stringify(resultado, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error al obtener presidente: ${error instanceof Error ? error.message : "Error desconocido"}`, }, ], }; } }
- src/index.ts:624-645 (schema)The tool specification including title, description, input schema (requiring 'id' as a positive integer), and annotations indicating it's read-only, non-destructive, idempotent, and open-world.{ title: "Obtener Presidente Específico", description: `Obtiene información detallada de un presidente específico. Args: - id (number): ID del presidente Returns: Información detallada del presidente. Ejemplo de uso: - "Dame información sobre el presidente con ID 5"`, inputSchema: { id: z.number().int().min(1).describe("ID del presidente"), }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, },
- src/index.ts:622-681 (registration)The server.registerTool call that registers the 'get_president' tool with the MCP server, passing the tool name, specification/schema, and handler function.server.registerTool( "get_president", { title: "Obtener Presidente Específico", description: `Obtiene información detallada de un presidente específico. Args: - id (number): ID del presidente Returns: Información detallada del presidente. Ejemplo de uso: - "Dame información sobre el presidente con ID 5"`, inputSchema: { id: z.number().int().min(1).describe("ID del presidente"), }, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, }, async ({ id }) => { try { const president = await apiRequest<any>(`/President/${id}`); const resultado = { id: president.id, nombre: president.name, apellido: president.lastName, nombre_completo: `${president.name} ${president.lastName}`, inicio_periodo: president.startPeriodDate, fin_periodo: president.endPeriodDate, partido_politico: president.politicalParty, descripcion: president.description, imagen: president.image, }; return { content: [ { type: "text", text: JSON.stringify(resultado, null, 2), }, ], }; } catch (error) { return { content: [ { type: "text", text: `Error al obtener presidente: ${error instanceof Error ? error.message : "Error desconocido"}`, }, ], }; } } );
- src/index.ts:22-38 (helper)The apiRequest helper function used by the get_president handler to make HTTP GET requests to the Colombia API base URL.async function apiRequest<T>(endpoint: string): Promise<T> { const url = `${API_BASE_URL}${endpoint}`; const response = await fetch(url, { method: "GET", headers: { "Accept": "application/json", "Content-Type": "application/json", }, }); if (!response.ok) { throw new Error(`API Error: ${response.status} ${response.statusText}`); } return response.json() as Promise<T>; }