search_locations
Find supported locations by entering keywords to access weather data. This tool, part of the Weather MCP Server, enables precise location lookup for current conditions and forecasts.
Instructions
Search supported locations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search keyword |
Implementation Reference
- src/mock-data.ts:434-457 (handler)Core implementation of location search: normalizes query, searches locationMapping keys and mockWeatherData location names for matches, returns unique matching location names.export function searchLocationsByQuery(query: string): string[] { const normalizedQuery = query.toLowerCase(); const matchingLocations: string[] = []; // Search in location mapping Object.keys(locationMapping).forEach(key => { if (key.includes(normalizedQuery)) { const location = mockWeatherData[locationMapping[key]]?.location; if (location && !matchingLocations.includes(location)) { matchingLocations.push(location); } } }); // Search in actual location names Object.values(mockWeatherData).forEach(data => { if (data.location.toLowerCase().includes(normalizedQuery) && !matchingLocations.includes(data.location)) { matchingLocations.push(data.location); } }); return matchingLocations; }
- src/weather-service.ts:70-73 (helper)WeatherService method that delegates search_locations tool execution to the core searchLocationsByQuery helper.async searchLocations(query: string): Promise<string[]> { // Use the enhanced search function from mock-data return searchLocationsByQuery(query); }
- src/index.ts:156-167 (handler)Primary MCP server handler for search_locations tool call: extracts query from args, invokes WeatherService.searchLocations, returns JSON stringified result.case 'search_locations': { const { query } = args as { query: string }; const locations = await this.weatherService.searchLocations(query); return { content: [ { type: 'text', text: JSON.stringify(locations, null, 2), }, ], }; }
- src/index.ts:85-98 (schema)Tool schema and registration in listTools response: defines name, description, and input schema requiring a 'query' string parameter.{ name: 'search_locations', description: 'Search supported locations', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search keyword', }, }, required: ['query'], }, },
- src/index.ts:35-109 (registration)Registration of tools list handler that includes the search_locations tool definition.this.server.setRequestHandler(ListToolsRequestSchema, async () => { return { tools: [ { name: 'get_current_weather', description: 'Get current weather information for a specified location', inputSchema: { type: 'object', properties: { location: { type: 'string', description: 'Location name (e.g., Hong Kong, Tokyo, London)', }, }, required: ['location'], }, }, { name: 'get_weather_forecast', description: 'Get weather forecast for a specified location', inputSchema: { type: 'object', properties: { location: { type: 'string', description: 'Location name', }, days: { type: 'number', description: 'Forecast days (1-7 days, default is 3 days)', minimum: 1, maximum: 7, }, }, required: ['location'], }, }, { name: 'get_weather_alerts', description: 'Get weather alert information', inputSchema: { type: 'object', properties: { location: { type: 'string', description: 'Location name (optional, if not provided, get all alerts)', }, }, }, }, { name: 'search_locations', description: 'Search supported locations', inputSchema: { type: 'object', properties: { query: { type: 'string', description: 'Search keyword', }, }, required: ['query'], }, }, { name: 'get_weather_stats', description: 'Get weather statistics information', inputSchema: { type: 'object', properties: {}, }, }, ] as Tool[], }; });