Repository navigation
Description
Motivation
Our MCP support lives in two places. wrapMcpServerWithSentry in @sentry/core creates the spans, and mcpServerIntegration applies it to every McpServer on its own. addFeedbackTool in @sentry/mcp has to be called on the server by hand. Each new @sentry/mcp feature (intent capture, a missing capability tool, ...) would add another wrapper to call, and the user has to know which one goes where.
addFeedbackTool also works without Sentry. Without a client it still registers submit_feedback, which answers agents with "Feedback isn't available", so the tool and the hints check for a client on every call.
Proposal
@sentry/mcp ships one integration per feature, plus the low-level APIs it has today:
import * as Sentry from '@sentry/node';
import { mcpFeedbackIntegration } from '@sentry/mcp';
Sentry.init({
dsn,
integrations: [mcpFeedbackIntegration({ serverName: 'Acme' })],
});
// Nothing to call on the server: it is wrapped automatically and the feedback tool attaches to it.
const server = new McpServer({ name: 'acme', version: '1.0.0' });wrapMcpServerWithSentryemits a new client hook,mcpServerWrapped, for every server it wraps, automatically or by hand. Integrations subscribe insetup(client)and keep their state per server, which also drops the module-level "last registered feedback tool" fallback.- Integrations only set up when the client is enabled with a DSN, so without Sentry the tool is never registered.
serverNamedefaults to the server'sserverInfo.titleorname.- The low-level APIs stay for servers the hook can't reach: tool catalogs, servers that don't use the MCP SDK, and handlers of their own.
createFeedbackTool,captureAgentFeedback,feedbackHintandwithFeedbackHintkeep working as they do now. Each integration calls them, so every feature has one implementation.
The split between the packages stays: a feature that only observes the server goes into core's wrapper, and one that changes what the agent sees (adds a tool, edits a result) goes into @sentry/mcp as an integration.
Order of init and wrapping
The hook needs a client when the server is wrapped:
- With auto-instrumentation,
initalready has to run beforenew McpServer()for the constructor to be hooked. - On Cloudflare,
instrumentDurableObjectWithSentrycallsinitbefore it constructs the Durable Object, so anMcpAgentserver built in a field or ininit()has a client.withSentrycallsinitbefore the fetch handler, so a server built per request does too. AnMcpServerbuilt at module scope is wrapped once its deferred constructor event is flushed ininit. - The gap is
wrapMcpServerWithSentrycalled by hand before any client exists. Core keeps those servers and emits the hook for them once a client sets up, the same way Cloudflare defers channel events. Servers wrapped at module scope live as long as the isolate or process, so holding on to them costs nothing extra.
On Cloudflare the worker and its Durable Objects share one cached client per isolate, and whichever entrypoint calls init first decides its integrations. The integration has to be in the options of both.
Not a breaking change
- The hook is new and has no subscribers until an integration uses it, so core behaves the same.
- The integrations are opt-in. Without one, no tool is added and no result changes, with automatic or manual wrapping.
addFeedbackTooland the other exports keep their behavior. We deprecateaddFeedbackToolin favor ofmcpFeedbackIntegrationand remove it in a later major. When both are used on one server, the tool is registered once.- The existing APIs keep working with any 11.x SDK. Only the integrations need the core version that emits the hook, so they log a debug warning when the hook is missing instead of failing silently.
Open questions
- Whether the feedback tool, registered when the server is wrapped, should appear before the server's own tools in
tools/list. - How to detect that core is too old to emit the hook.
Activity
linear-code commentedon Dec 3, 2026
JS-4225