Repository navigation
feat(mcp): Add a feedback tool for MCP servers - #26996
Conversation
size-limit report 📦Compared: d1b7e00 (PR test merge using base PR #26995 at beb309c) Against: beb309c (base PR #26995) · base run #68481 ✅ Baseline matches: this diff contains only this PR's changes.
|
Optional E2E testsSome optional checks were not successful. They do not block the merge. 1 not successful, 64 successful. See the run.
Successful checks
|
30d2501 to
d890f0e
Compare
506f5cb to
8f3517e
Compare
There was a problem hiding this comment.
The README says this works with @modelcontextprotocol/sdk v1, and the core MCP integration supports ^1.9.0. But feedbackInputSchema and feedbackOutputSchema in feedback.ts are built with zod/v4, and v1 only accepts zod v4 shapes from 1.23.0 on. Before 1.23.0 the SDK depends on zod ^3.23.8 and wraps the shape with v3's z.object.
I checked this with @modelcontextprotocol/sdk@1.22.0 and zod@3.25.76, registering a tool with a zod/v4 raw shape the same way addFeedbackTool does:
tools/listshows{"type":"object","properties":{}}, so the agent sees no fields.- Every
tools/callreturnsisErrorwithkeyValidator._parse is not a function.
On those servers addFeedbackTool registers a tool that can never succeed. The error hints then tell agents to call it after every hinted failure. That's worse than having no tool, because each stuck agent spends an extra failed call and the report is lost.
The e2e apps use ^1.26.0 and 1.32.1, so CI doesn't hit this. Before this lands, I'd state the floor (>=1.23.0 for v1) in the README, and either declare it as an optional peer or skip registration and hints with a debug.warn when the server's SDK is older.
|
I changed the readme to state that |
The SDK floor is now documented; superseded by a follow-up review.
There was a problem hiding this comment.
The README floor covers my earlier zod v4 concern, so I dismissed that review.
One small gap at the new floor: on @modelcontextprotocol/sdk 1.23.0 and 1.23.1, a registered tool stores its function as callback. The rename to handler came in 1.24.0. wrapRegisteredTool in errorHints.ts only looks for executor or handler, so on 1.23.x it returns early and no error hints get added. The feedback tool itself still works. Either also check callback there, or raise the documented floor to 1.24.0.
The Size Check failure isn't from this PR. It couldn't find base results for the stacked base branch.
isaacs
left a comment
There was a problem hiding this comment.
The design is sound. Moving to @sentry/mcp with an optional range peer on @sentry/core solves the real problem (a second copy of @sentry/core would have its own carrier, getClient() would return nothing, and the tool would always say feedback isn't available). I checked that the core APIs this package uses (getCombinedScopeData, isObjectLike, Client.getDataCollectionOptions, captureFeedback with tags) all exist in 11.0.0, so "works with any 11.x SDK" holds. Changing the thrown error's message and restoring it for Sentry in a global event processor is a little unusual, but it is needed because both MCP SDKs build the error result from error.message alone. The e2e tests check that Sentry keeps the original message.
captureAgentFeedback reporting success without a client should be fixed before landing. The OpenAI key pattern is a small change that should go in with it. The bump-version gap at the next major can be a follow-up issue, as long as someone files it now.
The earlier Warden comment about shouldHintFeedback rejecting all -32768..-32000 codes is outdated. Commit cc49af0cbc narrowed it to the client error codes, the same list as isJsonRpcServerError in core.
Optional, no action needed:
packages/mcp/src/addFeedbackTool.tslines 13-18 and 59: theserver.tool(...)fallback only runs on servers withoutregisterTool, and those are all v1 versions older than the stated 1.23.0 floor. Removing it drops a branch and the second method inMcpServerLike. Thetoolwrapping inpackages/mcp/src/errorHints.tsline 90 should stay, because 1.23+ servers can still register other tools with the deprecatedtool().feedbackHintandwithFeedbackHintuse the tool from the lastaddFeedbackToolorcreateFeedbackToolcall in the process. That is fine for one server config per process, and the JSDoc says so.restoreOriginalMessage(packages/mcp/src/errorHints.tslines 175-189) only restores an exception value that equals the hinted message exactly. If a later step truncates the value first (for examplemaxValueLength), the hinted message stays in Sentry. This is a rare case, not worth changing now.
… that already have a hint
…or result The filter only ever receives a thrown Error or a result with isError: true, so type it that way and export ToolErrorResult. Callbacks can now narrow with instanceof or read content without casts. Examples use CustomError so they don't suggest schema validation errors, which the MCP SDK handles before the tool runs.
…ckTool return value It uses the tool from the last addFeedbackTool call, so tools defined away from the server setup don't need the returned withHint threaded to them.
withFeedbackHint covers the same case without threading the return value, so addFeedbackTool returns nothing and there is one way to add the hint.
…Tool call feedbackHint now takes its tool name and recipient from addFeedbackTool like withFeedbackHint does, so a thrown error only needs a condition. The state moves to feedback.ts so both helpers share it.
Matches withFeedbackHint(result, condition), and the common call only needs the condition. toolName, recipient and available move to the second argument.
feedbackHint takes a condition with optional options, or a single options object that can hold the condition, so options never need an undefined first argument.
…mselves createFeedbackTool returns the tool's name, config and handler, and makes them the defaults for feedbackHint and withFeedbackHint, so a server with its own catalog keeps the right hint without calling addFeedbackTool. addFeedbackTool is built on it. feedbackInputSchema and getFeedbackToolDescription are no longer exported, since tool.config covers them.
addFeedbackTool and createFeedbackTool now record the tool name and server, so feedbackHint no longer needs toolName, recipient or available. The error hints keep naming their own server through an internal formatter.
feedbackHint fell back to submit_feedback before any tool existed, which could point agents at a tool the server doesn't have. It now matches withFeedbackHint.
createFeedbackTool already takes the server to name the agent, so it now also adds the error hints, with the same errorHints option as addFeedbackTool. addFeedbackTool checks that it can register the tool, then builds on it.
The feedback tool now declares an outputSchema and returns
structuredContent: { feedbackId } next to the text, so servers that require an
outputSchema on every tool can register tool.handler as is.
…active span The feedback handler now reads the client name from the per-request envelope MCP SDK v2 passes, then the server's handshake, then the mcp.client.name attribute on the active span, so catalogs without the server can still name the agent. Adds @sentry/conventions for the attribute name, which every Sentry SDK already installs.
The hint now says "report it to the Orders team", matching sentry-mcp's wording. Also fixes comments that still said only addFeedbackTool sets the tool, and drops a duplicated default.
Before 1.23.0, the v1 SDK wraps tool schemas with zod v3, so it can't read the feedback tool's zod v4 schema and every call fails.
Before 1.24.0, the v1 SDK keeps a registered tool's function under callback instead of handler, so the wrapper skipped those tools and no hints were added.
update({ callback }) puts a new function under the key we wrapped (v2 rebuilds
executor), which dropped the hint. Wrap update so the new function is wrapped
too, and follow renames for the errorHints filter.
…client, scrub current API keys Without a client, captureFeedback drops the event but still returns an ID, so custom handlers told the agent its report was sent. The check now lives in captureAgentFeedback instead of only the built-in handler. The key pattern only matched legacy 48-character OpenAI keys. It now also catches sk-proj-, sk-svcacct- and sk-ant- keys, since feedback events skip beforeSend.
Only v1 servers older than the 1.23.0 floor lack registerTool. Error hints still wrap tool(), since newer servers can register other tools with it.
…ersion Range peers like @sentry/mcp's on @sentry/core stay put within a major, but a major release would have shipped them still pinned to the old one. Move them to ^<major>.0.0 (^<major>.0.0-0 for prereleases), and fail before writing anything for a range form the script can't move.
…dler fits The fake typed the handler as taking no arguments, which the real handler, with its required input, isn't assignable to.
c2e1af5 to
7ad8373
Compare
The new `@sentry/mcp` agent feedback tool from [getsentry/sentry-javascript#26996](getsentry/sentry-javascript#26996) has no docs yet, so this adds an Agent Feedback page under JavaScript MCP Monitoring.
Follow up to #133046. Feedback is the product now and the browser widget is one way to send it. With [MCP agent feedback](getsentry/sentry-javascript#26996) landing in the same inbox, "the Feedback integration" no longer clearly means the widget. Setup docs, the loader script toggle, and the crash report notification hint now say "User Feedback Widget" wherever they're talking about the widget. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
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
addFeedbackToolandcreateFeedbackToolto cater for both simple setups and more dynamic ones like ours in sentry mcp server.Two ways to set it up for now:
Or, for servers that register tools through their own catalog, create the tool and register it like any other:
The tool returns the feedback ID as
structuredContentwith a matchingoutputSchema, next to the text.Error Hints
Failing tools get this sentence appended to their error:
With
serverName: 'Orders'the recipient becomes "the Orders team", and the tool name followsname. Successful results are never modified, error results get the hint as an extra text block sostructuredContentis never touched, and errors that already mention the feedback tool don't get a second hint.Only these errors receive the hint:
{ status: 429 },{ statusCode: 404 },{ response: { status: 403 } }McpErrorwith code-32602{ status: 502 }, a plainError,ECONNREFUSED(stringcode), anisErrorresultThe user can also customize which errors get hinted with
errorHintsoption: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
serverNameof the tooladdFeedbackToolorcreateFeedbackToolmade, and add nothing until that tool exists and Sentry has a client:Custom handler
If the user wants their own handler, for example to name the agent from their own per-call context,
captureAgentFeedbackdoes the filler check, scrubbing and sending: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.