You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "eschutho (via GitHub)" <gi...@apache.org> on 2026/10/08 15:26:24 UTC
[PR] fix(mcp): don't page MCP_ERROR_HOOK for user-class errors in the last-resort catch (SC-125493) [superset]
eschutho opened a new pull request, #45093:
URL: https://github.com/apache/superset/pull/45093
### SUMMARY
`ToolResultCompatibilityMiddleware.on_call_tool` has a last-resort `except Exception` that turns any escaping exception into `ToolResult(is_error=True)`. For any non-`ToolError` exception it also called `MCP_ERROR_HOOK`, **without checking whether the error was user-class**. `GlobalErrorHandlerMiddleware._handle_error` deliberately keeps user-class errors (bad arguments, permission denials, missing objects) out of the hook, because they are normal MCP traffic and would flood an error tracker.
**Root cause.** FastMCP treats the first middleware added as the outermost. In the default stack in `superset/mcp_service/server.py`, the compat middleware is outermost, so `GlobalErrorHandlerMiddleware` sees every error first, classifies it and re-raises it as `ToolError`, which the last-resort catch skips. A deployment can instead add the compat middleware (or its deprecated `StructuredContentStripperMiddleware` subclass) *after* `GlobalErrorHandlerMiddleware`, which puts it inside that handler. In that order, a raw FastMCP/pydantic argument `ValidationError` (for example, a tool with a required `request` param called with `{}`) reaches the last-resort catch first. The hook fires there with the `validation_message()` text, e.g. `Validation error in get_dataset_info: request: Field required`, and the outer handler never sees the exception. Every malformed agent call then becomes an error-level event in the error tracker.
**Fix.** Apply the same classification in the last-resort catch that `GlobalErrorHandlerMiddleware` already uses. The hook now fires only for system-class errors: `_is_user_error`, refined by `_datasource_error_is_user_error`, so a missing table is not paged but an unreachable database is. A small helper, `_is_user_error_for_reporting`, is shared by both call sites so the decision can't drift between them. `GlobalErrorHandlerMiddleware` keeps its existing behavior through the helper. The client-facing `ToolResult(is_error=True)` and its text are unchanged.
#### Tradeoffs
This changes what gets reported when an error reaches the last-resort catch. User-class errors that reach it (`ValidationError`, FastMCP `ValidationError`, `ValueError`, `PermissionError`, `ObjectNotFoundError`, sub-500 `SupersetException`s, datasource "missing object" errors, ...) **no longer fire `MCP_ERROR_HOOK`**, so they no longer reach Sentry or any other tracker. Before this change they were paged. They are still returned to the client as `is_error` results. System-class errors are unchanged: they still invoke the hook from this catch with the same context dict (`user_id`/`duration_ms` still `None`). `ToolError` is still never hooked here.
#### Follow-ups
- Some deployments register the compat middleware innermost, unlike `server.py` where it is outermost. This PR intentionally leaves that ordering alone. The middleware strips `outputSchema`/`structuredContent`, and moving it is a separate decision for those deployments. With this fix, both orderings report the same way.
### BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
N/A (backend only). Repro: a FastMCP server with `GlobalErrorHandlerMiddleware` added first and `StructuredContentStripperMiddleware` added last, and a tool `get_dataset_info(request: Req)` called with `{}`:
| | is_error | client text | `MCP_ERROR_HOOK` calls |
|---|---|---|---|
| before, compat innermost | True | `Error: Validation error in get_dataset_info: request: Field required` | **1** (fastmcp `ValidationError`, `duration_ms=None`) |
| after, compat innermost | True | same | **0** |
| after, `server.py` order (compat outermost) | True | same | 0 (as before) |
### TESTING INSTRUCTIONS
```
pytest tests/unit_tests/mcp_service/test_middleware.py \
tests/unit_tests/mcp_service/test_error_classification.py \
tests/unit_tests/mcp_service/test_worker_metadata_pool.py
```
New tests in `TestToolResultCompatibilityErrorHook`:
- `test_does_not_invoke_hook_for_user_error`, parametrized over pydantic `ValidationError`, FastMCP `ValidationError`, `ValueError`, `PermissionError` and a missing-table `SupersetErrorException`. Each one: hook not called, `is_error=True`, and the text is identical to what the catch produced before.
- `test_invokes_hook_for_datasource_connection_failure`: an unreachable database is still paged.
- `test_invalid_arguments_do_not_page_when_registered_inside_handler`: end to end through a real FastMCP `Client`, with the compat middleware added after `GlobalErrorHandlerMiddleware`.
- The existing `test_invokes_hook_for_exception_bypassing_error_handler` (`RuntimeError`) still checks that system errors invoke the hook with the full context contract.
Results:
- The 6 new user-error/end-to-end cases fail without the fix and pass with it. All 11 tests in the class pass.
- The three files above: 230 passed.
- Full `tests/unit_tests/mcp_service/` locally: 7450 passed. The only failures are 36 in `dataset/tool/test_query_dataset.py`, which fail identically on unmodified master because the local `freezegun` is too old for `real_asyncio`.
- `pre-commit run` on the changed files passes: ruff 0.9.7, ruff-format, mypy, pylint, auto-walrus.
### ADDITIONAL INFORMATION
- [ ] Has associated issue:
- [ ] Required feature flags:
- [ ] Changes UI
- [ ] Includes DB Migration (follow approval process in [SIP-59](https://github.com/apache/superset/issues/13351))
- [ ] Migration is atomic, supports rollback & is backwards-compatible
- [ ] Confirm DB migration upgrade and downgrade tested
- [ ] Runtime estimates and downtime expectations provided
- [ ] Introduces new feature or API
- [ ] Removes existing feature or API
🤖 Generated with [Claude Code](https://claude.com/claude-code)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): don't page MCP_ERROR_HOOK for user-class errors in the last-resort catch (SC-125493) [superset]
Posted by "eschutho (via GitHub)" <gi...@apache.org>.
eschutho merged PR #45093:
URL: https://github.com/apache/superset/pull/45093
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): don't page MCP_ERROR_HOOK for user-class errors in the last-resort catch (SC-125493) [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #45093:
URL: https://github.com/apache/superset/pull/45093#issuecomment-6063811838
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/45093?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:white_check_mark: All modified and coverable lines are covered by tests.
:white_check_mark: Project coverage is 79.34%. Comparing base ([`d27b734`](https://app.codecov.io/gh/apache/superset/commit/d27b73440872e5d3d3bfe0aed8b5d47bd7dec64a?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`1442234`](https://app.codecov.io/gh/apache/superset/commit/14422343952ccf3596c051fa10530b472e8808d5?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #45093 +/- ##
==========================================
- Coverage 82.63% 79.34% -3.30%
==========================================
Files 3006 3006
Lines 187212 187217 +5
Branches 43386 43386
==========================================
- Hits 154704 148538 -6166
- Misses 29742 35756 +6014
- Partials 2766 2923 +157
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/45093/flags?src=pr&el=flags&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Coverage Δ | |
|---|---|---|
| [hive](https://app.codecov.io/gh/apache/superset/pull/45093/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `36.16% <0.00%> (-0.01%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/45093/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [postgres](https://app.codecov.io/gh/apache/superset/pull/45093/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [presto](https://app.codecov.io/gh/apache/superset/pull/45093/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `38.01% <0.00%> (-0.01%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/45093/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `80.19% <100.00%> (-6.25%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/45093/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
| [unit](https://app.codecov.io/gh/apache/superset/pull/45093/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `79.58% <100.00%> (+<0.01%)` | :arrow_up: |
Flags with carried forward coverage won't be shown. [Click here](https://docs.codecov.io/docs/carryforward-flags?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#carryforward-flags-in-the-pull-request-comment) to find out more.
</details>
[:umbrella: View full report in Codecov by Harness](https://app.codecov.io/gh/apache/superset/pull/45093?dropdown=coverage&src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache).
<details><summary> :rocket: New features to boost your workflow: </summary>
- :snowflake: [Test Analytics](https://docs.codecov.com/docs/test-analytics): Detect flaky tests, report on failures, and find test suite problems.
- :package: [JS Bundle Analysis](https://docs.codecov.com/docs/javascript-bundle-analysis): Save yourself from yourself by tracking and limiting bundle sizes in JS merges.
</details>
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org
Re: [PR] fix(mcp): don't page MCP_ERROR_HOOK for user-class errors in the last-resort catch (SC-125493) [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on PR #45093:
URL: https://github.com/apache/superset/pull/45093#issuecomment-6063408415
## CodeAnt PR Risk: Low Risk
- The PR appears safe to merge; it applies consistent error classification at both reporting paths and tests user-error suppression, system-error reporting, and classification failures.
**Assessed commit:** `14422343952c`
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org