5 min read

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.

Imtiaz Rayhan
Imtiaz RayhanCo-Founder & Lead Engineer, DotCamp & TrimStats
Verified against live TrimStats APIs
Quick reference

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.

TransportHow it runsBest 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.
Workspace / API keys
Create a dedicated read-only 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.

Claude Code & Codex CLI (local stdio)bash
1# Claude Code
2claude mcp add trimstats --env TRIMSTATS_API_KEY=ts_live_your_api_key -- npx -y @trimstats/mcp
3
4# Codex CLI
5codex mcp add trimstats --env TRIMSTATS_API_KEY=ts_live_your_api_key -- npx -y @trimstats/mcp
6
7# Test interactively with MCP Inspector
8TRIMSTATS_API_KEY=ts_live_your_api_key npx @modelcontextprotocol/inspector npx -y @trimstats/mcp
Remote Streamable HTTP config (no local Node install)json
1{
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)

ToolRequired ArgsReturns
list_sitesNoneSites accessible to the API key (siteId, name, domain, mode).
get_site_overviewsiteIdKPIs, prior-period comparison, daily series, breakdowns, custom events, goals.
get_live_visitorssiteIdReal-time visitor count active in the last 5 minutes.
get_event_propertiessiteId, eventNameTop property keys and values for a custom event.
get_revenue_reportsiteIdAttributed revenue (USD cents), orders, AOV, and referrer/UTM/landing page breakdowns.
get_anomaly_insightssiteIdRolling 7-day anomalies with optional daily trends, drivers, and 30-day history.
get_ui_frictionsiteIdRage clicks, dead clicks, 90% scroll reach, and top friction pages and CSS selectors.
list_funnelssiteIdSaved funnel definitions (id, name, steps).
evaluate_funnelsiteId + funnelId or stepsStep-by-step windowFunnel() conversion and drop-off metrics.
get_retention_cohortssiteIdWeekly retention cohort matrix (2 to 12 weeks).
get_ai_crawlerssiteIdAI crawler fetches by category (ai_answers, indexing, training), crawler, and page.
get_ai_referralssiteIdHuman AI assistant visits, revenue, goals, and #:~:text= cited passages.

Security & rate-limit guardrails

  • Read-only annotations: Every tool declares readOnlyHint: true and destructiveHint: false, and operates strictly within your API key scope (workspace-wide or single-site).
  • No browser cross-origin access: POST https://collect.trimstats.com/mcp rejects requests with an Origin header (403) and omits wildcard CORS headers to prevent browser CSRF and DNS rebinding.
  • Shared Valkey rate limits: Remote /mcp and 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?
Yes. Point any Streamable HTTP MCP client at https://collect.trimstats.com/mcp with an Authorization: Bearer ts_live_... header. Local clients can also run npx -y @trimstats/mcp over stdio with zero runtime dependencies.
Can an MCP assistant modify my TrimStats sites, goals, or billing?
No. All 12 tools in @trimstats/mcp and /mcp are strictly read-only (readOnlyHint: true) and honor single-site API key restrictions and Valkey rate limits.

Related guides