Skip to main content
Glama
robertn702

OpenWeatherMap MCP Server

get-location-info

Retrieve precise location details using latitude and longitude coordinates through reverse geocoding, enabling accurate identification of geographic areas for enhanced weather and location-based services.

Instructions

Get location information from coordinates (reverse geocoding)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYesLatitude coordinate
longitudeYesLongitude coordinate

Implementation Reference

  • The complete handler implementation for the 'get-location-info' tool, registered inline with server.addTool(). Performs reverse geocoding by setting coordinates on the OpenWeather client and calling client.getLocation() to retrieve location name, country, state, etc.
    server.addTool({
      name: "get-location-info",
      description: "Get location information from coordinates (reverse geocoding)",
      parameters: getLocationInfoSchema,
      execute: async (args, { session, log }) => {
        try {
          log.info("Getting location info", { 
            latitude: args.latitude,
            longitude: args.longitude
          });
          
          // Get OpenWeather client
          const client = getOpenWeatherClient(session as SessionData | undefined);
          
          // Set coordinates directly for reverse geocoding
          client.setLocationByCoordinates(args.latitude, args.longitude);
          
          // Fetch location data using reverse geocoding
          const locationData = await client.getLocation();
          
          log.info("Successfully retrieved location info", { 
            latitude: args.latitude,
            longitude: args.longitude,
            location_name: locationData?.name
          });
          
          // Format the response
          const formattedLocation = JSON.stringify({
            coordinates: {
              latitude: args.latitude,
              longitude: args.longitude
            },
            location: locationData ? {
              name: locationData.name,
              country: locationData.country,
              state: locationData.state,
              local_names: locationData.local_names
            } : {
              message: "No location data found for these coordinates"
            }
          }, null, 2);
          
          return {
            content: [
              {
                type: "text",
                text: formattedLocation
              }
            ]
          };
        } catch (error) {
          log.error("Failed to get location info", { 
            error: error instanceof Error ? error.message : 'Unknown error' 
          });
          
          // Provide helpful error messages
          if (error instanceof Error) {
            if (error.message.includes('Invalid coordinates')) {
              throw new Error(`Invalid coordinates: latitude must be between -90 and 90, longitude must be between -180 and 180.`);
            }
            if (error.message.includes('Invalid API key')) {
              throw new Error('Invalid OpenWeatherMap API key. Please check your configuration.');
            }
          }
          
          throw new Error(`Failed to get location info: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    });
  • Zod input schema defining required latitude and longitude parameters with validation ranges for the get-location-info tool.
    export const getLocationInfoSchema = z.object({
      latitude: z.number().min(-90).max(90).describe("Latitude coordinate"),
      longitude: z.number().min(-180).max(180).describe("Longitude coordinate"),
    });
  • src/main.ts:629-697 (registration)
    Registration of the 'get-location-info' tool using FastMCP server.addTool(), specifying name, description, parameters schema, and execute handler.
    server.addTool({
      name: "get-location-info",
      description: "Get location information from coordinates (reverse geocoding)",
      parameters: getLocationInfoSchema,
      execute: async (args, { session, log }) => {
        try {
          log.info("Getting location info", { 
            latitude: args.latitude,
            longitude: args.longitude
          });
          
          // Get OpenWeather client
          const client = getOpenWeatherClient(session as SessionData | undefined);
          
          // Set coordinates directly for reverse geocoding
          client.setLocationByCoordinates(args.latitude, args.longitude);
          
          // Fetch location data using reverse geocoding
          const locationData = await client.getLocation();
          
          log.info("Successfully retrieved location info", { 
            latitude: args.latitude,
            longitude: args.longitude,
            location_name: locationData?.name
          });
          
          // Format the response
          const formattedLocation = JSON.stringify({
            coordinates: {
              latitude: args.latitude,
              longitude: args.longitude
            },
            location: locationData ? {
              name: locationData.name,
              country: locationData.country,
              state: locationData.state,
              local_names: locationData.local_names
            } : {
              message: "No location data found for these coordinates"
            }
          }, null, 2);
          
          return {
            content: [
              {
                type: "text",
                text: formattedLocation
              }
            ]
          };
        } catch (error) {
          log.error("Failed to get location info", { 
            error: error instanceof Error ? error.message : 'Unknown error' 
          });
          
          // Provide helpful error messages
          if (error instanceof Error) {
            if (error.message.includes('Invalid coordinates')) {
              throw new Error(`Invalid coordinates: latitude must be between -90 and 90, longitude must be between -180 and 180.`);
            }
            if (error.message.includes('Invalid API key')) {
              throw new Error('Invalid OpenWeatherMap API key. Please check your configuration.');
            }
          }
          
          throw new Error(`Failed to get location info: ${error instanceof Error ? error.message : 'Unknown error'}`);
        }
      }
    });
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries full burden but offers minimal behavioral insight. It doesn't disclose whether this is a read-only operation, potential rate limits, authentication needs, error handling (e.g., invalid coordinates), or what happens with edge cases (e.g., coordinates over water). The phrase 'reverse geocoding' hints at a standard mapping service behavior, but lacks specifics needed for full transparency.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the core purpose ('Get location information') and adds clarifying context ('from coordinates (reverse geocoding)'). There is zero wasted verbiage, making it highly concise and well-structured for quick understanding.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (reverse geocoding with 2 parameters), no annotations, and no output schema, the description is incomplete. It fails to explain what information is returned (e.g., address components, place types), potential limitations (e.g., coverage areas, accuracy), or how results are structured. This leaves significant gaps for an agent to use the tool effectively.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 100%, with clear descriptions for latitude and longitude parameters including valid ranges. The description adds no additional parameter semantics beyond what's in the schema, such as coordinate format (e.g., decimal degrees), precision requirements, or examples. Baseline 3 is appropriate since the schema adequately documents parameters.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the action ('Get location information') and the method ('from coordinates (reverse geocoding)'), which distinguishes it from sibling tools like 'geocode-location' (likely forward geocoding). However, it doesn't specify what type of location information is returned (e.g., address, place name, administrative details), leaving some ambiguity.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines3/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description implies usage when you have coordinates and need location information, but provides no explicit guidance on when to use this versus alternatives like 'geocode-location' (which likely converts addresses to coordinates). There's no mention of prerequisites, error conditions, or performance considerations, leaving usage context partially implied rather than clearly defined.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

Related Tools

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/robertn702/mcp-openweathermap'

If you have feedback or need assistance with the MCP directory API, please join our Discord server