Skip to content

feat(telemetry): track stateless MCP protocol connects#3013

Open
ignaciojimenezr wants to merge 1 commit into
MCPJam:mainfrom
ignaciojimenezr:stateless-protocol-telemetry
Open

feat(telemetry): track stateless MCP protocol connects#3013
ignaciojimenezr wants to merge 1 commit into
MCPJam:mainfrom
ignaciojimenezr:stateless-protocol-telemetry

Conversation

@ignaciojimenezr

@ignaciojimenezr ignaciojimenezr commented Jul 3, 2026

Copy link
Copy Markdown
Collaborator

usePostHog for telemetry on stateless mcp


Summary by cubic

Track and enrich stateless MCP protocol connect telemetry via PostHog. Emits one stateless_protocol_connect event per successful connect when the effective protocol pin is a stateless version.

  • New Features
    • Emit with standardEventProps("use_server_state") and rich metadata: mcp_protocol_version, protocol_pin_source, connection_transport, auth_mode, attempt type (direct|forced_oauth|synced_oauth_credentials|authorized_reconnect|protocol_revalidation), and lightweight counts (headers/capabilities/versions).
    • Capture at the reconnect chokepoint across all flows, de-dup per reconnect, and gate on isStatelessProtocolVersion(effectiveProtocolVersion); safe no-op when usePostHog is unavailable.
    • Add tests to confirm event shape and that sensitive fields like serverName and url are not included.

Written for commit 7079b5c. Summary will update on new commits.

Review in cubic

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 3, 2026
@chatgpt-codex-connector

Copy link
Copy Markdown

Codex usage limits have been reached for code reviews. Please check with the admins of this repo to increase the limits by adding credits.
Credits must be used to enable repository wide code reviews.

@chelojimenez

chelojimenez commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Snyk checks have passed. No issues have been found so far.

Status Scan Engine Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@dosubot dosubot Bot added the enhancement New feature or request label Jul 3, 2026

@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.

1 issue found across 1 file

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="mcpjam-inspector/client/src/hooks/use-server-state.ts">

<violation number="1" location="mcpjam-inspector/client/src/hooks/use-server-state.ts:1240">
P2: Telemetry for `stateless_protocol_connect` is currently sent before `reconnectServer(...)` finishes, so failed reconnects will still be counted as connects. That can skew protocol adoption metrics and make success-rate analysis unreliable. A safer pattern is to emit this event only after a successful reconnect (and optionally add a separate failure event in the catch path).</violation>
</file>

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

Fix all with cubic | Re-trigger cubic

Comment thread mcpjam-inspector/client/src/hooks/use-server-state.ts Outdated
@coderabbitai

coderabbitai Bot commented Jul 3, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

This change adds PostHog telemetry to stateless MCP reconnects in use-server-state.ts. It introduces stateless protocol detection, builds standardized event metadata, and captures stateless_protocol_connect during successful reconnect paths including protocol revalidation and OAuth-related retries. The test file adds PostHog mocking and coverage for the revalidation telemetry event.

Warning

There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure.

🔧 ESLint

If the error stems from missing dependencies, add them to the package.json file. For unrecoverable errors (e.g., due to private dependencies), disable the tool in the CodeRabbit configuration.

mcpjam-inspector/client/src/hooks/__tests__/use-server-state.protocol-revalidation.test.tsx

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: ESLint configuration in --config is invalid:

  • Unexpected top-level property "__esModule".

    at ConfigValidator.validateConfigSchema (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2177:19)
    at ConfigArrayFactory._normalizeConfigData (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3019:19)
    at ConfigArrayFactory._loadConfigData (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2984:21)
    at ConfigArrayFactory.loadFile (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2850:40)
    at createCLIConfigArray (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3660:35)
    at new CascadingConfigArrayFactory (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3735:29)
    at new CLIEngine (/soundcheck/node_modules/eslint/lib/cli-engine/cli-engine.js:617:36)
    at new ESLint (/soundcheck/node_modules/eslint/lib/eslint/eslint.js:430:27)
    at Object.execute (/soundcheck/node_modules/eslint/lib/cli.js:410:24)
    at async main (/soundcheck/node_modules/eslint/bin/eslint.js:152:22)

