obtener-clima
Retrieve current weather data for any specified city using this API tool. Get temperature, conditions, and forecasts to integrate weather information into applications or workflows.
Instructions
Herramienta para obtener clima
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | Ciudad para obtener el clima |
Implementation Reference
- src/tools/weatherTool.ts:16-31 (handler)The main handler function for the "obtener-clima" tool. It extracts the city from params, fetches weather data using getWeather service, and returns a formatted MCP response.export async function weatherToolHandler(params: any) { const { city } = params; // Utilizamos el servicio de clima const weatherData = await getWeather(city); // Devolvemos el resultado formateado para MCP return { content: [ { type: "text" as const, text: `El clima en ${weatherData.city} es ${weatherData.condition} con una temperatura de ${weatherData.temperature}.` } ] }; }
- src/tools/weatherTool.ts:7-9 (schema)Input schema for the "obtener-clima" tool, defining the required 'city' parameter using Zod.export const weatherInputSchema = { city: z.string().describe("Ciudad para obtener el clima") };
- src/main.ts:24-31 (registration)Registration of the "obtener-clima" tool in the MCP server, linking the name, description, input schema, and handler.server.registerTool( "obtener-clima", { description: "Herramienta para obtener clima", inputSchema: weatherInputSchema }, weatherToolHandler );
- src/services/weatherService.ts:19-27 (helper)Helper function that provides mock weather data for a given city, used by the tool handler.export async function getWeather(city: string): Promise<WeatherData> { // En un caso real, aquí se haría una llamada a una API de clima // Por ahora, devolvemos datos estáticos return { city, temperature: "25°C", condition: "soleado" }; }