maps_ip_location
Locate geographic positions using IP addresses to determine physical locations and map coordinates for network analysis and location-based services.
Instructions
IP 定位根据用户输入的 IP 地址,定位 IP 的所在位置
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| ip | Yes |
Input Schema (JSON Schema)
{
"properties": {
"ip": {
"title": "Ip",
"type": "string"
}
},
"required": [
"ip"
],
"type": "object"
}
Implementation Reference
- amap_mcp_server/server.py:84-108 (handler)The main handler function for the 'maps_ip_location' tool. It queries the Amap IP location API with the provided IP address and returns location details like province, city, adcode, and rectangle. The @mcp.tool() decorator registers the tool and infers the schema from the function signature (ip: str) and docstring.@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)}"}