mastra-ai/mastra · error · Error
Location '${location}' not found
Error message
Location '${location}' not found What it means
getWeather geocodes a free-text location via the Open-Meteo geocoding API. If the response contains no results (results array empty or absent), the code throws 'Location "X" not found'. This happens for misspelled place names, overly specific strings, or places the geocoder does not know.
Source
Thrown at packages/mcp/src/__fixtures__/tools.ts:41
export const weatherTool = createTool({
id: 'get-weather',
description: 'Get current weather for a location',
inputSchema: z.object({
location: z.string().describe('City name'),
}),
execute: async input => {
console.info('weather tool', input);
return await getWeather(input.location);
},
});
const getWeather = async (location: string) => {
const geocodingUrl = `https://geocoding-api.open-meteo.com/v1/search?name=${encodeURIComponent(location)}&count=1`;
const geocodingResponse = await fetch(geocodingUrl);
const geocodingData = (await geocodingResponse.json()) as GeocodingResponse;
if (!geocodingData.results?.[0]) {
throw new Error(`Location '${location}' not found`);
}
const { latitude, longitude, name } = geocodingData.results[0];
const weatherUrl = `https://api.open-meteo.com/v1/forecast?latitude=${latitude}&longitude=${longitude}¤t=temperature_2m,apparent_temperature,relative_humidity_2m,wind_speed_10m,wind_gusts_10m,weather_code`;
const response = await fetch(weatherUrl);
const data = (await response.json()) as WeatherResponse;
return {
temperature: data.current.temperature_2m,
feelsLike: data.current.apparent_temperature,
humidity: data.current.relative_humidity_2m,
windSpeed: data.current.wind_speed_10m,
windGust: data.current.wind_gusts_10m,
conditions: getWeatherCondition(data.current.weather_code),
location: name,
};View on GitHub (pinned to 75dd419e61)
Solutions
- Correct the spelling or use a canonical place/city name ('San Francisco' not 'SF the city by the bay').
- Disambiguate with country/state, e.g. 'Springfield, Illinois'.
- Retry if the geocoding API returned an unexpected empty response (transient outage).
- Pre-resolve coordinates yourself and skip geocoding if you already know lat/lon.
Example fix
// before
await getWeather("silicon valley hq");
// after
await getWeather("San Jose, California"); Defensive patterns
Strategy: fallback
Validate before calling
// Pre-check the location string before calling the tool:
function isPlausibleLocation(loc) {
return typeof loc === 'string' && loc.trim().length >= 2 && /[a-zA-Z\u00C0-\u024F]/.test(loc);
}
if (!isPlausibleLocation(userInput)) throw new TypeError('Provide a real place name, e.g. "Paris, France"'); Type guard
function isGeocodingHit(res: unknown): res is { results: Array<{ latitude: number; longitude: number; name: string }> } {
return typeof res === 'object' && res !== null &&
Array.isArray((res as any).results) && (res as any).results.length > 0;
} Try / catch
async function getWeatherSafe(location) {
try {
return await getWeather(location);
} catch (e) {
if (e instanceof Error && e.message.includes('not found')) {
// fallback: retry with disambiguated name, or inform the user
const alt = location.includes(',') ? location : location + ', ' + userCountryHint;
if (alt !== location) return getWeatherSafe(alt);
return { error: `Location "${location}" not found; try a canonical city name` };
}
throw e;
}
} Prevention
- Normalize user input: trim, fix casing, append country/state for ambiguous names.
- Offer an autocomplete/disambiguation step before calling the weather tool.
- Cache resolved geocoding results for repeat queries.
- Handle empty geocoding responses defensively even without an exception (results may be missing entirely).
When it happens
Trigger: Calling weatherTool with a location string that Open-Meteo geocoding cannot resolve: misspellings ('Nuuk' vs 'Nuugg'), non-city strings ('my house'), locations with only partial matches, or empty/whitespace-only strings.
Common situations: LLM agents passing imprecise location names; users entering addresses or POI names when the API only geocodes settlements; encoding/locale issues; transient upstream geocoding outages returning empty results.
Related errors
- Location '${inputData.city}' not found
- Model "${modelId}" is not available. Available models: ${ids
- ACP connection is not initialized
- Model "${this.options.model}" is not available. Available mo
- ClaudeSDKAgent resumeData must include either sessionId or c
AI-assisted analysis of mastra-ai/mastra@75dd419e61 (2026-08-30).
Data as JSON: /api/errors/763c56c931409ddf.
Report an issue: GitHub.