Skip to main content
Glama
hunter-arton

Google Search MCP Server

by hunter-arton

google_web_search

Perform web searches using the Google Custom Search API to gather diverse information, news, articles, or online content. Supports pagination and filtering by site or type for targeted results.

Instructions

Performs a web search using the Google Custom Search API, ideal for general queries, news, articles, and online content. Use this for broad information gathering, recent events, or when you need diverse web sources. Supports pagination and filtering by site or type. Maximum 10 results per request, with start index for pagination.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoNumber of results (1-10, default 5)
queryYesSearch query
siteNoOptional: Limit search to specific site (e.g., 'site:example.com')
startNoPagination start index (default 1)

Implementation Reference

  • Core handler function that performs the Google Custom Search web search, handles parameters like site restriction, rate limiting, API call, error handling, and formats results into a readable text response.
    async function performWebSearch(query: string, count: number = 5, start: number = 1, site: string = "") {
      checkRateLimit();
      
      let searchQuery = query;
      // If site is provided, append it to the query
      if (site && !query.includes("site:")) {
        searchQuery = `${query} site:${site}`;
      }
      
      const url = new URL('https://www.googleapis.com/customsearch/v1');
      url.searchParams.set('key', GOOGLE_API_KEY);
      url.searchParams.set('cx', GOOGLE_CSE_ID);
      url.searchParams.set('q', searchQuery);
      url.searchParams.set('num', Math.min(count, 10).toString()); // API limit is 10
      url.searchParams.set('start', start.toString());
    
      const response = await fetch(url, {
        headers: {
          'Accept': 'application/json',
        }
      });
    
      if (!response.ok) {
        throw new Error(`Google API error: ${response.status} ${response.statusText}\n${await response.text()}`);
      }
    
      const data = await response.json() as GoogleSearchResult;
      
      if (data.error) {
        throw new Error(`Google API error: ${data.error.code} ${data.error.message}`);
      }
    
      if (!data.items || data.items.length === 0) {
        return "No results found for your query.";
      }
    
      // Format the results
      return data.items.map((item, index) => 
        `[${index + 1}] Title: ${item.title}\nDescription: ${item.snippet}\nURL: ${item.link}`
      ).join('\n\n');
    }
  • Type guard function for validating input arguments to the google_web_search tool.
    function isGoogleWebSearchArgs(args: unknown): args is { query: string; count?: number; start?: number; site?: string } {
      return (
        typeof args === "object" &&
        args !== null &&
        "query" in args &&
        typeof (args as { query: string }).query === "string"
      );
    }
  • src/index.ts:11-43 (registration)
    Tool registration object defining the name, description, and input schema for google_web_search, used in listTools response.
    const WEB_SEARCH_TOOL: Tool = {
      name: "google_web_search",
      description:
        "Performs a web search using the Google Custom Search API, ideal for general queries, news, articles, and online content. " +
        "Use this for broad information gathering, recent events, or when you need diverse web sources. " +
        "Supports pagination and filtering by site or type. " +
        "Maximum 10 results per request, with start index for pagination. ",
      inputSchema: {
        type: "object",
        properties: {
          query: {
            type: "string",
            description: "Search query"
          },
          count: {
            type: "number",
            description: "Number of results (1-10, default 5)",
            default: 5
          },
          start: {
            type: "number",
            description: "Pagination start index (default 1)",
            default: 1
          },
          site: {
            type: "string",
            description: "Optional: Limit search to specific site (e.g., 'site:example.com')",
            default: ""
          },
        },
        required: ["query"],
      },
    };
  • Dispatch handler case within CallToolRequestSchema that validates arguments and invokes the performWebSearch function for google_web_search.
    case "google_web_search": {
      if (!isGoogleWebSearchArgs(args)) {
        throw new Error("Invalid arguments for google_web_search");
      }
      const { query, count = 5, start = 1, site = "" } = args;
      const results = await performWebSearch(query, count, start, site);
      return {
        content: [{ type: "text", text: results }],
        isError: false,
      };
    }
  • src/index.ts:285-286 (registration)
    Server request handler for ListToolsRequestSchema that registers and exposes the google_web_search tool.
      tools: [WEB_SEARCH_TOOL, IMAGE_SEARCH_TOOL],
    }));
Behavior3/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 key behavioral traits: 'maximum 10 results per request', 'supports pagination and filtering by site or type', and 'start index for pagination'. However, it doesn't cover important aspects like rate limits, authentication requirements, error conditions, or what the response format looks like.

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 efficiently structured in three sentences that each serve distinct purposes: stating the core functionality, providing usage guidance, and disclosing behavioral constraints. Every sentence earns its place with no redundant information, making it appropriately sized and front-loaded.

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

Completeness3/5

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

For a search tool with 4 parameters, 100% schema coverage, but no annotations and no output schema, the description provides adequate context about what the tool does and when to use it. However, it lacks information about the response format, error handling, and operational constraints like rate limits, which would be important for an API-based search tool.

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?

With 100% schema description coverage, the input schema already documents all 4 parameters thoroughly. The description adds minimal value beyond what's in the schema - it mentions 'filtering by site or type' and 'pagination' which map to the 'site' and 'start' parameters, but doesn't provide additional semantic context beyond what the schema descriptions already offer.

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 tool 'performs a web search using the Google Custom Search API' with specific examples of use cases (general queries, news, articles, online content). It distinguishes from the sibling tool 'google_image_search' by specifying this is for web content rather than images. However, it doesn't explicitly contrast with the sibling beyond the domain difference.

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

Usage Guidelines4/5

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

The description provides clear context for when to use this tool ('broad information gathering, recent events, or when you need diverse web sources'), which implicitly distinguishes it from the image search sibling. It doesn't explicitly state when NOT to use it or name alternatives beyond the implied contrast with image search.

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

Related 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/hunter-arton/google_search_mcp_server'

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