Skip to main content
Glama
garylab
by garylab

google_search_shopping

Search Google for shopping results to find products, compare prices, and locate retailers using customizable parameters like location and language.

Instructions

Search Google for results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYesThe query to search for
glNoThe country to search in, e.g. us, uk, ca, au, etc.
locationNoThe location to search in, e.g. San Francisco, CA, USA
hlNoThe language to search in, e.g. en, es, fr, de, etc.
pageNoThe page number to return, first page is 1 (integer value as string)1
autocorrectNoAutomatically correct (boolean value as string: 'true' or 'false')true
numNoThe number of results to return, max is 100 (integer value as string)10

Implementation Reference

  • MCP tool call handler that dispatches 'google_search_shopping' to google(tool_enum, ShoppingRequest) after validation.
    @server.call_tool() async def call_tool(name: str, arguments: dict[str, Any]) -> Sequence[TextContent | ImageContent | EmbeddedResource]: if not SERPER_API_KEY: return [TextContent(text=f"SERPER_API_KEY is empty!", type="text")] try: if name == SerperTools.WEBPAGE_SCRAPE.value: request = WebpageRequest(**arguments) result = await scape(request) return [TextContent(text=json.dumps(result, indent=2), type="text")] if not SerperTools.has_value(name): raise ValueError(f"Tool {name} not found") tool = SerperTools(name) request = google_request_map[tool](**arguments) result = await google(tool, request) return [TextContent(text=json.dumps(result, indent=2), type="text")] except Exception as e: return [TextContent(text=f"Error: {str(e)}", type="text")]
  • Core handler logic for Google search tools including shopping: builds API URL (e.g., /shopping) and fetches JSON from Serper API.
    async def google(tool: SerperTools, request: BaseModel) -> Dict[str, Any]: uri_path = tool.value.split("_")[-1] url = f"https://google.serper.dev/{uri_path}" return await fetch_json(url, request)
  • Pydantic input schema for google_search_shopping tool, extending BaseRequest with autocorrect and num fields.
    class ShoppingRequest(BaseRequest): autocorrect: Optional[str] = Field( "true", pattern=r"^(true|false)$", description="Automatically correct (boolean value as string: 'true' or 'false')", ) num: str = Field( "10", pattern=r"^([1-9]|[1-9]\d|100)$", description="The number of results to return, max is 100 (integer value as string)", )
  • Mapping from tool enum (including GOOGLE_SEARCH_SHOPPING) to corresponding request schema class, used for input validation and dispatch.
    google_request_map = { SerperTools.GOOGLE_SEARCH: SearchRequest, SerperTools.GOOGLE_SEARCH_IMAGES: SearchRequest, SerperTools.GOOGLE_SEARCH_VIDEOS: SearchRequest, SerperTools.GOOGLE_SEARCH_PLACES: AutocorrectRequest, SerperTools.GOOGLE_SEARCH_MAPS: MapsRequest, SerperTools.GOOGLE_SEARCH_REVIEWS: ReviewsRequest, SerperTools.GOOGLE_SEARCH_NEWS: SearchRequest, SerperTools.GOOGLE_SEARCH_SHOPPING: ShoppingRequest, SerperTools.GOOGLE_SEARCH_LENS: LensRequest, SerperTools.GOOGLE_SEARCH_SCHOLAR: AutocorrectRequest, SerperTools.GOOGLE_SEARCH_PATENTS: PatentsRequest, SerperTools.GOOGLE_SEARCH_AUTOCOMPLETE: AutocorrectRequest, }
  • HTTP client utility that performs POST to Serper API with API key and request payload, used by google() handler.
    async def fetch_json(url: str, request: BaseModel) -> Dict[str, Any]: payload = request.model_dump(exclude_none=True) headers = { 'X-API-KEY': SERPER_API_KEY, 'Content-Type': 'application/json' } ssl_context = ssl.create_default_context(cafile=certifi.where()) connector = aiohttp.TCPConnector(ssl=ssl_context) timeout = aiohttp.ClientTimeout(total=AIOHTTP_TIMEOUT) async with aiohttp.ClientSession(connector=connector, timeout=timeout) as session: async with session.post(url, headers=headers, json=payload) as response: response.raise_for_status() return await response.json()
  • Enum constant defining the tool name string.
    GOOGLE_SEARCH_SHOPPING = "google_search_shopping"

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/garylab/serper-mcp-server'

If you have feedback or need assistance with the MCP directory API, please join our Discord server