Skip to main content
Glama
Yang-Charles

Amap (Gaode Maps) MCP Server

by Yang-Charles

locate_ip

Find geographic location details including province, city, coordinates, and district for any IP address using Amap's geolocation service.

Instructions

获取用户的 IP 地址定位信息,返回省市区经纬度等信息。

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
ipNo用户的ip地址

Output Schema

TableJSON Schema
NameRequiredDescriptionDefault
dataNo
metaNo
errorNo
successYes

Implementation Reference

  • MCP tool handler for 'locate_ip': decorated function that takes optional IP, calls GdSDK.locate_ip, logs, and returns ApiResponse with location data or error.
    @mcp.tool(name="locate_ip", description="获取用户的 IP 地址定位信息,返回省市区经纬度等信息。")
    async def locate_ip(ip: Annotated[Optional[str], Field(description="用户的ip地址")] = None) -> ApiResponse:
      """
      根据 IP 地址定位位置。
    
      Args:
          ip (str): 要定位的 IP 地址。
    
      Returns:
          dict: 包含定位结果的字典。
      """
      logger.info(f"Locating IP: {ip}")
      try:
        result = await sdk.locate_ip(ip)
        if not result:
          ApiResponse.fail("定位结果为空,请检查日志,系统异常请检查相关日志,日志默认路径为/var/log/build_mcp。")
        logger.info(f"Locate IP result: {result}")
        return ApiResponse.ok(data=result, meta={"ip": ip})
      except Exception as e:
        logger.error(f"Error locating IP {ip}: {e}")
        return ApiResponse.fail(str(e))
  • Pydantic BaseModel defining the ApiResponse schema used for input validation and output typing in the locate_ip tool.
    T = TypeVar("T")
    
    
    class ApiResponse(BaseModel, Generic[T]):
      success: bool
      data: Optional[T] = None
      error: Optional[str] = None
      meta: Optional[Dict[str, Any]] = None
    
      @classmethod
      def ok(cls, data: T, meta: Dict[str, Any] = None) -> "ApiResponse[T]":
        return cls(success=True, data=data, meta=meta)
    
      @classmethod
      def fail(cls, error: str, meta: Dict[str, Any] = None) -> "ApiResponse[None]":
        return cls(success=False, error=error, meta=meta)
  • GdSDK helper method implementing the actual IP geolocation API call to Amap with retry logic.
    async def locate_ip(self, ip: str = None) -> Any | None:
      """
      IP定位接口
      https://lbs.amap.com/api/webservice/guide/api/ipconfig
    
      Args:
          ip (str, optional): 要查询的 IP,若为空,则使用请求方公网 IP。
    
      Returns:
          dict: 定位结果,若失败则返回 None。
      """
      url = f"{self.base_url}/v3/ip"
      params = {
        "key": self.api_key,
      }
      if ip:
        params["ip"] = ip
    
      result = await self._request_with_retry(
        method="GET",
        url=url,
        params=params
      )
    
      if result and result.get("status") == "1":
        return result
      else:
        self.logger.error(f"IP定位失败: {result}")
        return None
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It mentions the output format but doesn't describe error handling, rate limits, authentication needs, or whether the tool is read-only or has side effects. For a tool with no annotation coverage, this is a significant gap in transparency.

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

Conciseness4/5

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

The description is a single, efficient sentence that front-loads the purpose and output. It avoids unnecessary words, though it could be slightly more structured (e.g., separating purpose from output details).

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

Completeness3/5

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

Given the tool's low complexity (1 parameter, no nested objects) and the presence of an output schema, the description is minimally adequate. However, it lacks behavioral context (e.g., error cases, performance), which is needed since no annotations are provided. The output schema likely covers return values, so the description doesn't need to detail them.

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

Parameters3/5

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

The input schema has 100% description coverage, with the parameter 'ip' documented as '用户的ip地址' (user's IP address). The description doesn't add meaning beyond the schema, such as explaining default behavior when 'ip' is null or providing examples. Baseline 3 is appropriate since the schema does the heavy lifting.

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

Purpose4/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: '获取用户的 IP 地址定位信息' (get user's IP address location information) and specifies the output '返回省市区经纬度等信息' (returns province, city, district, latitude/longitude, etc.). It uses specific verbs and resources, though it doesn't explicitly differentiate from the sibling tool 'search_nearby'.

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

Usage Guidelines2/5

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

The description provides no guidance on when to use this tool versus alternatives like 'search_nearby'. It lacks context about use cases, prerequisites, or exclusions, leaving the agent to infer usage from the purpose alone.

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/Yang-Charles/build-mcp'

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