Skip to content

ops(mcp): /mcp emits zero usage telemetry (no wm_api_usage rows, no log drain) — auth rejections invisible, #4859 diagnosis was blind #4866

Description

@koala73

Gap

/mcp has zero queryable request telemetry. Found while diagnosing the 2026-07-05 paying-customer ticket (#4859/#4860): we could not see the customer's -32001 "Invalid API key" rejections or their tools/call failures anywhere — the diagnosis had to be reconstructed indirectly from REST-side Axiom rows and Convex lastUsedAt timestamps.

Specifics:

  1. wm_api_usage (Axiom) is emitted only by server/gateway.ts (emitUsageEvents). /mcp rewrites straight to api/mcp/handler.ts and never passes the gateway → no rows, ever. Auth rejections, quota 429s, and successes on the MCP surface are all invisible.
  2. The mcp.toolcall / mcp.tools_list_emitted structured console.log lines (api/mcp/telemetry.ts) assume "Vercel log drain → analytics consumer" — but no log drain is configured (GET /v2/integrations/log-drains returns []). The lines evaporate after Vercel's dashboard retention window.
  3. Auth failures emit no telemetry event at all (they return before dispatch), so even a drain wouldn't capture the bug(mcp): /mcp rejects all customer-issued wm_ API keys — X-WorldMonitor-Key path only checks WORLDMONITOR_VALID_KEYS env allowlist #4859 symptom.
  4. Sentry captures only tool-execution errors and (post-fix(mcp): accept customer wm_ API keys on /mcp + guard pro-token validate (#4859, #4860) #4863) pre-check transients — 401/429 traffic is invisible by design.

Proposal

  • Emit a RequestEvent into wm_api_usage from the MCP handler (route /mcp, auth_kind ∈ anon/env_key/pro/user_key, status, reason ∈ e.g. invalid_key/subscription_inactive/quota_429/ok, principal per principalIdForLog) via ctx.waitUntil, reusing server/_shared/usage.ts builders — same envelope, one new emitter callsite.
  • Alternatively (or additionally) configure a Vercel log drain so the existing mcp.toolcall lines land somewhere queryable — but the usage-event route gives customer_id-joinable data consistent with the REST surface, which is what support tickets need.
  • Alert candidate once data flows: sustained invalid_key spikes per principal/IP (would have surfaced bug(mcp): /mcp rejects all customer-issued wm_ API keys — X-WorldMonitor-Key path only checks WORLDMONITOR_VALID_KEYS env allowlist #4859's customer on day one).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions