Skip to content

feat: Add return/replace items functionality#3

Open
davidvasandani wants to merge 3 commits intorigwild:mainfrom
davidvasandani:feat/add-return-replace-items
Open

feat: Add return/replace items functionality#3
davidvasandani wants to merge 3 commits intorigwild:mainfrom
davidvasandani:feat/add-return-replace-items

Conversation

@davidvasandani
Copy link
Contributor

@davidvasandani davidvasandani commented Jul 23, 2025

Summary

  • Adds the ability to initiate returns or replacements for Amazon orders
  • Implements a new MCP tool initiate-return that navigates to Amazon's return page
  • Extracts and displays returnable items with their eligibility status

Changes

  1. Order History Enhancement:

    • Added returnUrl field to each order in order history
    • URL follows format: https://www.amazon.com/spr/returns/cart?orderId=XXX&ref=ppx_yo2ov_dt_b_return_replace
  2. New MCP Tool:

    • initiate-return: Accepts an order ID and navigates to the return page
    • Returns information about returnable items including title, price, and eligibility
  3. Return Page Scraping:

    • Properly detects the return page by checking for "Choose items to return" heading
    • Extracts item details from checkboxes and associated elements
    • Handles error cases when orders are not eligible for returns

Test Results

Successfully tested with real Amazon orders:

  • βœ… Navigates to return page correctly
  • βœ… Extracts all returnable items (tested with 6 items)
  • βœ… Shows item details: title, price, order number
  • βœ… Correctly identifies return eligibility status

Usage

// Get order history first
const orders = await getOrdersHistory()
// Each order now has a returnUrl field

// Initiate return for a specific order
const result = await initiateReturn('114-3824678-7026645')
// Returns list of returnable items with eligibility status

πŸ€– Generated with Claude Code

davidvasandani and others added 3 commits July 23, 2025 07:15
- Break out monolithic amazon.ts into separate modules:
  - products.ts: Product search and details functions
  - cart.ts: Cart management functions (add, clear, get content)
  - orders.ts: Order history functions

- Add dynamic Amazon domain extraction from cookies:
  - Automatically detects regional Amazon sites (amazon.co.uk, amazon.de, etc.)
  - Falls back to amazon.com if no cookies found
  - All URLs now use the detected domain instead of hardcoded values

- Update all imports and test files to use new module structure
- Add CLAUDE.md documentation for future Claude Code instances
- Fix TypeScript diagnostic issues

This refactoring improves code maintainability and enables the MCP server
to work with any regional Amazon site based on the provided cookies.

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Update getProductDetails test to dynamically search for products before testing
- Update addToCart test to find available products through search
- Fix cart confirmation message check to support both "Added to cart" and "Added to basket"
- Add helper functions to find suitable test products
- Tests now adapt to product availability instead of using hardcoded ASINs

This ensures tests remain functional even when specific products become unavailable.

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
- Add returnUrl field to order history data
- Create new MCP tool 'initiate-return' for starting returns
- Implement return page navigation and item extraction
- Extract returnable items with eligibility status
- Support both live and mock modes

πŸ€– Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant

Comments