Model Context Protocol (MCP) Server

Every diy-analytics instance ships a native Model Context Protocol server at /api/mcp.

API Keys for MCP and programmatic access

Connected Apps authorized via MCP connector

It lets AI coding assistants — Claude Desktop, Cursor, Zed, and custom agents — query real-time traffic, conversion funnels, error stack traces, and visitor cohorts while you work.


Supported clients


Authentication

Generate a bearer token

  1. In your dashboard, go to Profile → API Keys.
  2. Click Create New Key and give it a label (e.g. Claude Desktop).
  3. Copy the generated secret key.

Authenticate requests with either:

  • HTTP header: Authorization: Bearer <API_KEY>
  • Query parameter: https://your-instance.com/api/mcp?key=<API_KEY>

Client configuration

1. Claude Desktop

Add your instance to claude_desktop_config.json:

  • macOS: ~/Library/Application Support/Claude/claude_desktop_config.json
  • Windows: %APPDATA%\Claude\claude_desktop_config.json
json
1{ 2 "mcpServers": { 3 "diy-analytics": { 4 "command": "npx", 5 "args": [ 6 "-y", 7 "@modelcontextprotocol/server-fetch", 8 "https://analytics.yourdomain.com/api/mcp" 9 ], 10 "env": { 11 "AUTH_HEADER": "Bearer your_api_key_here" 12 } 13 } 14 } 15}

2. Cursor IDE

  1. Open Settings → Features → MCP.
  2. Click + Add New MCP Server.
  3. Set Type to SSE or HTTP.
  4. Enter the URL: https://analytics.yourdomain.com/api/mcp?key=YOUR_API_KEY.

3. Zed Editor

In your Zed settings.json:

json
1{ 2 "context_servers": { 3 "diy-analytics": { 4 "endpoint": "https://analytics.yourdomain.com/api/mcp", 5 "headers": { 6 "Authorization": "Bearer YOUR_API_KEY" 7 } 8 } 9 } 10}

4. claude.ai web connector (OAuth 2.1)

diy-analytics includes a built-in OAuth 2.1 server with dynamic client registration and PKCE (S256):

  1. Log into claude.ai.
  2. Go to Settings → Connectors → Add custom connector.
  3. Enter your endpoint URL: https://analytics.yourdomain.com/api/mcp.
  4. Click Connect and authorize access through the built-in consent modal.

Tool reference

The server exposes 15 read-only tools:

Tool NameParametersDescription
list_workspacesNoneLists all workspaces accessible by the authenticated user account
list_projectsworkspaceIdLists all projects within a specified workspace
get_projectprojectIdRetrieves metadata, configured domain, and settings for a project
get_analyticsprojectId, range, filtersQueries pageviews, sessions, bounce rates, and dimensional breakdowns
get_realtimeprojectIdReturns live active visitor sessions in the last 5 minutes
list_goalsprojectIdLists all configured conversion goals and completion statistics
list_funnelsprojectIdLists all defined conversion funnels
get_funnel_analysisprojectId, funnelId, rangeComputes step-by-step conversion and drop-off rates
list_errorsprojectIdLists distinct error groups with total occurrences and regression flags
get_error_occurrencesprojectId, fingerprintReturns detailed stack traces, breadcrumb timelines, and crash metrics
get_retentionprojectId, weeksComputes weekly retention cohort matrices (4, 8, or 12 weeks)
get_flowprojectId, rangeQueries page-to-page user journey transitions for Sankey visualizations
get_segmentsprojectIdReturns visitor counts across recency and frequency cohorts
exploreprojectId, conditions, logicExecutes ad-hoc multi-condition session queries
get_event_propertiesprojectId, eventNameReturns custom event payload property keys and value distributions

Next steps