Mr.Phil / mcp_serpapi.py
luciagomez's picture
upload mcp_serpapi.py
1476f54 verified
raw
history blame contribute delete
478 Bytes
from serpapi import GoogleSearch
import os
SERPAPI_KEY = os.getenv("SERPAPI_KEY")
def search_pdf_url(query):
params = {
"engine": "google",
"q": query,
"api_key": SERPAPI_KEY
}
search = GoogleSearch(params)
results = search.get_dict()
# Extract first PDF URL
for res in results.get("organic_results", []):
link = res.get("link", "")
if link.lower().endswith(".pdf"):
return link
return None