Nightjar MCP Server
MCP server that wraps Nightjar's analytics API, enabling Claude Code to query events, funnels, dashboards, and metrics through natural language.
README
Build an MCP Server
Companion repo for Build an MCP Server on Frontend Hire.
You wrap Nightjar, a privacy-first analytics product, in an MCP server that Claude Code can use. The API is given. Your server is the whole assignment.
Start here
Every lesson ends at a tag. Branch from the starter so you are never in detached HEAD:
git clone https://github.com/yaralahruthik/build-an-mcp-server
cd build-an-mcp-server
git checkout -b my-build 00-starter
bun install
cp .env.example .env
bun run seed
Then, in one terminal:
bun run api
Nightjar is now on http://localhost:8787. Leave it running. Everything you write
lives in src/ and scripts/, in a second terminal.
What you need
Bun, an editor, and Claude Code. No API key. Nothing in this repo calls a model, so your Claude subscription is the entire cost of the course. Lesson 11 adds a Cloudflare account, and the free tier covers it.
What is in the starter
api/is Nightjar: a Hono server over a seeded SQLite database. Do not edit it. Six lessons exist because this API is awkward in ways you cannot fix at the source, which is the situation you are actually in at work.src/server.tsis empty. Lesson one fills it.
The seed is deterministic: 121,541 events over the 90 complete days before today, 120,000 users, three funnels, four dashboards. Every count the lessons print is a count you will see, because the data is anchored to today rather than to a fixed date, and every window in the course is a whole number of complete days.
Today itself is empty on purpose. "Yesterday" is the most recent window with data in it.
Nightjar's API
| Endpoint | Notes |
|---|---|
GET /v1/events |
Cursor paginated, 100 rows per page maximum, no total count |
GET /v1/events/count |
Totals, optionally grouped by a property |
GET /v1/funnels |
Funnel ids and their step names |
GET /v1/funnels/:id |
Distinct users per step. Counts only, never rates |
GET /v1/metrics/timeseries |
Slow (about 3.5 seconds), and rate limited to 3 calls a minute |
GET /v1/dashboards |
Dashboard metadata |
GET /v1/dashboards/:id |
One dashboard |
All of them want RFC 3339 timestamps, take Authorization: Bearer <key>, and
return errors as {"error":{"code","message"}}.
Deploying it (lesson 11)
The MCP server runs on Cloudflare Workers with no code changes: src/worker.ts
hands the same Request to the same handler.
cp .dev.vars.example .dev.vars # local secrets for `bun run worker:dev`
bun run worker:dev # the Worker, under workerd, on :8790
wrangler secret put MCP_AUTH_TOKEN
wrangler secret put NIGHTJAR_API_KEY
wrangler secret put NIGHTJAR_API_URL
bun run deploy
wrangler dev reaches the Nightjar on your laptop. The deployed Worker cannot,
so until NIGHTJAR_API_URL points somewhere public, tools/list will work and
every tool call will return the timeout sentence from lesson five. The lesson
covers both honest ways to finish the loop.
Pointing it at your own API (lesson 12)
Everything Nightjar-specific lives in src/source/nightjar.ts. The tools talk
to the AnalyticsSource interface in src/source/types.ts, which asks four
questions and gets back data or a classified failure.
To swap the product:
- Implement
AnalyticsSourcefor your API insrc/source/your-api.ts. - Change one line in
src/source/index.ts. - Change the enums in
src/tools/count-events.tsto your event names and your properties, and mark the user-supplied ones insrc/untrusted.ts.
Nothing else moves. The results, the error sentences, the fencing, the transport, and the auth all keep working, because none of them ever knew whose API it was.
Checkpoints
| Tag | Lesson |
|---|---|
00-starter |
Overview |
01-the-smallest-server-that-connects |
1 |
02-where-the-naive-tool-breaks |
2 |
03-constraining-the-schema |
3 |
04-writing-the-result-for-a-reader |
4 |
05-errors-that-recover |
5 |
06-how-many-tools-is-too-many |
6 |
07-resources-and-prompts |
7 |
08-your-own-users-write-your-prompt |
8 |
09-from-stdio-to-http |
9 |
10-who-is-calling |
10 |
11-deploying-it |
11 |
12-point-it-at-your-own-api |
12 |
Join at any point with git checkout -b my-build <tag>, or diff your work against
the reference with git diff <previous-tag> <tag>.
If something looks wrong
"Yesterday" returns nothing. The database has aged past its window. Run
bun run seed again.
Every request returns unauthorized. Your .env is missing, or
NIGHTJAR_API_KEY does not match what the server started with. Restart
bun run api after editing .env.
The timeseries endpoint returns 429. That is the endpoint doing its job. Wait
for the Retry-After window, which is at most a minute.
推荐服务器
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 模型以安全和受控的方式获取实时的网络信息。