Skip to content

fix(mcp): Add the feedback hint to the error result instead of the thrown error - #27132

Open
logaretm wants to merge 3 commits into
developfrom
awad/js-4221-addfeedbacktool-turns-an-aborted-fetch-into-cannot-set-property
Open

logaretm wants to merge 3 commits into
developfrom
awad/js-4221-addfeedbacktool-turns-an-aborted-fetch-into-cannot-set-property

Conversation

@logaretm

@logaretm logaretm commented Dec 3, 2026 •

Copy link
Copy Markdown
Member

This PR changes how addFeedbackTool adds its hint to failed calls. Previously we caught failed handlers and re-wrote their message to include the hint and then re-thrown it.

// Before: rewrite the error so the SDK's result carries the hint
catch (error) {
  error.message = `${error.message}\n\n${hint}`; // throws if it cannot be set
  throw error;
}
// The client got:
// { isError: true, content: [{ type: 'text', text: 'Upstream returned 500\n\nIf this keeps failing…' }] }

This caused issues like #27128 where some error types' messages cannot be safely overwritten. The issue suggested a skip which defeats the purpose of what we are doing imo.

One thing we were doing is we also annotated structured error responses, so we could re-use that to do the same for thrown handlers. Meaning we don't have to override any messages, and we don't need to clean our hints from the captured errors sent to Sentry.

Returned error results now get the hint in the same place, after the SDK builds the result. Adding it first made SDK v2 skip the text it writes for non-object structuredContent.

// After: rethrow untouched, then hint the result the SDK built from it
catch (error) {
  callOutcomes.set(extra.signal, { name, thrown: error });
  throw error;
}
// The client gets:
// { isError: true, content: [
//   { type: 'text', text: 'Upstream returned 500' },
//   { type: 'text', text: 'If this keeps failing…' },
// ] }

closes #27128

…ssage is read-only

An aborted `fetch` throws a `DOMException`, whose `message` has only a getter, so adding the hint threw a `TypeError` that replaced the tool's error. The hint is now set as an own property, and values that can't take one (strings, plain objects, frozen errors) are rethrown as a new error with the hint.
@linear-code

linear-code Bot commented Dec 3, 2026

Copy link
Copy Markdown

JS-4221

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

size-limit report 📦

Compared: 9e0980e (PR test merge using develop at 2007cec)

Against: 2007cec (develop) · base run #68738

✅ Baseline matches: this diff contains only this PR's changes.

