amazon_product
Scrape Amazon product pages by ASIN with automatic parsing. Supports custom domain, device type, geolocation, and headless browser rendering.
Instructions
Scrape Amazon Product page with automatic parsing
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| query | Yes | Amazon product ASIN (e.g., "B09H74FXNW") | |
| jsRender | No | Should the request be opened in a headless browser, false by default | |
| domain | No | Amazon domain (e.g., amazon.com, amazon.co.uk) | |
| deviceType | No | Device type to emulate for the request | |
| geo | No | Amazon geo location (e.g., 10001 for US ZIP code) |
Implementation Reference
- The AmazonProductTool class extends Tool. The register() method (lines 31-69) defines the handler that scrapes an Amazon product page using the Scraper API with 'amazon_product' target, parses the response, and strips high-character-count fields (bullet_points, description) via transformResponse.
export class AmazonProductTool extends Tool { toolset = TOOLSET.ECOMMERCE; private static FIELDS_WITH_HIGH_CHAR_COUNT = ['bullet_points', 'description']; transformResponse = ({ data }: { data: object }) => { for (const fieldToRemove of AmazonProductTool.FIELDS_WITH_HIGH_CHAR_COUNT) { data = removeKeyFromNestedObject({ obj: data, keyToRemove: fieldToRemove }); } return { data: JSON.stringify(data) }; }; register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'amazon_product', { description: 'Scrape Amazon Product page with automatic parsing', inputSchema: { query: z.string().describe('Amazon product ASIN (e.g., "B09H74FXNW")'), jsRender: zodJsRender, domain: zodDomain, deviceType: zodDeviceType, geo: zodGeo, }, annotations: { readOnlyHint: true, openWorldHint: true, }, }, async (scrapingParams: ScrapingMCPParams, extra: ProgressExtra) => { const params = { ...scrapingParams, target: SCRAPER_API_TARGETS.AMAZON_PRODUCT, 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 amazon_product tool, defining 'query' (ASIN string required), and optional fields: 'jsRender', 'domain', 'deviceType', and 'geo'.
inputSchema: { query: z.string().describe('Amazon product ASIN (e.g., "B09H74FXNW")'), jsRender: zodJsRender, domain: zodDomain, deviceType: zodDeviceType, geo: zodGeo, }, - src/server/sapi-base-server.ts:75-75 (registration)The AmazonProductTool is instantiated and added to the allTools array in ScraperAPIBaseServer (line 75), which triggers its registration with the MCP server.
new AmazonProductTool(), - src/utils.ts:17-44 (helper)removeKeyFromNestedObject helper function used to recursively strip specified keys (e.g., 'bullet_points', 'description') from the scraped data object.
export const removeKeyFromNestedObject = ({ obj, keyToRemove, }: { obj: object; keyToRemove: string; }): object => { if (typeof obj !== 'object' || obj === null) { return obj; } if (Array.isArray(obj)) { return obj.map(item => removeKeyFromNestedObject({ obj: item, keyToRemove })); } const record = obj as Record<string, unknown>; const newObj: Record<string, unknown> = {}; for (const key in record) { if (key === keyToRemove) { continue; } newObj[key] = removeKeyFromNestedObject({ obj: record[key] as object, keyToRemove }); } return newObj; }; - src/tools/amazon-product/amazon-product-tool.ts:31-33 (registration)The register() method calls server.registerTool('amazon_product', ...) to register the tool name 'amazon_product' with the MCP server.
register = ({ server, sapiClient, auth }: ToolRegistrationArgs) => { server.registerTool( 'amazon_product',