Aggiunto connector Google Maps (mcp_local)
- Script: gmaps_mcp_server.py (MCP stdio, JSON-RPC 2.0)
- 6 tools: status, directions, geocode, reverse_geocode, search_places, distance_matrix
- Auth: API key via env GOOGLE_MAPS_API_KEY
- Verify: test Geocoding API con probe 'Rome, IT' ✅
- Dipendenze: googlemaps>=4.10.0
- Icone SVG pin Google Maps
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify Google Maps API key by doing a cheap Geocoding API call.
|
||||
|
||||
Output (JSON on stdout):
|
||||
{"ok": true, "message": "…"}
|
||||
{"ok": false, "message": "GOOGLE_MAPS_API_KEY not set"}
|
||||
{"ok": false, "message": "Missing dependency: pip install googlemaps"}
|
||||
{"ok": false, "message": "Geocoding API error: …"}
|
||||
"""
|
||||
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
|
||||
def main() -> None:
|
||||
api_key = os.environ.get("GOOGLE_MAPS_API_KEY", "").strip()
|
||||
if not api_key:
|
||||
print(json.dumps({
|
||||
"ok": False,
|
||||
"message": "GOOGLE_MAPS_API_KEY not set. Provide a valid Google Maps API key."
|
||||
}))
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
import googlemaps # type: ignore
|
||||
except ImportError as e:
|
||||
print(json.dumps({
|
||||
"ok": False,
|
||||
"message": f"Missing dependency: {e}. Run: pip install googlemaps"
|
||||
}))
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
client = googlemaps.Client(key=api_key)
|
||||
result = client.geocode("Rome, IT")
|
||||
except Exception as e:
|
||||
print(json.dumps({
|
||||
"ok": False,
|
||||
"message": f"Geocoding API error: {e}"
|
||||
}))
|
||||
sys.exit(1)
|
||||
|
||||
if not result:
|
||||
print(json.dumps({
|
||||
"ok": False,
|
||||
"message": "Geocoding API returned no result. The API key may be restricted or Geocoding API disabled."
|
||||
}))
|
||||
sys.exit(1)
|
||||
|
||||
print(json.dumps({
|
||||
"ok": True,
|
||||
"message": "Google Maps API key is valid. Directions, Geocoding, Places, and Distance Matrix APIs are reachable.",
|
||||
"details": {
|
||||
"probe_result": result[0].get("formatted_address", "Rome, Italy"),
|
||||
"lat": result[0].get("geometry", {}).get("location", {}).get("lat"),
|
||||
"lng": result[0].get("geometry", {}).get("location", {}).get("lng"),
|
||||
}
|
||||
}))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user