Conversation
Add an `mcpServer` integration that wraps `McpServer` instances at construction through an orchestrion constructor hook, so users no longer need to call `wrapMcpServerWithSentry` by hand. Covers both `@modelcontextprotocol/server` (v2, matched in its content-hashed chunk) and `@modelcontextprotocol/sdk` (v1). `wrapMcpServerWithSentry` stays a supported, idempotent no-op when the instance was already auto-wrapped. Rename the existing manual node-integration-test suite to `mcp-server/manual-instrumentation` and add `mcp-server/v1` and `mcp-server/v2` suites that exercise the auto-wrapping path. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 2 potential issues.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit e0e1545. Configure here.
Contributor
size-limit report 📦
|
mydea
added this pull request to stack #24534
September 21, 2026 08:30
Auto-instrumentation wraps each `McpServer` at construction with no explicit
capture options. The double-wrap guard previously ignored a later manual
`wrapMcpServerWithSentry(server, { recordInputs, recordOutputs })` entirely,
silently dropping the override so tool I/O could still be collected against a
server the user meant to opt out.
Track the mutable capture options per server (WeakMap) instead of a plain
WeakSet: a re-wrap now fills in options the first wrap left unset, so an
auto-wrap's defaults yield to a later manual override, while an explicit first
wrap still wins (unchanged, per `snapshots explicit overrides from the first
wrap`). The transport reads these options per message, so the update applies to
subsequent requests.
Also export `mcpServerIntegration` from the runtime packages that surface the
other tracing integrations (node, bun, deno, elysia, aws/gcp serverless,
astro), alongside `mastraIntegration`.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Making `mcpServerIntegration` a default (tracing) integration pulls the `wrapMcpServerWithSentry` instrumentation tree (~8.7 KB gzipped) into the `init` path, which was previously tree-shaken out. Bump the two affected `@sentry/node` scenarios to their measured sizes: - `@sentry/node`: 135 -> 139 KB - `@sentry/node - without channel injection`: 114 -> 117 KB `@sentry/node - without tracing` is unchanged (the integration is tracing-only). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
mydea
marked this pull request as ready for review
September 21, 2026 09:05
mydea
requested review from
JPeer264,
betegon,
isaacs,
nicohrubec and
s1gr1d
and removed request for
a team
September 21, 2026 09:05
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

McpServerinstances currently only produce spans when the user manually callswrapMcpServerWithSentry. This adds anmcpServerintegration (default, tracing) that wraps everyMcpServerat construction through an orchestrion constructor hook, so no manual call is needed.Both SDK families are covered:
@modelcontextprotocol/server(v2) — whoseMcpServerlives in a content-hashed tsdown chunk, so it's matched by a regexfilePathwithclassName: 'McpServer'as the real selector, the same shapemastra.tsuses — and@modelcontextprotocol/sdk(v1). The subscriber just hands the constructed instance to the existingwrapMcpServerWithSentry, reusing all of its transport/handler instrumentation rather than reimplementing anything.wrapMcpServerWithSentrystays fully supported. Re-wrapping an already-wrapped instance never patches it twice, but capture options are tracked per server (WeakMap): a later call fills inrecordInputs/recordOutputsleft unset by an earlier wrap. So the auto-wrap's defaults yield to a later manual override — a user can stillwrapMcpServerWithSentry(server, { recordInputs: false })to opt out — while an explicit first wrap still wins. The transport reads these options per message.mcpServerIntegrationis re-exported from the runtime packages that surface the other tracing integrations (node, bun, deno, elysia, aws/gcp serverless, astro), alongsidemastraIntegration.🤖 Generated with Claude Code