You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by ru...@apache.org on 2026/08/05 16:27:27 UTC
(superset) branch master updated: fix(mcp): stop false-flagging successful responses with error_type:null as failures (#42580) (#42736)
This is an automated email from the ASF dual-hosted git repository.
rusackas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git
The following commit(s) were added to refs/heads/master by this push:
new 9c97d4859c6 fix(mcp): stop false-flagging successful responses with error_type:null as failures (#42580) (#42736)
9c97d4859c6 is described below
commit 9c97d4859c6825c776b84b4b559d814953caeee8
Author: Evan Rusackas <ev...@preset.io>
AuthorDate: Wed Aug 5 09:27:17 2026 -0700
fix(mcp): stop false-flagging successful responses with error_type:null as failures (#42580) (#42736)
Co-authored-by: Claude Code <no...@anthropic.com>
---
superset/mcp_service/middleware.py | 14 ++++++++++----
.../mcp_service/test_middleware_logging.py | 20 +++++++++++++++++++-
2 files changed, 29 insertions(+), 5 deletions(-)
diff --git a/superset/mcp_service/middleware.py b/superset/mcp_service/middleware.py
index c74494e34b4..43d3f129eeb 100644
--- a/superset/mcp_service/middleware.py
+++ b/superset/mcp_service/middleware.py
@@ -227,13 +227,19 @@ class LoggingMiddleware(Middleware):
"""Check if a tool result contains an error schema response.
MCP tools return error schemas (ChartError, DashboardError, etc.)
- instead of raising exceptions. These serialize to JSON containing
- an "error_type" field.
+ instead of raising exceptions. These serialize to JSON with a
+ populated "error_type" field. Success schemas also declare an
+ optional "error_type" field (defaulting to null) for a uniform
+ response shape, so its mere presence in the serialized JSON isn't
+ a reliable signal -- only a truthy value is.
"""
+ from superset.utils.json import loads as json_loads
+
try:
- return '"error_type"' in result.content[0].text
- except (AttributeError, IndexError):
+ payload = json_loads(result.content[0].text)
+ except (AttributeError, IndexError, TypeError, ValueError):
return False
+ return bool(isinstance(payload, dict) and payload.get("error_type"))
def _extract_context_info(
self, context: MiddlewareContext
diff --git a/tests/unit_tests/mcp_service/test_middleware_logging.py b/tests/unit_tests/mcp_service/test_middleware_logging.py
index eed0334648e..9e6893df856 100644
--- a/tests/unit_tests/mcp_service/test_middleware_logging.py
+++ b/tests/unit_tests/mcp_service/test_middleware_logging.py
@@ -278,7 +278,7 @@ class TestLoggingMiddlewareOnCallTool:
ctx = _make_context(name="generate_chart", params={"dataset_id": 5})
response_text = (
'{"success": false, "chart": null, '
- '"error": {"error_type": "validation_error"}}'
+ '"error": "invalid dataset", "error_type": "validation_error"}'
)
original_result = ToolResult(
content=[mt.TextContent(type="text", text=response_text)]
@@ -559,6 +559,24 @@ class TestIsErrorResponse:
middleware = LoggingMiddleware()
assert middleware._is_error_response(ToolResult(content=[])) is False
+ def test_success_response_with_null_error_type_not_detected_as_error(
+ self,
+ ) -> None:
+ """Regression for #42580: response schemas like ExecuteSqlResponse
+ declare "error"/"error_type" as always-present nullable fields, so a
+ fully successful response still serializes the literal "error_type"
+ substring (as "error_type":null). The substring check must not treat
+ that the same as an actual error schema payload with a non-null
+ error_type value."""
+ middleware = LoggingMiddleware()
+ success_json = (
+ '{"success": true, "rows": [{"database": "bronze_layer", '
+ '"tables": 161}], "row_count": 1, "error": null, '
+ '"error_type": null}'
+ )
+ result = ToolResult(content=[mt.TextContent(type="text", text=success_json)])
+ assert middleware._is_error_response(result) is False
+
@patch("superset.mcp_service.middleware.event_logger")
@patch("superset.mcp_service.middleware.get_user_id", return_value=42)
@pytest.mark.asyncio