zaragoza-bus-stops
Find bus stops in Zaragoza by entering coordinates to access public transport locations and plan routes.
Instructions
Get all bus stops in Zaragoza
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude | Yes | ||
| longitude | Yes |
Implementation Reference
- index.js:80-99 (handler)Handler function that fetches bus stops from the API, computes nearest positions using helpers, and returns formatted content or error message.async ({ latitude, longitude }) => { const response = await fetch("https://dndzgz.herokuapp.com/services/bus"); if (response.ok) { const data = await response.json(); const nearestPositions = getTopNearestPositions( data.locations, latitude, longitude ); return { content: [{ type: "text", text: JSON.stringify(nearestPositions) }], }; } else { return { content: [ { type: "text", text: "It was not possible to get the bus stops" }, ], }; } }
- index.js:76-79 (schema)Zod schema defining input parameters: latitude and longitude as numbers.{ latitude: z.number(), longitude: z.number(), },
- index.js:73-100 (registration)Tool registration call using McpServer.tool() with name, description, input schema, and handler function.server.tool( "zaragoza-bus-stops", "Get all bus stops in Zaragoza", { latitude: z.number(), longitude: z.number(), }, async ({ latitude, longitude }) => { const response = await fetch("https://dndzgz.herokuapp.com/services/bus"); if (response.ok) { const data = await response.json(); const nearestPositions = getTopNearestPositions( data.locations, latitude, longitude ); return { content: [{ type: "text", text: JSON.stringify(nearestPositions) }], }; } else { return { content: [ { type: "text", text: "It was not possible to get the bus stops" }, ], }; } } );
- index.js:259-264 (helper)Helper to retrieve the top N nearest positions from an ordered list (default 10).function getTopNearestPositions(positions, latitude, longitude, size = 10) { return getOrderedPositionsByDistance(positions, latitude, longitude).slice( 0, size ); }
- index.js:266-279 (helper)Helper to compute distances using haversine formula and sort positions by distance.function getOrderedPositionsByDistance(positions, latitude, longitude) { return positions .map((position) => { const distanceInMeters = haversineDistanceInMeters( { lat: latitude, lon: longitude }, position ); return { ...position, distanceInMeters, }; }) .sort((a, b) => a.distanceInMeters - b.distanceInMeters); }
- index.js:281-297 (helper)Haversine formula implementation to calculate distance between two lat/lon positions in meters.function haversineDistanceInMeters(position1, position2) { const toRadians = (degrees) => degrees * (Math.PI / 180); const radiusOfEarth = 6371; const dLat = toRadians(position2.lat - position1.lat); const dLon = toRadians(position2.lon - position1.lon); const a = Math.sin(dLat / 2) * Math.sin(dLat / 2) + Math.cos(toRadians(position1.lat)) * Math.cos(toRadians(position2.lat)) * Math.sin(dLon / 2) * Math.sin(dLon / 2); const c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); return radiusOfEarth * c * 1000; }