Clarity MCP Server
Enables Claude to query Microsoft Clarity analytics remotely via HTTP, with bearer token authentication and caching to manage API quotas.
README
Clarity MCP Server — Remote Setup Guide
A Model Context Protocol (MCP) server that lets Claude query Microsoft Clarity analytics — and lets a remote client connect to it from Claude Desktop, running entirely off your office PC.
1. How the pieces fit together
Your office PC
┌─────────────────────────────────────────────────┐
│ server.py (FastMCP, listens on port 8000) │
│ │ │
│ ├── clarity_client.py → calls Clarity API │
│ ├── cache.py → saves your 10/day │
│ │ quota │
│ └── bearer token auth → blocks strangers │
└─────────────────────┬─────────────────────────────┘
│
ngrok / Cloudflare Tunnel
│ (makes an outbound connection,
│ gives you a public https:// URL)
▼
https://your-tunnel-url.ngrok-free.app/mcp
│
▼
Claude Desktop (custom connector)
Four files do the actual work:
| File | Job |
|---|---|
exceptions.py |
Defines specific error types (auth failed, bad input, rate-limited) so failures are readable, not raw tracebacks |
cache.py |
A simple 1-hour cache so repeat questions don't burn your 10-requests/day Clarity quota |
clarity_client.py |
The only file that talks to Clarity's real API — validates input, handles auth, parses responses |
server.py |
Wraps all of the above as 4 MCP tools, adds bearer-token auth, and serves it over HTTP instead of stdio |
2. Why HTTP instead of stdio
Every MCP tutorial you'll find starts with stdio transport — the server and client run as one local process pair, no networking involved. That's great for testing on your own machine, but a client sitting elsewhere can't spawn a process on your PC. So this server uses streamable-HTTP transport instead: it's a normal web server listening on a port, reachable by URL, exactly like any REST API.
That single line does it:
mcp.run(transport="http", host="0.0.0.0", port=8000)
3. Why authentication is not optional here
The moment your server has a public URL, it's public — not "unlisted,"
actually public. Anyone who discovers the URL could call your Clarity
tools and burn your 10 daily requests, or worse. So this server uses
FastMCP's StaticTokenVerifier: a single secret string
(MCP_ACCESS_TOKEN) that the client must send with every request as
Authorization: Bearer <token>. No token, no access — verified above:
requests without it get an immediate 401.
This token is not your Clarity API token. Think of it as a second, separate password — one you invent, one that only unlocks your MCP server, never Clarity directly.
4. Setup on your Windows PC (PowerShell)
# 1. Get the project onto your PC (copy this folder over, or unzip it)
cd C:\Users\<you>\clarity-mcp-server
# 2. Create and activate a virtual environment
python -m venv venv
.\venv\Scripts\Activate.ps1
# 3. Install dependencies
pip install -r requirements.txt
# 4. Create your real .env file from the example
Copy-Item .env.example .env
notepad .env
In .env, fill in:
CLARITY_API_TOKEN— from Clarity dashboard: Settings → Data Export → Generate new API tokenMCP_ACCESS_TOKEN— invent one. Quick way:Paste the output in aspython -c "import secrets; print(secrets.token_urlsafe(32))"MCP_ACCESS_TOKEN.
# 5. Run the server
python server.py
You should see Starting Clarity MCP server on http://0.0.0.0:8000/mcp.
Leave this window open — closing it stops the server.
5. Making it reachable from outside the office (the tunnel)
Since the connecting client is remote and you can't port-forward on an office network, use a tunnel — it makes an outbound connection from your PC, so no firewall changes or IT tickets needed.
Option A — ngrok (fastest to test):
# one-time: download from https://ngrok.com/download, unzip, then:
.\ngrok.exe http 8000
It prints a URL like https://a1b2c3d4.ngrok-free.app — this forwards
to your local port 8000. Free tier URLs change every restart; fine for
demos, annoying for daily use.
Option B — Cloudflare Tunnel (more stable, still free):
winget install --id Cloudflare.cloudflared
cloudflared tunnel --url http://localhost:8000
Gives a similar public URL, and can be configured with a fixed subdomain if you set up a free Cloudflare account.
Either way, the client's connector URL becomes:
https://<your-tunnel-domain>/mcp
6. What to share with the connecting client
Two things, ideally over a secure channel (Teams DM, not email in plaintext):
- The tunnel URL:
https://your-tunnel-url/mcp - The
MCP_ACCESS_TOKENvalue from your.env
Their side (Claude Desktop): Settings → Connectors → Add custom connector → paste the URL → when prompted for a header, add:
Authorization: Bearer <the MCP_ACCESS_TOKEN you gave them>
Once connected, they can ask Claude things like "what's our traffic
overview for the last 3 days?" and Claude will call your
get_traffic_overview tool.
7. Testing it yourself first (recommended before sharing access)
# Terminal 1
python server.py
# Terminal 2 — simulate a request without a token (should fail with 401)
curl.exe -X POST http://localhost:8000/mcp -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" -d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/list\"}"
# With the token (should get further)
curl.exe -X POST http://localhost:8000/mcp -H "Content-Type: application/json" -H "Accept: application/json, text/event-stream" -H "Authorization: Bearer YOUR_MCP_ACCESS_TOKEN" -d "{\"jsonrpc\":\"2.0\",\"id\":1,\"method\":\"tools/list\",\"params\":{}}"
8. Known limitations, said plainly
- Uptime is tied to your PC. Sleep, restart, or closing the terminal kills the connection. Fine for a scheduled demo, not for something a client relies on daily.
- 10 requests/day is Microsoft's hard limit, not something this code can raise. The cache buys you headroom, it doesn't remove the ceiling — after the cache TTL expires, a fresh question still spends a real request.
- Dimension names: the list in
clarity_client.py(Browser,Device,Country/Region,OS,Source,Medium,Campaign,Channel,URL) matches Clarity's dashboard filters, but Microsoft doesn't publish one definitive canonical list, and multi-word dimensions have had quirks in the past (seemicrosoft/clarity#630on GitHub). If a dimension call errors out unexpectedly, double check the exact spelling against your own Clarity dashboard's filter dropdown. - Free ngrok URLs are not permanent — if you restart ngrok, the URL changes and you'll need to re-share it with the client.
9. If this becomes more than a demo
Running long-term off a desk PC + tunnel is a workaround, not a real
deployment. If ongoing access is needed, the natural next
step — especially since your office already uses Microsoft tooling —
is deploying server.py to Azure App Service or a small Azure
Container App, which gives you a permanent HTTPS URL, no tunnel, and
no dependency on your PC staying on.
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。