aminghadersohi commented on code in PR #41698:
URL: https://github.com/apache/superset/pull/41698#discussion_r3546897698
##########
tests/unit_tests/mcp_service/utils/test_token_utils.py:
##########
@@ -677,3 +677,43 @@ def test_progressive_truncation(self) -> None:
assert isinstance(result, dict)
assert result["id"] == 1 # Scalar fields preserved
assert len(notes) > 0
+
+ def test_large_dashboard_respects_default_max_list_items(self) -> None:
+ """Regression test for the Medialab large-dashboard report.
+
+ A dashboard with 463 charts and 48 native_filters should have
+ native_filters (48 items) left untouched under the new default cap
+ of 100, while charts (463 items) is truncated to 100 — a clear
+ improvement over the old flat 30-item cap, which truncated both.
+ """
+ response = {
Review Comment:
Fixed in 8a75f54. Added `response: dict[str, Any] = {...}` annotation (`Any`
was already imported in this file).
##########
tests/unit_tests/mcp_service/utils/test_token_utils.py:
##########
@@ -677,3 +677,43 @@ def test_progressive_truncation(self) -> None:
assert isinstance(result, dict)
assert result["id"] == 1 # Scalar fields preserved
assert len(notes) > 0
+
+ def test_large_dashboard_respects_default_max_list_items(self) -> None:
+ """Regression test for the Medialab large-dashboard report.
+
+ A dashboard with 463 charts and 48 native_filters should have
+ native_filters (48 items) left untouched under the new default cap
+ of 100, while charts (463 items) is truncated to 100 — a clear
+ improvement over the old flat 30-item cap, which truncated both.
+ """
+ response = {
+ "id": 1,
+ "dashboard_title": "x" * 2000, # forces Phase 2 to trigger
+ "charts": [{"id": i, "slice_name": f"chart_{i}"} for i in
range(463)],
+ "native_filters": [{"id": i, "name": f"filter_{i}"} for i in
range(48)],
+ }
+ result, was_truncated, notes = truncate_oversized_response(response,
3000)
+ assert was_truncated is True
+ assert isinstance(result, dict)
+ assert len(result["charts"]) == 100
+ assert len(result["native_filters"]) == 48
+ assert any("charts" in n and "463" in n for n in notes)
+ assert not any("native_filters" in n for n in notes)
+
+ def test_large_dashboard_respects_custom_max_list_items(self) -> None:
+ """A custom max_list_items below both list sizes should truncate both
fields."""
+ response = {
Review Comment:
Fixed in 8a75f54. Same fix — added `response: dict[str, Any] = {...}`.
##########
superset/mcp_service/constants.py:
##########
@@ -28,3 +28,4 @@
# Response size guard defaults
DEFAULT_TOKEN_LIMIT = 25_000 # ~25k tokens prevents overwhelming LLM context
windows
DEFAULT_WARN_THRESHOLD_PCT = 80 # Log warnings above 80% of limit
+DEFAULT_MAX_LIST_ITEMS = 100 # Phase 2 list-field truncation cap; matches
MAX_PAGE_SIZE
Review Comment:
Fixed in 8a75f54. Annotated as `DEFAULT_MAX_LIST_ITEMS: int = 100`.
##########
superset/mcp_service/utils/token_utils.py:
##########
@@ -469,8 +471,9 @@ def _get_tool_specific_suggestions(
# Maximum character length for string fields before truncation
_MAX_STRING_CHARS = 500
-# Maximum items to keep in list fields before truncation
-_MAX_LIST_ITEMS = 30
+# Maximum items to keep in list fields before truncation (configurable via
+# MCP_RESPONSE_SIZE_CONFIG["max_list_items"])
+_MAX_LIST_ITEMS = DEFAULT_MAX_LIST_ITEMS
Review Comment:
Fixed in 8a75f54. Annotated as `_MAX_LIST_ITEMS: int =
DEFAULT_MAX_LIST_ITEMS`.
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]