Skip to content

Capture host environment signals on MCP initialize#540

Open
edgarsskore wants to merge 2 commits into
mainfrom
feat/initialize-host-signals
Open

Capture host environment signals on MCP initialize#540
edgarsskore wants to merge 2 commits into
mainfrom
feat/initialize-host-signals

Conversation

@edgarsskore

@edgarsskore edgarsskore commented Jul 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Telemetry-only change, no behavior impact. Claude Code CLI, Claude Code inside the Claude Desktop app, and Cowork all report clientInfo.name = 'claude-code', so client_name alone cannot attribute initializes to the actual host.

Adds three raw, non-PII environment signals to the existing run_server_mcp_initialized event (no new event types):

Property Source env var CC CLI CC in Desktop app Cowork Other clients
host_entrypoint CLAUDE_CODE_ENTRYPOINT cli claude-desktop
host_agent AI_AGENT claude-code_<v>_harness claude-code_<v>_harness
host_plugin_id basename of CLAUDE_PLUGIN_DATA plugin id or — desktop-commander-inline desktop-commander-inline

No client-specific branching in code — raw values are captured and segmentation happens in analytics:

CASE
  WHEN host_entrypoint = 'cli'            THEN 'claude-code-cli'
  WHEN host_entrypoint = 'claude-desktop' THEN 'claude-code-in-desktop-app'
  WHEN host_plugin_id  = 'desktop-commander-inline' THEN 'cowork'
  ELSE 'claude-code-other'
END

Testing

Verified end-to-end against production BigQuery telemetry with one controlled initialize per host (fresh client id each): all three contexts produced distinct signatures; non-Claude clients (e.g. codex-mcp-client) send no extra fields. Only the basename of CLAUDE_PLUGIN_DATA is captured — no user paths.

🤖 Generated with Claude Code

Summary by CodeRabbit

  • Chores
    • Improved initialization reporting by enriching the telemetry event with contextual environment details (entrypoint, agent, and plugin identifier) and truncating values for consistency.

Claude Code CLI, Claude Code inside the Claude Desktop app, and Cowork
all report clientInfo.name 'claude-code', so client_name alone cannot
attribute initializes to the actual host. Capture three raw, non-PII
environment signals on run_server_mcp_initialized so analytics can tell
them apart without client-specific branching in code:

- host_entrypoint (CLAUDE_CODE_ENTRYPOINT): 'cli' for Claude Code CLI,
  'claude-desktop' for Claude Code inside the desktop app
- host_agent (AI_AGENT): e.g. 'claude-code_2-1-198_harness'
- host_plugin_id (basename of CLAUDE_PLUGIN_DATA): plugin identifier,
  e.g. 'desktop-commander-inline' for the desktop app's inline plugin

Verified against production telemetry with one controlled initialize
per host: Cowork sets no entrypoint/agent but carries the inline plugin
id, giving a distinct signature for all three contexts. Clients that
set none of these send no extra fields.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@coderabbitai

coderabbitai Bot commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro

Run ID: b9278b4c-b3ce-45c5-b0f1-e9a69980457e

📥 Commits

Reviewing files that changed from the base of the PR and between 0bdb8d8 and 14e2aa3.

📒 Files selected for processing (1)
  • src/server.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/server.ts

📝 Walkthrough

Walkthrough

src/server.ts now emits run_server_mcp_initialized telemetry with host_entrypoint, host_agent, and host_plugin_id derived from environment variables, and adds a path import to compute the plugin id.

Changes

Initialization Telemetry Enrichment

Layer / File(s) Summary
Add path import and enrich telemetry event
src/server.ts
Adds path import and updates the run_server_mcp_initialized capture call to include host_entrypoint, host_agent, and host_plugin_id derived from process.env.

Estimated code review effort: 1 (Trivial) | ~3 minutes

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly summarizes the main telemetry change: capturing host environment signals during MCP initialization.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
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.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch feat/initialize-host-signals

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.

Same convention as containerName/containerImage: an oversized
environment value can get the whole event rejected by GA4, so clip
each host signal to 100 chars instead of trusting host-controlled
env vars to be short.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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