geolocation-from-address
Convert a physical address in Zaragoza into precise geolocation coordinates (latitude, longitude) and a formatted address. Useful for locating bus stops, tram stations, or bizi stations within the city.
Instructions
Get the geolocation (latitude and longitude) from an address and the formatted address that was found, only for Zaragoza. Can be used to find a bus stops, tram stations or bizi stations
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes |
Implementation Reference
- index.js:206-252 (handler)The handler function for the 'geolocation-from-address' tool. It fetches the geolocation (lat, lng) and formatted address from Google's Geocoding API for addresses in Zaragoza, Spain. Requires GOOGLE_MAPS_API_KEY env var. Returns JSON string of location data or error messages.async ({ address }) => { const GOOGLE_MAPS_API_KEY = process.env.GOOGLE_MAPS_API_KEY; if (!GOOGLE_MAPS_API_KEY) { return { content: [ { type: "text", text: "You should configure the GOOGLE_MAPS_API_KEY for MCP DNDzgz", }, ], }; } const encodedAddress = encodeURIComponent(`${address}, Zaragoza, Spain`); const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}&key=${GOOGLE_MAPS_API_KEY}`; const response = await fetch(url); if (response.ok) { const data = await response.json(); if (data.status === "OK" && data.results.length > 0) { const location = data.results[0].geometry.location; location.confindence = data.results[0].geometry.location_type; location.formatted_address = data.results[0].formatted_address; return { content: [{ type: "text", text: JSON.stringify(location) }], }; } else { return { content: [ { type: "text", text: `No geolocation found for the address: ${address}`, }, ], }; } } else { return { content: [ { type: "text", text: `Failed to fetch geolocation for the address: ${address}`, }, ], }; } }
- index.js:203-205 (schema)Input schema for the tool: requires 'address' as a string.{ address: z.string(), },
- index.js:200-253 (registration)Registration of the 'geolocation-from-address' tool on the MCP server, specifying name, description, input schema, and handler function.server.tool( "geolocation-from-address", "Get the geolocation (latitude and longitude) from an address and the formatted address that was found, only for Zaragoza. Can be used to find a bus stops, tram stations or bizi stations", { address: z.string(), }, async ({ address }) => { const GOOGLE_MAPS_API_KEY = process.env.GOOGLE_MAPS_API_KEY; if (!GOOGLE_MAPS_API_KEY) { return { content: [ { type: "text", text: "You should configure the GOOGLE_MAPS_API_KEY for MCP DNDzgz", }, ], }; } const encodedAddress = encodeURIComponent(`${address}, Zaragoza, Spain`); const url = `https://maps.googleapis.com/maps/api/geocode/json?address=${encodedAddress}&key=${GOOGLE_MAPS_API_KEY}`; const response = await fetch(url); if (response.ok) { const data = await response.json(); if (data.status === "OK" && data.results.length > 0) { const location = data.results[0].geometry.location; location.confindence = data.results[0].geometry.location_type; location.formatted_address = data.results[0].formatted_address; return { content: [{ type: "text", text: JSON.stringify(location) }], }; } else { return { content: [ { type: "text", text: `No geolocation found for the address: ${address}`, }, ], }; } } else { return { content: [ { type: "text", text: `Failed to fetch geolocation for the address: ${address}`, }, ], }; } } );