MCP usage analytics
When people reach tools through the gateway's MCP servers, you want to know which of those servers and tools they actually use. MCP usage analytics answers that from the gateway's own records. It counts how many people called MCP tools each day, week and month, split by MCP server, by tool or by the client app that made the call, it lists every tool with its calls, failures, users, average call time and spend, and it shows which coding agents call which servers and tools. Nothing has to change in the tools or the clients, because every MCP tool call already lands in the daily usage rollups.
The numbers come from three places the gateway already writes. The tool name of each call is recorded as server/tool, so the server is the part before the /. The User-Agent header of each call is recorded as a User-Agent: tag, the same tag user agent analytics reads. The client app is recorded as an MCP-Client: <label> tag when you name a client identity header or a JWT client claim, as the next section explains.
Scenario
A platform team connected a ticketing server, a wiki server and a code search server to the gateway and rolled them out to two hundred engineers. A quarter later they want to know what to keep paying for. The MCP Server Activity tab shows that forty engineers use the ticketing server every week while the wiki server has three weekly users, that jira/create_issue fails one call in twelve, and that most of the ticketing calls come from one coding agent. The team keeps the ticketing server, fixes the failing tool, and retires the wiki server, all from the gateway's own records.
Record the MCP client label
The client split needs to know which app made each call. Name the header your MCP clients send with their identity in general_settings.mcp_client_id_header, and optionally give each client a readable name in mcp_allowed_clients, as MCP access control describes.
general_settings:
mcp_client_id_header: x-mcp-client
mcp_allowed_clients:
- alias: Codex
value: codex-mcp-client
With the header set, every MCP tool call that carries it gets an MCP-Client: <label> tag. A caller that signs in with a JWT is labelled by the claim named in spanway_jwtauth.mcp_client_id_jwt_field instead, the same identity the allowlist checks, so a JWT caller cannot credit its calls to another client by sending a different header. The label is the alias when the value is listed in mcp_allowed_clients, and the value itself otherwise. Characters that cannot be printed are dropped and the label is cut at 120 characters. Without the header setting or the JWT claim setting, no client tag is written, the Client label split stays empty and everything else still works. Setting the allowlist also rejects unlisted clients, so leave mcp_allowed_clients out when you only want the labels.
Only calls made after you set the header carry the tag, because the tag is written when the call is logged.
Steps
-
Make sure people call MCP tools through the gateway with a key of their own, so each person can be counted. A key with no user, such as a shared service key, adds to the call counts but not to the active users.
-
In the Admin UI open Usage, stay on the global view with no user picked, and open the MCP Server Activity tab. Below the per server rows you find three panels, MCP active users, Tool usage and Top agents by MCP.
-
In MCP active users, pick DAU, WAU or MAU in Active users period and Server, Tool or Client label in Active users split. The table shows one row per server, tool or client label and one column per day, week or month, oldest on the left. From the API the weekly numbers per server look like this.
curl "http://localhost:4000/tag/mcp/active-users?period=week&dimension=server" -H "Authorization: Bearer $SPANWAY_API_KEY" -
Read Tool usage for every tool called in the date range picked at the top of the page, most called first. The same list from the API takes
start_dateandend_date.curl "http://localhost:4000/tag/mcp/tools?start_date=2026-11-01&end_date=2026-11-24" -H "Authorization: Bearer $SPANWAY_API_KEY" -
In Top agents by MCP, pick Server, Tool or Client label in Top agents split to see which agents call each server or tool.
curl "http://localhost:4000/tag/mcp/agents?start_date=2026-11-01&end_date=2026-11-24&dimension=tool" -H "Authorization: Bearer $SPANWAY_API_KEY"
What each control does
| Control | What it does | Default | When to change it |
|---|---|---|---|
| Active users period | DAU counts the people who called an MCP tool on each of the last 7 days. WAU counts them in each of the last 7 weeks, Monday to Sunday. MAU counts them in each of the last 7 calendar months. A person counts once per period however many calls they make. | DAU | Use WAU or MAU to judge adoption, since daily numbers swing with weekends. |
| Active users split | Server groups the counts by MCP server, so you can see which servers people use and retire idle ones. Tool shows each tool on its own. Client label groups them by the app that made the call. | Server | Pick Client label to compare client apps, after you set mcp_client_id_header. |
| Top agents split | Server and Tool list, for each server or tool, the agents that called it, read from the User-Agent header and grouped the way the Top agents panel groups them. Client label lists each client label with its calls and no agent list, because the label is already the name you gave that client. | Server | Pick Tool to find which agent drives a busy or failing tool. |
The Tool usage panel has no controls of its own and follows the date range at the top of the page. These views only read counts. They change nothing, so they write no audit row.
Expected result
The active users call answers 200 with the window it counted and one row per key and period, newest period first. A tool called with no server, for example a local tool the gateway hosts itself, has a null key and shows as (no server).
{"period": "week", "dimension": "server", "start_date": "2026-10-12", "end_date": "2026-11-24", "results": [{"key": "jira", "period_start": "2026-11-23", "period_end": "2026-11-29", "active_users": 14}, {"key": "deepwiki", "period_start": "2026-11-23", "period_end": "2026-11-29", "active_users": 6}]}
The tools call answers one row per tool, at most 500, with requests, successful_requests, failed_requests, spend, active_users, avg_latency_ms (null when no call was timed) and last_used.
{"start_date": "2026-11-01", "end_date": "2026-11-24", "results": [{"tool": "jira/create_issue", "server": "jira", "requests": 812, "successful_requests": 790, "failed_requests": 22, "spend": 0.81, "active_users": 23, "avg_latency_ms": 640.5, "last_used": "2026-11-24"}]}
The agents call answers one row per agent tag and key, at most 500, with the same counts plus tokens. A request carries both a short and a full User-Agent: tag, such as User-Agent: claude-cli and User-Agent: claude-cli/2.1.0, so the API lists both and the Admin UI folds them into one agent.
{"dimension": "server", "start_date": "2026-11-01", "end_date": "2026-11-24", "results": [{"tag": "User-Agent: claude-cli", "key": "jira", "requests": 640, "successful_requests": 631, "failed_requests": 9, "tokens": 0, "spend": 0.64, "active_users": 18}]}
Routes
| Method | Path | Summary |
|---|---|---|
| GET | /tag/mcp/active-users | Daily, weekly or monthly active users per MCP server, tool or MCP client label |
| GET | /tag/mcp/tools | Calls, failures, spend, users and latency per MCP tool in a date range |
| GET | /tag/mcp/agents | MCP tool calls per agent, split by MCP server, tool or MCP client label |
All dates are UTC days. The active users route always counts the last 7 days, weeks or months up to today. The tools and agents routes take a range of up to 366 days.
Who can use it
The routes are for proxy admins and admin viewers, like the user agent analytics routes. Any other key is refused with a 401 that says only a proxy admin may use the route, unless an admin lists the routes in the key's allowed_routes. Custom roles do not grant them yet. The numbers are gateway wide, so grant them only to people who may see every team's usage. The Usage page shows the three panels to proxy admins and admin viewers only.
Errors
| Status | What it means | Fix |
|---|---|---|
400 end_date is before start_date. Send a start_date on or before the end_date. | The range on the tools or agents route runs backwards. | Swap the dates. |
400 The range is longer than 366 days. Pick a shorter range. | The tools or agents range covers more than 366 days. | Ask for a year or less at a time. |
| 401 | The call carried no key, an invalid one, or a key that is not a proxy admin or admin viewer. | Send an admin key, or grant the routes to the key. |
| 422 | start_date or end_date is missing or not YYYY-MM-DD, or period or dimension is not one of the listed values. | Send dates as YYYY-MM-DD, period as day, week or month, and dimension as server, tool or client. |
| 500 database not connected | The gateway has no database, so there are no rollups to read. | Set DATABASE_URL and restart the gateway. |
500 Failed to read MCP usage analytics. The gateway log has the cause. | The rollup query failed in the database. | Read the MCP usage analytics query failed line in the gateway log. |
| Empty Client label split | No MCP call in the window carried a client label. | Set mcp_client_id_header and make sure the clients send that header, or set spanway_jwtauth.mcp_client_id_jwt_field for clients that sign in with a JWT. |
| Calls but no active users | The keys that made the calls belong to no user. | Give each person a key of their own. |
The error reference lists the same errors.
Logs
| Level | Line | Meaning | Action |
|---|---|---|---|
| ERROR | MCP usage analytics query failed: <reason> | One of the /tag/mcp routes failed in the database and the caller got a 500. | Read the database error after the colon. A missing table means the database migrations have not run. |
The routes add no metric of their own. For live rates, the Prometheus metrics spanway_mcp_tool_calls_total and spanway_mcp_tool_call_spend_metric count MCP tool calls and their spend by mcp_server_name and mcp_tool_name. The client label is not a metric label, so a client split is only available here and in Query and Explore.
The same rollups are open to Query and Explore, which is the place to build your own charts. Explore has an MCP tool dimension (tool names start with the server name) but no MCP server dimension, so use the server split on this page, or a SQL query on the Query page, to group by server. To chart a client app in Explore, use the request tag dimension and filter on the tag MCP-Client: <label>.
Related
- User agent analytics counts users per coding agent and SDK for all traffic, not only MCP calls.
- Usage page describes the MCP Server Activity tab and the other tabs.
- MCP access control explains
mcp_allowed_clientsandmcp_client_id_header. - Query and Explore builds charts and SQL over the same daily rollups.