Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions .claude/settings.local.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"permissions": {
"allow": [
"Bash(npm run build:*)",
"Bash(rm:*)",
"Bash(ls:*)",
"mcp__ide__getDiagnostics",
"Bash(git checkout:*)",
"Bash(git add:*)",
"Bash(git rm:*)",
"Bash(git commit:*)",
"Bash(gh repo view:*)",
"Bash(gh repo fork:*)",
"Bash(git remote add:*)",
"Bash(git push:*)",
"Bash(node:*)"
],
"deny": []
}
}
8 changes: 8 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"cSpell.words": [
"activecart",
"featurebullets",
"networkidle",
"yohtmlc"
]
}
87 changes: 87 additions & 0 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
# CLAUDE.md

This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository.

## Overview

This is an Amazon MCP (Model Context Protocol) Server that enables AI assistants to interact with Amazon services through web scraping. The server uses Puppeteer for browser automation and exposes Amazon functionality through MCP tools.

## Development Commands

```bash
# Install dependencies (use -D flag for Puppeteer)
npm install -D

# Build TypeScript to JavaScript
npm run build

# Clean mock HTML files
npm run clean
```

## Architecture

### Core Components

- **MCP Server** (`src/index.ts`): Defines and exposes tools via the MCP protocol
- **Amazon Scraper** (`src/amazon.ts`): Contains all Amazon interaction logic using Puppeteer and Cheerio
- **Configuration** (`src/config.ts`): Manages server settings and paths
- **Browser Utils** (`src/utils.ts`): Helper functions for Puppeteer browser automation

### Key Dependencies

- `@modelcontextprotocol/sdk`: MCP framework
- `puppeteer`: Browser automation
- `cheerio`: HTML parsing
- `zod`: Schema validation

### Authentication

The server requires Amazon cookies for authentication:
1. Export cookies from browser using a cookie export extension
2. Save to `amazonCookies.json` in project root
3. Format: Array of cookie objects with standard properties

## Important Implementation Details

### Browser Automation
- Uses headless Chrome with specific flags to avoid detection
- Implements user agent spoofing
- Handles Amazon's anti-bot measures

### Error Handling
- Detects login page redirects and throws authentication errors
- Implements retry logic for network failures
- Provides detailed error messages for debugging

### Mock Mode
- Set `USE_MOCK_RESPONSES=true` in environment to use mock HTML files
- Mock files stored in `mock/` directory
- Useful for development and testing without hitting Amazon

### Logging
- Server logs to `~/Library/Logs/Claude/mcp-server-amazon.log`
- Check logs for debugging authentication or scraping issues

## MCP Tools Exposed

1. `search-products`: Search Amazon catalog
2. `get-product-details`: Get detailed product information
3. `get-orders-history`: View past orders
4. `get-cart-content`: View current cart
5. `add-to-cart`: Add items to cart
6. `clear-cart`: Remove all items from cart
7. `perform-purchase`: Complete purchase (mock mode only)

## Testing Approach

No formal test suite exists. Testing is done through:
- Manual testing with Claude Desktop
- Mock mode for development
- Log analysis for debugging

## Common Issues

1. **Authentication failures**: Update cookies from browser
2. **Scraping failures**: Amazon HTML structure may have changed
3. **Rate limiting**: Add delays between requests if needed
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ This server allows you to interact with Amazon's services using the MCP (Model C
- **Cart management**: Add items or clear your Amazon cart
- **Ordering**: Place orders (fake for demonstration purposes)
- **Orders history**: Retrieve your recent Amazon orders details
- **Returns**: Initiate returns or replacements for eligible orders

## Demo

Expand Down
18 changes: 9 additions & 9 deletions amazonCookies.example.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[
{
"domain": ".amazon.es",
"domain": ".amazon.com",
"expirationDate": 1765985623.4719,
"hostOnly": false,
"httpOnly": false,
Expand All @@ -13,7 +13,7 @@
"value": "262-3992533-1234567"
},
{
"domain": "www.amazon.es",
"domain": "www.amazon.com",
"expirationDate": 1751038456.64728,
"hostOnly": true,
"httpOnly": false,
Expand All @@ -26,7 +26,7 @@
"value": "eyJ3YXNtVGVzxxxxxxxxxxxxxxx"
},
{
"domain": ".amazon.es",
"domain": ".amazon.com",
"expirationDate": 1766055357.407565,
"hostOnly": false,
"httpOnly": false,
Expand All @@ -39,7 +39,7 @@
"value": "xxxxxxxxxx"
},
{
"domain": ".amazon.es",
"domain": ".amazon.com",
"expirationDate": 1765985623.472211,
"hostOnly": false,
"httpOnly": false,
Expand All @@ -52,7 +52,7 @@
"value": "2082787201l"
},
{
"domain": ".amazon.es",
"domain": ".amazon.com",
"expirationDate": 1765985623.313376,
"hostOnly": false,
"httpOnly": true,
Expand All @@ -65,7 +65,7 @@
"value": "Atza|IwEBIOy-xxxxxxxxx"
},
{
"domain": ".amazon.es",
"domain": ".amazon.com",
"expirationDate": 1765985623.313526,
"hostOnly": false,
"httpOnly": true,
Expand All @@ -78,7 +78,7 @@
"value": "\"5qfQRHBU2eZuCZkFhj+xxxxxxxxx\""
},
{
"domain": ".amazon.es",
"domain": ".amazon.com",
"expirationDate": 1765985623.471672,
"hostOnly": false,
"httpOnly": false,
Expand All @@ -91,7 +91,7 @@
"value": "262-2607238-3505323"
},
{
"domain": ".amazon.es",
"domain": ".amazon.com",
"expirationDate": 1766055357.407166,
"hostOnly": false,
"httpOnly": false,
Expand All @@ -104,7 +104,7 @@
"value": "HUoAsHXDi+Hxxxxxxxxxxxxxxxxx"
},
{
"domain": ".amazon.es",
"domain": ".amazon.com",
"expirationDate": 1765985623.313788,
"hostOnly": false,
"httpOnly": true,
Expand Down
Loading