MCP Server (Local Stdio & Remote HTTP)
Connect Claude Desktop, Claude Code, Cursor, Codex, or any MCP client to your TrimStats analytics via npx @trimstats/mcp (stdio) or the hosted Streamable HTTP endpoint at /mcp.
How do I connect Claude, Cursor, or Codex to TrimStats using MCP?
Create a read-only ts_live_ API key under Workspace -> API keys, then run npx -y @trimstats/mcp over local stdio with TRIMSTATS_API_KEY or connect any Streamable HTTP MCP client directly to https://collect.trimstats.com/mcp with Authorization: Bearer. Both transports expose 12 read-only analytics tools.
How Model Context Protocol (MCP) connects AI tools to live analytics
The Model Context Protocol (MCP) is an open standard that lets AI assistants call typed, read-only tools directly instead of asking you to copy-paste CSV exports into chat. When you ask Claude, Cursor, or Codex "why did /pricing drop this week?", the assistant invokes get_anomaly_insights and get_ui_friction against live ClickHouse data and cites exact numbers.
| Transport | How it runs | Best suited for |
|---|---|---|
| Local stdio (`@trimstats/mcp`) | Your MCP client spawns npx -y @trimstats/mcp locally and talks over stdin/stdout. | Desktop IDE and CLI agents (Claude Code, Codex CLI, Cursor, Claude Desktop) where Node.js is already installed. |
| Remote Streamable HTTP (`/mcp`) | Your client sends HTTPS POST requests directly to https://collect.trimstats.com/mcp with a Bearer key. | Cloud-hosted assistants, locked-down workstations, or CI agents without local Node execution. |
ts_live_... key per AI assistant or workstation under Workspace -> API keys so you can scope access to a single site and revoke it independently.Choose stdio or remote Streamable HTTP
TrimStats supports both local stdio (npx -y @trimstats/mcp, zero runtime dependencies) and remote stateless Streamable HTTP (POST https://collect.trimstats.com/mcp). Both transports expose the exact same 12 read-only tools and authenticate with a read-only ts_live_... key from Workspace -> API keys.
1# Claude Code2claude mcp add trimstats --env TRIMSTATS_API_KEY=ts_live_your_api_key -- npx -y @trimstats/mcp34# Codex CLI5codex mcp add trimstats --env TRIMSTATS_API_KEY=ts_live_your_api_key -- npx -y @trimstats/mcp67# Test interactively with MCP Inspector8TRIMSTATS_API_KEY=ts_live_your_api_key npx @modelcontextprotocol/inspector npx -y @trimstats/mcp1{2 "mcpServers": {3 "trimstats": {4 "type": "http",5 "url": "https://collect.trimstats.com/mcp",6 "headers": {7 "Authorization": "Bearer ts_live_your_api_key"8 }9 }10 }11}Available MCP tools (12 read-only)
| Tool | Required Args | Returns |
|---|---|---|
list_sites | None | Sites accessible to the API key (siteId, name, domain, mode). |
get_site_overview | siteId | KPIs, prior-period comparison, daily series, breakdowns, custom events, goals. |
get_live_visitors | siteId | Real-time visitor count active in the last 5 minutes. |
get_event_properties | siteId, eventName | Top property keys and values for a custom event. |
get_revenue_report | siteId | Attributed revenue (USD cents), orders, AOV, and referrer/UTM/landing page breakdowns. |
get_anomaly_insights | siteId | Rolling 7-day anomalies with optional daily trends, drivers, and 30-day history. |
get_ui_friction | siteId | Rage clicks, dead clicks, 90% scroll reach, and top friction pages and CSS selectors. |
list_funnels | siteId | Saved funnel definitions (id, name, steps). |
evaluate_funnel | siteId + funnelId or steps | Step-by-step windowFunnel() conversion and drop-off metrics. |
get_retention_cohorts | siteId | Weekly retention cohort matrix (2 to 12 weeks). |
get_ai_crawlers | siteId | AI crawler fetches by category (ai_answers, indexing, training), crawler, and page. |
get_ai_referrals | siteId | Human AI assistant visits, revenue, goals, and #:~:text= cited passages. |
Security & rate-limit guardrails
- Read-only annotations: Every tool declares
readOnlyHint: trueanddestructiveHint: false, and operates strictly within your API key scope (workspace-wide or single-site). - No browser cross-origin access:
POST https://collect.trimstats.com/mcprejects requests with anOriginheader (403) and omits wildcard CORS headers to prevent browser CSRF and DNS rebinding. - Shared Valkey rate limits: Remote
/mcpand stdio requests share the 60 requests/minute per-key and 120 requests/minute per-workspace limits, and revoking a key purges collector caches immediately.
Common technical questions
Does the TrimStats MCP server work without installing Node.js locally?
Can an MCP assistant modify my TrimStats sites, goals, or billing?
Related guides
Authenticate with workspace or single-site Bearer API keys to query overview KPIs, live visitors, revenue, funnels, cohorts, UI friction, insights, and AI traffic from the collector.
Learn how visitors, sessions, bounce rate, and active dwell time work, plus how TrimStats calculates core KPIs and click-to-filter segments.
How TrimStats detects traffic drops, spikes, conversion dips, and friction surges against rolling 7-day baselines and delivers alerts and digests to email, Slack, Discord, and HMAC-signed webhooks.