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(); });

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