get_grid_location
Retrieve grid coordinates (nx, ny) for Korean weather data by inputting city, district, and neighborhood details. Essential for accurate API calls to the Korea Meteorological Administration.
Instructions
한국 기상청 API에 사용되는 격자 좌표(nx, ny)를 조회합니다. 사용자가 입력한 시/도, 구/군, 동/읍/면 정보를 바탕으로 해당 지역의 기상청 격자 좌표를 데이터베이스에서 검색하여 반환합니다. 이 도구는 기상청 API 호출에 필요한 정확한 좌표값을 얻기 위해 필수적으로 사용됩니다.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| city | Yes | ||
| dong | Yes | ||
| gu | Yes |
Implementation Reference
- src/server.py:13-52 (handler)The handler function that implements the logic for the get_grid_location tool. It connects to a SQLite database, queries for grid coordinates (nx, ny) using fuzzy matching (LIKE) on city, gu, dong, and returns a formatted string with the results.def get_grid_location(city: str, gu: str, dong: str) -> str: """Get grid location(nx, ny) for Korea Weather Args: city: City Name (e.g. 서울특별시) gu: Gu Name (e.g. 서초구) dong: Dong Name (e.g. 양재1동) """ try: # Connect to SQLite database db_path = Path(__file__).parent.parent / "data" / "weather_grid.db" if not db_path.exists(): return f"Error: Database not found at {db_path}" conn = sqlite3.connect(db_path) cursor = conn.cursor() # Query the database for the grid coordinates query = """ SELECT level1, level2, level3, grid_x, grid_y FROM weather_grid WHERE level1 LIKE ? AND level2 LIKE ? AND level3 LIKE ? """ cursor.execute(query, (f"%{city}%", f"%{gu}%", f"%{dong}%")) result = cursor.fetchone() if not result: return f"No location found for City: {city}, Gu: {gu}, Dong: {dong}" level1, level2, level3, nx, ny = result # Close the connection conn.close() # Return formatted string return f"City(시): {level1}, Gu(구): {level2}, Dong(동): {level3}, Nx: {nx}, Ny: {ny}" except Exception as e: return f"Error retrieving grid location: {str(e)}"
- src/server.py:9-12 (registration)The @mcp.tool decorator that registers the get_grid_location tool, specifying its name and description for the MCP server.@mcp.tool( name="get_grid_location", description="한국 기상청 API에 사용되는 격자 좌표(nx, ny)를 조회합니다. 사용자가 입력한 시/도, 구/군, 동/읍/면 정보를 바탕으로 해당 지역의 기상청 격자 좌표를 데이터베이스에서 검색하여 반환합니다. 이 도구는 기상청 API 호출에 필요한 정확한 좌표값을 얻기 위해 필수적으로 사용됩니다." )