Skip to main content
Glama
jikime

Python MCP Korea Weather Service

get_grid_location

Retrieve grid coordinates (nx, ny) for Korean weather API calls by entering city, district, and neighborhood details to enable accurate weather data queries.

Instructions

한국 기상청 API에 사용되는 격자 좌표(nx, ny)를 조회합니다. 사용자가 입력한 시/도, 구/군, 동/읍/면 정보를 바탕으로 해당 지역의 기상청 격자 좌표를 데이터베이스에서 검색하여 반환합니다. 이 도구는 기상청 API 호출에 필요한 정확한 좌표값을 얻기 위해 필수적으로 사용됩니다.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
cityYes
guYes
dongYes

Implementation Reference

  • The handler function that executes the get_grid_location tool logic: connects to SQLite DB, queries with LIKE for city/gu/dong, parses result, returns formatted location and grid coordinates (nx, ny).
    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)
    Registers the get_grid_location tool in the MCP server using the @mcp.tool decorator, specifying name and detailed description.
    @mcp.tool( name="get_grid_location", description="한국 기상청 API에 사용되는 격자 좌표(nx, ny)를 조회합니다. 사용자가 입력한 시/도, 구/군, 동/읍/면 정보를 바탕으로 해당 지역의 기상청 격자 좌표를 데이터베이스에서 검색하여 반환합니다. 이 도구는 기상청 API 호출에 필요한 정확한 좌표값을 얻기 위해 필수적으로 사용됩니다." )
  • Defines input schema with type hints (city: str, gu: str, dong: str) -> str and docstring describing parameters.
    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동) """
  • main.py:4-40 (helper)
    Standalone helper function implementing grid location lookup with exact matching, returning (nx, ny) tuple or None.
    def get_grid_location(city, gu, dong): """ 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동) Returns: tuple: (nx, ny) grid coordinates or None if not found """ db_path = Path(__file__).parent / "data" / "weather_grid.db" if not db_path.exists(): raise FileNotFoundError(f"Database not found: {db_path}") conn = sqlite3.connect(db_path) cursor = conn.cursor() try: cursor.execute( """ SELECT grid_x, grid_y FROM weather_grid WHERE level1 = ? AND level2 = ? AND level3 = ? """, (city, gu, dong) ) result = cursor.fetchone() if result: return result else: return None finally: conn.close()

Other Tools

Latest Blog Posts

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/jikime/py-mcp-ko-weather'

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