Skip to content

feat(mcp): Ship @sentry/mcp features as integrations #27143

Todo

Description

@logaretm

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' });
  • wrapMcpServerWithSentry emits a new client hook, mcpServerWrapped, for every server it wraps, automatically or by hand. Integrations subscribe in setup(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.
  • serverName defaults to the server's serverInfo.title or name.
  • 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, feedbackHint and withFeedbackHint keep 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, init already has to run before new McpServer() for the constructor to be hooked.
  • On Cloudflare, instrumentDurableObjectWithSentry calls init before it constructs the Durable Object, so an McpAgent server built in a field or in init() has a client. withSentry calls init before the fetch handler, so a server built per request does too. An McpServer built at module scope is wrapped once its deferred constructor event is flushed in init.
  • The gap is wrapMcpServerWithSentry called 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.
  • addFeedbackTool and the other exports keep their behavior. We deprecate addFeedbackTool in favor of mcpFeedbackIntegration and 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

  1. self-assigned this
    on Dec 3, 2026
  2. linear-code commented on Dec 3, 2026

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions