search_cities
Find city coordinates by name to enable accurate weather data retrieval for specific locations.
Instructions
Recherche des villes par nom pour obtenir leurs coordonnées
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Nom de la ville à rechercher |
Implementation Reference
- src/index.js:364-393 (handler)Implementation of the search_cities tool handler. Fetches city search results from Open-Meteo geocoding API, formats up to 10 results with name, coordinates, admin1, country, population.async searchCities(query) { const url = `${GEOCODING_API}?name=${encodeURIComponent(query)}&count=10&language=fr&format=json`; const response = await fetch(url); const data = await response.json(); if (!response.ok || !data.results) { throw new Error(`Aucune ville trouvée pour "${query}"`); } let resultText = `🔍 Villes trouvées pour "${query}":\n\n`; data.results.forEach((city, index) => { resultText += `${index + 1}. **${city.name}**\n`; resultText += ` 📍 ${city.latitude}°, ${city.longitude}°\n`; if (city.admin1) resultText += ` 🏛️ ${city.admin1}\n`; if (city.country) resultText += ` 🌍 ${city.country}\n`; if (city.population) resultText += ` 👥 ${city.population.toLocaleString()} habitants\n`; resultText += `\n`; }); return { content: [ { type: 'text', text: resultText.trim(), }, ], }; }
- src/index.js:123-136 (schema)Tool schema definition in the ListTools response, including name, description, and input schema requiring a 'query' string.{ name: 'search_cities', description: 'Recherche des villes par nom pour obtenir leurs coordonnées', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Nom de la ville à rechercher' } }, required: ['query'], }, },
- src/index.js:159-160 (registration)Dispatch/registration of the tool handler in the CallToolRequestSchema switch statement.case 'search_cities': return await this.searchCities(args.query);