Skip to main content
Glama

google_search

Search for information using Google search API to retrieve relevant web results based on your query parameters.

Instructions

Search for information using Google search API

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
countNoMaximum number of results (from 1 to 20)
queryYesSearch query. For example: 'python fastapi'
timeoutNoTimeout in seconds (20-1500)

Implementation Reference

  • src/index.ts:259-298 (registration)
    Registration and handler for the 'google_search' tool. Defines Zod input schema, tool description, and the async handler that normalizes parameters and proxies the HTTP POST request to the AnySite '/api/google/search' API endpoint, returning JSON results or error.
    // Register google_search tool
    server.tool(
      "google_search",
      "Perform Google search",
      {
        query: z.string().describe("Search query"),
        count: z.number().default(10).describe("Max results (1-20)"),
        timeout: z.number().default(300).describe("Timeout in seconds")
      },
      async ({ query, count, timeout }) => {
        const requestData = {
          timeout,
          query,
          count: Math.min(Math.max(1, count), 20)
        };
        log(`Starting Google search for: ${query}`);
        try {
          const response = await makeRequest(API_CONFIG.ENDPOINTS.GOOGLE_SEARCH, requestData);
          return {
            content: [
              {
                type: "text",
                text: JSON.stringify(response, null, 2)
              }
            ]
          };
        } catch (error) {
          log("Google search error:", error);
          return {
            content: [
              {
                type: "text",
                text: `Google search API error: ${formatError(error)}`
              }
            ],
            isError: true
          };
        }
      }
    );
  • TypeScript interface defining the input schema for GoogleSearchPayload used by the google_search tool.
    export interface GoogleSearchPayload {
      query: string;
      count?: number;
      timeout?: number;
    }
  • Runtime validation function for GoogleSearchPayload input arguments matching the tool schema constraints.
    export function isValidGoogleSearchPayload(
      args: unknown
    ): args is GoogleSearchPayload {
      if (typeof args !== "object" || args === null) return false;
      const obj = args as Record<string, unknown>;
    
      if (typeof obj.query !== "string" || !obj.query.trim()) return false;
      if (obj.count !== undefined && (typeof obj.count !== "number" || obj.count <= 0 || obj.count > 20)) return false;
      if (obj.timeout !== undefined && (typeof obj.timeout !== "number" || obj.timeout < 20 || obj.timeout > 1500)) return false;
    
      return true;
    }
  • API endpoint constant used by the google_search handler to forward requests.
    GOOGLE_SEARCH: "/api/google/search",
    INSTAGRAM_USER: "/api/instagram/user",
  • Generic HTTP request helper function used by all tools including google_search to communicate with the AnySite backend API.
    const makeRequest = (endpoint: string, data: any, method: string = "POST"): Promise<any> => {
      return new Promise((resolve, reject) => {
        const url = new URL(endpoint, API_CONFIG.BASE_URL);
        const postData = JSON.stringify(data);
    
        const options = {
          hostname: url.hostname,
          port: url.port || 443,
          path: url.pathname,
          method: method,
          headers: {
            "Content-Type": "application/json",
            "Content-Length": Buffer.byteLength(postData),
            "access-token": API_KEY,
            ...(ACCOUNT_ID && { "x-account-id": ACCOUNT_ID })
          }
        };
    
        const req = https.request(options, (res) => {
          let responseData = "";
          res.on("data", (chunk) => {
            responseData += chunk;
          });
    
          res.on("end", () => {
            try {
              const parsed = JSON.parse(responseData);
              if (res.statusCode && res.statusCode >= 200 && res.statusCode < 300) {
                resolve(parsed);
              } else {
                reject(new Error(`API error ${res.statusCode}: ${JSON.stringify(parsed)}`));
              }
            } catch (e) {
              reject(new Error(`Failed to parse response: ${responseData}`));
            }
          });
        });
    
        req.on("error", (error) => {
          reject(error);
        });
    
        req.write(postData);
        req.end();
      });
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 states it's a search operation but doesn't mention any behavioral traits such as rate limits, authentication needs, response format, or potential errors. This is a significant gap for a tool with no annotation coverage.

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 directly states the tool's function without any unnecessary words. It's appropriately sized and front-loaded, 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 lack of annotations and output schema, the description is incomplete. It doesn't address behavioral aspects like rate limits or response structure, which are crucial for a search tool. The schema covers parameters well, but overall context is insufficient for effective tool use.

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%, so the schema fully documents all parameters (query, count, timeout). The description doesn't add any meaning beyond what the schema provides, such as search syntax tips or result formatting, which keeps it at the baseline score of 3.

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 ('information using Google search API'), making the purpose immediately understandable. However, it doesn't differentiate from sibling tools, which are all for different platforms (Instagram, LinkedIn, Reddit) rather than alternative search tools, so the distinction is inherent but not explicitly stated.

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. It doesn't mention any context-specific scenarios, prerequisites, or exclusions, leaving the agent to infer usage based on the tool name alone.

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/anysiteio/hdw-mcp-server'

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