Skip to main content
Glama
2025-06-23_15-37_create_getProductDetails.md9.24 kB
rigwild: Add a new feature to read a product details by ASIN (getProductDetails) there is 1 parameter which is ASIN. ASIN is a product identifier The URL to the product is: https://www.amazon.es/-/en/gp/product/B0B15FKR8T With format like https://www.amazon.es/-/en/gp/product/{ASIN} When you are navigating to the page, you should scrape: - The product title at selector `span#productTitle` - The product price - If the product is subscribe and save (to verify, check `#subscriptionPrice` is not empty), use selector `$("#subscriptionPrice .a-price .a-offscreen").textContent` - Otherwise, use selector `$(".priceToPay").textContent` - The product description - `#productOverview_feature_div` - `#featurebullets_feature_div` - `#productFactsDesktop_feature_div` - `#brandSnapshot_feature_div` - The product reviews - The average rating at selector `$("#averageCustomerReviews span.a-size-small.a-color-base").textContent.trim()` - The number of reviews at selector `$("#acrCustomerReviewLink span").getAttribute("aria-label")` - The product images at selector `$("#main-image-container img").src` tell me how you plan to execute the change, ONLY SAY, then i will tell you if I agree or not. also suggest any data i could add GitHub Copilot: Here's my plan to execute the `getProductDetails` feature: ## Implementation Plan 1. **Add new function in amazon.ts**: - Create `getProductDetails(asin: string)` function following the same pattern as existing functions - Add mock support with `USE_MOCKS` and `EXPORT_LIVE_SCRAPING_FOR_MOCKS` - Navigate to `https://www.amazon.es/-/en/gp/product/{asin}` - Include login check with `throwIfNotLoggedIn` 2. **Data extraction structure**: ```typescript interface ProductDetails { asin: string title: string price: string priceType: 'subscribe-and-save' | 'regular' description: { overview?: string features?: string facts?: string brandSnapshot?: string } reviews: { averageRating?: string totalReviews?: string } mainImage?: string } ``` 3. **Add new tool in index.ts**: - Tool name: `get-product-details` - Parameter: `asin` (10-character string validation using zod) - Same error handling pattern as existing tools - Return formatted JSON response 4. **Scraping implementation**: - Wait for product page to load using appropriate selectors - Extract data using the selectors you specified - Handle cases where elements might not exist (optional fields) - Export mock data when `EXPORT_LIVE_SCRAPING_FOR_MOCKS` is enabled ## Additional data suggestions: - **Availability status** (in stock, out of stock, limited availability) - **Product dimensions/weight** (if available) - **Brand name** - **Product category/department** - **Delivery information** (Prime eligible, delivery dates) - **Product variants** (size, color options if available) - **Related/recommended products ASINs** - **Product badges** (Amazon's Choice, Best Seller, etc.) Do you agree with this approach? rigwild: i dont need more data, lets code GitHub Copilot: I'll implement the `getProductDetails` feature now. Let me start by adding the function to `amazon.ts` and then add the tool to `index.ts`. ```` ```` Made changes. Now I need to update the import statement in `index.ts` to include the new function and add the new tool: ``` Made changes. ``` ```` ```` Made changes. Perfect! I've successfully implemented the `getProductDetails` feature. Here's what I added: ## What was implemented: 1. **In `amazon.ts`**: - Added `ProductDetails` interface with all the required fields - Added `getProductDetails(asin: string)` function that follows the same pattern as existing functions - Includes mock support and live scraping export functionality - Navigates to the product URL using the provided ASIN - Includes login check with `throwIfNotLoggedIn` - Extracts all the data you requested using the specified selectors 2. **In `index.ts`**: - Updated the import to include `getProductDetails` - Added new `get-product-details` tool with proper ASIN validation - Includes the same error handling pattern as other tools - Returns formatted JSON response ## Key features implemented: - **Product title** from `span#productTitle` - **Price detection** with automatic detection of subscribe-and-save vs regular pricing - **Description sections** from all 4 specified selectors - **Reviews data** including average rating and total reviews count - **Main product image** from the specified selector - **Mock support** for testing - **Error handling** and validation - **Logging** for debugging The function will return a structured `ProductDetails` object with all the scraped information, and it's now available as a tool that can be called with any valid 10-character ASIN. rigwild: add a test GitHub Copilot: I'll check the current file contents first and then add a test for the `getProductDetails` function. Let me see what test files already exist and follow the same pattern. Let me check the existing test files to see their pattern: Let me examine one of the existing test files to understand the pattern: Now let me check another test file to confirm the pattern: Perfect! Now I understand the test pattern. Let me create a test file for `getProductDetails`: Made changes. Perfect! I've created a comprehensive test file for the `getProductDetails` function that follows the same pattern as the existing tests. The test includes: ## Test Features: 1. **Main functionality test** with a valid ASIN (B0B15FKR8T - the example you provided) 2. **Result validation** checking that all required fields are present 3. **Detailed logging** showing what was extracted: - Product title - Price and price type - Number of description sections found - Whether reviews data is available - Whether main image is available 4. **Error handling test** with an invalid ASIN to ensure proper validation 5. **Clear pass/fail indicators** with ✅ and ❌ symbols The test file is located at amazon.getProductDetails.test.ts and can be run to verify that the `getProductDetails` function works correctly. You can run this test by executing: ```bash node build/amazon.getProductDetails.test.js ``` (after building the TypeScript files) rigwild: how can i return the product details and product image to be shown in claude desktop UI? #file:index.ts:122-156 GitHub Copilot: To display the product details and image properly in Claude Desktop UI, you need to return both text and image content types. Here's how to modify the tool: ````typescript server.tool( 'get-product-details', 'Get detailed information about a product using its ASIN', { asin: z .string() .length(10, { message: 'ASIN must be a 10-character string.' }) .describe('The ASIN (Amazon Standard Identification Number) of the product to get details for. Must be a 10-character string.'), }, async ({ asin }) => { let result: Awaited<ReturnType<typeof getProductDetails>> try { result = await getProductDetails(asin) } catch (error: any) { console.error('[ERROR][get-product-details] Error in get-product-details tool:', error) return { content: [ { type: 'text', text: `An error occurred while retrieving product details. Error: ${error.message}`, }, ], } } const content: any[] = [] // Add product image if available if (result.mainImage) { content.push({ type: 'image', data: result.mainImage, mimeType: 'image/jpeg' }) } // Add formatted product details const productInfo = `# ${result.title} **ASIN:** ${result.asin} **Price:** ${result.price} **Subscribe & Save Available:** ${result.canUseSubscribeAndSave ? 'Yes' : 'No'} ## Reviews ${result.reviews.averageRating ? `⭐ **Rating:** ${result.reviews.averageRating}` : ''} ${result.reviews.reviewsCount ? `📝 **Reviews:** ${result.reviews.reviewsCount}` : ''} ## Description ${result.description.overview ? `**Overview:**\n${result.description.overview}\n\n` : ''} ${result.description.features ? `**Features:**\n${result.description.features}\n\n` : ''} ${result.description.facts ? `**Product Facts:**\n${result.description.facts}\n\n` : ''} ${result.description.brandSnapshot ? `**Brand Info:**\n${result.description.brandSnapshot}\n\n` : ''} --- *Product URL: https://www.amazon.es/-/en/gp/product/${result.asin}*` content.push({ type: 'text', text: productInfo }) return { content } } ) ```` This modification: 1. **Returns the product image** using the `image` content type with the URL from `result.mainImage` 2. **Formats the product details** as Markdown for better readability in Claude Desktop 3. **Structures the information** with clear sections (title, price, reviews, description) 4. **Includes the product URL** for easy access 5. **Handles missing data** gracefully by only showing sections that have content The image will be displayed inline with the product details, making it much more user-friendly in the Claude Desktop UI.

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/drahmad89/amazon-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server