Skip to main content
Glama

google_search

Retrieve structured data from Google search results to extract information for analysis or integration.

Instructions

Retrieve structured data from Google search results

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
queryYesThe search query to perform
countryNoCountry code for localized results (e.g., US, GB)US

Implementation Reference

  • The core handler function that constructs a Google search URL, sends a scrape request to the Olostep API using the '@olostep/google-search' parser, parses the JSON response, and returns structured search results or error messages.
    handler: async ({ query, country }: { query: string; country?: string }, apiKey: string, orbitKey?: string) => {
        try {
            const headers = new Headers({
                'Content-Type': 'application/json',
                'Authorization': `Bearer ${apiKey}`
            });
    
            const searchUrl = new URL('https://www.google.com/search');
            searchUrl.searchParams.append('q', query);
            if (country) searchUrl.searchParams.append('gl', country);
    
            const payload = {
                formats: ["parser_extract"],
                parser_extract: { parser_id: "@olostep/google-search" },
                url_to_scrape: searchUrl.toString(),
                wait_before_scraping: 0,
                ...(orbitKey && { force_connection_id: orbitKey })
            };
    
            const response = await fetch(OLOSTEP_SCRAPE_API_URL, {
                method: 'POST',
                headers: headers,
                body: JSON.stringify(payload)
            });
    
            if (!response.ok) {
                const errorDetails = await response.json();
                return {
                    isError: true,
                    content: [{
                        type: "text",
                        text: `Olostep API Error: ${response.status} ${response.statusText}. Details: ${JSON.stringify(errorDetails)}`
                    }]
                };
            }
    
            const data = await response.json() as GoogleSearchResponse;
            
            if (data.result?.json_content) {
                const parsedContent = JSON.parse(data.result.json_content);
                return {
                    content: [{
                        type: "text",
                        text: JSON.stringify(parsedContent, null, 2)
                    }]
                };
            } else {
                return {
                    isError: true,
                    content: [{
                        type: "text",
                        text: "Error: No search results found in Olostep API response."
                    }]
                };
            }
    
        } catch (error: unknown) {
            return {
                isError: true,
                content: [{
                    type: "text",
                    text: `Error: Failed to perform Google search. ${error instanceof Error ? error.message : String(error)}`
                }]
            };
        }
    }
  • Input schema using Zod validation: requires 'query' string and optional 'country' string (defaults to 'US').
    schema: {
        query: z.string().describe("The search query to perform"),
        country: z.string().optional().default("US").describe("Country code for localized results (e.g., US, GB)")
    },
  • src/index.ts:164-176 (registration)
    MCP server registration of the 'google_search' tool, including API key validation and content type normalization.
    server.tool(
        getGoogleSearch.name,
        getGoogleSearch.description,
        getGoogleSearch.schema,
        async (params) => {
            if (!OLOSTEP_API_KEY) return missingApiKeyError;
            const result = await getGoogleSearch.handler(params, OLOSTEP_API_KEY, ORBIT_KEY);
            return {
                ...result,
                content: result.content.map(item => ({ ...item, type: item.type as "text" }))
            };
        }
    );
  • TypeScript interface for typing the response from the Olostep API scrape.
    interface GoogleSearchResponse {
        result?: {
            json_content?: string;
        };
    }
  • Tool name definition as 'google_search'.
    name: "google_search",
Behavior2/5

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

No annotations are provided, so the description carries the full burden of behavioral disclosure. It states the tool retrieves structured data, implying a read-only operation, but doesn't cover critical aspects like rate limits, authentication needs, error handling, or what 'structured data' entails (e.g., format, fields). This leaves significant gaps for a tool interacting with an external service.

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 unnecessary words. Every part earns its place by specifying the action, data type, and source. No fluff or redundancy is present.

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 complexity of a search tool with no annotations and no output schema, the description is incomplete. It doesn't explain the return values (what 'structured data' includes), error conditions, or operational constraints like rate limits. For a tool that likely involves external API calls, more context is needed to use it effectively.

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 both parameters ('query' and 'country'). The description adds no additional meaning beyond what's in the schema, such as query formatting examples or country code implications. Baseline 3 is appropriate when the schema does all the work.

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 ('Retrieve') and resource ('structured data from Google search results'), making the purpose immediately understandable. It distinguishes this from siblings like 'search_web' by specifying Google as the source and structured data as the output. However, it doesn't explicitly contrast with all siblings (e.g., 'answers' might also retrieve information).

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 like 'search_web' or 'answers'. It doesn't mention prerequisites, constraints, or typical use cases. The agent must infer usage from the name and description alone without explicit direction.

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

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