Clarity MCP Server

Clarity MCP Server

Bridges Microsoft Clarity's analytics API with Claude, enabling custom date ranges and page-level filtering on top of Clarity's native limitations.

Category
访问服务器

README

Clarity MCP Server

A Model Context Protocol (MCP) server that bridges Microsoft Clarity's analytics API with Claude, adding custom date ranges and page-level filtering on top of Clarity's native limitations.

Why This Exists

Microsoft Clarity's public API exposes only a rolling 1–3 day lookback window and lacks page-level filtering — requesting URL breakdowns across an entire site can return thousands of rows and crash on size limits. This server solves both problems:

  1. Custom date ranges: Capture daily snapshots automatically (or manually trigger them), then query any historical range you've captured. Past data before captures began is unrecoverable (Clarity itself doesn't store it), but from the day you start using this, your full historical record accumulates.
  2. Page-level filtering: Filter results by URL substring after Clarity returns data (post-processing), avoiding the oversized-response crashes and letting you focus on specific pages without re-querying.

What You Get

Three tools accessible from Claude:

  • get_clarity_insights — fetch live Clarity data (last 1–3 days) with optional URL filtering
  • capture_clarity_snapshot — manually save today's data locally so it survives past Clarity's 3-day window
  • get_clarity_historical_insights — query any date range you've captured, with optional URL filtering

Hard Limits (Microsoft's, Not Ours)

Constraint Value
Requests per project per day 10
Date range Rolling 1, 2, or 3 days (no arbitrary historical windows)
Dimensions per request Max 3
Response size Max 1,000 rows, no pagination

These are baked into Clarity's public API and aren't configurable. Plan your queries accordingly.

Prerequisites

  • Node.js v18+
  • An active Microsoft Clarity project with admin access (only admins can generate API tokens)
  • Claude Desktop (for MCP integration)

Setup

1. Generate an API Token

  1. Go to your Clarity project → Settings → Data Export
  2. Click Generate new API token (requires project admin)
  3. Name it (4–32 alphanumeric chars, plus -, _, .)
  4. Copy immediately — shown once

2. Install This Server

git clone https://github.com/mad7droid/clarity-mcp-server.git
cd clarity-mcp-server
npm install
npm run build

3. Configure

Create .env in the project root:

CLARITY_API_TOKEN=your_jwt_token_here

4. Wire Into Claude Desktop

Edit ~/Library/Application Support/Claude/claude_desktop_config.json:

{
  "mcpServers": {
    "clarity": {
      "command": "node",
      "args": ["/path/to/clarity-mcp-server/dist/index.js"],
      "env": {
        "CLARITY_API_TOKEN": "your_jwt_token"
      }
    }
  }
}

Replace /path/to/clarity-mcp-server with the actual path.

5. Restart Claude Desktop

Fully quit and reopen Claude Desktop. The Clarity tools should now appear.

Usage

Live Insights (Last 1–3 Days)

Ask Claude:

"What's my site traffic for the last 2 days, broken down by device and OS?"

Claude will call get_clarity_insights with numOfDays: 2, dimension1: "Device", dimension2: "OS".

Page-Level Filtering

Ask Claude:

"Show me traffic to /dashboard for the last day."

Claude will call get_clarity_insights with urlFilter: "/dashboard". The URL dimension is auto-added if needed, and results are filtered post-fetch to avoid oversized responses.

Capture Today's Data

Ask Claude:

"Save today's analytics snapshot."

Claude will call capture_clarity_snapshot, writing data/YYYY-MM-DD.json locally. This uses 1 of your 10 daily requests.

Query Historical Ranges

Ask Claude:

"Show me traffic from July 15 to July 20."

Claude will call get_clarity_historical_insights with your requested dates. It returns:

  • Found dates: snapshots available locally
  • Missing dates: days you didn't capture (permanently unrecoverable — Clarity never stores them)
  • Data: per-day snapshots with optional URL filtering applied

Important Notes

Daily Capture Strategy

To build a useful historical archive, run capture_clarity_snapshot roughly daily. A few tips:

  • One call per day is enough: Each call captures the full URL breakdown. Calling multiple times same day just overwrites.
  • Historical depth: After 3 days without a capture, that date is lost forever (Clarity's API won't return it).
  • Fire and forget: Set a daily reminder in your calendar, or ask Claude each morning. No background daemon needed.

URL Filtering Behavior

  • Filtering happens after Clarity returns data (post-processing).
  • Results are still bound by Clarity's 1,000-row upstream limit — if Clarity already dropped rows before your filter sees them, they're gone.
  • Case-insensitive substring matching: urlFilter: "/admin" matches /admin, /Admin/Users, etc.

Historical Query Limitations

get_clarity_historical_insights only returns data for days you've captured. There is no way to backfill older dates after the fact; only days you explicitly captured with capture_clarity_snapshot are available.

If you started using this server on July 20, you cannot later retrieve data from July 10–19, even if Clarity still has it in the live window — the data was never captured locally.

Examples

Example 1: Diagnose a High-Traffic Day

You: "Show me the top 20 pages from yesterday by traffic volume."
Claude: Calls get_clarity_insights { numOfDays: 1, dimension1: "URL" }

Example 2: Track a Page's Performance Over Time

You: "What was the traffic to /checkout over the last 7 days?"
Claude: Calls get_clarity_historical_insights { startDate: "2026-07-14", endDate: "2026-07-20", urlFilter: "/checkout" }
         Returns data from whichever days you captured, lists missing dates.

Example 3: Compare Devices Across a Week

You: "How does mobile traffic compare to desktop for the last 7 days?"
Claude: Calls get_clarity_historical_insights for the range, but notes that Device breakdown is not available historically (only live data via get_clarity_insights has Device dimension).
         Suggests querying the last 3 days live instead for an accurate comparison.

Architecture

See docs/ARCHITECTURE.md for a deep dive into the code structure and module responsibilities.

Integration with Claude

See docs/CLAUDE_DESKTOP_SETUP.md for detailed Claude Desktop integration steps and troubleshooting.

Error Handling

HTTP Code Meaning Fix
401 Missing/invalid/expired token Regenerate in Data Export settings
403 Token not authorized for this project Verify token is from the correct project
400 Invalid parameters numOfDays must be 1/2/3; dimensions must match the supported list
429 Daily limit (10/project) exceeded Wait for daily reset (~24h)

Supported Dimensions

When requesting breakdowns, use one or more of:

Browser, Device, Country/Region, OS, Source, Medium, Campaign, Channel, URL

Note: Historical snapshots are captured with URL dimension only. Other dimensions are only available for live queries (last 1–3 days).

License

MIT. See LICENSE for details.

Contributing

Contributions are welcome. Please open an issue or pull request on GitHub.

References

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选