Skip to main content
Glama
rendyfebry

Google PSE MCP Server

by rendyfebry

search

Search the web using Google's Custom Search API to find relevant information, filter results by language or safety, and control pagination for research or data gathering.

Instructions

Search the Web using Google Custom Search API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
qYesSearch query
pageNoPage number
sizeNoNumber of search results to return per page. Valid values are integers between 1 and 10, inclusive.
sortNoSort expression (e.g., 'date'). Only 'date' is supported by the API.
safeNoEnable safe search filtering. Default: false.
lrNoRestricts the search to documents written in a particular language (e.g., lang_en, lang_ja)
siteRestrictedNoIf true, use the Site Restricted API endpoint (/v1/siterestrict). If false, use the standard API endpoint (/v1). Default: true.

Implementation Reference

  • The core handler logic for the 'search' tool. Processes input arguments, builds and sends a request to the Google Custom Search API (site-restricted or standard), handles errors, and returns search results as formatted JSON.
    if (request.params.name === "search") {
        const args = request.params.arguments as any;
        const {
            q,
            page = 1,
            size = 10,
            lr,
            safe = false,
            sort
        } = args;
    
        if (!q) {
            throw new Error("Missing required argument: q");
        }
        if (!API_KEY) {
            throw new Error("API_KEY is not configured");
        }
        if (!CX) {
            throw new Error("CX is not configured");
        }
    
        // Build query params
        const params = new URLSearchParams();
        params.append("key", API_KEY);
        params.append("cx", CX);
        params.append("q", q);
        params.append("fields", "items(title,htmlTitle,link,snippet,htmlSnippet)");
    
        // Language restriction
        if (lr !== undefined) {
            params.append("lr", String(lr));
        }
    
        // SafeSearch mapping (boolean only)
        if (safe !== undefined) {
            if (typeof safe !== "boolean") {
                throw new Error("SafeSearch (safe) must be a boolean");
            }
            params.append("safe", safe ? "active" : "off");
        }
    
        // Sort validation
        if (sort !== undefined) {
            if (sort === "date") {
                params.append("sort", "date");
            } else {
                throw new Error("Only 'date' is supported for sort");
            }
        }
    
        // Pagination
        params.append("num", String(size));
    
        if (page > 0 && size > 0) {
            const start = ((page - 1) * size) + 1;
            params.append("start", String(start));
        } else {
            params.append("start", "1");
        }
    
        const siteRestricted = args.siteRestricted !== undefined ? args.siteRestricted : SITE_RESTRICTED_DEFAULT;
        const endpoint = siteRestricted ? "/v1/siterestrict" : "/v1";
        const url = `${API_HOST}${endpoint}?${params.toString()}`;
        const response = await fetch(url, {
            method: "GET"
        });
    
        if (!response.ok) {
            throw new Error(`Search API request failed: ${response.status} ${response.statusText}`);
        }
    
        const result = await response.json();
    
        // Return the items array (list of articles)
        const items = result?.items ?? [];
        return {
            content: [{
                type: "text",
                text: JSON.stringify(items, null, 2)
            }]
        };
    }
  • Tool schema definition including name, description, and detailed inputSchema with properties, types, descriptions, and required fields for the 'search' tool.
    {
        name: "search",
        description: "Search the Web using Google Custom Search API",
        inputSchema: {
            type: "object",
            properties: {
                q: { type: "string", description: "Search query" },
                page: { type: "integer", description: "Page number" },
                size: { type: "integer", description: "Number of search results to return per page. Valid values are integers between 1 and 10, inclusive." },
                sort: {
                    type: "string",
                    description: "Sort expression (e.g., 'date'). Only 'date' is supported by the API."
                },
                safe: {
                    type: "boolean",
                    description: "Enable safe search filtering. Default: false."
                },
                lr: { type: "string", description: "Restricts the search to documents written in a particular language (e.g., lang_en, lang_ja)" },
                siteRestricted: {
                    type: "boolean",
                    description: "If true, use the Site Restricted API endpoint (/v1/siterestrict). If false, use the standard API endpoint (/v1). Default: true."
                },
            },
            required: ["q"]
        }
    }
  • src/index.ts:40-71 (registration)
    Registers the 'search' tool with the MCP server by handling ListToolsRequestSchema and returning the tool specification in the tools array.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
        return {
            tools: [
                {
                    name: "search",
                    description: "Search the Web using Google Custom Search API",
                    inputSchema: {
                        type: "object",
                        properties: {
                            q: { type: "string", description: "Search query" },
                            page: { type: "integer", description: "Page number" },
                            size: { type: "integer", description: "Number of search results to return per page. Valid values are integers between 1 and 10, inclusive." },
                            sort: {
                                type: "string",
                                description: "Sort expression (e.g., 'date'). Only 'date' is supported by the API."
                            },
                            safe: {
                                type: "boolean",
                                description: "Enable safe search filtering. Default: false."
                            },
                            lr: { type: "string", description: "Restricts the search to documents written in a particular language (e.g., lang_en, lang_ja)" },
                            siteRestricted: {
                                type: "boolean",
                                description: "If true, use the Site Restricted API endpoint (/v1/siterestrict). If false, use the standard API endpoint (/v1). Default: true."
                            },
                        },
                        required: ["q"]
                    }
                }
            ]
        };
    });
Behavior2/5

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

With no annotations provided, the description carries the full burden of behavioral disclosure. It mentions the API used but fails to describe key behaviors like rate limits, authentication requirements, error handling, or the format of search results. For a web search tool with 7 parameters, this leaves significant gaps in understanding how it operates.

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

Conciseness5/5

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

The description is a single, efficient sentence that front-loads the core purpose without any wasted words. It's appropriately sized for a tool with this complexity, making it easy to parse quickly.

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

Completeness2/5

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

Given the tool's complexity (7 parameters, no output schema, no annotations), the description is incomplete. It lacks information on result format, error conditions, authentication, and usage constraints, which are critical for an AI agent to use this tool effectively in real-world scenarios.

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 description coverage is 100%, meaning all parameters are documented in the schema. The description adds no additional parameter semantics beyond what's in the schema, so it meets the baseline of 3 without compensating or detracting.

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

Purpose4/5

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

The description clearly states the verb ('Search') and resource ('the Web'), specifying it uses the Google Custom Search API. It's specific about the action and technology, though without sibling tools to distinguish from, it can't achieve the full differentiation that would warrant a 5.

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?

The description provides no guidance on when to use this tool versus alternatives, prerequisites, or exclusions. It simply states what the tool does without context for usage decisions, which is insufficient for effective tool selection.

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/rendyfebry/google-pse-mcp'

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