Files
skald-connectors/connectors/google-trends/verify.py
T
Daniele 5e4c41183c google-trends: fix broken MCP handshake and RSS articles (v2 / 1.1.0)
The server never implemented `initialize`, so every MCP client got
-32601 to its opening request and aborted before listing a tool. Also
missing: `notifications/initialized` and `ping`; `tools/list` returned a
bare array instead of {"tools": [...]}; notifications (no `id`) got a
full response written to stdout.

Rewritten to the shape the other local connectors already use (TOOLS
manifest + TOOL_DISPATCH, `_text_result` with isError, handle_request
returning None for notifications).

Also fixed:
- include_articles always returned nothing: trendspyg emits
  `news_articles`, the mapper read `articles`. explore_link kept too.
- fn(**arguments) turned a bad argument into -32603; handlers now take
  an args dict and coerce/clamp.
- errors were returned as successful results; now isError: true, with
  trendspyg's typed exceptions translated into actionable messages.
- browser calls could run ~100s (10 retries x 8s); capped at ~25s.
- verify.py shipped but connector.json declared no `verify` block; wired
  it and upgraded the script to a real RSS fetch.
- explore mutated trendspyg's ExploreEnvelope; dropped the no-op
  output_format param; trendspyg pinned >=1.6.0 and imported defensively.
2026-08-24 17:29:36 +01:00

54 lines
1.5 KiB
Python

#!/usr/bin/env python3
"""Verify the Google Trends connector: import + a real RSS fetch (fast, no browser)."""
import json
import sys
def check() -> dict:
"""Verify trendspyg is installed and the RSS path actually returns trends."""
try:
import trendspyg
except Exception as e:
return {"ok": False, "message": f"trendspyg is not installed: {e}"}
version = getattr(trendspyg, "__version__", "unknown")
try:
trends = trendspyg.download_google_trends_rss(
geo="US",
output_format="dict",
include_images=False,
include_articles=False,
)
except Exception as e:
return {
"ok": False,
"message": f"trendspyg v{version} is installed but Google Trends is unreachable: {e}",
"details": {"version": version},
}
if not trends:
return {
"ok": False,
"message": f"trendspyg v{version} reached Google Trends but got no trends back.",
"details": {"version": version},
}
return {
"ok": True,
"message": f"trendspyg v{version} — fetched {len(trends)} trending topics from Google Trends.",
"details": {
"version": version,
"trends_fetched": len(trends),
"rss_path": "verified (no browser needed)",
"explore_path": "not tested here (requires Chrome/Selenium)",
},
}
if __name__ == "__main__":
result = check()
sys.stdout.write(json.dumps(result))
sys.exit(0 if result["ok"] else 1)