Skip to main content
Glama

Travel MCP

by Erredebe
geocode.ts1.49 kB
import { z } from "zod"; import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js"; export function registerGeocode(server: McpServer) { server.tool( "geocode", "Convert an address or place name to coordinates using OpenStreetMap Nominatim", { query: z.string().describe("Address or place name"), }, async ({ query }) => { const url = `https://nominatim.openstreetmap.org/search?format=json&q=${encodeURIComponent(query)}`; const ctrl = new AbortController(); const id = setTimeout(() => ctrl.abort(), 8000); try { const res = await fetch(url, { headers: { "User-Agent": "mcp/1.0" }, signal: ctrl.signal, }); const data = await res.json(); if (!Array.isArray(data) || data.length === 0) { return { content: [ { type: "text", text: `No results for ${query}.` } ], }; } const { lat, lon, display_name } = data[0]; return { content: [ { type: "text", text: JSON.stringify({ latitude: lat, longitude: lon, display_name }, null, 2), }, ], }; } catch (err: any) { return { content: [ { type: "text", text: JSON.stringify({ error: err.message }), }, ], }; } finally { clearTimeout(id); } } ); }

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/Erredebe/travel-mcp'

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