maps_geo
Convert structured addresses and landmark names into precise latitude and longitude coordinates using geocoding technology.
Instructions
将详细的结构化地址转换为经纬度坐标。支持对地标性名胜景区、建筑物名称解析为经纬度坐标
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| address | Yes | ||
| city | No |
Input Schema (JSON Schema)
{
"properties": {
"address": {
"title": "Address",
"type": "string"
},
"city": {
"anyOf": [
{
"type": "string"
},
{
"type": "null"
}
],
"default": null,
"title": "City"
}
},
"required": [
"address"
],
"type": "object"
}
Implementation Reference
- amap_mcp_server/server.py:44-82 (handler)The maps_geo tool handler function decorated with @mcp.tool(), which performs geocoding by converting a structured address (with optional city) to latitude/longitude coordinates using the Amap Geocoding API (https://restapi.amap.com/v3/geocode/geo). Returns detailed geocoding results or error.@mcp.tool() def maps_geo(address: str, city: Optional[str] = None) -> Dict[str, Any]: """将详细的结构化地址转换为经纬度坐标。支持对地标性名胜景区、建筑物名称解析为经纬度坐标""" try: params = { "key": AMAP_MAPS_API_KEY, "address": address } if city: params["city"] = city response = requests.get( "https://restapi.amap.com/v3/geocode/geo", params=params ) response.raise_for_status() data = response.json() if data["status"] != "1": return {"error": f"Geocoding failed: {data.get('info') or data.get('infocode')}"} geocodes = data.get("geocodes", []) results = [] for geo in geocodes: results.append({ "country": geo.get("country"), "province": geo.get("province"), "city": geo.get("city"), "citycode": geo.get("citycode"), "district": geo.get("district"), "street": geo.get("street"), "number": geo.get("number"), "adcode": geo.get("adcode"), "location": geo.get("location"), "level": geo.get("level") }) return {"return": results} except requests.exceptions.RequestException as e: return {"error": f"Request failed: {str(e)}"}
- amap_mcp_server/server.py:44-44 (registration)Registration of the maps_geo tool using the @mcp.tool() decorator from FastMCP.@mcp.tool()
- amap_mcp_server/server.py:45-45 (schema)Input schema defined by function signature: address (str, required), city (Optional[str]). Output: Dict[str, Any] with geocoding results.def maps_geo(address: str, city: Optional[str] = None) -> Dict[str, Any]: