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

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
resultYes

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()
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It describes the action (retrieves from database), input basis (administrative divisions), and purpose (obtain coordinates for API calls). However, it lacks details on error handling, database limitations, or response format, which are important for a tool with no annotation coverage.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured in three sentences: first states the tool's purpose, second explains the input-output mapping, third provides usage context. Each sentence adds essential information without redundancy, making it appropriately concise and front-loaded.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the tool's moderate complexity (3 required parameters, no annotations, but has an output schema), the description is mostly complete. It covers purpose, parameters, and usage context. The output schema likely handles return value documentation, so the description doesn't need to explain outputs. However, it could benefit from more behavioral details like error cases or data freshness.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters5/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

The input schema has 0% description coverage, so the description must compensate. It explicitly explains the meaning of all three parameters: '시/도, 구/군, 동/읍/면 정보' (city/province, district, neighborhood/town/village), clarifying that these are administrative divisions used to search the database. This adds significant value beyond the schema's bare property names.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose: '조회합니다' (retrieves) grid coordinates (nx, ny) from a database based on administrative divisions. It specifies the resource (격자 좌표), the source (한국 기상청 API), and distinguishes it from the sibling tool get_forecast by focusing on coordinate lookup rather than weather forecasting.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool: '기상청 API 호출에 필요한 정확한 좌표값을 얻기 위해 필수적으로 사용됩니다' (essential for obtaining accurate coordinates needed for Korea Meteorological Administration API calls). However, it does not explicitly mention when not to use it or name alternatives beyond the implied distinction from get_forecast.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

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