geocode
Convert city names or addresses into latitude and longitude coordinates using the Nominatim OpenStreetMap API for location-based applications.
Instructions
도시 이름이나 주소를 입력하면 위도(lat)와 경도(lon) 좌표를 반환합니다. Nominatim OpenStreetMap API를 사용합니다.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | 검색할 도시 이름 또는 주소 (예: 서울, Tokyo, Paris) |
Output Schema
| Name | Required | Description | Default |
|---|---|---|---|
| content | Yes |
Implementation Reference
- src/index.ts:143-198 (handler)The 'geocode' tool is registered using `server.registerTool` in `src/index.ts`. It takes a `query` string and uses the Nominatim OpenStreetMap API to retrieve the geographical coordinates (latitude and longitude) for the given location.
server.registerTool( 'geocode', { description: '도시 이름이나 주소를 입력하면 위도(lat)와 경도(lon) 좌표를 반환합니다. Nominatim OpenStreetMap API를 사용합니다.', inputSchema: z.object({ query: z.string().describe('검색할 도시 이름 또는 주소 (예: 서울, Tokyo, Paris)') }), outputSchema: z.object({ content: z.array( z.object({ type: z.literal('text'), text: z.string().describe('위도/경도 좌표 결과') }) ) }) }, async ({ query }) => { const url = `https://nominatim.openstreetmap.org/search?q=${encodeURIComponent(query)}&format=json&limit=1` const response = await fetch(url, { headers: { 'User-Agent': 'MCP-Geocode-Tool/1.0' } }) if (!response.ok) { const errorText = `오류: API 요청 실패 (상태 코드: ${response.status})` return { content: [{ type: 'text' as const, text: errorText }], structuredContent: { content: [{ type: 'text' as const, text: errorText }] } } } const results = (await response.json()) as Array<{ lat: string lon: string display_name: string }> if (results.length === 0) { const errorText = `"${query}"에 대한 검색 결과가 없습니다.` return { content: [{ type: 'text' as const, text: errorText }], structuredContent: { content: [{ type: 'text' as const, text: errorText }] } } } const { lat, lon, display_name } = results[0] const text = `📍 ${display_name}\n위도(lat): ${lat}\n경도(lon): ${lon}` return { content: [{ type: 'text' as const, text }], structuredContent: { content: [{ type: 'text' as const, text }] } } } )