Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,11 @@ classifiers = [
requires-python = ">=3.12"
dependencies = [
"fastmcp>=2.13.0.2",
"google-search-results>=2.4.2",
"python-dotenv>=1.0.0",
"httpx>=0.25.0",
"uvicorn>=0.38.0",
"starlette>=0.50.0"
"starlette>=0.50.0",
"serpapi>=0.1.5",
]

[project.optional-dependencies]
Expand Down
15 changes: 7 additions & 8 deletions src/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import os
import json
from typing import Any
from serpapi import SerpApiClient as SerpApiSearch
import serpapi
import httpx
import logging
from datetime import datetime
Expand Down Expand Up @@ -186,8 +186,7 @@ async def search(params: dict[str, Any] = {}, raw: bool = False) -> str:
}

try:
search_client = SerpApiSearch(search_params)
data = search_client.get_dict()
data = serpapi.search(search_params).as_dict()

# Return raw JSON if requested
if raw:
Expand Down Expand Up @@ -240,15 +239,15 @@ async def search(params: dict[str, Any] = {}, raw: bool = False) -> str:
else:
return "No results found for the given query. Try adjusting your search parameters or engine."

except httpx.HTTPStatusError as e:
if e.response.status_code == 429:
except serpapi.exceptions.HTTPError as e:
if "429" in str(e):
return "Error: Rate limit exceeded. Please try again later."
elif e.response.status_code == 401:
elif "401" in str(e):
return "Error: Invalid SerpApi API key. Check your API key in the path or Authorization header."
elif e.response.status_code == 403:
elif "403" in str(e):
return "Error: SerpApi API key forbidden. Verify your subscription and key validity."
else:
return f"Error: {e.response.status_code} - {e.response.text}"
return f"Error: {str(e)}"
except Exception as e:
return f"Error: {str(e)}"

Expand Down
Loading