google_ai_mode
Scrape Google AI Mode search results with automatic parsing. Supports geo and device customization for targeted extraction.
Instructions
Scrape Google AI Mode (Search with AI) results with automatic parsing
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Search query for Google AI Mode (e.g., "What are the top three dog breeds?") | |
| geo | No | Geo location for AI mode search (e.g., "us", "uk") | |
| deviceType | No | Device type to emulate for the request |
Implementation Reference
- The GoogleAiModeTool class that contains the full handler logic for executing the 'google_ai_mode' tool. It registers the tool with input schema (query, geo, deviceType), builds params with target=GOOGLE_AI_MODE, calls sapiClient.scrape(), and returns the scraped data.
export class GoogleAiModeTool extends Tool { toolset = TOOLSET.AI; transformResponse = ({ data }: { data: object }) => { return { data: JSON.stringify(data) }; }; register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'google_ai_mode', { description: 'Scrape Google AI Mode (Search with AI) results with automatic parsing', inputSchema: { query: z.string().describe('Search query for Google AI Mode (e.g., "What are the top three dog breeds?")'), geo: zodGeo, deviceType: zodDeviceType, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.GOOGLE_AI_MODE, parse: true, } satisfies ScraperAPIParams; const { data } = await sapiClient.scrape<object>({ auth, scrapingParams: params, extra }); return { content: [ { type: 'text', text: JSON.stringify(data), }, ], }; } ); }; } - The input schema definition for the google_ai_mode tool: 'query' (string), 'geo' (optional string with description), and 'deviceType' (from zodDeviceType). The output is a text response with JSON-stringified data.
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'google_ai_mode', { description: 'Scrape Google AI Mode (Search with AI) results with automatic parsing', inputSchema: { query: z.string().describe('Search query for Google AI Mode (e.g., "What are the top three dog breeds?")'), geo: zodGeo, deviceType: zodDeviceType, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, - src/server/sapi-base-server.ts:66-72 (registration)Registration of GoogleAiModeTool in the allTools array within SapiBaseServer, which instantiates the tool so it gets registered with the MCP server.
static allTools: Tool[] = [ new ScrapeAsMarkdownTool(), new ScreenshotTool(), new GoogleSearchTool(), new GoogleAdsTool(), new GoogleLensTool(), new GoogleAiModeTool(), - Imports and the zodGeo helper schema used for geo location parameter validation.
import z from 'zod'; import { ScraperAPIParams, ScrapingMCPParams } from 'types'; import { SCRAPER_API_TARGETS, TOOLSET } from '../../constants'; import { zodDeviceType } from '../../zod/zod-types'; import { Tool, ToolRegistrationArgs } from '../tool'; import { ProgressExtra } from '../../utils'; const zodGeo = z .string() .describe('Geo location for AI mode search (e.g., "us", "uk")') .optional(); - src/constants.ts:10-15 (helper)SCRAPER_API_TARGETS enum defining GOOGLE_AI_MODE = 'google_ai_mode', which is used as the target parameter when scraping.
export enum SCRAPER_API_TARGETS { GOOGLE_SEARCH = 'google_search', GOOGLE_TRAVEL_HOTELS = 'google_travel_hotels', GOOGLE_ADS = 'google_ads', GOOGLE_LENS = 'google_lens', GOOGLE_AI_MODE = 'google_ai_mode',