fix(core): resolve MCP capture policy per operation - #23437
Open
betegon wants to merge 3 commits into
Open
Conversation
MCP servers can be wrapped before a Sentry client exists, causing inherited data collection settings to be fixed to their fallback values. Resolve inherited policy when an operation begins and retain request policy through response correlation. Co-Authored-By: OpenAI Codex <codex@openai.com>
Node module evaluation and Cloudflare Durable Object initialization can wrap MCP servers before Sentry binds a client. Exercise both runtimes with marker content so capture-policy regressions are observable. Co-Authored-By: OpenAI Codex <codex@openai.com>
Contributor
size-limit report 📦
|
Keep the public input and output capture defaults protected when an MCP operation has no active client or explicit overrides. Co-Authored-By: OpenAI Codex <codex@openai.com>
betegon
marked this pull request as ready for review
August 14, 2026 19:37
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.
MCP server instrumentation now honors the active Sentry client's GenAI input
and output collection settings even when the server was wrapped before that
client became available. Explicit wrapper overrides still win independently,
and the existing default remains unchanged when no policy is configured.
The capture decision belongs to the operation that starts the span.
Request/response pairs therefore retain one policy for their full lifetime
instead of allowing response timing or a different active scope to change what
gets recorded. Notifications resolve against the client active when their
operation begins. Explicit options are also snapshotted on the first wrap,
preserving the wrapper's idempotent behavior.
This is shared transport behavior, so it applies to sessionful MCP SDK v1 and
stable MCP SDK v2 without changing the public API. Packaged SDK coverage uses
the Node and Cloudflare MCP fixtures. A disposable Cloudflare Worker running
the packaged SDK also verified the policy matrix against Sentry for both modern
and legacy-compatible requests.
Root cause
wrapMcpServerWithSentryreaddataCollection.genAIonce, while the wrapperwas being constructed. Common Node import ordering and Cloudflare Durable
Object initialization can run that code before Sentry binds a client, causing
the
truefallback to become the permanent capture policy for every operationhandled by that server.
Fixes #23436