Skip to content

Commit 10e2005

Browse files
committed
Initial commit
0 parents  commit 10e2005

28 files changed

Lines changed: 11278 additions & 0 deletions

.env.example

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# RedTrack API key (required)
2+
REDTRACK_API_KEY=your_api_key_here
3+
4+
# Optional: custom .env file location
5+
# REDTRACK_ENV_FILE=.env

.gitattributes

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
* text=auto eol=lf

.github/workflows/ci.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [master]
6+
pull_request:
7+
8+
jobs:
9+
test:
10+
runs-on: ${{ matrix.os }}
11+
strategy:
12+
matrix:
13+
os: [ubuntu-latest, windows-latest]
14+
steps:
15+
- uses: actions/checkout@v4
16+
- uses: oven-sh/setup-bun@v2
17+
- run: bun install --frozen-lockfile
18+
- run: bun test
19+
- run: bunx biome check .

.github/workflows/release.yml

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
name: Release
2+
3+
on:
4+
push:
5+
tags: ["v*"]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
build:
12+
runs-on: ${{ matrix.runner }}
13+
strategy:
14+
matrix:
15+
include:
16+
- target: bun-darwin-arm64
17+
runner: macos-latest
18+
artifact: mcp-redtrack-darwin-arm64
19+
- target: bun-darwin-x64
20+
runner: macos-13
21+
artifact: mcp-redtrack-darwin-x64
22+
- target: bun-linux-x64
23+
runner: ubuntu-latest
24+
artifact: mcp-redtrack-linux-x64
25+
- target: bun-windows-x64
26+
runner: windows-latest
27+
artifact: mcp-redtrack-windows-x64.exe
28+
steps:
29+
- uses: actions/checkout@v4
30+
- uses: oven-sh/setup-bun@v2
31+
32+
- name: Set version from tag
33+
run: |
34+
VERSION=${GITHUB_REF_NAME#v}
35+
bun -e "const p=require('./package.json');p.version='$VERSION';require('fs').writeFileSync('package.json',JSON.stringify(p,null,2)+'\n')"
36+
shell: bash
37+
38+
- run: bun install --frozen-lockfile
39+
- run: bun test
40+
41+
- name: Build binary
42+
run: bun build src/index.ts --compile --target=${{ matrix.target }} --outfile=${{ matrix.artifact }}
43+
44+
- uses: actions/upload-artifact@v4
45+
with:
46+
name: ${{ matrix.artifact }}
47+
path: ${{ matrix.artifact }}
48+
49+
release:
50+
needs: build
51+
runs-on: ubuntu-latest
52+
steps:
53+
- uses: actions/download-artifact@v4
54+
with:
55+
path: artifacts
56+
57+
- name: Make binaries executable
58+
run: chmod +x artifacts/mcp-redtrack-darwin-*/mcp-redtrack-darwin-* artifacts/mcp-redtrack-linux-*/mcp-redtrack-linux-*
59+
60+
- uses: softprops/action-gh-release@v2
61+
with:
62+
generate_release_notes: true
63+
files: artifacts/**/*
64+
65+
publish:
66+
needs: build
67+
runs-on: ubuntu-latest
68+
steps:
69+
- uses: actions/checkout@v4
70+
- uses: oven-sh/setup-bun@v2
71+
72+
- name: Set version from tag
73+
run: |
74+
VERSION=${GITHUB_REF_NAME#v}
75+
bun -e "const p=require('./package.json');p.version='$VERSION';require('fs').writeFileSync('package.json',JSON.stringify(p,null,2)+'\n')"
76+
77+
- run: bun install --frozen-lockfile
78+
- run: bun run build:npm
79+
80+
- uses: actions/setup-node@v4
81+
with:
82+
node-version: 18
83+
registry-url: https://registry.npmjs.org
84+
85+
- run: npm publish --access public
86+
env:
87+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

.gitignore

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
node_modules/
2+
dist/
3+
mcp-redtrack
4+
*.tgz
5+
.env
6+
.env.local

AGENTS.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Agent Guidelines — mcp-redtrack
2+
3+
## Project structure
4+
5+
```
6+
src/
7+
├── index.ts # Entry point (stdio transport)
8+
├── server.ts # McpServer creation + tool registration
9+
├── config/
10+
│ └── env.ts # Zod-validated environment config
11+
├── services/
12+
│ ├── redtrack-api.ts # REST client with retry logic
13+
│ └── format.ts # Table/CSV/date formatters
14+
├── tools/
15+
│ ├── index.ts # registerAllTools barrel
16+
│ ├── campaigns.ts # Campaign tools (3)
17+
│ ├── logs.ts # Click & conversion log tools (2)
18+
│ ├── reports.ts # Aggregated report tool (1)
19+
│ └── entities.ts # Offers, sources, networks, landings, settings (7)
20+
└── utils/
21+
└── logger.ts # stderr logger
22+
```
23+
24+
## Authentication
25+
26+
All RedTrack API calls use `api_key` as a query parameter. The key is read from
27+
`REDTRACK_API_KEY` env var or `.env` file. No OAuth or token refresh needed.
28+
29+
## API conventions
30+
31+
- Base URL: `https://api.redtrack.io`
32+
- All GET endpoints accept query parameters
33+
- Pagination: `page` + `per` params
34+
- Date filtering: `date_from` + `date_to` (YYYY-MM-DD)
35+
- Status values: 1=active, 2=paused, 3=deleted
36+
- Comma-separated IDs for multi-filter (e.g. `ids=1,2,3`)
37+
38+
## Report grouping dimensions
39+
40+
campaign, offer, source, landing, network, country, region, city,
41+
os, browser, device, device_brand, connection_type, isp,
42+
date, hour, day_of_week, sub1-sub20,
43+
rt_source, rt_medium, rt_campaign, rt_adgroup, rt_ad, rt_placement, rt_keyword
44+
45+
## Tool registration pattern
46+
47+
```typescript
48+
export function registerXTools(server: McpServer): void {
49+
server.tool("tool_name", "description", { ...zodSchema }, async (args) => {
50+
const data = await apiCall(args);
51+
return { content: [{ type: "text", text: formatResult(data) }] };
52+
});
53+
}
54+
```
55+
56+
## Best practices
57+
58+
- Always return `{ content: [{ type: "text", text }] }`
59+
- Default date ranges to last 7 days for log queries
60+
- Use `formatTable()` for list responses, `JSON.stringify` for single items
61+
- Log to stderr only (stdout is MCP protocol)
62+
- Handle API errors by throwing (MCP SDK surfaces them to the client)

CLAUDE.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# mcp-redtrack
2+
3+
MCP server for the RedTrack affiliate tracking API.
4+
5+
## Quick reference
6+
7+
| Item | Value |
8+
|------|-------|
9+
| Runtime | Bun (dev) / Node 18+ (npm) |
10+
| Entry | `src/index.ts` |
11+
| Build | `bun run build` (binary) or `bun run build:npm` (Node) |
12+
| Test | `bun test` |
13+
| Lint | `biome check .` |
14+
| API base | `https://api.redtrack.io` |
15+
| Auth | `api_key` query parameter on every request |
16+
| Swagger | `swagger.json` (local copy) |
17+
18+
## Key patterns
19+
20+
- **MCP response format**: always `{ content: [{ type: "text", text: string }] }`
21+
- **fetchWithRetry**: exponential backoff on 429/5xx, 30s timeout, 2 retries
22+
- **Date defaults**: log tools default to last 7 days if no date range provided
23+
- **Config**: Zod-validated env, lazy singleton, .env file support
24+
- **Logging**: all logs to stderr via `log.info/warn/error/debug`
25+
26+
## Tools (14 total)
27+
28+
### Campaigns (3)
29+
- `get_campaigns` — list with filters and optional stats
30+
- `get_campaign` — single campaign by ID
31+
- `get_campaigns_v2` — v2 endpoint
32+
33+
### Logs (2)
34+
- `get_clicks` — click-level log (GET /tracks)
35+
- `get_conversions` — conversion-level log
36+
37+
### Reports (1)
38+
- `get_report` — aggregated stats grouped by dimension
39+
40+
### Entities (7)
41+
- `get_offers` / `get_offer` — offer management
42+
- `get_sources` / `get_source` — traffic sources
43+
- `get_networks` — affiliate networks
44+
- `get_landings` — landing pages
45+
- `get_settings` — account settings
46+
47+
## Adding new tools
48+
49+
1. Create `src/tools/newmodule.ts` with `registerXTools(server)` export
50+
2. Add Zod schemas for all parameters
51+
3. Call API via `services/redtrack-api.ts`
52+
4. Format output with `formatTable()` or JSON
53+
5. Register in `src/tools/index.ts`

README.md

Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
<p align="center">
2+
<img src="logo.svg" alt="mcp-redtrack" height="52">
3+
</p>
4+
5+
<h1 align="center">mcp-redtrack</h1>
6+
7+
<p align="center">MCP server for the <a href="https://redtrack.io">RedTrack</a> affiliate tracking API. Query campaigns, clicks, conversions, and reports from any MCP-compatible client (Claude Code, Claude Desktop, Cursor, etc.).</p>
8+
9+
## Quick start
10+
11+
```bash
12+
npx mcp-redtrack setup YOUR_API_KEY
13+
```
14+
15+
This prints the config snippet for your MCP client.
16+
17+
### Claude Code
18+
19+
```bash
20+
claude mcp add redtrack -e REDTRACK_API_KEY=YOUR_API_KEY -- npx mcp-redtrack
21+
```
22+
23+
### Claude Desktop / Cursor
24+
25+
Add to your MCP settings JSON:
26+
27+
```json
28+
{
29+
"mcpServers": {
30+
"redtrack": {
31+
"command": "npx",
32+
"args": ["mcp-redtrack"],
33+
"env": {
34+
"REDTRACK_API_KEY": "YOUR_API_KEY"
35+
}
36+
}
37+
}
38+
}
39+
```
40+
41+
## Tools (14)
42+
43+
### Campaigns
44+
| Tool | Description |
45+
|------|-------------|
46+
| `get_campaigns` | List campaigns with filtering by title, status, source, tags, date range |
47+
| `get_campaign` | Get single campaign by ID with full config |
48+
| `get_campaigns_v2` | List campaigns via v2 endpoint |
49+
50+
### Logs
51+
| Tool | Description |
52+
|------|-------------|
53+
| `get_clicks` | Click-level log with IP, country, device, campaign details (max 10k/page) |
54+
| `get_conversions` | Conversion log with payout, cost, revenue, attribution (max 10k/page) |
55+
56+
### Reports
57+
| Tool | Description |
58+
|------|-------------|
59+
| `get_report` | Aggregated stats grouped by dimension (campaign, offer, country, date, sub1-20, etc.) |
60+
61+
### Entities
62+
| Tool | Description |
63+
|------|-------------|
64+
| `get_offers` | List offers with filtering |
65+
| `get_offer` | Single offer by ID |
66+
| `get_sources` | List traffic sources |
67+
| `get_source` | Single source by ID |
68+
| `get_networks` | List affiliate networks |
69+
| `get_landings` | List landing pages |
70+
| `get_settings` | Account settings (timezone, currency, conversion types) |
71+
72+
## Environment variables
73+
74+
| Variable | Required | Default | Description |
75+
|----------|----------|---------|-------------|
76+
| `REDTRACK_API_KEY` | Yes || Your RedTrack API key |
77+
| `REDTRACK_ENV_FILE` | No | `.env` | Path to .env file |
78+
79+
## Development
80+
81+
```bash
82+
bun install # install deps
83+
bun run dev # run MCP server
84+
bun test # run tests
85+
bun run lint # check formatting & lint
86+
bun run inspect # open MCP inspector
87+
bun run build # compile standalone binary
88+
bun run build:npm # bundle for Node.js / npm
89+
```
90+
91+
## License
92+
93+
MIT

biome.json

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
{
2+
"$schema": "https://biomejs.dev/schemas/2.4.8/schema.json",
3+
"formatter": {
4+
"indentStyle": "space",
5+
"indentWidth": 2,
6+
"lineWidth": 90
7+
},
8+
"javascript": {
9+
"formatter": {
10+
"quoteStyle": "double",
11+
"semicolons": "always",
12+
"trailingCommas": "all"
13+
}
14+
},
15+
"linter": {
16+
"rules": {
17+
"recommended": true
18+
}
19+
},
20+
"overrides": [
21+
{
22+
"includes": ["tests/**"],
23+
"linter": {
24+
"rules": {
25+
"suspicious": {
26+
"noExplicitAny": "off"
27+
},
28+
"complexity": {
29+
"useLiteralKeys": "off"
30+
},
31+
"style": {
32+
"useTemplate": "off"
33+
}
34+
}
35+
}
36+
}
37+
]
38+
}

0 commit comments

Comments
 (0)