Add SerpAPI Flights connector: mcp_remote, flight search via Google Flights, verify.py with MCP initialize probe
This commit is contained in:
@@ -0,0 +1,66 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify SerpAPI Flights MCP connectivity.
|
||||
|
||||
Reads serpapiApiKey from the environment, sends a lightweight JSON-RPC
|
||||
initialize to https://mcp.serpapi.com/{key}/mcp, and prints:
|
||||
|
||||
{"ok": true, "message": "SerpAPI Flights MCP endpoint is reachable"}
|
||||
{"ok": false, "message": "SerpAPI Flights MCP endpoint is unreachable: <reason>"}
|
||||
|
||||
stdlib only (urllib).
|
||||
"""
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
import urllib.error
|
||||
import urllib.request
|
||||
|
||||
|
||||
def _result(ok, message):
|
||||
print(json.dumps({"ok": ok, "message": message}))
|
||||
sys.exit(0 if ok else 1)
|
||||
|
||||
|
||||
def main():
|
||||
api_key = os.environ.get("serpapiApiKey", "").strip()
|
||||
if not api_key:
|
||||
api_key = os.environ.get("SERPAPI_API_KEY", "").strip()
|
||||
if not api_key:
|
||||
_result(False, "No SerpAPI API key provided (serpapiApiKey env var is empty)")
|
||||
|
||||
url = f"https://mcp.serpapi.com/{api_key}/mcp"
|
||||
|
||||
body = json.dumps({
|
||||
"jsonrpc": "2.0",
|
||||
"id": 1,
|
||||
"method": "initialize",
|
||||
"params": {
|
||||
"protocolVersion": "2025-03-26",
|
||||
"capabilities": {},
|
||||
"clientInfo": {"name": "skald-verify", "version": "1.0.0"},
|
||||
},
|
||||
}).encode("utf-8")
|
||||
|
||||
req = urllib.request.Request(
|
||||
url,
|
||||
data=body,
|
||||
headers={"Content-Type": "application/json"},
|
||||
method="POST",
|
||||
)
|
||||
|
||||
try:
|
||||
with urllib.request.urlopen(req, timeout=15) as resp:
|
||||
if 200 <= resp.status < 300:
|
||||
_result(True, "SerpAPI Flights MCP endpoint is reachable")
|
||||
_result(False, f"SerpAPI returned HTTP {resp.status}")
|
||||
except urllib.error.HTTPError as e:
|
||||
if e.code in (401, 403):
|
||||
_result(False, "SerpAPI API key is invalid or unauthorized "
|
||||
f"(HTTP {e.code})")
|
||||
_result(False, f"SerpAPI returned HTTP {e.code}: {e.reason}")
|
||||
except Exception as e:
|
||||
_result(False, f"SerpAPI Flights MCP endpoint is unreachable: {e}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user