Skip to main content
Glama
ronantakizawa

GIS Data Conversion MCP

coordinates_to_location

Convert latitude and longitude coordinates into human-readable location names using reverse geocoding to identify places on maps.

Instructions

Convert latitude/longitude coordinates to location name using reverse geocoding

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
latitudeYesLatitude coordinate
longitudeYesLongitude coordinate

Implementation Reference

  • The handler function for 'coordinates_to_location' that performs reverse geocoding via HTTPS request to Nominatim OSM service, parsing the JSON response to return location details including display_name, address, type, etc.
    async coordinatesToLocation(args: any): Promise<ToolResponse> {
      const { latitude, longitude } = args;
      
      if (latitude === undefined || longitude === undefined) {
        throw new McpError(
          ErrorCode.InvalidParams,
          'Missing required parameters: latitude, longitude'
        );
      }
      
      try {
        console.error(`[Converting] Coordinates (${latitude}, ${longitude}) to location name`);
        
        // Using Nominatim OSM service (free, but has usage limitations)
        const url = `https://nominatim.openstreetmap.org/reverse?format=json&lat=${latitude}&lon=${longitude}`;
        
        return new Promise<ToolResponse>((resolve, reject) => {
          // Use the imported https module directly
          const req = https.request(url, {
            method: 'GET',
            headers: {
              'User-Agent': 'GisFormatMcpServer/1.0'
            }
          }, (res) => {
            if (res.statusCode !== 200) {
              reject(new Error(`Geocoding service returned ${res.statusCode}: ${res.statusMessage}`));
              return;
            }
            
            let data = '';
            res.on('data', (chunk) => {
              data += chunk;
            });
            
            res.on('end', () => {
              try {
                const parsedData = JSON.parse(data);
                
                // Always return detailed format
                const result = {
                  displayName: parsedData.display_name,
                  address: parsedData.address,
                  type: parsedData.type,
                  osmId: parsedData.osm_id,
                  osmType: parsedData.osm_type,
                  category: parsedData.category
                };
                
                resolve(this.formatToolResponse(JSON.stringify(result, null, 2)));
              } catch (error) {
                reject(new Error(`Failed to parse geocoding response: ${error instanceof Error ? error.message : String(error)}`));
              }
            });
          });
          
          req.on('error', (error) => {
            reject(new Error(`Geocoding request failed: ${error.message}`));
          });
          
          req.end();
        });
      } catch (error) {
        console.error('[Error] Coordinates to location conversion failed:', error);
        throw new McpError(
          ErrorCode.InternalError,
          `Coordinates to location conversion failed: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Input schema definition for the coordinates_to_location tool, specifying latitude and longitude as required number properties.
    inputSchema: {
      type: 'object',
      properties: {
        latitude: {
          type: 'number',
          description: 'Latitude coordinate',
        },
        longitude: {
          type: 'number',
          description: 'Longitude coordinate',
        }
      },
      required: ['latitude', 'longitude'],
    },
  • src/index.ts:255-272 (registration)
    Registration of the coordinates_to_location tool in the ListTools response, including name, description, and input schema.
    {
      name: 'coordinates_to_location',
      description: 'Convert latitude/longitude coordinates to location name using reverse geocoding',
      inputSchema: {
        type: 'object',
        properties: {
          latitude: {
            type: 'number',
            description: 'Latitude coordinate',
          },
          longitude: {
            type: 'number',
            description: 'Longitude coordinate',
          }
        },
        required: ['latitude', 'longitude'],
      },
    }

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/ronantakizawa/gis-dataconvertersion-mcp'

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