Farm Infra analytics
Farm reports request and MCP tool activity to your Farm Infra project
when the server's environment has a Farm Infra API key. There's no package to install and nothing
to add to farm.config.ts.
FARMJS_API_KEY=farmjs_…Create the key on the API keys page with the Site analytics preset: it can only send analytics, for the one project you choose, and optionally for one environment. Farm Infra knows the key's project, so nothing else is needed.
Set the variable wherever the server runs: .env for farm dev, and your host's environment
variables for production. Farm reads it when the server starts, so the build doesn't need it. An
app without FARMJS_API_KEY sends nothing.
The key farm login saves is for previews only and can't send analytics.
Keys for several projects
A key whose scope is a whole organization or several projects also needs the project to report to. Copy its ID from the project's page in Farm Infra:
FARMJS_API_KEY=farmjs_…
FARMJS_PROJECT_ID=proj_…The project must be in the key's scope. With a key for one project, FARMJS_PROJECT_ID is
optional; if you set it, it must be that project.
Environments
Every event is tagged production, staging or development: FARMJS_ENVIRONMENT if set, then
Vercel's environment (preview is staging), then NODE_ENV. A key restricted to one environment
only sends for that environment. In any other, such as farm dev with a production-only key,
Farm stops sending quietly instead of warning on every start.
Write-only keys
Projects that created a write-only key (fti_…) before API keys had permissions can keep using it
in FARMJS_API_KEY until it expires. It names its own project and environment. New projects use a
Site analytics key instead.
Environment variables
| Variable | Purpose |
|---|---|
FARMJS_API_KEY | A Farm Infra API key with the analytics:write permission (farmjs_…), or an older write-only key (fti_…). |
FARMJS_PROJECT_ID | The project to report to. Only for a key that reaches more than one project. |
FARMJS_ENVIRONMENT | production, staging or development. Defaults to Vercel's environment (preview is staging), then NODE_ENV. |
FARMJS_API_URL | Farm Infra's address, if it isn't https://app.farmjs.dev. Must be HTTPS, except for localhost. |
A value Farm can't use, such as a malformed key or project ID, leaves analytics off and prints one warning when the server starts. It never stops the app. If Farm Infra refuses the key, Farm stops sending until the server restarts and prints one warning that says what to change:
| Farm Infra answers | Warning |
|---|---|
| The key reaches several projects and none was named | Set FARMJS_PROJECT_ID, or use a key scoped to one project. |
The key can't send analytics, such as farm login's | Create a Site analytics key and set it as FARMJS_API_KEY. |
| The key was revoked or has expired (401) | Create a new Site analytics key. |
| The key only sends another environment | None: Farm stops quietly. |
| Anything else that refuses the request | The status, and to check FARMJS_API_KEY and FARMJS_PROJECT_ID. |
Farm never prints the key.
Turn it off
import { defineConfig } from "@farm.js/core";
export default defineConfig({
analytics: false,
});With analytics: false, the production server doesn't include the analytics code at all.
Removing FARMJS_API_KEY also turns it off.
What is sent
- For each request: a random ID, the matched route template (such as
/users/[id]), or a docs page's own path, the path that was requested (such as/users/42), the method, the response status and the time until Farm returned the response. - For each registered MCP tool call, including calls to the docs engine's MCP endpoint: the tool name, whether it succeeded, and its duration, linked to its request.
- The kind of client that sent each request, and its name when Farm knows it. See Which client sent a request.
Farm never sends query strings, fragments, origins, headers, cookies, IP addresses, full user-agents, request or response bodies, tool arguments or results, or error messages.
Which client sent a request
Farm reads the request's headers in the app and sends only the result: a kind, a vendor and a name from Farm's own list. The user-agent itself never leaves the app.
| Kind | How Farm tells | Examples |
|---|---|---|
agent | A user-agent token an AI vendor documents for fetches a person asked for, or ChatGPT agent's Web Bot Auth Signature-Agent | ChatGPT-User, Claude-User, Perplexity-User, ChatGPT agent |
crawler | A documented AI crawler token | GPTBot, OAI-SearchBot, ClaudeBot, PerplexityBot, CCBot |
harness | A coding agent's token, the MCP client Farm named, or MCP's Streamable HTTP headers | Claude Code, Codex, Cursor, VS Code, any MCP client |
search | A search engine crawler token | Googlebot, Bingbot, Applebot, DuckDuckBot |
preview | A link preview token | Slackbot, facebookexternalhit, Twitterbot, Discordbot |
monitor | An uptime check or scheduler token | UptimeRobot, Vercel Cron, Farm.js clock |
bot | Any other client that calls itself a bot or carries a contact URL, or a headless browser | AhrefsBot, Headless Chrome |
script | An HTTP library or command-line tool | curl, Node.js fetch, Bun, python-requests |
browser | A browser user-agent and the Sec-Fetch-Site and Sec-Fetch-Dest headers every browser sends | Chrome, Safari, Firefox, Edge |
unknown | None of the above, or tokens from two vendors at once |
Farm Infra counts agent, crawler and harness as agent traffic. A browser user-agent without
fetch metadata is unknown, not browser: scripts copy browser user-agents, but Node's fetch,
curl and most scrapers don't send Sec-Fetch-Site or Sec-Fetch-Dest.
Every kind is the client's own claim, not a verified identity: any client can send any header.
Use it to understand traffic, never to grant access. classifyFarmClient(request) from
@farm.js/core returns the same result anywhere you have the request, such as middleware.
MCP clients
An MCP client names itself once, in its initialize message (clientInfo.name), and Farm's MCP
servers answer each request on its own, so a tool call that comes later can't say who made it.
While analytics is on, Farm reads a client's initialize request in the app (up to 64 KiB) and,
for a client on its list, answers with an Mcp-Session-Id that names it, such as
farm.cursor.9f2c…. MCP clients send that header with every later request, so each tool call is
reported as Cursor, Claude, VS Code, Windsurf, Zed, ChatGPT, Codex, Gemini CLI or another listed
client. Claude Code is named by its user-agent either way.
- A client Farm doesn't list gets no session ID and is reported as
MCP client. - A server that issues its own session IDs keeps them.
- The body never leaves the app, and the session ID grants nothing: any client can send one.
- Without
FARMJS_API_KEY, or withanalytics: false, Farm reads no request bodies and adds no header.
What path contains
path is the path the request asked for, below the app's basePath: /users/42 for a request to
https://shop.example/users/42?ref=mail. Farm Infra shows it in the request log and keeps the
template for grouping, so Top routes still count /users/[id] once. Anything in your paths
reaches Farm Infra and is kept for seven days. If your paths carry what shouldn't leave the app,
such as a token in a reset link (/reset/<token>) or an email address, set analytics: false.
A path longer than 1,024 characters, or one starting with //, is left out and the request is
reported by its template alone. Farm.js versions before paths send no path.
What route contains
route is a template, never the requested path (that's path). The one exception is a docs page:
its path is part of your docs, not something a visitor typed, so it's reported as itself:
| Request | route |
|---|---|
| A page, API, integration, or plugin endpoint route | Its pattern: /users/[id], /api/stats |
A Markdown mirror (/blog/hello.md) | The page's pattern plus .md: /blog/[slug].md |
A docs page (/docs/routing) or its Markdown | The page's path: /docs/routing, /docs/routing.md |
Any other path below the docs (/docs/missing) | The docs route: /docs/[...slug] |
The docs API (/api/docs?query=...) | /api/docs, or /api/docs/[...path] below it |
| An MCP server Farm or the docs engine serves | Its endpoint: /mcp, plus /mcp/server-card |
llms.txt, sitemap.xml, robots.txt, .well-known files | The fixed path: /llms.txt, /.well-known/farmjs.json |
| The OpenAPI spec or reference, the image optimizer | The configured path: /openapi.json, /_farm/image |
| Anything nothing answered (a 404, or a 405 with no route) | /[unmatched] |
Farm lists your docs pages when it builds (in farm dev, on the first docs request and again
after a file is added or removed). A docs adapter that doesn't list its pages, or a page whose path
has characters other than letters, digits, -, _, . and /, stays on /docs/[...slug].
A deeper path the docs engine serves outside its pages keeps only its leading segments, such as
/.well-known/mcp/[...path]. Static assets and the app's own metadata files (robots.ts,
sitemap.ts, opengraph-image) are not reported.
Tool discovery: /.well-known/farmjs.json
Every Farm app serves a public manifest at /.well-known/farmjs.json (under its basePath), so
Farm Infra, agents and other tools can see which Farm version it runs and list its MCP tools,
including the ones nothing has called yet, without the app sending anything. It describes:
app: Farm's version, the renderer, the base path and the build (the deployment ID, ordevelopment).packages: the installed versions of the app's@farm.js/*and@farming-labs/*packages.mcp.servers: each MCP server's name, version, path andauthorization("required"when it runsauthorizeor a guard covers its path,"none"for a public server), its tools (name, title, description, whether it's an API endpoint,defineToolor a server function, the read-only, destructive, idempotent and open-world hints, and the input and output JSON Schemas), its resources (name, URI or template, MIME type) and its prompts (name, description, argument schema). The docs engine's MCP endpoint is listed too, with the tools it lists overtools/listas standalone tools, without resources or prompts.webmcp: whether@farm.js/webmcpis on, and the browser tools the app's source defines withdefineWebMCPToolorregisterWebMCPTool: name, title, description, hints, and the input schema when it's written out (inputSchemaSource: "literal"). A schema built at runtime, such asz.toJSONSchema(...), is listed as"computed". Farm reads them from your source files, at build time in production and on each request infarm dev.integrations: each integration's key, category (auth,payment,monitoring…) and type, such asstripe. Never its configuration.agent: the API catalog,llms.txtand OpenAPI spec, when they're on.plugins: the names of the app's plugins.site.url: the public origin the app is served from, ornull. See Site URL.
It never includes keys, file paths, integration configuration or anything a request carries. The only value it reads from the environment is the site's own public origin.
Anyone can read it, in farm dev and in production, with or without FARMJS_API_KEY, and every
reader gets the same document. It's served with CORS for any origin, an ETag, and
Cache-Control: public, max-age=0, must-revalidate. It lists only what an anonymous MCP client
could already list:
- A server that requires
authorize, or sits behind a guard written for its path, keeps its name, version, path andauthorization: "required", with emptytools,resourcesandprompts. - Endpoint tools never include the endpoint's method and route, which MCP clients never see.
Farm Infra reads it from the Site URL you set on the project's Settings, as any other client
does, so it lists a protected server's identity but not its tools. analytics: false doesn't
change the manifest.
agent.manifest hides what you'd rather not publish: a section
set to false is served as null, packages: "names" drops the versions, app can leave out the
version, renderer or build, mcp can drop schemas or hide a server or a single tool, and webmcp
can hide browser tools. Hidden tools are hidden from Farm Infra too.
Turn the manifest off with agent: { manifest: false }. Farm Infra then can't list the app's tools
either.
Site URL
site.url tells Farm Infra and other readers where the app lives, read when each request is
served:
| Source | Set by | Example |
|---|---|---|
FARM_SITE_URL | You | https://acme.com |
VERCEL_PROJECT_PRODUCTION_URL | Vercel, on every deployment | acme.com (https:// added) |
RENDER_EXTERNAL_URL | Render | https://acme.onrender.com |
RAILWAY_PUBLIC_DOMAIN | Railway, with a public domain | acme.up.railway.app |
Farm names the first usable one, in this order. Only a public https origin is usable: no path,
query, credentials, IP address, localhost or single-label host. FARM_SITE_URL decides alone when
it's set: an invalid one serves url: null rather than a host's guess. Put the app's base path in
basePath, not in the URL; readers join the two.
On Vercel the production address is served by preview deployments too, so a preview names the
production site. Netlify sets its URL for the build only, so a Netlify app sets FARM_SITE_URL.
On Cloudflare, set it as a Worker variable.
An empty Site URL on a Farm Infra project is filled from site.url once Farm Infra has
confirmed that the address serves a Farm manifest too. A Site URL you set is never replaced.
agent: { manifest: { site: false } } serves site: null.
Farm 0.1.34 served the manifest at /.well-known/farmjs. That path still answers the same way, so
tools that read it there keep working; new readers should use /.well-known/farmjs.json.
Earlier releases gave Farm Infra's signed request (the farmjs-infra-signature header) a fuller
view with protected servers' tools and endpoint routes. Apps now ignore that header.
Delivery
Analytics never delays or changes a response. Events are queued in memory and sent in the
background through the runtime's waitUntil, in batches of up to 50, with a two-second timeout per
request and bounded retries. At most 500 events are held, and an event is dropped after five
minutes or five failed attempts. When the server shuts down, Farm tries once more to send what's
queued. It's best-effort: a crash or a platform's runtime limit can drop events.
What it can't see
Only requests that reach Farm's server runtime are counted. Pages served as static files, by a CDN cache or blocked by a firewall before reaching the app, aren't. Turning analytics on doesn't make a static page dynamic. Unhandled exceptions with no final response aren't given an invented status.
It runs on Node-compatible server runtimes. Edge runtimes are not supported yet.
This is separate from Farm's own product telemetry, which is controlled by the
telemetry option, and from OpenTelemetry.
Send request and MCP tool analytics to your Farm Infra project by setting one API key.