Skip to content

Commit da2c187

Browse files
author
clamp-bot
committed
sync from monorepo @ 09fad3a
0 parents  commit da2c187

10 files changed

Lines changed: 2668 additions & 0 deletions

File tree

.github/banner.png

177 KB
Loading

.github/workflows/ci.yml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
name: CI
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
branches: [main]
7+
pull_request:
8+
branches: [main]
9+
10+
concurrency:
11+
group: ci-${{ github.ref }}
12+
cancel-in-progress: true
13+
14+
jobs:
15+
build:
16+
name: Type-check & build
17+
runs-on: ubuntu-latest
18+
steps:
19+
- uses: actions/checkout@v4
20+
21+
- uses: actions/setup-node@v4
22+
with:
23+
node-version: 20
24+
25+
# No package-lock in the synced public repo (the monorepo's lock lives
26+
# at the workspace root and isn't part of the sync), so skip cache: npm.
27+
- run: npm install --ignore-scripts
28+
29+
- name: Type check
30+
run: npx tsc --noEmit
31+
32+
- name: Build
33+
run: npm run build

CHANGELOG.md

Lines changed: 207 additions & 0 deletions
Large diffs are not rendered by default.

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2025 Clamp
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 273 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,273 @@
1+
<p align="center">
2+
<a href="https://clamp.sh">
3+
<img src="https://raw.githubusercontent.com/clamp-sh/mcp/main/.github/banner.png" alt="Clamp" />
4+
</a>
5+
</p>
6+
7+
<p align="center">
8+
<a href="https://www.npmjs.com/package/@clamp-sh/mcp"><img src="https://img.shields.io/npm/v/@clamp-sh/mcp?style=flat-square&color=B8E847&labelColor=1a1a1a" alt="npm version" /></a>
9+
<a href="https://www.npmjs.com/package/@clamp-sh/mcp"><img src="https://img.shields.io/npm/dm/@clamp-sh/mcp?style=flat-square&color=B8E847&labelColor=1a1a1a" alt="npm downloads" /></a>
10+
<a href="https://github.com/clamp-sh/mcp/actions/workflows/ci.yml"><img src="https://github.com/clamp-sh/mcp/actions/workflows/ci.yml/badge.svg" alt="CI" /></a>
11+
<a href="LICENSE"><img src="https://img.shields.io/npm/l/@clamp-sh/mcp?style=flat-square&color=B8E847&labelColor=1a1a1a" alt="license" /></a>
12+
<a href="https://glama.ai/mcp/servers/clamp-sh/mcp"><img src="https://glama.ai/mcp/servers/clamp-sh/mcp/badges/score.svg" alt="mcp MCP server" /></a>
13+
</p>
14+
15+
# @clamp-sh/mcp
16+
17+
Stdio MCP server for [Clamp](https://clamp.sh) analytics. Gives your AI assistant access to pageviews, visitors, referrers, countries, cities, devices, custom events, and conversion funnels, plus tools to create funnels and set up metric alerts.
18+
19+
Works with any MCP client: Claude Desktop, VS Code Copilot, Cursor, Windsurf, Cline, or anything that speaks the [Model Context Protocol](https://modelcontextprotocol.io).
20+
21+
> **Using Cursor, VS Code, Claude Code, or Claude Desktop?** There is a one-click remote install in the Clamp dashboard that handles auth via OAuth, no API key to paste. Open a project, go to the Installation tab, and pick your editor. This package is the stdio path for CI, headless agents, custom clients, and self-hosted Clamp instances.
22+
23+
## Setup
24+
25+
### VS Code / Copilot
26+
27+
Add to `.vscode/mcp.json` in your project:
28+
29+
```json
30+
{
31+
"servers": {
32+
"clamp": {
33+
"type": "stdio",
34+
"command": "npx",
35+
"args": ["-y", "@clamp-sh/mcp"],
36+
"env": {
37+
"CLAMP_API_KEY": "sk_proj..."
38+
}
39+
}
40+
}
41+
}
42+
```
43+
44+
### Claude Code
45+
46+
```bash
47+
claude mcp add clamp -- npx -y @clamp-sh/mcp
48+
```
49+
50+
Then set your API key:
51+
52+
```bash
53+
export CLAMP_API_KEY="sk_proj..."
54+
```
55+
56+
### Claude Desktop
57+
58+
Add to `claude_desktop_config.json`:
59+
60+
```json
61+
{
62+
"mcpServers": {
63+
"clamp": {
64+
"command": "npx",
65+
"args": ["-y", "@clamp-sh/mcp"],
66+
"env": {
67+
"CLAMP_API_KEY": "sk_proj..."
68+
}
69+
}
70+
}
71+
}
72+
```
73+
74+
### Cursor
75+
76+
Add to `.cursor/mcp.json`:
77+
78+
```json
79+
{
80+
"mcpServers": {
81+
"clamp": {
82+
"command": "npx",
83+
"args": ["-y", "@clamp-sh/mcp"],
84+
"env": {
85+
"CLAMP_API_KEY": "sk_proj..."
86+
}
87+
}
88+
}
89+
}
90+
```
91+
92+
### API key
93+
94+
Get your API key from the Clamp dashboard under **Settings > API Keys**. Keys are scoped to a project and start with `sk_proj`.
95+
96+
## Tools
97+
98+
### Free (all plans)
99+
100+
| Tool | What it does |
101+
|---|---|
102+
| `traffic.overview` | Pageviews, visitors, sessions, bounce rate, avg duration. Period comparison included. |
103+
| `traffic.timeseries` | Event counts over time with automatic granularity. |
104+
| `traffic.compare` | Compare any metric across two arbitrary periods. Returns absolute and percent delta. |
105+
| `traffic.live` | Visitors active in the last N minutes plus their top pages, referrers, and countries. |
106+
| `breakdown` | Group visitors and pageviews by any dimension: `pathname`, `referrer_host` (channel comes back joined), `country`, `city` (country joined), `device_type`, `browser`, `browser_version`, `os`, `os_version`, `entry_page`, `exit_page`, `region`, `channel`, or any UTM field. |
107+
| `pages.engagement` | Per-page metrics with `view`: `summary` (pageviews+visitors), `engagement` (adds avg engagement seconds and bounce rate), `sections` (per-section view counts for one pathname; needs the section-views SDK extension). |
108+
| `events.list` | Custom event counts with property filtering and grouping. |
109+
| `revenue.sum` | Sum revenue from Money-typed event properties. Split by currency, optionally grouped by referrer_host, country, channel, UTM, etc. |
110+
| `sessions.paths` | Aggregate session paths: top entry → exit pairs with pages per session and duration. |
111+
| `projects.list` | List all projects this credential can access. |
112+
| `docs.search` | Keyword-search the Clamp docs index. |
113+
114+
### Pro
115+
116+
| Tool | What it does |
117+
|---|---|
118+
| `funnels.create` | Define and immediately evaluate a multi-step conversion funnel. |
119+
| `funnels.list` | Retrieve a funnel with cohort filters (country, channel, device, UTM). |
120+
| `alerts.create` | Set up metric alerts (e.g. "visitors drops_by 30% over 7d"). |
121+
| `alerts.list` | List every alert configured for the project. |
122+
| `alerts.delete` | Delete an alert by id. |
123+
124+
### Common parameters
125+
126+
**period**`"today"`, `"yesterday"`, `"7d"`, `"30d"`, `"90d"`, or a custom range as `"YYYY-MM-DD:YYYY-MM-DD"`. Defaults to `"30d"`.
127+
128+
**limit** — Max rows returned, 1-50. Defaults to 10.
129+
130+
**Filters** — Most tools accept `pathname`, `referrer_host`, `channel`, `country`, `device_type`, and the full UTM set (`utm_source`, `utm_medium`, `utm_campaign`, `utm_content`, `utm_term`). Funnels accept the same cohort filters.
131+
132+
**referrer_host** — Filter results to visitors from a specific source. Must match the value returned by `breakdown(dimension="referrer_host")` exactly (e.g. `"news.ycombinator.com"`, `"twitter.com"`, `"github.com"`). Works on overview, breakdown, pages.engagement, events, timeseries, and funnels.
133+
134+
**dimension** (`breakdown` only) — see the `breakdown` row above for valid values.
135+
136+
**view** (`pages.engagement` only) — `"summary"` (default), `"engagement"`, or `"sections"`. `"sections"` requires `pathname`.
137+
138+
## Prompts
139+
140+
Pre-built analytics workflows the AI can follow. Each prompt tells the model which tools to call, in what order, and how to present the results.
141+
142+
| Prompt | What it produces |
143+
|---|---|
144+
| `weekly_report` | Traffic summary, top pages, referrers, countries, one actionable insight. |
145+
| `traffic_diagnosis` | Root-cause analysis for traffic changes. Drills into channels, countries, devices, pages. |
146+
| `conversion_audit` | Funnel drop-off analysis with cohort segmentation. |
147+
| `channel_breakdown` | Traffic quality comparison across sources (volume vs engagement). |
148+
| `page_performance` | Deep-dive on a single page: trends, referrers, devices, engagement vs site average. |
149+
150+
## Examples
151+
152+
### Traffic overview
153+
154+
> "How's my traffic this week?"
155+
156+
Calls `traffic.overview` with `period="7d"`. Returns pageviews, visitors, sessions, bounce rate, avg duration, and comparison to the previous week.
157+
158+
> "What's the bounce rate on /pricing?"
159+
160+
Calls `traffic.overview` with `pathname="/pricing"`. Returns metrics for that single page, including comparison to the prior period.
161+
162+
> "Show me traffic trends for the last 90 days"
163+
164+
Calls `traffic.timeseries` with `period="90d"`. Returns daily counts over the full window.
165+
166+
### Sources and geography
167+
168+
> "Where are my visitors coming from?"
169+
170+
Calls `breakdown` with `dimension="referrer_host"`. Returns referrer hostnames with channel classification (organic_search, direct, referral, paid, email, organic_social) joined into each row.
171+
172+
> "Show me only organic search traffic to /blog"
173+
174+
Calls `breakdown` with `dimension="referrer_host"`, `channel="organic_search"`, and `pathname="/blog"`.
175+
176+
> "Which countries send the most traffic?"
177+
178+
Calls `breakdown` with `dimension="country"`. Returns ISO country codes with visitor and pageview counts.
179+
180+
> "Which cities in Germany have the most visitors?"
181+
182+
Calls `breakdown` with `dimension="city"` and `country="DE"`. Returns city names with country and visitor/pageview counts.
183+
184+
> "Which pages did Hacker News visitors read?"
185+
186+
Calls `pages.engagement` with `referrer_host="news.ycombinator.com"` (default `view="summary"`). Returns only pages viewed by traffic from HN.
187+
188+
> "How's traffic from Twitter trending?"
189+
190+
Calls `traffic.timeseries` with `referrer_host="twitter.com"`. Returns the pageview curve for visitors from a single source.
191+
192+
### Devices
193+
194+
> "What's the mobile vs desktop split?"
195+
196+
Calls `breakdown` with `dimension="device_type"`.
197+
198+
> "Which browsers are my visitors using?"
199+
200+
Calls `breakdown` with `dimension="browser"`.
201+
202+
### Custom events
203+
204+
> "How many signups happened this month?"
205+
206+
Calls `events.list` with `name="signup"` and `period="30d"`.
207+
208+
> "Break down signups by plan"
209+
210+
Calls `events.list` with `name="signup"` and `group_by="plan"`. Returns counts per property value (e.g. free: 42, pro: 18, growth: 7).
211+
212+
> "How many signups came from the spring campaign?"
213+
214+
Calls `events.list` with `name="signup"` and `utm_campaign="spring-launch"`.
215+
216+
### Funnels (Pro)
217+
218+
Funnels let you track multi-step conversion and filter by cohorts: country, channel, device type, and UTM parameters. This is where you answer questions like "how many mobile users from Germany actually signed up?"
219+
220+
> "Create a funnel from pricing page to signup to checkout"
221+
222+
Calls `funnels.create` with steps `["pageview:/pricing", "signup", "checkout_completed"]`. Returns step-by-step conversion rates immediately.
223+
224+
> "How does the pricing-to-signup funnel convert on mobile?"
225+
226+
Calls `funnels.list` with `name="pricing-to-signup"` and `device_type="mobile"`.
227+
228+
> "Compare funnel conversion for US vs Germany"
229+
230+
Two calls to `funnels.list`, one with `country="US"` and one with `country="DE"`.
231+
232+
> "What's the funnel conversion for visitors from Google?"
233+
234+
Calls `funnels.list` with `channel="organic_search"`.
235+
236+
> "How many mobile users from Germany signed up?"
237+
238+
Create a single-step funnel with `steps=["signup"]` and filter with `country="DE"` and `device_type="mobile"`. Cohort filtering works on any funnel, including single-event funnels.
239+
240+
### Alerts (Pro)
241+
242+
> "Alert me if visitors drop by 30% week over week"
243+
244+
Calls `alerts.create` with `metric="visitors"`, `condition="drops_by"`, `threshold=30`, `period="7d"`.
245+
246+
> "Alert me if bounce rate on /pricing goes above 70%"
247+
248+
Calls `alerts.create` with `metric="bounce_rate"`, `condition="above"`, `threshold=70`, `pathname="/pricing"`.
249+
250+
### Workflows
251+
252+
> "Run a weekly report"
253+
254+
Follows the `weekly_report` prompt. Calls overview, top pages, referrers, countries, and timeseries, then synthesizes a structured report with trends and one actionable insight.
255+
256+
> "Why did traffic drop last week?"
257+
258+
Follows the `traffic_diagnosis` prompt. Systematically checks channels, countries, devices, and pages to isolate the root cause.
259+
260+
> "Audit our conversion funnel"
261+
262+
Follows the `conversion_audit` prompt. Analyzes funnel drop-offs, segments by device/country/channel, and identifies the biggest optimization opportunity.
263+
264+
> "How is /pricing performing?"
265+
266+
Follows the `page_performance` prompt. Pulls page-specific metrics, referrers, device split, and compares engagement to the site average.
267+
268+
## Environment variables
269+
270+
| Variable | Required | Description |
271+
|---|---|---|
272+
| `CLAMP_API_KEY` | Yes | Project API key (`sk_proj...`). |
273+
| `CLAMP_API_URL` | No | Override the API base. Defaults to `https://api.clamp.sh`. Set this when pointing at a self-hosted Clamp instance. |

glama.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"$schema": "https://glama.ai/mcp/schemas/server.json",
3+
"maintainers": [
4+
"sbj-o"
5+
]
6+
}

package.json

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
{
2+
"name": "@clamp-sh/mcp",
3+
"version": "4.0.0",
4+
"description": "Clamp MCP server. Sixteen analytics tools for AI agents — traffic, breakdowns, pages, engagement, events, revenue, sessions, funnels, alerts. Stdio for local agents and HTTP for remote.",
5+
"license": "MIT",
6+
"homepage": "https://clamp.sh/mcp",
7+
"repository": {
8+
"type": "git",
9+
"url": "git+https://github.com/clamp-sh/clamp.git",
10+
"directory": "packages/mcp"
11+
},
12+
"bugs": {
13+
"url": "https://github.com/clamp-sh/clamp/issues"
14+
},
15+
"keywords": [
16+
"mcp",
17+
"model-context-protocol",
18+
"analytics",
19+
"ai-agents",
20+
"claude",
21+
"cursor",
22+
"clamp"
23+
],
24+
"main": "dist/index.mjs",
25+
"types": "dist/index.d.mts",
26+
"exports": {
27+
".": {
28+
"types": "./dist/index.d.mts",
29+
"import": "./dist/index.mjs"
30+
},
31+
"./tools": {
32+
"types": "./dist/tools.d.mts",
33+
"import": "./dist/tools.mjs"
34+
}
35+
},
36+
"bin": {
37+
"clamp-mcp": "dist/index.mjs"
38+
},
39+
"scripts": {
40+
"build": "tsup src/index.ts src/tools.ts --format esm --dts",
41+
"dev": "tsup src/index.ts src/tools.ts --format esm --dts --watch"
42+
},
43+
"dependencies": {
44+
"@modelcontextprotocol/sdk": "^1",
45+
"zod": "^4.3.6"
46+
},
47+
"devDependencies": {
48+
"@types/node": "^22",
49+
"tsup": "^8",
50+
"typescript": "^5"
51+
}
52+
}

0 commit comments

Comments
 (0)