google_lens
Scrape and parse Google Lens image search results by providing an image URL. Get structured data from visual searches.
Instructions
Scrape Google Lens image search results with automatic parsing
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Image URL for Google Lens search (e.g., "https://example.com/image.jpg") | |
| jsRender | No | Should the request be opened in a headless browser, false by default | |
| deviceType | No | Device type to emulate for the request |
Implementation Reference
- The GoogleLensTool class extending Tool. Contains the register() method which defines the tool handler, input schema, and invokes the ScraperAPI client with target 'google_lens'. Also includes transformResponse to strip high-character-count fields like 'url_thumbnail'.
export class GoogleLensTool extends Tool { toolset = TOOLSET.SEARCH; private static FIELDS_WITH_HIGH_CHAR_COUNT = ['url_thumbnail']; transformResponse = ({ data }: { data: object }) => { for (const fieldToRemove of GoogleLensTool.FIELDS_WITH_HIGH_CHAR_COUNT) { data = removeKeyFromNestedObject({ obj: data, keyToRemove: fieldToRemove }); } return { data: JSON.stringify(data) }; }; register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'google_lens', { description: 'Scrape Google Lens image search results with automatic parsing', inputSchema: { query: z.string().describe('Image URL for Google Lens search (e.g., "https://example.com/image.jpg")'), jsRender: zodJsRender, deviceType: zodDeviceType, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.GOOGLE_LENS, 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, }, ], }; } ); }; } - The input schema for the 'google_lens' tool: requires a 'query' (image URL string), optional 'jsRender' (boolean), and optional 'deviceType' (enum: desktop/mobile/tablet).
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'google_lens', { description: 'Scrape Google Lens image search results with automatic parsing', inputSchema: { query: z.string().describe('Image URL for Google Lens search (e.g., "https://example.com/image.jpg")'), jsRender: zodJsRender, deviceType: zodDeviceType, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, - src/server/sapi-base-server.ts:66-117 (registration)GoogleLensTool is instantiated in the allTools array in ScraperAPIBaseServer, which is the central registration point for all tools.
static allTools: Tool[] = [ new ScrapeAsMarkdownTool(), new ScreenshotTool(), new GoogleSearchTool(), new GoogleAdsTool(), new GoogleLensTool(), new GoogleAiModeTool(), new GoogleTravelHotelsTool(), new AmazonSearchTool(), new AmazonProductTool(), new AmazonPricingTool(), new AmazonSellersTool(), new AmazonBestsellersTool(), new WalmartSearchTool(), new WalmartProductTool(), new TargetSearchTool(), new TargetProductTool(), new TiktokPostTool(), new TiktokShopSearchTool(), new TiktokShopProductTool(), new TiktokShopUrlTool(), new YoutubeMetadataTool(), new YoutubeChannelTool(), new YoutubeSubtitlesTool(), new YoutubeSearchTool(), new RedditPostTool(), new RedditSubredditTool(), new RedditUserTool(), new BingSearchTool(), new ChatGPTTool(), new PerplexityTool(), ]; registerTools({ toolsets }: { toolsets: TOOLSET[] }) { if (toolsets.length === 0) { this.registerAllTools(); return; } for (const toolset of toolsets) { const tools = ScraperAPIBaseServer.allTools.filter(tool => tool.toolset === toolset); for (const tool of tools) { tool.register({ server: this.server, sapiClient: this.sapiClient, auth: this.auth }); } } } registerAllTools() { for (const tool of ScraperAPIBaseServer.allTools) { tool.register({ server: this.server, sapiClient: this.sapiClient, auth: this.auth }); } } - src/tools/index.ts:1-10 (registration)Re-exports the google-lens module from the tools barrel index.
export * from './amazon-search'; export * from './amazon-product'; export * from './amazon-pricing'; export * from './amazon-sellers'; export * from './amazon-bestsellers'; export * from './bing-search'; export * from './chatgpt'; export * from './google-search'; export * from './google-ads'; export * from './google-lens'; - Helper method transformResponse strips the 'url_thumbnail' field from the API response to reduce character count, then stringifies the result.
private static FIELDS_WITH_HIGH_CHAR_COUNT = ['url_thumbnail']; transformResponse = ({ data }: { data: object }) => { for (const fieldToRemove of GoogleLensTool.FIELDS_WITH_HIGH_CHAR_COUNT) { data = removeKeyFromNestedObject({ obj: data, keyToRemove: fieldToRemove }); }