Title: SentryGlobalFilter: handle the mcp host type of `@nestjs/mcp` · Issue #26693 · getsentry/sentry-javascript · GitHub
Open Graph Title: SentryGlobalFilter: handle the mcp host type of `@nestjs/mcp` · Issue #26693 · getsentry/sentry-javascript
X Title: SentryGlobalFilter: handle the mcp host type of `@nestjs/mcp` · Issue #26693 · getsentry/sentry-javascript
Description: Problem Statement @nestjs/mcp is the official NestJS module for Model Context Protocol servers. It runs every tool method through Nest's enhancers with the execution context type 'mcp', and its docs say that global filters run on those c...
Open Graph Description: Problem Statement @nestjs/mcp is the official NestJS module for Model Context Protocol servers. It runs every tool method through Nest's enhancers with the execution context type 'mcp', and its doc...
X Description: Problem Statement @nestjs/mcp is the official NestJS module for Model Context Protocol servers. It runs every tool method through Nest's enhancers with the execution context type 'mcp',...
Opengraph URL: https://github.com/getsentry/sentry-javascript/issues/26693
X: @github
Domain: github.com
IPv4 address: 140.82.114.4
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"SentryGlobalFilter: handle the mcp host type of `@nestjs/mcp`","articleBody":"### Problem Statement\n\n`@nestjs/mcp` is the official NestJS module for Model Context Protocol servers. It runs every tool method through Nest's enhancers with the execution context type `'mcp'`, and its docs say that global filters run on those calls too (https://docs.nestjs.com/mcp/primitives):\n\n> Global guards, interceptors and filters (`app.useGlobalGuards()`, `APP_GUARD`) run on MCP calls too, as they do on GraphQL resolvers, and on the HTTP request that carries them. An enhancer written for HTTP routes that reads `context.switchToHttp().getRequest()` should check `context.getType() === 'http'` first.\n\n`SentryGlobalFilter.catch` has branches for `graphql`, `rpc` and `ws`. Every other host type falls through to the HTTP path: it captures the exception and calls `super.catch(exception, host)`, and `BaseExceptionFilter` then replies through the HTTP adapter.\n\nMeasured with `{ provide: APP_FILTER, useClass: SentryGlobalFilter }`, the Fastify adapter and a tool that throws an `Error` (`@sentry/nestjs` 11.10.0, `@nestjs/core` 12.3.3, `@nestjs/platform-fastify` 12.3.3, `@nestjs/mcp` 0.0.3, Node 24; the same code is on `develop`, `packages/nestjs/src/setup.ts`):\n\n- The event is captured once, with the mechanism `auto.http.nestjs.global_filter`.\n- `BaseExceptionFilter` hands the call's context object to the HTTP adapter: `isHeadersSent` returns `undefined`, and `reply` throws `TypeError: this.raw.getHeader is not a function`.\n- That `TypeError` leaves the filter, and it is what `@nestjs/mcp` answers with `Internal server error`. The client sees the right text, because `@nestjs/mcp` gives that answer to any error that is not an `HttpException`.\n- Nest's own handler never logs the original error under `ExceptionsHandler`.\n\nSo nothing is lost today, but the result rests on the adapter failing on an object that is no response.\n\n### Solution Brainstorm\n\nA branch for `mcp` that does what the `graphql` branch does: rethrow an `HttpException` untouched, otherwise capture with a mechanism of its own (`auto.mcp.nestjs.global_filter`, say) and rethrow, without touching the HTTP adapter. `@nestjs/mcp` turns the rethrown error into the tool error.\n\n### Additional Context\n\nWorkaround in use, registered in place of `SentryGlobalFilter`. A filter that returns nothing counts as not handled on an MCP call (`ExternalExceptionsHandler` in `@nestjs/core`): Nest logs the error and rethrows it.\n\n```ts\n@Catch()\nexport class SentryMcpFilter extends SentryGlobalFilter {\n public override catch(exception: unknown, host: ArgumentsHost): void {\n if (host.getType\u003cstring>() === \"mcp\") {\n captureException(exception, { mechanism: { handled: false } });\n return;\n }\n\n super.catch(exception, host);\n }\n}\n```\n\nWith it the adapter is not called, the error is captured once, logged once under `ExceptionsHandler`, and answered with `Internal server error`.\n\nReproduction:\n\n```ts\n@Injectable()\nclass ProbeTools {\n @Tool({ name: \"throws_error\", description: \"Throws\" })\n throwsError(): never {\n throw new Error(\"boom\");\n }\n}\n\n@Module({\n imports: [\n SentryModule.forRoot(),\n McpModule.forRoot({ name: \"probe\", version: \"0.0.0\" }),\n ],\n providers: [\n { provide: APP_FILTER, useClass: SentryGlobalFilter },\n ProbeTools,\n ],\n})\nclass AppModule {}\n\nconst app = await NestFactory.create(AppModule, new FastifyAdapter());\nconst client = await connectMcpClient(app); // from '@nestjs/mcp/testing'\nawait client.callTool({ name: \"throws_error\" });\n```\n\n\n### Priority\n\n\u003csub>React with 👍 to help prioritize this issue. Please use comments to provide useful context, avoiding `+1` or `me too`, to help us triage it.\u003c/sub>","author":{"url":"https://github.com/reichhartd","@type":"Person","name":"reichhartd"},"datePublished":"2026-11-20T10:12:42Z","url":"https://github.com/getsentry/sentry-javascript/issues/26693"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:1c977f2f-0c88-445c-c0d8-c3ddf234a82f |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B480:2F8368:3C57BB:518205:6B043FB1 |
| html-safe-nonce | 300394ea6b2faa7ddc5be46acb22dc2c250fdd209cbb0419301a656a6e2d317d |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCNDgwOjJGODM2ODozQzU3QkI6NTE4MjA1OjZCMDQzRkIxIiwidmlzaXRvcl9pZCI6IjQyNjE5MjM5OTI2NzM0NjgzMzciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | fd6000fce0a48c8d2961b49e9a5d366a165b0b8c6d2c72f1eb8512546678c7db |
| hovercard-subject-tag | issue:6509351538 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/getsentry/sentry-javascript/26693/issue_layout |
| twitter:image | https://opengraph.githubassets.com/599faaf01b1b420f99ad4968c138626f113f7c6f957786079938cabb5a5f4cfd/getsentry/sentry-javascript/issues/26693 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/599faaf01b1b420f99ad4968c138626f113f7c6f957786079938cabb5a5f4cfd/getsentry/sentry-javascript/issues/26693 |
| og:image:alt | Problem Statement @nestjs/mcp is the official NestJS module for Model Context Protocol servers. It runs every tool method through Nest's enhancers with the execution context type 'mcp', and its doc... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | reichhartd |
| hostname | github.com |
| expected-hostname | github.com |
| None | 9185ccfefd80c1ff2d9ddcdb0cd2becf46b5a1efbbf30741a895e4bb8de25e64 |
| turbo-cache-control | no-preview |
| go-import | github.com/getsentry/sentry-javascript git https://github.com/getsentry/sentry-javascript.git |
| octolytics-dimension-user_id | 1396951 |
| octolytics-dimension-user_login | getsentry |
| octolytics-dimension-repository_id | 3328572 |
| octolytics-dimension-repository_nwo | getsentry/sentry-javascript |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 3328572 |
| octolytics-dimension-repository_network_root_nwo | getsentry/sentry-javascript |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 06dc448a76fe4751ac1db26524aefa3aa3e889a8 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width