fix(web): count canonical MCP sources in analytics

Merged
BR
2mo ago
+134-19

Summary

  • classify both the canonical sourcebot-mcp-server source and legacy mcp source as MCP analytics activity
  • standardize ask_codebase on the canonical MCP source
  • keep MCP activity in the combined non-web and global active-user metrics
  • add regression coverage for MCP and API source classification

Regression

MCP analytics was introduced in #950 on March 4, 2026 using the mcp source. The shared MCP tool refactor in #1014 on March 22, 2026 changed tool audit metadata to sourcebot-mcp-server without updating the analytics query, which still required an exact mcp match.

Testing

  • yarn workspace @sourcebot/web eslint src/ee/features/analytics/actions.ts src/ee/features/analytics/actions.test.ts src/ee/features/mcp/constants.ts src/ee/features/mcp/server.ts
  • yarn workspace @sourcebot/web test src/app/api/(server)/ee/mcp/route.test.ts src/features/tools/adapters.test.ts src/ee/features/analytics/actions.test.ts --run
  • yarn workspace @sourcebot/web tsc --noEmit (blocked by existing generated .next/types errors in unrelated settings pages)

[!NOTE]
Low Risk
Changes are limited to EE analytics classification and MCP audit/telemetry source strings, with PGlite regression tests and no auth or data-migration impact.

Overview
Fixes EE analytics undercounting MCP usage after audit metadata moved from the legacy mcp label to sourcebot-mcp-server. The analytics SQL now derives a source_category (mcp, api, or sourcebot) so both labels roll into MCP metrics, and MCP/API/non-web active-user counts use that column instead of one-off metadata->>'source' checks.

MCP server labeling is centralized on shared constants (MCP_SERVER_SOURCE, LEGACY_MCP_SERVER_SOURCE), including ask_codebase, which still wrote mcp. Regression coverage runs the real aggregation query against PGlite via a new dev dependency.

Reviewed by Cursor Bugbot for commit 710bcb15b0af6a3889041bbcec986a9a0937df80. Bugbot is set up for automated code reviews on this repo. Configure here.


Summary by cubic

Fixes MCP analytics so both the canonical sourcebot-mcp-server and legacy mcp audit sources are classified as MCP activity, preventing MCP usage from being undercounted after the shared MCP tool refactor.

  • Standardizes ask_codebase to use the canonical MCP source.
  • Adds regression coverage for MCP and API source classification.

Summary by CodeRabbit

  • Bug Fixes

    • Fixed analytics so MCP activity using the canonical source label is included correctly.
    • Preserved analytics tracking for activity using the legacy MCP source label.
    • Improved classification of MCP, API, and Sourcebot activity for more accurate usage metrics and active-user reporting.
  • Consistency

    • Standardized MCP activity source labeling across supported MCP interactions for more reliable analytics.
    • Ensured MCP activity is consistently recognized across current and legacy source labels.