maps_ip_location
Locate geographic positions using IP addresses with the Gaode Maps MCP server tool.
Instructions
IP 定位根据用户输入的 IP 地址,定位 IP 的所在位置
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Implementation Reference
- amap_mcp_server/server.py:84-108 (handler)The handler function for the 'maps_ip_location' tool. It takes an IP address as input, queries the Amap IP geolocation API (https://restapi.amap.com/v3/ip), and returns location details including province, city, adcode, and bounding rectangle. Includes error handling for API failures.@mcp.tool() def maps_ip_location(ip: str) -> Dict[str, Any]: """IP 定位根据用户输入的 IP 地址,定位 IP 的所在位置""" try: response = requests.get( "https://restapi.amap.com/v3/ip", params={ "key": AMAP_MAPS_API_KEY, "ip": ip } ) response.raise_for_status() data = response.json() if data["status"] != "1": return {"error": f"IP Location failed: {data.get('info') or data.get('infocode')}"} return { "province": data.get("province"), "city": data.get("city"), "adcode": data.get("adcode"), "rectangle": data.get("rectangle") } except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"}
- amap_mcp_server/server.py:84-84 (registration)The @mcp.tool() decorator registers the maps_ip_location function as an MCP tool.@mcp.tool()
- amap_mcp_server/server.py:85-86 (schema)Function signature defines input schema (ip: str) and output (Dict[str, Any]). Docstring provides tool description in Chinese.def maps_ip_location(ip: str) -> Dict[str, Any]: """IP 定位根据用户输入的 IP 地址,定位 IP 的所在位置"""