Skip to main content
Glama
2025-06-23_20-02_create_clearCart.md3.32 kB
rigwild: Add a new feature to clear the cart on Amazon Navigate to this page: https://www.amazon.es/-/en/gp/cart/view.html Find the delete buttons and click them to remove all items from the cart. $$('span[data-action="delete-active"]') Add a small delay between clicks to ensure the page updates correctly. 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 #file:CLAUDE.md #file:amazon.ts #file:index.ts GitHub Copilot: Let me examine the current code structure to understand how to implement the clear cart feature. Based on my examination of the codebase, here's my plan to implement the clear cart feature: ## Execution Plan: 1. **Add `clearCart()` function in amazon.ts**: - Navigate to `https://www.amazon.es/-/en/gp/cart/view.html` - Use the selector `$$('span[data-action="delete-active"]')` to find all delete buttons - Click each delete button with a small delay (500ms) between clicks - Wait for page updates after each deletion - Handle potential modals/confirmations - Return summary of items removed 2. **Add the MCP tool in index.ts**: - Register `clear-cart` tool with no parameters - Call the `clearCart()` function - Return success/failure message with count of items removed 3. **Create test file `amazon.clearCart.test.ts`**: - Test with mock HTML containing cart items - Test empty cart scenario - Test error handling 4. **Add mock data in `mocks/clearCart.html`**: - Sample cart page with multiple items to test deletion ## Suggested Additional Data: - **Confirmation parameter**: Optional boolean to require explicit confirmation before clearing (default: false) - **Return detailed summary**: List of items that were removed (title, price, quantity) - **Partial clear option**: Ability to specify max number of items to remove - **Dry run mode**: Preview what would be removed without actually clearing Do you agree with this plan? rigwild: dont need a mock for this feature! its only an action. I dont care about the data of the removed items, just clear dont ask for confirmation to user, just clear the cart no dry run mode execute the change GitHub Copilot: I'll implement the clear cart feature according to your requirements. Let me start by adding the function to amazon.ts. ```` ```` Made changes. I need to fix the timeout method. Let me update it to use the correct Puppeteer API: ``` Made changes. ``` Now I need to export the `clearCart` function and add it to the index.ts file. First, let me check the current exports: Good, the function is already exported. Now I need to add it to the imports and create the tool in index.ts: ``` Made changes. ``` Now I need to add the tool definition. Let me see where to add it in the index.ts file: ```` ```` Made changes. Now let me create a test file for the clearCart function: Made changes. Let me check what testing framework is being used by looking at existing test files: I see the project uses simple test functions rather than a testing framework. Let me update the test file to match this pattern: ``` Made changes. ``` Now let me check for any compilation errors and build the project: Great! Now let me build the project to ensure everything compiles correctly:

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