MCP server
Let AI assistants like Claude and Cursor read your Stancelens stats over the Model Context Protocol.
The Stancelens MCP server gives an assistant read-only tools for your analytics: headline stats, time series, breakdowns, realtime, funnels, retention, insights and plain-English questions. It can't change settings or send events.
| Remote endpoint | Local stdio server | |
|---|---|---|
| Where it runs | Stancelens, at https://stancelens.com/api/mcp | Your machine (@stancelens/mcp, Node 20.3+) |
| Sign-in | OAuth (sign in to Stancelens and approve), or an API key in the Authorization header | An API key in STANCELENS_API_KEY |
| Use it from | Custom connectors in claude.ai and Claude Desktop (OAuth); Claude Code, Cursor and other clients that can send a header | Clients that start a local command: Claude Desktop, Claude Code, Cursor |
| Tools | All nine | All nine, forwarded to the remote endpoint |
Both speak MCP 2026-07-28 and the earlier initialize-based versions 2025-11-25, 2025-06-18, 2025-03-26 and 2024-11-05, so current and older clients work. An assistant's access is never wider than yours: it can read only sites you can view.
Custom connector (OAuth)
In claude.ai or Claude Desktop, open Settings → Connectors, choose Add custom connector and enter the URL https://stancelens.com/api/mcp. Choose Connect: you're sent to Stancelens to sign in and approve read-only access, then back to Claude. There's no key to copy.
- The connector gets read-only access tokens that refresh automatically. It never sees your password.
- Connected apps are listed under Account in Stancelens, where you can disconnect one. Disconnecting revokes its tokens at once.
- Other clients that support MCP authorization set themselves up from the URL alone: Stancelens publishes the standard discovery documents (
/.well-known/oauth-protected-resourceand/.well-known/oauth-authorization-server) and requires PKCE.
Remote endpoint with an API key
Streamable HTTP, stateless. URL https://stancelens.com/api/mcp with the header Authorization: Bearer <API key>. Create a key under Account → API keys; a key can read every site its user can view, and nothing else. Cursor reads ~/.cursor/mcp.json (or .cursor/mcp.json in a project).
claude mcp add --transport http stancelens https://stancelens.com/api/mcp \
--header "Authorization: Bearer el_live_..."Browser-based clients: a request that carries an Origin header is refused (403) unless the origin is the Stancelens host itself or is listed in the server's STANCELENS_MCP_ALLOWED_ORIGINS (comma-separated). Clients that aren't browsers send no Origin and aren't affected.
Local stdio server
The package isn't published to npm yet. Build it from the Stancelens repository (Bun builds it, Node 20.3 or newer runs it):
cd packages/mcp
bun install
bun run build # writes dist/index.js, a single file with no runtime dependencies| Variable | |
|---|---|
STANCELENS_API_KEY | Required. An API key (el_live_...). |
STANCELENS_HOST | Optional. Your Stancelens URL. Default https://stancelens.com. |
STANCELENS_SITE_ID | Optional. Site used when a tool call leaves out site_id. |
STANCELENS_TIMEOUT_MS | Optional. Per-request timeout towards the host, in milliseconds. Default 30000. |
MCP messages go to stdout and log lines to stderr. Without an API key, or with a malformed host, the server exits with status 1 and says why on stderr. Claude Desktop reads claude_desktop_config.json (Settings → Developer → Edit Config).
{
"mcpServers": {
"stancelens": {
"command": "node",
"args": ["/absolute/path/to/stancelens/packages/mcp/dist/index.js"],
"env": { "STANCELENS_API_KEY": "el_live_..." }
}
}
}The stdio server forwards every tool call to the remote endpoint of the same host with the same key, so both list the same tools and return the same results. Only when the host has no /api/mcp endpoint at all does it fall back to the REST API for list_sites, get_stats, get_timeseries, get_breakdown and get_realtime, with less detail: custom events instead of goal conversions, no compare, and a 30-minute realtime window without an event list.
Tools
| Tool | What it answers |
|---|---|
list_sites | Which sites you can read (id, name, domain, timezone, currency, role). |
get_stats | Headline numbers for a period, with the comparison period and % change. |
get_timeseries | Metrics per hour, day, week or month (at most 400 points). |
get_breakdown | Top pages, referrers, channels, UTM tags, countries, devices, custom events, props.<key> and more. |
get_realtime | Visitors in the last 5 minutes, page views per minute, top pages and sources right now. |
get_funnel | Conversion through a saved funnel (funnel_id) or ad-hoc steps; with neither, lists saved funnels. |
get_retention | Cohort retention by day, week or month, optionally from a start event to a return event. |
ask | A plain-English question, answered by Stancelens's query engine with its interpretation. |
get_insights | Anomalies, biggest movers, new referrers, conversion changes, error spikes and Web Vitals regressions. |
Common inputs: site_id, period (today, yesterday, 24h, 7d, 30d, mtd, lastmonth, 90d, 6mo, 12mo, ytd, all, or custom with from/to as YYYY-MM-DD) and filters, a list like {"dimension": "country", "op": "is", "values": ["DE"]} where op is is, is_not or contains.
Results are compact JSON, both as text and as structuredContent. Periods are calendar days in the site timezone (list_sites shows it), as in the dashboard. Each result names its period, percentages are 0 to 100 and durations are in seconds (*_s). Breakdowns return at most 100 rows. Errors such as an unknown site_id come back as tool errors (isError) the assistant can read.
Things to ask
- Which referrers grew most this month compared with last month?
- What's the signup conversion rate from the pricing page, by country?
- Did anything unusual happen to traffic or errors this week?
- How does week-4 retention look for users who signed up in October?