Nightjar MCP Server
Click on "Deploy Server".
Wait a few minutes for the server to deploy. Once ready, it will show a "Started" state.
In the chat, type
@followed by the MCP server name and your instructions, e.g., "@Nightjar MCP ServerWhat was the conversion rate for the signup funnel yesterday?"
That's it! The server will respond to your query, and you can continue using it as needed.
Here is a step-by-step guide with screenshots.
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 seedThen, in one terminal:
bun run apiNightjar is now on http://localhost:8787. Leave it running. Everything you write
lives in src/ and scripts/, in a second terminal.
Related MCP server: log-query-mcp
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 |
| Cursor paginated, 100 rows per page maximum, no total count |
| Totals, optionally grouped by a property |
| Funnel ids and their step names |
| Distinct users per step. Counts only, never rates |
| Slow (about 3.5 seconds), and rate limited to 3 calls a minute |
| Dashboard metadata |
| 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 deploywrangler 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 fail. 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 |
| Overview |
| 1 |
| 2 |
| 3 |
| 4 |
| 5 |
| 6, the seven-tool server before the deletion |
| 6 |
| 7 |
| 8 |
| 9 |
| 10 |
| 11 |
| 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.
This server cannot be deployed
Maintenance
Related MCP Connectors
Analytics for MCP servers. Query your tool calls, first-call success, retries and schema cost.
Hosted MCP server connecting claude.ai, ChatGPT and other AI apps to your own computer
Clamp Analytics MCP server: traffic, revenue, funnels, cohorts, errors, and search, for AI agents.
Augments MCP Server - A comprehensive framework documentation provider for Claude Code
Related MCP Servers
- AlicenseAqualityCmaintenanceAn MCP server that gives Claude read access to Umami web analytics, allowing natural language queries for stats, breakdowns, pageview trends, live visitors, and user journeys.101MIT
- FlicenseAqualityCmaintenanceMCP server that exposes Discord and Twitch/Chatty chat log query tools to Claude Code, enabling searching messages, channel stats, user messages, and events from chat logs.7-
- AlicenseNot gradedqualityCmaintenanceA local MCP server that lets Claude answer plain-language questions about your Anthropic usage and spend across the developer API platform and Claude Enterprise products.MIT
- AlicenseBqualityCmaintenanceMCP server for Framedash game telemetry -- query game analytics, heatmaps, perf regressions, retention, and alerts from Claude and other AI agents. Works with Unity, Unreal Engine 5, and Godot projects.1263MIT