fix(mcp): enforce MAX_PAGE_SIZE limit on list tools to prevent oversized responses (#38959)

This commit is contained in:
Amin Ghadersohi
2026-03-30 22:48:03 +02:00
committed by GitHub
parent 38fdfb4ca2
commit 2c9cf0bd55
7 changed files with 79 additions and 3 deletions

View File

@@ -28,6 +28,7 @@ from superset.mcp_service.chart.schemas import (
ChartFilter,
ListChartsRequest,
)
from superset.mcp_service.constants import MAX_PAGE_SIZE
@pytest.fixture
@@ -133,6 +134,19 @@ class TestListChartsRequestSchema:
with pytest.raises(ValueError, match="Input should be greater than 0"):
ListChartsRequest(page_size=0)
def test_page_size_exceeds_max(self):
"""Test that page_size over MAX_PAGE_SIZE raises validation error."""
with pytest.raises(
ValueError,
match=f"Input should be less than or equal to {MAX_PAGE_SIZE}",
):
ListChartsRequest(page_size=MAX_PAGE_SIZE + 1)
def test_page_size_at_max(self):
"""Test that page_size at MAX_PAGE_SIZE is accepted."""
request = ListChartsRequest(page_size=MAX_PAGE_SIZE)
assert request.page_size == MAX_PAGE_SIZE
def test_filter_validation(self):
"""Test that filter validation works correctly."""
# Valid filter