Skip to content

fix(web): count canonical MCP sources in analytics - #1651

Merged
brendan-kellam merged 4 commits into
mainfrom
fix/mcp-analytics-source
Sep 11, 2026
Merged

fix(web): count canonical MCP sources in analytics#1651
brendan-kellam merged 4 commits into
mainfrom
fix/mcp-analytics-source

Conversation

@brendan-kellam

@brendan-kellam brendan-kellam commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

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 710bcb1. 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.

Written for commit 710bcb1. Summary will update on new commits.

Review in cubic

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.

@github-actions

This comment has been minimized.

@coderabbitai

coderabbitai Bot commented Sep 11, 2026

Copy link
Copy Markdown
Contributor

Review Change StackReview Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Advanced

Run ID: a8b4eb90-1259-4dcc-a938-4a946b7e8418

📥 Commits

Reviewing files that changed from the base of the PR and between e0f376a and 710bcb1.

⛔ Files ignored due to path filters (1)
  • yarn.lock is excluded by !**/yarn.lock, !**/*.lock
📒 Files selected for processing (2)
  • packages/web/package.json
  • packages/web/src/ee/features/analytics/actions.test.ts

Included review availability: Your plan provides up to 8 included reviews per hour; 7 remain after this review.


Walkthrough

The change centralizes MCP source labels and updates analytics classification for canonical and legacy MCP activity. Tests execute the analytics query against PGlite and verify aggregate metrics.

Changes

MCP analytics source classification

Layer / File(s) Summary
Centralize MCP source identifiers
packages/web/src/ee/features/mcp/constants.ts, packages/web/src/ee/features/mcp/server.ts
MCP source labels use shared constants. MCP metadata, event capture, and askCodebase calls use the canonical source constant.
Classify and validate MCP analytics
packages/web/src/ee/features/analytics/actions.ts, packages/web/src/ee/features/analytics/actions.test.ts, packages/web/package.json, CHANGELOG.md
Analytics derives source_category and classifies canonical and legacy MCP sources as mcp. Active-user and request filters use the derived category. The test runs the query against seeded PGlite data and checks aggregate counts. The changelog records the fix.

Priority: ➖ Normal

Estimated code review effort: 2 (Simple) | ~10 minutes

Change: Bug fix · Severity of issue fixed: Medium

Suggested reviewers: jsourcebot

Merge Risk: ⚪ Minimal · up to 710bc

MCP activity is classified consistently for canonical and legacy audit sources, with aggregate analytics coverage added. No actionable merge risk remains.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files. (1 skipped: 1 … Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (4 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely describes the main change: fixing analytics to count canonical MCP sources.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Full details: Docstring Coverage

Explanation

Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Docstring coverage is scoped to functions touched by this diff. Analyzed 1 functions across 4 files. (1 skipped: 1 unsupported.)

  • Fix all pre-merge checks with AI
✨ Finishing Touches 💡 1
📝 Generate docstrings 💡
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/mcp-analytics-source

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All reported issues were addressed

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread packages/web/src/ee/features/analytics/actions.test.ts Outdated
@brendan-kellam
brendan-kellam merged commit 31734dc into main Sep 11, 2026
14 checks passed
@brendan-kellam
brendan-kellam deleted the fix/mcp-analytics-source branch September 11, 2026 22:15
@github-actions

Copy link
Copy Markdown
Contributor

License Audit

⚠️ Status: PASS

Metric Count
Total packages 2174
Resolved (non-standard) 26
Unresolved 0
Strong copyleft 0
Weak copyleft 28

Weak Copyleft Packages (informational)

Package Version License
@img/sharp-libvips-darwin-arm64 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-darwin-x64 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-linux-arm 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-linux-arm64 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-linux-ppc64 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-linux-riscv64 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-linux-s390x 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-linux-x64 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-linuxmusl-arm64 1.3.3 LGPL-3.0-or-later
@img/sharp-libvips-linuxmusl-x64 1.3.3 LGPL-3.0-or-later
@img/sharp-wasm32 0.35.4 Apache-2.0 AND LGPL-3.0-or-later AND MIT
@img/sharp-win32-arm64 0.35.4 Apache-2.0 AND LGPL-3.0-or-later
@img/sharp-win32-ia32 0.35.4 Apache-2.0 AND LGPL-3.0-or-later
@img/sharp-win32-x64 0.35.4 Apache-2.0 AND LGPL-3.0-or-later
axe-core 4.10.3 MPL-2.0
dompurify 3.4.13 (MPL-2.0 OR Apache-2.0)
lightningcss 1.32.0 MPL-2.0
lightningcss-android-arm64 1.32.0 MPL-2.0
lightningcss-darwin-arm64 1.32.0 MPL-2.0
lightningcss-darwin-x64 1.32.0 MPL-2.0
lightningcss-freebsd-x64 1.32.0 MPL-2.0
lightningcss-linux-arm-gnueabihf 1.32.0 MPL-2.0
lightningcss-linux-arm64-gnu 1.32.0 MPL-2.0
lightningcss-linux-arm64-musl 1.32.0 MPL-2.0
lightningcss-linux-x64-gnu 1.32.0 MPL-2.0
lightningcss-linux-x64-musl 1.32.0 MPL-2.0
lightningcss-win32-arm64-msvc 1.32.0 MPL-2.0
lightningcss-win32-x64-msvc 1.32.0 MPL-2.0
Resolved Packages (26)
Package Version Original Resolved Source
@sentry/cli 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-darwin 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-darwin 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-linux-arm 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-linux-arm 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-linux-arm64 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-linux-arm64 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-linux-i686 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-linux-i686 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-linux-x64 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-linux-x64 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-win32-arm64 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-win32-arm64 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-win32-i686 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-win32-i686 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-win32-x64 2.58.5 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.5: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
@sentry/cli-win32-x64 2.58.6 FSL-1.1-MIT FSL-1.1-MIT GitHub repo (getsentry/sentry-cli LICENSE at tag 2.58.6: "Functional Source License, Version 1.1, MIT Future License"); npm registry reports FSL-1.1-MIT for this exact version. Not an SPDX-registered identifier: source-available, converts to MIT two years after release
codemirror-lang-elixir 4.0.0 UNKNOWN Apache-2.0 GitHub repo (livebook-dev/codemirror-lang-elixir LICENSE is the Apache 2.0 text); npm registry lists Apache-2.0 for later versions
khroma 2.1.0 UNKNOWN MIT GitHub repo (fabiospampinato/khroma license file: "The MIT License (MIT)")
lezer-elixir 1.1.2 UNKNOWN Apache-2.0 GitHub repo (livebook-dev/lezer-elixir LICENSE is the Apache 2.0 text); npm registry lists Apache-2.0 for later versions
map-stream 0.1.0 UNKNOWN MIT GitHub repo (dominictarr/map-stream LICENCE: "The MIT License (MIT)"); npm registry lists MIT for the latest tag
memorystream 0.3.1 UNKNOWN MIT extracted from object - legacy licenses: [{"type":"MIT"}] field in package.json, confirmed by the MIT LICENSE file in the repo
pause-stream 0.0.11 ["MIT","Apache2"] (MIT OR Apache-2.0) extracted from object - license: ["MIT","Apache2"] array in package.json, confirmed by LICENSE file ("Dual Licensed MIT and Apache 2"); "Apache2" normalized to the SPDX id Apache-2.0
posthog-js 1.369.0 SEE LICENSE IN LICENSE (Apache-2.0 AND MIT) LICENSE file referenced by the "SEE LICENSE IN LICENSE" pointer (Apache-2.0 for the project, with bundled MIT-licensed portions); npm registry reports "(Apache-2.0 AND MIT)"
valid-url 1.0.9 UNKNOWN MIT GitHub repo (ogt/valid-url LICENSE: "This software is released under the MIT license")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant