The connector shipped no requirements.txt, so ensure_installed_host()
installed nothing and every tool call failed with "No module named
'googlemaps'" while the server still answered tools/list — skald logged
"connected — 6 tool(s)" on a connector that could not work.
- add requirements.txt (googlemaps>=4.10.0); deps were declared in the
manifest's `dependencies` field, which skald only uses for the card
- wire the shipped verify.py through a `verify` manifest block, so a
broken install fails visibly at enable time instead of silently
- verify.py puts .pydeps on sys.path: skald sets PYTHONPATH only for the
server process, not for the `sh -c "python3 verify.py"` verify step
- drop the inert mcp_config.env {SECRET:…} placeholder — those tokens are
substituted in the URL only, never in env values
- realign manifest/fragment versions (were 2/1.0.1 vs 5/1.0.4); skald
prefers the manifest, so "update available" could never appear
- requires ENV -> API_KEY; drop deprecated secrets/ path from error text
- regenerate the index
72 lines
2.3 KiB
Python
72 lines
2.3 KiB
Python
#!/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
|
|
|
|
# Skald installs our deps with `pip install --target .pydeps` beside this file and
|
|
# puts that dir on PYTHONPATH for the *server* process only — the verify step gets
|
|
# a bare `sh -c "python3 verify.py"`, so `import googlemaps` would fail here even
|
|
# on a correctly installed connector. Put .pydeps on sys.path ourselves.
|
|
_PYDEPS = os.path.join(os.path.dirname(os.path.abspath(__file__)), ".pydeps")
|
|
if os.path.isdir(_PYDEPS):
|
|
sys.path.insert(0, _PYDEPS)
|
|
|
|
|
|
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()
|