zaragoza-bizi-stations
Find bicycle rental stations in Zaragoza by entering your location coordinates to access the public Bizi service network.
Instructions
Get all Bizi stations in Zaragoza, the bicycle rental public service
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| latitude | Yes | ||
| longitude | Yes |
Implementation Reference
- index.js:135-157 (handler)Handler function fetches Bizi stations data from API, computes the top nearest stations based on provided latitude and longitude using helper functions, and returns JSON stringified nearest positions.async ({ latitude, longitude }) => { const response = await fetch("https://dndzgz.herokuapp.com/services/bizi"); 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 Bizi stations", }, ], }; } }
- index.js:131-134 (schema)Zod schema defining required input parameters: latitude and longitude as numbers.{ latitude: z.number(), longitude: z.number(), },
- index.js:128-158 (registration)Registration of the zaragoza-bizi-stations tool on the MCP server, including name, description, input schema, and inline handler function.server.tool( "zaragoza-bizi-stations", "Get all Bizi stations in Zaragoza, the bicycle rental public service", { latitude: z.number(), longitude: z.number(), }, async ({ latitude, longitude }) => { const response = await fetch("https://dndzgz.herokuapp.com/services/bizi"); 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 Bizi stations", }, ], }; } } );
- index.js:259-263 (helper)Helper function that gets the top N (default 10) nearest positions by slicing the ordered list.function getTopNearestPositions(positions, latitude, longitude, size = 10) { return getOrderedPositionsByDistance(positions, latitude, longitude).slice( 0, size );
- index.js:281-297 (helper)Helper function computing haversine distance in meters between two positions, used in sorting nearest stations.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; }