Repository navigation
chore(mcp): Add @sentry/mcp package scaffold - #26995
Merged
Merged
Conversation
Contributor
size-limit report 📦Compared: beb309c (PR test merge using develop at 399a4d5) Against: 399a4d5 (develop) · base run #68449 ✅ Baseline matches: this diff contains only this PR's changes.
|
Contributor
Optional E2E testsSome optional checks were not successful. They do not block the merge. 3 not successful, 62 successful. See the run.
Successful checks
|
msonnb
approved these changes
Dec 1, 2026
maxcell
approved these changes
Dec 1, 2026
logaretm
force-pushed
the
awad/mcp-package-scaffold
branch
from
December 1, 2026 14:27
830e1e7 to
cd17cbd
Compare
…mplate Publish @sentry/mcp to npm and the release registry, list it in the root README, and add it to the bug report package dropdown.
logaretm
force-pushed
the
awad/mcp-package-scaffold
branch
from
December 1, 2026 19:01
cd17cbd to
b5185af
Compare
logaretm
added a commit
that referenced
this pull request
Dec 1, 2026
For context on why this is its own package, refer to #26995 MCP server authors have no easy way to hear from agents that get stuck on their tools, this PR adds `addFeedbackTool` and `createFeedbackTool` to cater for both simple setups and more dynamic ones like ours in sentry mcp server. Two ways to set it up for now: ```ts import * as Sentry from '@sentry/node'; import { McpServer } from '@modelcontextprotocol/server'; import { addFeedbackTool } from '@sentry/mcp'; Sentry.init({ dsn: process.env.SENTRY_DSN, tracesSampleRate: 1 }); // Whatever MCP setup they have, as long as we have the `server` const server = Sentry.wrapMcpServerWithSentry(new McpServer({ name: 'orders', version: '1.0.0' })); // user adds tools and other stuff... // ... // Adds the feedback tool, wraps other tools with a "honey pot" hint on error. addFeedbackTool(server, { serverName: 'Orders' }); ``` Or, for servers that register tools through their own catalog, create the tool and register it like any other: ```ts import { createFeedbackTool } from '@sentry/mcp'; // Same options as addFeedbackTool. `server` is optional: it names the agent on each report and adds the error hints const tool = createFeedbackTool({ serverName: 'Orders', server }); server.registerTool(tool.name, tool.config, tool.handler); ``` The tool returns the feedback ID as `structuredContent` with a matching `outputSchema`, next to the text. ### Error Hints Failing tools get this sentence appended to their error: ``` If this keeps failing after you adjust your request, report it to the Orders team with `submit_feedback`. └─────────────────── condition ───────────────────┘ └─ recipient ─┘ └── toolName ───┘ ``` With `serverName: 'Orders'` the recipient becomes "the Orders team", and the tool name follows `name`. Successful results are never modified, error results get the hint as an extra text block so `structuredContent` is never touched, and errors that already mention the feedback tool don't get a second hint. Only these errors receive the hint: | Failure | Hint? | | --- | --- | | `{ status: 429 }`, `{ statusCode: 404 }`, `{ response: { status: 403 } }` | No | | `McpError` with code `-32602` | No | | `{ status: 502 }`, a plain `Error`, `ECONNREFUSED` (string `code`), an `isError` result | Yes | The user can also customize which errors get hinted with `errorHints` option: ```ts addFeedbackTool(server); // default: shouldHintFeedback addFeedbackTool(server, { errorHints: false }); // no hints addFeedbackTool(server, { // (toolName, failure) => boolean; failure is the thrown Error or the isError result errorHints: (toolName, failure) => shouldHintFeedback(failure) && toolName !== 'search_orders', }); ``` ### Hints on other results For results that aren't errors but still suggest a problem, like an empty search, authors add the hint themselves. Both helpers use the name and `serverName` of the tool `addFeedbackTool` or `createFeedbackTool` made, and add nothing until that tool exists and Sentry has a client: ```ts import { feedbackHint, withFeedbackHint } from '@sentry/mcp'; // adds the hint as its own text block, leaves structuredContent and the existing content alone return orders.length ? result : withFeedbackHint(result, 'If this stays empty after you broaden the query'); // or just the sentence, for your own messages throw new Error(`Index is rebuilding. ${feedbackHint('If this keeps failing after the rebuild')}`); ``` ### Custom handler If the user wants their own handler, for example to name the agent from their own per-call context, `captureAgentFeedback` does the filler check, scrubbing and sending: ```ts import { captureAgentFeedback, createFeedbackTool } from '@sentry/mcp'; const tool = createFeedbackTool({ serverName: 'Orders' }); server.registerTool(tool.name, tool.config, input => { const result = captureAgentFeedback(input, { clientName: 'cursor', // shown as "MCP agent (cursor)" userId: 'user-42', // dropped from the name when dataCollection.userInfo is false scrub: msg => msg.replace(/s3:\/\/\S+/g, '[REDACTED]'), // runs after built-in token/email scrubbing }); if (!result.ok) { return { isError: true, content: [{ type: 'text', text: result.error }] }; // filler like "N/A" } return { content: [{ type: 'text', text: 'Feedback sent.' }], structuredContent: { feedbackId: result.feedbackId } }; }); ``` --- The e2e tests call the tool over MCP SDK v1 with zod 3.25 and over v2, and check the feedback envelope it sends and the structured result.
52 tasks done
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.
Initial thinking is we create a name-space for MCP related stuff rather than add confusing API names to all of our server SDKs, so a
@sentry/mcppackage acts as a home for the feedback tool and any other tools we may want to publish in the future.Secondly, it is a JS framework-and-runtime-agnostic tool so it shouldn't belong to any runtime specific SDK and it should also pair with any SDK the user might be using.
Third reason is we may need to have several sub-export adaptors for each MCP framework to make their wiring easier if we have to.
Also allows us to pull in dependencies when we need to, like
zodhere.