search_cities
Search for cities by name to retrieve their coordinates using the Weather MCP Server, enabling precise location-based weather data access.
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)The main handler function for the 'search_cities' tool. It queries the Open-Meteo geocoding API with the input query, fetches up to 10 matching cities, and returns a formatted text response listing each city with name, coordinates, region, country, and 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:126-135 (schema)Input schema definition for the search_cities tool, specifying that it requires a 'query' string parameter.inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Nom de la ville à rechercher' } }, required: ['query'], },
- src/index.js:123-136 (registration)Tool metadata registration in the ListTools response, including name, description, and full input schema.{ 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 search_cities tool call to the handler method within the CallToolRequest switch statement.case 'search_cities': return await this.searchCities(args.query);