Path Size % Change Change
@sentry/browser 30.73 kB - -
@sentry/browser - with treeshaking flags 28.85 kB - -
@sentry/browser - with treeshaking flags tracing without tracing 28.7 kB - -
@sentry/browser (incl. Tracing) 54.07 kB - -
@sentry/browser (incl. Tracing Core) 40.89 kB - -
@sentry/browser (incl. Tracing + Span Streaming) 54.08 kB - -
@sentry/browser (incl. Tracing, Profiling) 56.97 kB - -
@sentry/browser (incl. Tracing, Replay) 94.06 kB - -
@sentry/browser (incl. Tracing, Replay) - with treeshaking flags 82.59 kB - -
@sentry/browser (incl. Tracing, Replay with Canvas) 98.9 kB - -
@sentry/browser (incl. Tracing, Replay, Feedback) 111.85 kB - -
@sentry/browser (incl. Feedback) 48.59 kB - -
@sentry/browser (incl. sendFeedback) 31.29 kB - -
@sentry/browser (incl. FeedbackAsync) 36.34 kB - -
@sentry/browser (incl. Metrics) 32.04 kB - -
@sentry/browser (incl. Logs) 32.32 kB - -
@sentry/browser (incl. Metrics & Logs) 33 kB - -
@sentry/react 32.61 kB - -
@sentry/react (incl. Tracing) 56.57 kB - -
@sentry/vue 39.07 kB - -
@sentry/vue (incl. Tracing) 57.19 kB - -
@sentry/svelte 30.77 kB - -
@sentry/effect (client) 42.29 kB - -
@sentry/effect (client, incl. Tracing) 55.1 kB - -
@sentry/effect (client, incl. Tracing, Logs, Metrics) 66.59 kB - -
@sentry/remix (Remix 3 client bundle) 59.55 kB - -
CDN Bundle 32.54 kB - -
CDN Bundle (incl. Tracing) 54.17 kB - -
CDN Bundle (incl. Logs, Metrics) 35.25 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) 56.63 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) 76.2 kB - -
CDN Bundle (incl. Tracing, Replay) 91.98 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) 94.49 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) 97.44 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) 99.89 kB - -
CDN Bundle - uncompressed 94.94 kB - -
CDN Bundle (incl. Tracing) - uncompressed 160.29 kB - -
CDN Bundle (incl. Logs, Metrics) - uncompressed 103.28 kB - -
CDN Bundle (incl. Tracing, Logs, Metrics) - uncompressed 167.92 kB - -
CDN Bundle (incl. Replay, Logs, Metrics) - uncompressed 233.67 kB - -
CDN Bundle (incl. Tracing, Replay) - uncompressed 280.72 kB - -
CDN Bundle (incl. Tracing, Replay, Logs, Metrics) - uncompressed 288.35 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback) - uncompressed 292.65 kB - -
CDN Bundle (incl. Tracing, Replay, Feedback, Logs, Metrics) - uncompressed 300.27 kB - -
@sentry/nextjs (client) 59.93 kB - -
@sentry/sveltekit (client) 54.89 kB - -
@sentry/astro (client) - rolldown, without tracing 35.83 kB - -
@sentry/core/server 45.96 kB - -
@sentry/core/browser 14.55 kB - -
@sentry/node 157.76 kB - -
@sentry/node/import (ESM hook with diagnostics-channel injection) 83.63 kB - -
@sentry/node - without tracing 89.75 kB -0.01% -1 B 🔽
@sentry/node - without channel injection 147.11 kB - -
@sentry/aws-serverless 100.65 kB -0.01% -1 B 🔽
@sentry/cloudflare (withSentry) - minified 213.32 kB - -
@sentry/cloudflare (withSentry) 495.18 kB - -
@sentry/cloudflare (withSentry, instrumented CommonJS package) - minified 216.26 kB - -
@sentry/nextjs/cloudflare (withSentry) - minified 241.52 kB - -

View base workflow run

@github-actions

github-actions Bot commented Dec 3, 2026 •

Copy link
Copy Markdown
Contributor

Optional E2E tests

Some optional checks were not successful. They do not block the merge. 1 not successful, 2 successful. See the run.

Check Status
❌ CI: Optional E2E Tests / E2E node-express-mcp-v2 (MCP SDK OpenTelemetry) Test (optional) Failing after 55s Details
Successful checks
Check Status
✅ CI: Optional E2E Tests / E2E node-express-mcp-v1 Test (optional) Successful in 1m Details
✅ CI: Optional E2E Tests / E2E node-express-mcp-v2 Test (optional) Successful in 1m Details

…the thrown error

The hint now goes into the error result the MCP SDK builds from a thrown error, by wrapping its `tools/call` request handler, so the error itself is never modified. This also hints when the SDK rejects a tool's output against its `outputSchema`.
@logaretm logaretm changed the title fix(mcp): Keep the tool error and its feedback hint when the error message is read-only fix(mcp): Add the feedback hint to the error result instead of the thrown error Dec 3, 2026
@logaretm
logaretm marked this pull request as ready for review December 3, 2026 15:36
@logaretm
logaretm requested a review from nicohrubec December 3, 2026 15:51
@logaretm
logaretm added this pull request to stack #27136 December 3, 2026 15:51
@logaretm
logaretm force-pushed the awad/js-4221-addfeedbacktool-turns-an-aborted-fetch-into-cannot-set-property branch 2 times, most recently from e68c711 to 11dcb1e Compare December 3, 2026 16:17
Returned error results now get the hint in the same place as thrown errors and rejected output, after the SDK's own changes to the result. Before, the hint was added first, so MCP SDK v2 skipped the text it writes for non-object structuredContent and the error details never reached the client. The tool callback now only records what happened.
@logaretm
logaretm force-pushed the awad/js-4221-addfeedbacktool-turns-an-aborted-fetch-into-cannot-set-property branch from 11dcb1e to a8e8d9b Compare December 3, 2026 16:39
@logaretm
logaretm requested a review from timfish December 3, 2026 17:12

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

addFeedbackTool turns an aborted fetch into "Cannot set property message of which has only a getter"

2 participants