compare_cities
Retrieve detailed information and distance for two cities using their unique identifiers.
Instructions
Fetch full details for two cities and the distance between them in one call.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city1 | Yes | First city UUID | |
| city2 | Yes | Second city UUID | |
| preferredLanguages | No | Comma-separated BCP 47 language tags |
Implementation Reference
- src/server.ts:281-298 (registration)The 'compare_cities' tool is registered on the MCP server via `server.tool()`, defining its name, description, Zod schema for inputs (city1 UUID, city2 UUID, optional preferredLanguages), and the async handler that fetches both city details and distance between them.
server.tool( 'compare_cities', 'Fetch full details for two cities and the distance between them in one call.', { city1: z.string().describe('First city UUID'), city2: z.string().describe('Second city UUID'), preferredLanguages: z.string().optional().describe('Comma-separated BCP 47 language tags'), }, async ({ city1, city2 }) => { const [cityA, cityB, dist] = await Promise.all([ client.cities.get(city1), client.cities.get(city2), client.cities.distance(city1, city2), ]); const result = { city1: cityA, city2: cityB, distanceKm: dist.distanceKm }; return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }, ); - src/server.ts:289-297 (handler)The async handler function that executes the tool logic: it calls `client.cities.get()` for both cities and `client.cities.distance()` concurrently via Promise.all, then returns the combined result with city details and distance in km.
async ({ city1, city2 }) => { const [cityA, cityB, dist] = await Promise.all([ client.cities.get(city1), client.cities.get(city2), client.cities.distance(city1, city2), ]); const result = { city1: cityA, city2: cityB, distanceKm: dist.distanceKm }; return { content: [{ type: 'text', text: JSON.stringify(result, null, 2) }] }; }, - src/server.ts:284-288 (schema)Zod schema defining the tool's input parameters: city1 (string UUID), city2 (string UUID), and optional preferredLanguages (comma-separated BCP 47 tags).
{ city1: z.string().describe('First city UUID'), city2: z.string().describe('Second city UUID'), preferredLanguages: z.string().optional().describe('Comma-separated BCP 47 language tags'), },