Skip to main content
Glama
garylab

Serper MCP Server

by garylab

google_search_images

Search Google Images for pictures. Adjust parameters like country, language, and time period to refine results.

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
tbsNoThe time period to search in, e.g. d, w, m, y
numNoThe number of results to return, max is 100 (integer value as string)10

Implementation Reference

  • The 'google' handler function that executes the tool logic for google_search_images. It takes a SerperTools enum value (GOOGLE_SEARCH_IMAGES) and a request model, extracts the URI path by taking the last part of the tool name (e.g., 'images'), and makes a POST request to https://google.serper.dev/images with the 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)
  • SearchRequest schema is used for google_search_images input validation. Contains fields: q (query), gl (country), location, hl (language), page, tbs (time period), and num (number of results).
    class SearchRequest(BaseRequest):
        tbs: Optional[str] = Field(
            None, description="The time period to search in, e.g. d, w, m, y"
        )
        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)",
        )
  • The 'call_tool' function dispatches incoming tool requests. When name matches 'google_search_images', it creates a SearchRequest from arguments and calls google() with the SerperTools.GOOGLE_SEARCH_IMAGES enum.
    @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)
  • The 'list_tools' function registers google_search_images as a Tool with name from the enum and description 'Search Google for results', using SearchRequest schema.
    @server.list_tools()
    async def list_tools() -> List[Tool]:
        tools = []
    
        for k, v in google_request_map.items():
            tools.append(
                Tool(
                    name=k.value,
                    description="Search Google for results",
                    inputSchema=v.model_json_schema(),
                ),
            )
    
        tools.append(Tool(
            name=SerperTools.WEBPAGE_SCRAPE,
            description="Scrape webpage by url",
            inputSchema=WebpageRequest.model_json_schema(),
        ))
    
        return tools
  • The 'fetch_json' helper makes the actual HTTP POST request to the Serper API with the appropriate headers and payload, used by the 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()
Behavior1/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations, the description carries full burden for behavioral disclosure. It only says 'Search Google for results' without indicating pagination, result format, or that it returns images. Critical behavioral traits are missing.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness2/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is extremely short (5 words), but this is underspecification rather than conciseness. It fails to convey the tool's specific purpose or usage, so it is not effectively structured.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness1/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the 7 parameters and no output schema, the description is grossly incomplete. It provides no context on result handling, pagination, or image-specific behavior, leaving the agent underinformed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema coverage is 100% with clear parameter descriptions (q, gl, location, etc.). The description adds no additional meaning, but baseline 3 is appropriate since the schema is self-explanatory.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose2/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description 'Search Google for results' is vague and does not specify that this tool searches for images. Among siblings like google_search_news and google_search_videos, it should differentiate by mentioning 'images'. It fails to clearly state the resource type.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

No guidance is provided on when to use this tool versus its many siblings (e.g., google_search, google_search_images, etc.). There is no mention of context or alternatives, making it hard for an agent to decide.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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