mcpjam-inspector/client/src/hooks/use-server-state.ts

Oops! Something went wrong! :(

ESLint: 8.57.1

Error: ESLint configuration in --config is invalid:

  • Unexpected top-level property "__esModule".

    at ConfigValidator.validateConfigSchema (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2177:19)
    at ConfigArrayFactory._normalizeConfigData (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3019:19)
    at ConfigArrayFactory._loadConfigData (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2984:21)
    at ConfigArrayFactory.loadFile (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:2850:40)
    at createCLIConfigArray (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3660:35)
    at new CascadingConfigArrayFactory (/soundcheck/node_modules/@eslint/eslintrc/dist/eslintrc.cjs:3735:29)
    at new CLIEngine (/soundcheck/node_modules/eslint/lib/cli-engine/cli-engine.js:617:36)
    at new ESLint (/soundcheck/node_modules/eslint/lib/eslint/eslint.js:430:27)
    at Object.execute (/soundcheck/node_modules/eslint/lib/cli.js:410:24)
    at async main (/soundcheck/node_modules/eslint/bin/eslint.js:152:22)


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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@mcpjam-inspector/client/src/hooks/use-server-state.ts`:
- Around line 1226-1249: The stateless_protocol_connect telemetry in the
reconnect path is being emitted more than once for a single logical reconnect
when reconnectServerInternal retries through the OAuth fallback branch. Move or
guard the capture in use-server-state.ts so it only fires once per
user-initiated reconnect (for example, before the retry path starts, or behind a
per-attempt flag), and make sure guardedReconnectServer/reconnectServerInternal
do not re-evaluate and re-capture connectionDefaults on the second authorization
attempt.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: 7f4b3c09-2748-446d-b26c-7c8f193a9c61

📥 Commits

Reviewing files that changed from the base of the PR and between 28479fe and e01713d.

📒 Files selected for processing (1)
  • mcpjam-inspector/client/src/hooks/use-server-state.ts

Comment thread mcpjam-inspector/client/src/hooks/use-server-state.ts Outdated
@ignaciojimenezr ignaciojimenezr force-pushed the stateless-protocol-telemetry branch from e01713d to 7079b5c Compare July 6, 2026 05:34
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. and removed size:M This PR changes 30-99 lines, ignoring generated files. labels Jul 6, 2026

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
mcpjam-inspector/client/src/hooks/use-server-state.ts (1)

1246-1264: 📐 Maintainability & Code Quality | 🔵 Trivial | ⚡ Quick win

Pin-resolution precedence is duplicated — a quiet drift risk.

The server-override/host-pin resolution here mirrors the logic in buildResolverConnectionDefaults (Lines 1205-1223). Should either side's precedence ever change, protocol_pin_source would silently misreport without any test catching it. Consider extracting a single shared resolver so telemetry and the wire payload can never disagree.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@mcpjam-inspector/client/src/hooks/use-server-state.ts` around lines 1246 -
1264, The pin-resolution logic in useServerState duplicates the precedence used
by buildResolverConnectionDefaults, which can let protocol_pin_source drift from
the actual wire payload. Extract the shared server-override/host-pin resolution
into a single helper and use it from both buildResolverConnectionDefaults and
the protocolPinSource calculation so they always derive from the same source of
truth.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@mcpjam-inspector/client/src/hooks/use-server-state.ts`:
- Around line 1246-1264: The pin-resolution logic in useServerState duplicates
the precedence used by buildResolverConnectionDefaults, which can let
protocol_pin_source drift from the actual wire payload. Extract the shared
server-override/host-pin resolution into a single helper and use it from both
buildResolverConnectionDefaults and the protocolPinSource calculation so they
always derive from the same source of truth.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: c37980d7-19be-4399-9e47-73d79fa2bfa1

📥 Commits

Reviewing files that changed from the base of the PR and between e01713d and 7079b5c.

📒 Files selected for processing (2)
  • mcpjam-inspector/client/src/hooks/__tests__/use-server-state.protocol-revalidation.test.tsx
  • mcpjam-inspector/client/src/hooks/use-server-state.ts

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

Labels

enhancement New feature or request size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants