Get Amazon.in Product Detail
get_productRetrieve detailed Amazon.in product information including price, MRP, discount, rating, reviews, and availability. Provide an ASIN or product URL to get structured data.
Instructions
Fetch a single amazon.in product's details by ASIN or URL.
Scrapes the product page and returns price, MRP, discount %, rating, review count, availability, bullets, brand, seller, delivery info, and a Keepa price-history URL.
Args:
asin_or_url (string): plain 10-char ASIN (e.g., "B0BDHWDR12") or any amazon.in product URL containing /dp/
Returns: JSON with schema: { "asin": string, "title": string, "url": string, "image": string, "price_inr": number, "price_display": string, "mrp_inr": number, "discount_percent": number, "rating": number, "review_count": number, "in_stock": boolean, "availability": string, "bullets": string[], "brand": string, "seller": string, "delivery": string, "price_history_url": string }
Error handling:
"Could not extract ASIN" → input was not a valid ASIN or amazon.in URL
"Bot-check page" → retry after a delay
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| asin_or_url | Yes | Amazon.in ASIN (10 chars) or any product URL containing /dp/<ASIN> |
Implementation Reference
- src/index.ts:277-302 (handler)The async handler function for the 'get_product' tool. It extracts an ASIN from input (via extractAsinFromUrl), fetches the product page HTML (via fetchHtml), parses it into a ProductDetail object (via parseProduct), and returns the result as JSON.
async (params) => { const asin = extractAsinFromUrl(params.asin_or_url.trim()); if (!asin) { return { content: [ { type: "text", text: "Error: Could not extract ASIN. Pass a 10-character ASIN (e.g., B0BDHWDR12) or an amazon.in URL containing /dp/<ASIN>.", }, ], }; } try { const url = `${AMAZON_BASE}/dp/${asin}`; const html = await fetchHtml(url); const product = parseProduct(html, asin); const text = JSON.stringify(product, null, 2); return { content: [{ type: "text", text: truncate(text, product) }], structuredContent: product as unknown as Record<string, unknown>, }; } catch (err) { return { content: [{ type: "text", text: friendlyError(err) }] }; } } - src/index.ts:126-134 (schema)Zod schema defining the input for get_product: a single string field 'asin_or_url' (10-2048 chars) that accepts either a plain ASIN or an amazon.in URL containing /dp/<ASIN>.
const GetProductInputSchema = z .object({ asin_or_url: z .string() .min(10) .max(2048) .describe("Amazon.in ASIN (10 chars) or any product URL containing /dp/<ASIN>"), }) .strict(); - src/index.ts:234-303 (registration)Registration of the 'get_product' tool with the MCP server, including title, description, input schema (GetProductInputSchema.shape), annotations, and the handler callback.
server.registerTool( "get_product", { title: "Get Amazon.in Product Detail", description: `Fetch a single amazon.in product's details by ASIN or URL. Scrapes the product page and returns price, MRP, discount %, rating, review count, availability, bullets, brand, seller, delivery info, and a Keepa price-history URL. Args: - asin_or_url (string): plain 10-char ASIN (e.g., "B0BDHWDR12") or any amazon.in product URL containing /dp/<ASIN> Returns: JSON with schema: { "asin": string, "title": string, "url": string, "image": string, "price_inr": number, "price_display": string, "mrp_inr": number, "discount_percent": number, "rating": number, "review_count": number, "in_stock": boolean, "availability": string, "bullets": string[], "brand": string, "seller": string, "delivery": string, "price_history_url": string } Error handling: - "Could not extract ASIN" → input was not a valid ASIN or amazon.in URL - "Bot-check page" → retry after a delay`, inputSchema: GetProductInputSchema.shape, annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true, }, }, async (params) => { const asin = extractAsinFromUrl(params.asin_or_url.trim()); if (!asin) { return { content: [ { type: "text", text: "Error: Could not extract ASIN. Pass a 10-character ASIN (e.g., B0BDHWDR12) or an amazon.in URL containing /dp/<ASIN>.", }, ], }; } try { const url = `${AMAZON_BASE}/dp/${asin}`; const html = await fetchHtml(url); const product = parseProduct(html, asin); const text = JSON.stringify(product, null, 2); return { content: [{ type: "text", text: truncate(text, product) }], structuredContent: product as unknown as Record<string, unknown>, }; } catch (err) { return { content: [{ type: "text", text: friendlyError(err) }] }; } } ); - src/parse.ts:335-371 (helper)The parseProduct() function that parses the product HTML into a ProductDetail object, extracting title, prices, MRP, discount, rating, review count, availability, feature bullets, brand, seller, and delivery info.
export function parseProduct(html: string, asin: string): ProductDetail { const $: CheerioAPI = cheerio.load(html); const title = firstText($("#productTitle")) || firstText($("h1#title span")) || "Unknown product"; const prices = extractProductPrices($); const ratings = extractProductRating($); const stock = extractAvailability($, typeof prices.priceInr === "number"); const sellerInfo = extractSellerInfo($); const detail: ProductDetail = { asin, title, url: withAffiliateTag(`${AMAZON_BASE}/dp/${asin}`), in_stock: stock.inStock, bullets: extractBullets($), price_history_url: keepaUrl(asin), }; const image = extractProductImage($); if (image) detail.image = image; if (prices.priceText) detail.price_display = prices.priceText; if (typeof prices.priceInr === "number") detail.price_inr = prices.priceInr; if (typeof prices.mrpInr === "number") detail.mrp_inr = prices.mrpInr; if (typeof prices.discountPercent === "number") detail.discount_percent = prices.discountPercent; if (typeof ratings.rating === "number") detail.rating = ratings.rating; if (typeof ratings.reviewCount === "number") detail.review_count = ratings.reviewCount; if (stock.availability) detail.availability = stock.availability; if (sellerInfo.brand) detail.brand = sellerInfo.brand; if (sellerInfo.seller) detail.seller = sellerInfo.seller; if (sellerInfo.delivery) detail.delivery = sellerInfo.delivery; return detail; } - src/parse.ts:41-45 (helper)The extractAsinFromUrl() helper that validates and extracts an ASIN from either a raw 10-character ASIN string or an amazon.in URL containing /dp/<ASIN>.
export function extractAsinFromUrl(input: string): string | undefined { if (ASIN_REGEX.test(input)) return input; const match = input.match(ASIN_FROM_URL_REGEX); return match?.[1]?.toUpperCase(); }