Skip to content
Draft
Show file tree
Hide file tree
Changes from 2 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
79 changes: 79 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
# AGENTS.md

Development guidance for coding agents (Claude Code, Cursor, Codex, and others) when working on mcp-edd.

## Project Overview

MCP server for the Easy Digital Downloads REST API. Registers 16 tools for accessing EDD store data including products, sales, customers, statistics, discounts, and download logs, plus a connection validator.
Comment thread
jack-arturo marked this conversation as resolved.
Outdated

## Architecture

```
src/
├── index.ts # MCP server entry, tool registrations
├── edd-client.ts # EDD REST API client with retry logic
├── types.ts # Zod schemas and TypeScript types
├── env.ts # Environment loading + validation
└── stdio.ts # Redirects console.log/info/debug to stderr so they can't corrupt the stdio protocol stream
```

`src/stdio.ts` is imported first thing in `src/index.ts:2` so the console patch is applied before anything can write to stdout.

## Tools

All 16 tools are registered via `server.registerTool(...)` in `src/index.ts`:

- `edd_list_products`, `edd_get_product`
- `edd_list_sales`, `edd_get_sale`
- `edd_list_customers`, `edd_get_customer`
- `edd_get_stats`, `edd_get_stats_by_date`, `edd_get_stats_by_product`, `edd_get_stats_by_preset`
- `edd_list_discounts`, `edd_get_discount`, `edd_get_discount_by_code`, `edd_list_active_discounts`
- `edd_get_download_logs`
- `edd_validate_connection`

## Common Commands

```bash
npm run build # Compile TypeScript (tsc) + chmod +x dist/index.js
npm run dev # Watch mode (tsx watch src/index.ts)
npm start # Run compiled server (node dist/index.js)
npm test # Unit tests only
npm run test:integration # Integration tests (needs credentials)
npm run test:all # All tests
npm run lint # ESLint over src/
npm run format # Prettier write over src/
```

## Testing

Unit tests use Jest with mocked fetch (`tests/unit/`). Integration tests (`tests/integration/`) require environment variables:

```bash
EDD_API_URL=https://example.com/edd-api/
EDD_API_KEY=your-key
EDD_API_TOKEN=your-token
```

## Environment Variables

Validated in `src/env.ts:81` (`validateEnv`); all three are required:

- `EDD_API_URL` — EDD store API base URL (normalized to `.../edd-api/` form)
- `EDD_API_KEY` — EDD API public key
- `EDD_API_TOKEN` — EDD API token

`loadEnv` (`src/env.ts:9`) also reads a `.env` file, searching `./.env`, `$HOME/.mcp-edd.env`, and `$HOME/.config/mcp-edd/.env`.

## Key Patterns

- Uses the modern `McpServer` class from the MCP SDK 1.x (`src/index.ts:3`).
- Zod schemas for input validation.
- Exponential backoff retry, 3 attempts by default (`src/edd-client.ts:147`).
- The V2 products endpoint is public (no auth required for public products); all other endpoints require auth (`src/edd-client.ts:231`).

## EDD API Notes

- Auth via query params: `?key=xxx&token=xxx`.
- Stats endpoint returns data directly (not wrapped in a `stats` object); the client normalizes the flat response.
- Date format for ranges: YYYYMMDD.
- Product and date filters are issued via separate client methods (`getStatsByProduct` vs `getStatsByDateRange`) and are not combined in a single stats request.
53 changes: 1 addition & 52 deletions CLAUDE.md
Original file line number Diff line number Diff line change
@@ -1,52 +1 @@
# CLAUDE.md

Development guidance for Claude Code when working on mcp-edd.

## Project Overview

MCP server for Easy Digital Downloads REST API. Provides 12 tools for accessing EDD store data including sales, customers, products, discounts, and statistics.

## Architecture

```
src/
├── index.ts # MCP server entry, tool definitions
├── edd-client.ts # EDD REST API client with retry logic
├── types.ts # Zod schemas and TypeScript types
└── env.ts # Environment variable validation
```

## Common Commands

```bash
npm run build # Compile TypeScript
npm run dev # Watch mode development
npm test # Unit tests only
npm run test:integration # Integration tests (needs credentials)
npm run test:all # All tests
npm run lint # ESLint
```

## Testing

Unit tests use Jest with mocked fetch. Integration tests require environment variables:

```bash
EDD_API_URL=https://example.com/edd-api/
EDD_API_KEY=your-key
EDD_API_TOKEN=your-token
```

## Key Patterns

- Uses modern McpServer class from SDK 1.x
- Zod schemas for input validation
- Exponential backoff retry (3 attempts)
- Products endpoint is public (no auth), all others require auth

## EDD API Notes

- Auth via query params: `?key=xxx&token=xxx`
- Stats endpoint returns data directly (not wrapped in `stats` object)
- Date format for ranges: YYYYMMDD
- Product and date filters cannot be combined on stats endpoint
@AGENTS.md
Loading