You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "aminghadersohi (via GitHub)" <gi...@apache.org> on 2026/09/17 11:00:17 UTC
[PR] fix(mcp): return a specific error per failure class on tool calls [superset]
aminghadersohi opened a new pull request, #44387:
URL: https://github.com/apache/superset/pull/44387
### SUMMARY
MCP clients cannot act on a failed tool call today, because three unrelated failures reach the caller as one undifferentiated message.
**Where it comes from.** FastMCP catches every non-`FastMCPError` raised inside a tool body and re-raises it as `ToolError(f"Error calling tool {name!r}: {e}") from e` *before* any middleware error hook runs (`FastMCP._call_tool`). `GlobalErrorHandlerMiddleware._handle_error` then matches its very first branch:
```python
if isinstance(error, ToolError):
# Tool errors are already formatted for MCP
raise error
```
…and re-raises. Its entire per-type branch chain below that line — `MCPPermissionDeniedError`, `PermissionError`, `SupersetSecurityException`, `OperationalError`, `SupersetException`, the internal-error fallback — is therefore **unreachable for anything a tool raises**. The caller gets whatever `str(exc)` happened to say, prefixed by FastMCP's generic wrapper.
Argument errors are the one class that still worked: FastMCP raises those from its argument parser *outside* the tool body, so they were the only failures reaching the branch chain.
This also went unnoticed in tests because every existing case injects a **raw** exception into `on_message`, exercising the branch chain directly — no test drove a tool exception through FastMCP's wrapping first.
Two consequences beyond the message text:
- `_is_user_error()` was evaluated on the `ToolError` wrapper, which is in `_USER_ERROR_TYPES`. Every tool failure — including genuine 500-class defects — was logged at `WARNING` without `exc_info`, and `MCP_ERROR_HOOK` was never invoked for them, so operators lost system-error capture.
- The client-facing text never passed through `_sanitize_error_for_logging`, so raw driver output and server paths reached the caller verbatim.
**The fix** is in the shared handler, not in individual tools: classify on the unwrapped `__cause__`. `LoggingMiddleware` already did exactly this for its own metrics, so this extracts that into `_unwrap_tool_error()` and uses it in both places. A `ToolError` raised deliberately by tool code is re-raised by FastMCP untouched and carries no `__cause__`, so it still passes through unchanged.
One new branch is added for **datasource/query failures**, which previously had nowhere sensible to land and fell through to "Internal error" — wording that implies a service defect rather than a dropped table. Only the enumerated `SupersetErrorType` is echoed; raw driver output is not.
### BEFORE/AFTER
Driving the real middleware stack with an in-process FastMCP client:
| Failure | Before | After |
| --- | --- | --- |
| RBAC denial | `Error calling tool 'list_users': Permission denied: can_get on User…` (clean only because `str()` happened to be) | `Permission denied: can_get on User for user <u> (tool: list_users)` |
| Non-RBAC authz denial | `Error calling tool 'x': nope` | `Permission denied for x: You don't have access to this resource.` |
| Dropped table | `Error calling tool 'get_chart_data': relation "orders" does not exist (postgresql://admin:hunter2@db.internal/prod)` | `Datasource error in get_chart_data: the query against the underlying datasource failed (TABLE_DOES_NOT_EXIST_ERROR). The tool name and arguments were valid — the datasource, table, or column it reads may be missing, renamed, or unreachable.` |
| Wrong argument name | `Validation error in needs_id: id: Missing required argument; identifier: Unexpected keyword argument` | unchanged — this advice fits this class |
| Internal defect | `Error calling tool 'x': unexpected failure in /srv/app/superset/…` | `Internal error in x: An unexpected error occurred. Error ID: <id>.` |
Note rows 3 and 5: a connection string and a server path previously reached the caller verbatim. Both are now withheld — this narrows disclosure, it does not widen it. Permission denials continue to name the permission and the resource, exactly as before.
### TESTING INSTRUCTIONS
```bash
pytest tests/unit_tests/mcp_service/test_error_classification.py
pytest tests/unit_tests/mcp_service/
```
`tests/unit_tests/mcp_service/test_error_classification.py` drives each failure class end to end through a real `Client(mcp)` and the production middleware, so it fails if FastMCP's wrapping is reintroduced into the classification path. It asserts that:
- the RBAC case matches the `Permission denied: <permission> on <resource>` shape and carries no schema guidance;
- the argument-error case keeps its validation guidance naming the offending fields;
- the datasource case blames the query and states the call was valid;
- the four classes do not share a message;
- neither the planted connection string nor the planted server path appears in any response.
A guard test pins the FastMCP wrapping behaviour the fix is built on, so a future upgrade that changes it surfaces as a clear failure rather than silent drift.
Manually: call any tool as a user lacking its permission and confirm the denial names the permission and resource; call a tool with a misspelled argument and confirm the validation guidance is unchanged; call `get_chart_data` on a chart whose table has been dropped and confirm it reports a datasource failure.
### 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
--
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): return a specific error per failure class on tool calls [superset]
Posted by "codecov[bot] (via GitHub)" <gi...@apache.org>.
codecov[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5713309897
## [Codecov](https://app.codecov.io/gh/apache/superset/pull/44387?dropdown=coverage&src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) Report
:x: Patch coverage is `0%` with `29 lines` in your changes missing coverage. Please review.
:white_check_mark: Project coverage is 57.38%. Comparing base ([`4c77b0b`](https://app.codecov.io/gh/apache/superset/commit/4c77b0b924a9bd770110915eacd68f5619e8241d?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)) to head ([`c5bb07b`](https://app.codecov.io/gh/apache/superset/commit/c5bb07bd3e239ee73ff749dfd2126b301ff98421?dropdown=coverage&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache)).
| [Files with missing lines](https://app.codecov.io/gh/apache/superset/pull/44387?dropdown=coverage&src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | Patch % | Lines |
|---|---|---|
| [superset/mcp\_service/middleware.py](https://app.codecov.io/gh/apache/superset/pull/44387?src=pr&el=tree&filepath=superset%2Fmcp_service%2Fmiddleware.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache#diff-c3VwZXJzZXQvbWNwX3NlcnZpY2UvbWlkZGxld2FyZS5weQ==) | 0.00% | [29 Missing :warning: ](https://app.codecov.io/gh/apache/superset/pull/44387?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) |
> :exclamation: There is a different number of reports uploaded between BASE (4c77b0b) and HEAD (c5bb07b). Click for more details.
>
> <details><summary>HEAD has 109 uploads less than BASE</summary>
>
>| Flag | BASE (4c77b0b) | HEAD (c5bb07b) |
>|------|------|------|
>|hive|14|1|
>|python|85|2|
>|presto|14|1|
></details>
<details><summary>Additional details and impacted files</summary>
```diff
@@ Coverage Diff @@
## master #44387 +/- ##
===========================================
- Coverage 80.40% 57.38% -23.02%
===========================================
Files 2932 2932
Lines 174525 174551 +26
Branches 40548 40554 +6
===========================================
- Hits 140319 100172 -40147
- Misses 31537 73424 +41887
+ Partials 2669 955 -1714
```
| [Flag](https://app.codecov.io/gh/apache/superset/pull/44387/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/44387/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `37.14% <0.00%> (-0.02%)` | :arrow_down: |
| [mysql](https://app.codecov.io/gh/apache/superset/pull/44387/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/44387/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/44387/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.21% <0.00%> (-0.02%)` | :arrow_down: |
| [python](https://app.codecov.io/gh/apache/superset/pull/44387/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `39.26% <0.00%> (-45.49%)` | :arrow_down: |
| [sqlite](https://app.codecov.io/gh/apache/superset/pull/44387/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/44387/flags?src=pr&el=flag&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=apache) | `?` | |
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/44387?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): return a specific error per failure class on tool calls [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5777973076
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</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): return a specific error per failure class on tool calls [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi merged PR #44387:
URL: https://github.com/apache/superset/pull/44387
--
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): return a specific error per failure class on tool calls [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #44387:
URL: https://github.com/apache/superset/pull/44387#discussion_r4036350280
##########
superset/mcp_service/middleware.py:
##########
@@ -165,6 +177,105 @@ def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
logger.warning("MCP_ERROR_HOOK raised an exception: %s", hook_error)
+def _unwrap_tool_error(error: Exception) -> Exception:
+ """Return the original exception behind FastMCP's ``ToolError`` wrapper.
+
+ FastMCP catches every non-``FastMCPError`` raised inside a tool body and
+ re-raises it as ``ToolError(f"Error calling tool {name!r}: {e}") from e``
+ *before* any middleware error hook runs (see ``FastMCP._call_tool``). By
+ the time :class:`GlobalErrorHandlerMiddleware` sees a tool failure, the
+ concrete type — ``MCPPermissionDeniedError``, ``SupersetException``,
+ ``OperationalError`` — is no longer the exception itself, only its
+ ``__cause__``. Classifying the wrapper instead of the cause collapses
+ every distinct failure into one undifferentiated message.
+
+ A ``ToolError`` raised deliberately by tool code is re-raised by FastMCP
+ untouched and therefore carries no ``__cause__``; it is already formatted
+ for MCP and is returned as-is.
+ """
+ if isinstance(error, ToolError) and error.__cause__ is not None:
+ cause = error.__cause__
+ if isinstance(cause, Exception):
+ return cause
Review Comment:
**Suggestion:** A deliberately raised `ToolError` chained from another exception is mistaken for FastMCP's wrapper, so its tool-authored client message is replaced by cause-based handling.
**Assessment:** 🟠 `Major` · 🔁 `Occurrence: Rarely` · 🏷️ `Api mismatch`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=ee17a1fe0c7b4b3584d74529a2108c03&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=ee17a1fe0c7b4b3584d74529a2108c03&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/mcp_service/middleware.py
**Line:** 196:199
**Comment:**
*Api Mismatch: A deliberately raised `ToolError` chained from another exception is mistaken for FastMCP's wrapper, so its tool-authored client message is replaced by cause-based handling.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44387&comment_hash=c40ffa17d6160e3a199693d71fe0a7b16d0afcb99d872ec1f9807fc91b036a50&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44387&comment_hash=c40ffa17d6160e3a199693d71fe0a7b16d0afcb99d872ec1f9807fc91b036a50&reaction=dislike'>👎</a>
##########
superset/mcp_service/middleware.py:
##########
@@ -165,6 +177,105 @@ def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
logger.warning("MCP_ERROR_HOOK raised an exception: %s", hook_error)
+def _unwrap_tool_error(error: Exception) -> Exception:
+ """Return the original exception behind FastMCP's ``ToolError`` wrapper.
+
+ FastMCP catches every non-``FastMCPError`` raised inside a tool body and
+ re-raises it as ``ToolError(f"Error calling tool {name!r}: {e}") from e``
+ *before* any middleware error hook runs (see ``FastMCP._call_tool``). By
+ the time :class:`GlobalErrorHandlerMiddleware` sees a tool failure, the
+ concrete type — ``MCPPermissionDeniedError``, ``SupersetException``,
+ ``OperationalError`` — is no longer the exception itself, only its
+ ``__cause__``. Classifying the wrapper instead of the cause collapses
+ every distinct failure into one undifferentiated message.
+
+ A ``ToolError`` raised deliberately by tool code is re-raised by FastMCP
+ untouched and therefore carries no ``__cause__``; it is already formatted
+ for MCP and is returned as-is.
+ """
+ if isinstance(error, ToolError) and error.__cause__ is not None:
+ cause = error.__cause__
+ if isinstance(cause, Exception):
+ return cause
+ return error
+
+
+# Exception classes that mean "the query behind this tool failed", not "the
+# caller used the tool wrong". The tool name and arguments were valid; the
+# datasource, table, column, or connection it reads is broken or gone.
+_DATASOURCE_ERROR_EXCEPTIONS = (
+ ColumnNotFoundException,
+ DatabaseNotFound,
+ QueryObjectValidationError,
+ SupersetGenericDBErrorException,
+ SupersetParseError,
+ SupersetTimeoutException,
+ SupersetVizException,
+ SQLAlchemyError,
Review Comment:
**Suggestion:** `SupersetTimeoutException` and `SupersetGenericDBErrorException` have 4xx statuses, so `_is_user_error` logs these datasource failures only as warnings and skips `MCP_ERROR_HOOK` capture.
**Assessment:** 🟠 `Major` · 🔁 `Occurrence: Sometimes` · 🏷️ `Incorrect condition logic`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=a0221704089f49f7b5aa1bc7cdf2ff14&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=a0221704089f49f7b5aa1bc7cdf2ff14&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/mcp_service/middleware.py
**Line:** 210:214
**Comment:**
*Incorrect Condition Logic: `SupersetTimeoutException` and `SupersetGenericDBErrorException` have 4xx statuses, so `_is_user_error` logs these datasource failures only as warnings and skips `MCP_ERROR_HOOK` capture.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44387&comment_hash=01c6408ecb711f66b25f74d2fbb525363a8098647e6a77fcd1aaf0de57ea9e60&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44387&comment_hash=01c6408ecb711f66b25f74d2fbb525363a8098647e6a77fcd1aaf0de57ea9e60&reaction=dislike'>👎</a>
##########
superset/mcp_service/middleware.py:
##########
@@ -165,6 +177,105 @@ def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
logger.warning("MCP_ERROR_HOOK raised an exception: %s", hook_error)
+def _unwrap_tool_error(error: Exception) -> Exception:
+ """Return the original exception behind FastMCP's ``ToolError`` wrapper.
+
+ FastMCP catches every non-``FastMCPError`` raised inside a tool body and
+ re-raises it as ``ToolError(f"Error calling tool {name!r}: {e}") from e``
+ *before* any middleware error hook runs (see ``FastMCP._call_tool``). By
+ the time :class:`GlobalErrorHandlerMiddleware` sees a tool failure, the
+ concrete type — ``MCPPermissionDeniedError``, ``SupersetException``,
+ ``OperationalError`` — is no longer the exception itself, only its
+ ``__cause__``. Classifying the wrapper instead of the cause collapses
+ every distinct failure into one undifferentiated message.
+
+ A ``ToolError`` raised deliberately by tool code is re-raised by FastMCP
+ untouched and therefore carries no ``__cause__``; it is already formatted
+ for MCP and is returned as-is.
+ """
+ if isinstance(error, ToolError) and error.__cause__ is not None:
+ cause = error.__cause__
+ if isinstance(cause, Exception):
+ return cause
+ return error
+
+
+# Exception classes that mean "the query behind this tool failed", not "the
+# caller used the tool wrong". The tool name and arguments were valid; the
+# datasource, table, column, or connection it reads is broken or gone.
+_DATASOURCE_ERROR_EXCEPTIONS = (
+ ColumnNotFoundException,
+ DatabaseNotFound,
+ QueryObjectValidationError,
+ SupersetGenericDBErrorException,
+ SupersetParseError,
+ SupersetTimeoutException,
+ SupersetVizException,
+ SQLAlchemyError,
+)
+
+# ``SupersetError.error_type`` values in the DB-engine, viz, and SQL Lab
+# families. Superset raises a bare ``SupersetErrorException`` for many of
+# these, so the exception class alone is not enough to classify them.
+_DATASOURCE_ERROR_TYPES = frozenset(
+ {
+ SupersetErrorType.COLUMN_DOES_NOT_EXIST_ERROR,
+ SupersetErrorType.CONNECTION_DATABASE_TIMEOUT,
+ SupersetErrorType.CONNECTION_HOST_DOWN_ERROR,
+ SupersetErrorType.CONNECTION_PORT_CLOSED_ERROR,
+ SupersetErrorType.CONNECTION_UNKNOWN_DATABASE_ERROR,
+ SupersetErrorType.DATABASE_NOT_FOUND_ERROR,
+ SupersetErrorType.FAILED_FETCHING_DATASOURCE_INFO_ERROR,
+ SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
+ SupersetErrorType.INVALID_SQL_ERROR,
+ SupersetErrorType.OBJECT_DOES_NOT_EXIST_ERROR,
+ SupersetErrorType.RESULTS_BACKEND_ERROR,
+ SupersetErrorType.SCHEMA_DOES_NOT_EXIST_ERROR,
+ SupersetErrorType.SQLLAB_TIMEOUT_ERROR,
+ SupersetErrorType.SYNTAX_ERROR,
+ SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
+ SupersetErrorType.TABLE_NOT_FOUND_ERROR,
+ SupersetErrorType.UNKNOWN_DATASOURCE_TYPE_ERROR,
+ SupersetErrorType.VIZ_GET_DF_ERROR,
+ }
+)
+
+
+def _datasource_error_reason(error: Exception) -> str | None:
+ """Return the enumerated reason for a datasource failure, if any.
+
+ Only ``SupersetErrorType`` members are returned — they are a closed,
+ non-sensitive vocabulary. Raw driver output (which can carry SQL, table
+ contents, or connection strings) is never surfaced from here.
+ """
+ errors = getattr(error, "errors", None)
+ single_error = getattr(error, "error", None)
+ if isinstance(error, SupersetErrorsException) and errors:
+ # SupersetErrorsException carries a list of SupersetError.
+ error_type = getattr(errors[0], "error_type", None)
Review Comment:
**Suggestion:** Only `errors[0]` is examined, so a multi-error exception with a later datasource error is not classified as a datasource failure and loses its specific reason.
**Assessment:** 🟠 `Major` · 🔁 `Occurrence: Sometimes` · 🏷️ `Logic error`
[](https://docs.codeant.ai/cli/resolve-pr-comments-skill) [](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=16f5c425d8ba434794fc7ca2f3b1056b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) [](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=16f5c425d8ba434794fc7ca2f3b1056b&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset)
<details>
<summary><b>Prompt for AI Agent 🤖 </b></summary>
```mdx
This is a comment left during a code review.
**Path:** superset/mcp_service/middleware.py
**Line:** 253:255
**Comment:**
*Logic Error: Only `errors[0]` is examined, so a multi-error exception with a later datasource error is not classified as a datasource failure and loses its specific reason.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
```
</details>
<a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44387&comment_hash=1a594d2b0b7dc1f3c3baa6dc803b475e73ed6a4ea221300c24d53db620dcf170&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F44387&comment_hash=1a594d2b0b7dc1f3c3baa6dc803b475e73ed6a4ea221300c24d53db620dcf170&reaction=dislike'>👎</a>
--
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): return a specific error per failure class on tool calls [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on code in PR #44387:
URL: https://github.com/apache/superset/pull/44387#discussion_r4079258204
##########
superset/mcp_service/middleware.py:
##########
@@ -165,6 +177,105 @@ def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
logger.warning("MCP_ERROR_HOOK raised an exception: %s", hook_error)
+def _unwrap_tool_error(error: Exception) -> Exception:
+ """Return the original exception behind FastMCP's ``ToolError`` wrapper.
+
+ FastMCP catches every non-``FastMCPError`` raised inside a tool body and
+ re-raises it as ``ToolError(f"Error calling tool {name!r}: {e}") from e``
+ *before* any middleware error hook runs (see ``FastMCP._call_tool``). By
+ the time :class:`GlobalErrorHandlerMiddleware` sees a tool failure, the
+ concrete type — ``MCPPermissionDeniedError``, ``SupersetException``,
+ ``OperationalError`` — is no longer the exception itself, only its
+ ``__cause__``. Classifying the wrapper instead of the cause collapses
+ every distinct failure into one undifferentiated message.
+
+ A ``ToolError`` raised deliberately by tool code is re-raised by FastMCP
+ untouched and therefore carries no ``__cause__``; it is already formatted
+ for MCP and is returned as-is.
+ """
+ if isinstance(error, ToolError) and error.__cause__ is not None:
+ cause = error.__cause__
+ if isinstance(cause, Exception):
+ return cause
Review Comment:
Agreed: a cause alone is not enough to identify the FastMCP wrapper. This was addressed in 4f25bce9b0 by separating the metrics-only unwrap from `_unwrap_fastmcp_wrapped_error`, which requires both a cause and FastMCP’s message prefix before replacing client-facing text. A deliberately authored `raise ToolError(...) from exc` without that prefix is preserved. I verified the existing regression guard: removing just the prefix condition makes `TestUnwrapFastMCPWrappedError.test_passes_through_deliberate_tool_error_chained_off_a_cause` fail (the other three tests in that class pass). The round-2 helper cross-references also point at the correct guarded helper.
##########
superset/mcp_service/middleware.py:
##########
@@ -165,6 +177,105 @@ def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
logger.warning("MCP_ERROR_HOOK raised an exception: %s", hook_error)
+def _unwrap_tool_error(error: Exception) -> Exception:
+ """Return the original exception behind FastMCP's ``ToolError`` wrapper.
+
+ FastMCP catches every non-``FastMCPError`` raised inside a tool body and
+ re-raises it as ``ToolError(f"Error calling tool {name!r}: {e}") from e``
+ *before* any middleware error hook runs (see ``FastMCP._call_tool``). By
+ the time :class:`GlobalErrorHandlerMiddleware` sees a tool failure, the
+ concrete type — ``MCPPermissionDeniedError``, ``SupersetException``,
+ ``OperationalError`` — is no longer the exception itself, only its
+ ``__cause__``. Classifying the wrapper instead of the cause collapses
+ every distinct failure into one undifferentiated message.
+
+ A ``ToolError`` raised deliberately by tool code is re-raised by FastMCP
+ untouched and therefore carries no ``__cause__``; it is already formatted
+ for MCP and is returned as-is.
+ """
+ if isinstance(error, ToolError) and error.__cause__ is not None:
+ cause = error.__cause__
+ if isinstance(cause, Exception):
+ return cause
+ return error
+
+
+# Exception classes that mean "the query behind this tool failed", not "the
+# caller used the tool wrong". The tool name and arguments were valid; the
+# datasource, table, column, or connection it reads is broken or gone.
+_DATASOURCE_ERROR_EXCEPTIONS = (
+ ColumnNotFoundException,
+ DatabaseNotFound,
+ QueryObjectValidationError,
+ SupersetGenericDBErrorException,
+ SupersetParseError,
+ SupersetTimeoutException,
+ SupersetVizException,
+ SQLAlchemyError,
Review Comment:
I checked the concrete exception classes and am not applying the proposed escalation. `SupersetTimeoutException.status == 408` and `SupersetGenericDBErrorException.status == 400` are intentional user-error classifications, not reliable evidence of an operational outage. The timeout class also carries generic BACKEND_TIMEOUT_ERROR and is no longer classified as datasource-specific by class alone. More importantly, the generic engine reason can represent a malformed adhoc column; paging on it contradicts the Sep 21 human review and recreates the false-page this PR fixes. The status gate in 4e330a6a34 preserves sub-500 WARNING/no-hook semantics. Bare status-500 connection exceptions still remain ERROR and invoke the hook. The strengthened end-to-end guard in 36d7b47463 covers both the 400 engine catch-all and a 403 connection-access denial; removing only the status gate yields four failures in TestDatasourceErrorSeverity. Leaving this suggestion unresolved rather than marking an inte
ntionally rejected behavior change as implemented.
##########
superset/mcp_service/middleware.py:
##########
@@ -165,6 +177,105 @@ def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
logger.warning("MCP_ERROR_HOOK raised an exception: %s", hook_error)
+def _unwrap_tool_error(error: Exception) -> Exception:
+ """Return the original exception behind FastMCP's ``ToolError`` wrapper.
+
+ FastMCP catches every non-``FastMCPError`` raised inside a tool body and
+ re-raises it as ``ToolError(f"Error calling tool {name!r}: {e}") from e``
+ *before* any middleware error hook runs (see ``FastMCP._call_tool``). By
+ the time :class:`GlobalErrorHandlerMiddleware` sees a tool failure, the
+ concrete type — ``MCPPermissionDeniedError``, ``SupersetException``,
+ ``OperationalError`` — is no longer the exception itself, only its
+ ``__cause__``. Classifying the wrapper instead of the cause collapses
+ every distinct failure into one undifferentiated message.
+
+ A ``ToolError`` raised deliberately by tool code is re-raised by FastMCP
+ untouched and therefore carries no ``__cause__``; it is already formatted
+ for MCP and is returned as-is.
+ """
+ if isinstance(error, ToolError) and error.__cause__ is not None:
+ cause = error.__cause__
+ if isinstance(cause, Exception):
+ return cause
+ return error
+
+
+# Exception classes that mean "the query behind this tool failed", not "the
+# caller used the tool wrong". The tool name and arguments were valid; the
+# datasource, table, column, or connection it reads is broken or gone.
+_DATASOURCE_ERROR_EXCEPTIONS = (
+ ColumnNotFoundException,
+ DatabaseNotFound,
+ QueryObjectValidationError,
+ SupersetGenericDBErrorException,
+ SupersetParseError,
+ SupersetTimeoutException,
+ SupersetVizException,
+ SQLAlchemyError,
+)
+
+# ``SupersetError.error_type`` values in the DB-engine, viz, and SQL Lab
+# families. Superset raises a bare ``SupersetErrorException`` for many of
+# these, so the exception class alone is not enough to classify them.
+_DATASOURCE_ERROR_TYPES = frozenset(
+ {
+ SupersetErrorType.COLUMN_DOES_NOT_EXIST_ERROR,
+ SupersetErrorType.CONNECTION_DATABASE_TIMEOUT,
+ SupersetErrorType.CONNECTION_HOST_DOWN_ERROR,
+ SupersetErrorType.CONNECTION_PORT_CLOSED_ERROR,
+ SupersetErrorType.CONNECTION_UNKNOWN_DATABASE_ERROR,
+ SupersetErrorType.DATABASE_NOT_FOUND_ERROR,
+ SupersetErrorType.FAILED_FETCHING_DATASOURCE_INFO_ERROR,
+ SupersetErrorType.GENERIC_DB_ENGINE_ERROR,
+ SupersetErrorType.INVALID_SQL_ERROR,
+ SupersetErrorType.OBJECT_DOES_NOT_EXIST_ERROR,
+ SupersetErrorType.RESULTS_BACKEND_ERROR,
+ SupersetErrorType.SCHEMA_DOES_NOT_EXIST_ERROR,
+ SupersetErrorType.SQLLAB_TIMEOUT_ERROR,
+ SupersetErrorType.SYNTAX_ERROR,
+ SupersetErrorType.TABLE_DOES_NOT_EXIST_ERROR,
+ SupersetErrorType.TABLE_NOT_FOUND_ERROR,
+ SupersetErrorType.UNKNOWN_DATASOURCE_TYPE_ERROR,
+ SupersetErrorType.VIZ_GET_DF_ERROR,
+ }
+)
+
+
+def _datasource_error_reason(error: Exception) -> str | None:
+ """Return the enumerated reason for a datasource failure, if any.
+
+ Only ``SupersetErrorType`` members are returned — they are a closed,
+ non-sensitive vocabulary. Raw driver output (which can carry SQL, table
+ contents, or connection strings) is never surfaced from here.
+ """
+ errors = getattr(error, "errors", None)
+ single_error = getattr(error, "error", None)
+ if isinstance(error, SupersetErrorsException) and errors:
+ # SupersetErrorsException carries a list of SupersetError.
+ error_type = getattr(errors[0], "error_type", None)
Review Comment:
Agreed; this was addressed in 4f25bce9b0. `_datasource_error_reason` scans all errors in a `SupersetErrorsException` and returns the first recognized datasource reason, rather than examining only errors[0]. The regression fixture has GENERIC_COMMAND_ERROR first and TABLE_DOES_NOT_EXIST_ERROR second. I verified that changing the scan back to errors[:1] fails `test_reason_scans_every_error_in_a_multi_error_exception`, while the complete scan passes. The later datasource error therefore retains its enumerated reason.
--
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): return a specific error per failure class on tool calls [superset]
Posted by "netlify[bot] (via GitHub)" <gi...@apache.org>.
netlify[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5720067001
### <span aria-hidden="true">✅</span> Deploy Preview for *superset-docs-preview* ready!
| Name | Link |
|:-:|------------------------|
|<span aria-hidden="true">🔨</span> Latest commit | d484220c3c0e9fd91963227e0a2ab21c2400c881 |
|<span aria-hidden="true">🔍</span> Latest deploy log | https://app.netlify.com/projects/superset-docs-preview/deploys/6aac3f9ed20e180008546d95 |
|<span aria-hidden="true">😎</span> Deploy Preview | [https://deploy-preview-44387--superset-docs-preview.netlify.app](https://deploy-preview-44387--superset-docs-preview.netlify.app) |
|<span aria-hidden="true">📱</span> Preview on mobile | <details><summary> Toggle QR Code... </summary><br /><br /><br /><br />_Use your smartphone camera to open QR code link._</details> |
|<span aria-hidden="true">🤖</span> Make changes | [Run an agent on this branch](https://app.netlify.com/projects/superset-docs-preview/agent-runs#DcrLDYAgDADQXXqWBD8QdAPHwLZEEpSmejHG3eX2Du8F0XrIDQtAB5vGE_fmA8VcwphTRkN85lgMq1a92iKWUp-V2vMx4phmpsFyH6y1wU2eZgffDw) |
---
<!-- [superset-docs-preview Preview](https://deploy-preview-44387--superset-docs-preview.netlify.app) -->
_To edit notification comments on pull requests, go to your [Netlify project configuration](https://app.netlify.com/projects/superset-docs-preview/configuration/notifications#deploy-notifications)._
--
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): return a specific error per failure class on tool calls [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5770394099
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</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): return a specific error per failure class on tool calls [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5722117933
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</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): return a specific error per failure class on tool calls [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5791819891
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</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): return a specific error per failure class on tool calls [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5716147432
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
<details>
<summary>
Bito Usage Guide
</summary>
**Commands**
Type the following command in the pull request comment and save the comment.
- `/review` - Manually triggers an incremental AI Review.
- `/review full` - Manually triggers a full AI Review.
- `/pause` - Pauses automatic reviews on this pull request.
- `/resume` - Resumes automatic reviews.
- `/resolve` - Marks all Bito-posted review comments as resolved.
- `/abort` - Cancels all in-progress reviews.
Refer to the <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/available-commands" target="_blank" rel="noopener noreferrer">documentation</a> for additional commands.
**Configuration**
This repository uses `Superset` You can customize the agent settings <a href="https://alpha.bito.ai/home/ai-agents/code-review-agent" target="_blank" rel="noopener noreferrer">here</a> or contact your Bito workspace admin at evan@preset.io.
**Documentation & Help**
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/getting-started/install-run-using-bito-cloud/create-or-customize-an-agent-instance" target="_blank" rel="noopener noreferrer">Customize agent settings</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/implementing-custom-code-review-rules" target="_blank" rel="noopener noreferrer">Review rules</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent" target="_blank" rel="noopener noreferrer">General documentation</a>
- <a href="https://docs.bito.ai/bito-dev-agents/ai-code-review-agent/faqs" target="_blank" rel="noopener noreferrer">FAQ</a>
</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): return a specific error per failure class on tool calls [superset]
Posted by "Copilot (via GitHub)" <gi...@apache.org>.
Copilot commented on code in PR #44387:
URL: https://github.com/apache/superset/pull/44387#discussion_r4036337529
##########
superset/mcp_service/middleware.py:
##########
@@ -165,6 +177,105 @@ def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
logger.warning("MCP_ERROR_HOOK raised an exception: %s", hook_error)
+def _unwrap_tool_error(error: Exception) -> Exception:
+ """Return the original exception behind FastMCP's ``ToolError`` wrapper.
+
+ FastMCP catches every non-``FastMCPError`` raised inside a tool body and
+ re-raises it as ``ToolError(f"Error calling tool {name!r}: {e}") from e``
+ *before* any middleware error hook runs (see ``FastMCP._call_tool``). By
+ the time :class:`GlobalErrorHandlerMiddleware` sees a tool failure, the
+ concrete type — ``MCPPermissionDeniedError``, ``SupersetException``,
+ ``OperationalError`` — is no longer the exception itself, only its
+ ``__cause__``. Classifying the wrapper instead of the cause collapses
+ every distinct failure into one undifferentiated message.
+
+ A ``ToolError`` raised deliberately by tool code is re-raised by FastMCP
+ untouched and therefore carries no ``__cause__``; it is already formatted
+ for MCP and is returned as-is.
+ """
+ if isinstance(error, ToolError) and error.__cause__ is not None:
+ cause = error.__cause__
+ if isinstance(cause, Exception):
+ return cause
+ return error
+
+
+# Exception classes that mean "the query behind this tool failed", not "the
+# caller used the tool wrong". The tool name and arguments were valid; the
+# datasource, table, column, or connection it reads is broken or gone.
+_DATASOURCE_ERROR_EXCEPTIONS = (
+ ColumnNotFoundException,
+ DatabaseNotFound,
+ QueryObjectValidationError,
+ SupersetGenericDBErrorException,
Review Comment:
`QueryObjectValidationError` is not specific to a datasource: Superset raises it for missing/invalid query fields and invalid result types (for example, `common/query_actions.py:144-147` and `:405-408`). Because this tuple is checked before the generic `SupersetException` branch, those caller/configuration errors will be reported as “the tool name and arguments were valid” and blamed on the datasource. Remove this class from the datasource exception tuple; only classify it by an explicit datasource error type if that distinction is needed.
This issue also appears in the following locations of the same file:
- line 214
- line 223
- line 1219
--
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): return a specific error per failure class on tool calls [superset]
Posted by "codeant-ai-for-open-source[bot] (via GitHub)" <gi...@apache.org>.
codeant-ai-for-open-source[bot] commented on code in PR #44387:
URL: https://github.com/apache/superset/pull/44387#discussion_r4079260262
##########
superset/mcp_service/middleware.py:
##########
@@ -165,6 +177,105 @@ def _invoke_error_hook(error: Exception, hook_context: dict[str, Any]) -> None:
logger.warning("MCP_ERROR_HOOK raised an exception: %s", hook_error)
+def _unwrap_tool_error(error: Exception) -> Exception:
+ """Return the original exception behind FastMCP's ``ToolError`` wrapper.
+
+ FastMCP catches every non-``FastMCPError`` raised inside a tool body and
+ re-raises it as ``ToolError(f"Error calling tool {name!r}: {e}") from e``
+ *before* any middleware error hook runs (see ``FastMCP._call_tool``). By
+ the time :class:`GlobalErrorHandlerMiddleware` sees a tool failure, the
+ concrete type — ``MCPPermissionDeniedError``, ``SupersetException``,
+ ``OperationalError`` — is no longer the exception itself, only its
+ ``__cause__``. Classifying the wrapper instead of the cause collapses
+ every distinct failure into one undifferentiated message.
+
+ A ``ToolError`` raised deliberately by tool code is re-raised by FastMCP
+ untouched and therefore carries no ``__cause__``; it is already formatted
+ for MCP and is returned as-is.
+ """
+ if isinstance(error, ToolError) and error.__cause__ is not None:
+ cause = error.__cause__
+ if isinstance(cause, Exception):
+ return cause
+ return error
+
+
+# Exception classes that mean "the query behind this tool failed", not "the
+# caller used the tool wrong". The tool name and arguments were valid; the
+# datasource, table, column, or connection it reads is broken or gone.
+_DATASOURCE_ERROR_EXCEPTIONS = (
+ ColumnNotFoundException,
+ DatabaseNotFound,
+ QueryObjectValidationError,
+ SupersetGenericDBErrorException,
+ SupersetParseError,
+ SupersetTimeoutException,
+ SupersetVizException,
+ SQLAlchemyError,
Review Comment:
✅ **Customized review instruction saved!**
**Instruction:**
> Preserve the status gate that treats intentional 4xx user errors, including timeout and generic database exceptions, as WARNING without invoking MCP_ERROR_HOOK; only escalate bare status-500 connection exceptions.
**Applied to:**
- `superset/mcp_service/middleware.py`
---
💡 *To manage or update this instruction, visit: [CodeAnt AI Settings](https://app.codeant.ai/org/settings/learnings)*
--
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): return a specific error per failure class on tool calls [superset]
Posted by "aminghadersohi (via GitHub)" <gi...@apache.org>.
aminghadersohi commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5789954862
@rebenitez1802 thanks for the round-2 pass — the Medium is a real regression and your diagnosis of the mechanism was exact. All three round-2 items are addressed at head `579edc5c`; details and the revert-verification for each below.
### 🟡 Medium — connection-severity override escalated sub-500 exceptions to ERROR + page
Fixed in `4e330a6a34`, with the guard strengthened in `36d7b47463`.
`_datasource_error_is_user_error` now takes exactly the gate you proposed — escalate only when the status is already ≥500, so the override **only ever de-escalates** (`middleware.py:411-416`):
```python
reason = _datasource_error_reason(error)
if reason is None:
return None
if getattr(error, "status", 500) < 500:
return True
return reason not in _CONNECTION_REASONS
```
Both shapes you named are covered. I re-verified the guard myself rather than taking the commit message's word for it: deleting *only* the two status-gate lines and changing nothing else yields exactly four failures, and they are the right four —
```
FAILED TestDatasourceErrorSeverity::test_sub_500_exceptions_are_never_escalated
FAILED TestDatasourceErrorSeverity::test_security_exception_with_connection_reason_is_not_escalated
FAILED TestDatasourceErrorSeverity::test_sub_500_connection_reason_logs_warning_without_error_hook[malformed_column-Datasource error in malformed_column:]
FAILED TestDatasourceErrorSeverity::test_sub_500_connection_reason_logs_warning_without_error_hook[connection_denied-Permission denied]
4 failed, 36 passed
```
`malformed_column` is the status-400 `SupersetGenericDBErrorException` carrying `GENERIC_DB_ENGINE_ERROR` — the `generate_chart` → `_compile_chart` adhoc-column path you traced; `connection_denied` is the status-403 `SupersetSecurityException` carrying `CONNECTION_ACCESS_DENIED_ERROR`. Both assert WARNING level *and* spy on `MCP_ERROR_HOOK` to confirm it is not fired. Genuine connection failures still arrive as bare status-500 `SupersetErrorException` and continue to page.
You were also right that the old docstring contradicted itself by claiming `_DATASOURCE_ERROR_EXCEPTIONS` members keep their 4xx status — untrue for `SupersetGenericDBErrorException`. The docstring is rewritten to describe the actual rule and now names the BigQuery/Snowflake/Athena/Databricks/Trino catch-all case explicitly, so the next reader does not have to rediscover it.
### 🟢 Low — stale `_unwrap_tool_error` cross-references
Fixed in `4e330a6a34`. Both sites now point at `_unwrap_fastmcp_wrapped_error` — the docstring (`middleware.py:1218`) and the comment (`middleware.py:1295`). `grep` over the file confirms the only remaining `_unwrap_tool_error` references are its own definition (`:227`), its docstring pointer *to* the other helper (`:239`), and its one real call site in `LoggingMiddleware` (`:883`), which is the metrics-only path and is correct as-is.
### 🟢 Low — testing-instruction line contradicted the Scope paragraph
Fixed in the PR description. The "Manually:" line no longer mentions `get_chart_data`; it points at `generate_chart` against a dataset whose table has been dropped, which does raise and does reach the branch, and it explicitly notes that the earlier `get_chart_data` suggestion was wrong for the reason your Scope observation gives.
### Test state
`tests/unit_tests/mcp_service/test_error_classification.py` → 40 passed. Whole `tests/unit_tests/mcp_service/` suite → 4935 passed, 2 skipped.
### CI red is upstream, not this PR
For the record, since the four red checks look alarming: `babel-extract`, `unit-tests (current)`, `unit-tests-required` and `Python Unit Test Results` are one upstream `messages.pot` drift, not anything this branch did. Master commit `7dd70eaf2d` (#44036) reworded the `DatabaseConnectionMoveValidationError` string in `superset/commands/database/exceptions.py` without regenerating the template:
```
+ "…SSH tunnel endpoint, or OAuth2 endpoint URIs… (or SSH tunnel credential / OAuth2 client secret)…" [in source]
- "…or SSH tunnel endpoint… (or SSH tunnel credential)…" [in template]
```
Evidence it is not ours: `messages.pot` and `superset/commands/database/exceptions.py` are both **byte-identical to `origin/master`** on this branch (`git diff origin/master HEAD --` is empty for both), so the check fails on master itself; this PR's diff adds zero translatable strings; the single failing test out of 17,618 in `unit-tests (current)` is `check_pot_drift_test.py`, and `unit-tests-required` / `Python Unit Test Results` are aggregators of it. Byte-identical failures are currently on unrelated open PRs from other authors — #44559 (@deepujain), #44552 (@rusackas), #44537 (@sadpandajoe) among others. Per this repo's contributor guidance the fix belongs in a separate branch rather than as an unrelated file in this PR, so I have deliberately not touched the template here.
--
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): return a specific error per failure class on tool calls [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5713246286
AI Code Review is in progress (usually takes 3 to 15 minutes unless it's a very large PR).
--
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): return a specific error per failure class on tool calls [superset]
Posted by "bito-code-review[bot] (via GitHub)" <gi...@apache.org>.
bito-code-review[bot] commented on PR #44387:
URL: https://github.com/apache/superset/pull/44387#issuecomment-5713630626
<!-- Bito Reply -->
The requested change has been implemented in `superset/mcp_service/middleware.py`. The `QueryObjectValidationError` class has been removed from the `_DATASOURCE_ERROR_EXCEPTIONS` tuple, ensuring that such errors are no longer incorrectly classified as datasource-related failures. This prevents the misleading error message that previously suggested the tool name and arguments were valid when a query validation error occurred.
**superset/mcp_service/middleware.py**
```
# Exception classes that mean "the query behind this tool failed", not "the
# caller used the tool wrong". The tool name and arguments were valid; the
# datasource, table, column, or connection it reads is broken or gone.
_DATASOURCE_ERROR_EXCEPTIONS = (
ColumnNotFoundException,
DatabaseNotFound,
SupersetGenericDBErrorException,
SupersetParseError,
SupersetTimeoutException,
SupersetVizException,
SQLAlchemyError,
)
```
--
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