google_search
Scrape Google Search results and automatically parse them. Customize by geolocation, locale, and JavaScript rendering.
Instructions
Scrape Google Search results with automatic parsing
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query | |
| geo | No | Geolocation of the desired request, expressed as a country name | |
| locale | No | Locale of the desired request | |
| jsRender | No | Should the request be opened in a headless browser, false by default |
Implementation Reference
- The handler that executes the Google Search tool logic: builds params with target='google_search', calls sapiClient.scrape(), transforms the response by removing high-char-count fields, and returns text content.
async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.GOOGLE_SEARCH, parse: true, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); const { data: text } = this.transformResponse({ data }); return { content: [ { type: 'text', text, }, ], }; } - Input schema for the google_search tool: requires 'query' (string), and optional 'geo', 'locale', 'jsRender' using shared Zod types.
inputSchema: { query: z.string().describe('Search query'), geo: zodGeo, locale: zodLocale, jsRender: zodJsRender, }, - src/tools/google-search/google-search-tool.ts:28-65 (registration)Registration of the google_search tool with the MCP server, including description, annotations (readOnlyHint, openWorldHint), input schema, and the handler callback.
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'google_search', { description: 'Scrape Google Search results with automatic parsing', inputSchema: { query: z.string().describe('Search query'), geo: zodGeo, locale: zodLocale, jsRender: zodJsRender, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.GOOGLE_SEARCH, parse: true, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); const { data: text } = this.transformResponse({ data }); return { content: [ { type: 'text', text, }, ], }; } ); }; - Helper method that strips high-character-count fields (images, image_data, factoids, etc.) from the response to reduce payload size, then stringifies the result.
transformResponse = ({ data }: { data: object }) => { for (const fieldToRemove of GoogleSearchTool.FIELDS_WITH_HIGH_CHAR_COUNT) { data = removeKeyFromNestedObject({ obj: data, keyToRemove: fieldToRemove }); } return { data: JSON.stringify(data) }; };