You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by mi...@apache.org on 2026/05/07 16:18:39 UTC

(superset) branch fix/mcp-list-datasets-schema-request-wrapper updated (c5b4fd79788 -> b2c647cc42d)

This is an automated email from the ASF dual-hosted git repository.

aminghadersohi pushed a change to branch fix/mcp-list-datasets-schema-request-wrapper
in repository https://gitbox.apache.org/repos/asf/superset.git


    omit c5b4fd79788 test(mcp): add -> None return types and remove redundant ToolError import
    omit c57de66407d fix(mcp): use valid opr value in docstring filter examples; fix dashboard docstring test
    omit d7205c204d1 test(mcp): fix and strengthen TestListDatasetsRequestWrapper tests
    omit 71f210cd898 fix(mcp): clarify request wrapper pattern in list_datasets, list_charts, list_dashboards
     add b5186d1c65c fix(reports): keep body sized so standalone screenshots don't time out (#39944)
     add d3c44e311eb chore(deps): bump aws-actions/amazon-ecr-login from 2.1.4 to 2.1.5 (#39931)
     add 7593d2a164d chore(deps): bump caniuse-lite from 1.0.30001791 to 1.0.30001792 in /docs (#39933)
     add 9ac4711ac8c fix(mcp): prevent DetachedInstanceError in get_chart_preview (#39921)
     add 9b520312a1a fix(mcp): use tiktoken for response-size-guard token estimation (#39912)
     new e884229367b fix(mcp): clarify request wrapper pattern in list_datasets, list_charts, list_dashboards
     new 392921935ea test(mcp): fix and strengthen TestListDatasetsRequestWrapper tests
     new 88af399d502 fix(mcp): use valid opr value in docstring filter examples; fix dashboard docstring test
     new b2c647cc42d test(mcp): add -> None return types and remove redundant ToolError import

This update added new revisions after undoing existing revisions.
That is to say, some revisions that were in the old version of the
branch are not in the new version.  This situation occurs
when a user --force pushes a change and generates a repository
containing something like this:

 * -- * -- B -- O -- O -- O   (c5b4fd79788)
            \
             N -- N -- N   refs/heads/fix/mcp-list-datasets-schema-request-wrapper (b2c647cc42d)

You should already have received notification emails for all of the O
revisions, and so the following emails describe only the N revisions
from the common base, B.

Any revisions marked "omit" are not gone; other references still
refer to them.  Any revisions marked "discard" are gone forever.

The 4 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.


Summary of changes:
 .github/workflows/ephemeral-env-pr-close.yml       |   2 +-
 .github/workflows/ephemeral-env.yml                |   4 +-
 docs/package.json                                  |   2 +-
 docs/yarn.lock                                     |   8 +-
 pyproject.toml                                     |   8 +-
 requirements/base.txt                              |   5 +-
 requirements/development.txt                       |   7 +
 .../mcp_service/chart/tool/get_chart_preview.py    |  25 ++-
 superset/mcp_service/middleware.py                 |  19 +--
 superset/mcp_service/utils/token_utils.py          |  93 ++++++++--
 superset/templates/superset/spa.html               |   7 +
 tests/unit_tests/extension_tests.py                |  47 ++++++
 .../chart/tool/test_get_chart_preview.py           | 188 +++++++++++++++++++++
 tests/unit_tests/mcp_service/test_middleware.py    |  17 +-
 .../mcp_service/utils/test_token_utils.py          |  64 +++++--
 15 files changed, 445 insertions(+), 51 deletions(-)


(superset) 02/04: test(mcp): fix and strengthen TestListDatasetsRequestWrapper tests

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aminghadersohi pushed a commit to branch fix/mcp-list-datasets-schema-request-wrapper
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 392921935ea8ee55776bcb341a397ec41ec85026
Author: Amin Ghadersohi <am...@gmail.com>
AuthorDate: Thu May 7 16:18:25 2026 +0000

    test(mcp): fix and strengthen TestListDatasetsRequestWrapper tests
    
    - Fix test_sortable_columns_in_docstring: assertion used plain-text match
      but docstring now uses RST backtick format; use substring check for both
      'Sortable columns for' and 'order_column' separately
    - Fix test_dataset_filter_valid_col: opr='ct' is not a valid
      ColumnOperatorEnum value; use opr='sw' (starts-with) instead
    - Add test_request_wrapper_enforced_by_tool: exercises the wrapper pattern
      through the actual FastMCP client call (not just schema instantiation),
      verifying the MCP tool layer accepts request={...} correctly
    - Strengthen test_flat_kwargs_rejected: assert that the ToolError message
      references the unexpected arguments ('search', 'Unexpected', or 'request')
      so the test cannot pass on unrelated failures
---
 .../mcp_service/dataset/tool/test_dataset_tools.py | 46 +++++++++++++++++-----
 1 file changed, 37 insertions(+), 9 deletions(-)

diff --git a/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py b/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
index aa93389921f..63e2044d100 100644
--- a/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
+++ b/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
@@ -1700,7 +1700,8 @@ class TestDatasetSortableColumns:
 
         # Check list_datasets docstring for sortable columns documentation
         assert list_datasets.__doc__ is not None
-        assert "Sortable columns for order_column:" in list_datasets.__doc__
+        assert "Sortable columns for" in list_datasets.__doc__
+        assert "order_column" in list_datasets.__doc__
         for col in SORTABLE_DATASET_COLUMNS:
             assert col in list_datasets.__doc__
 
@@ -2088,19 +2089,20 @@ class TestListDatasetsRequestWrapper:
 
     LLMs sometimes pass parameters like ``search``, ``page``, or ``page_size``
     as flat top-level kwargs instead of nesting them inside a ``request``
-    object.  These tests confirm the correct call shape and that the schema
-    rejects invalid filter column names (e.g. ``created_by_fk``).
+    object.  These tests confirm the correct call shape through both the Pydantic
+    schema and the actual MCP tool layer, and verify that invalid filter column
+    names (e.g. ``created_by_fk``) are rejected.
     """
 
     def test_request_wrapper_with_search(self):
-        """Parameters passed inside request= are accepted."""
+        """Parameters passed inside request= are accepted by the schema."""
         request = ListDatasetsRequest(search="sales", page=1, page_size=10)
         assert request.search == "sales"
         assert request.page == 1
         assert request.page_size == 10
 
     def test_request_wrapper_defaults(self):
-        """No-arg constructor produces valid defaults."""
+        """No-arg constructor produces valid schema defaults."""
         request = ListDatasetsRequest()
         assert request.search is None
         assert request.page == 1
@@ -2109,7 +2111,7 @@ class TestListDatasetsRequestWrapper:
     def test_dataset_filter_valid_col(self):
         """Valid col values are accepted by DatasetFilter."""
         for col in ("table_name", "schema", "database_name"):
-            f = DatasetFilter(col=col, opr="ct", value="test")
+            f = DatasetFilter(col=col, opr="sw", value="test")
             assert f.col == col
 
     def test_dataset_filter_invalid_col_raises(self):
@@ -2124,19 +2126,45 @@ class TestListDatasetsRequestWrapper:
             with pytest.raises(ValidationError):
                 DatasetFilter(col=bad_col, opr="eq", value="1")
 
+    @patch("superset.daos.dataset.DatasetDAO.list")
+    @pytest.mark.asyncio
+    async def test_request_wrapper_enforced_by_tool(self, mock_list, mcp_server):
+        """The MCP tool layer accepts the request wrapper and returns results.
+
+        Verifies end-to-end that wrapping params in ``request={}`` works through
+        the actual FastMCP tool call, not just schema validation.
+        """
+        mock_list.return_value = ([], 0)
+        async with Client(mcp_server) as client:
+            result = await client.call_tool(
+                "list_datasets",
+                {"request": {"search": "sales", "page": 1, "page_size": 5}},
+            )
+        data = json.loads(result.content[0].text)
+        assert data["count"] == 0
+        assert data["datasets"] == []
+
     @pytest.mark.asyncio
     async def test_flat_kwargs_rejected(self, mcp_server):
-        """Passing search/page/page_size as top-level kwargs raises a ToolError.
+        """Passing search/page/page_size as top-level kwargs raises a ToolError
+        that specifically mentions the unexpected arguments.
 
-        This is the exact failure pattern reported in story #105712: LLMs call
+        This is the exact failure pattern from story #105712: LLMs call
         ``list_datasets(search=..., page=..., page_size=...)`` instead of
         ``list_datasets(request={...})``.
         """
         from fastmcp.exceptions import ToolError
 
-        with pytest.raises(ToolError):
+        with pytest.raises(ToolError) as exc_info:
             async with Client(mcp_server) as client:
                 await client.call_tool(
                     "list_datasets",
                     {"search": "sales", "page": 1, "page_size": 10},
                 )
+        error_text = str(exc_info.value)
+        # The error must call out the unexpected arguments, not some unrelated failure
+        assert (
+            "search" in error_text
+            or "Unexpected" in error_text
+            or "request" in error_text
+        )


(superset) 04/04: test(mcp): add -> None return types and remove redundant ToolError import

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aminghadersohi pushed a commit to branch fix/mcp-list-datasets-schema-request-wrapper
in repository https://gitbox.apache.org/repos/asf/superset.git

commit b2c647cc42d64016265e901d9c101a44ac5a1a4e
Author: Amin Ghadersohi <am...@gmail.com>
AuthorDate: Thu May 7 16:18:26 2026 +0000

    test(mcp): add -> None return types and remove redundant ToolError import
    
    All 6 new test methods in TestListDatasetsRequestWrapper were missing
    the required -> None return type annotation (Rule 12). Also remove the
    inline `from fastmcp.exceptions import ToolError` in test_flat_kwargs_rejected
    since ToolError is already imported at module top-level (line 27).
---
 .../mcp_service/dataset/tool/test_dataset_tools.py         | 14 ++++++--------
 1 file changed, 6 insertions(+), 8 deletions(-)

diff --git a/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py b/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
index 63e2044d100..66a7f3fba80 100644
--- a/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
+++ b/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
@@ -2094,27 +2094,27 @@ class TestListDatasetsRequestWrapper:
     names (e.g. ``created_by_fk``) are rejected.
     """
 
-    def test_request_wrapper_with_search(self):
+    def test_request_wrapper_with_search(self) -> None:
         """Parameters passed inside request= are accepted by the schema."""
         request = ListDatasetsRequest(search="sales", page=1, page_size=10)
         assert request.search == "sales"
         assert request.page == 1
         assert request.page_size == 10
 
-    def test_request_wrapper_defaults(self):
+    def test_request_wrapper_defaults(self) -> None:
         """No-arg constructor produces valid schema defaults."""
         request = ListDatasetsRequest()
         assert request.search is None
         assert request.page == 1
         assert request.filters == []
 
-    def test_dataset_filter_valid_col(self):
+    def test_dataset_filter_valid_col(self) -> None:
         """Valid col values are accepted by DatasetFilter."""
         for col in ("table_name", "schema", "database_name"):
             f = DatasetFilter(col=col, opr="sw", value="test")
             assert f.col == col
 
-    def test_dataset_filter_invalid_col_raises(self):
+    def test_dataset_filter_invalid_col_raises(self) -> None:
         """Column names not in the Literal are rejected with a validation error.
 
         This guards against LLMs passing ``created_by_fk`` or similar
@@ -2128,7 +2128,7 @@ class TestListDatasetsRequestWrapper:
 
     @patch("superset.daos.dataset.DatasetDAO.list")
     @pytest.mark.asyncio
-    async def test_request_wrapper_enforced_by_tool(self, mock_list, mcp_server):
+    async def test_request_wrapper_enforced_by_tool(self, mock_list, mcp_server) -> None:
         """The MCP tool layer accepts the request wrapper and returns results.
 
         Verifies end-to-end that wrapping params in ``request={}`` works through
@@ -2145,7 +2145,7 @@ class TestListDatasetsRequestWrapper:
         assert data["datasets"] == []
 
     @pytest.mark.asyncio
-    async def test_flat_kwargs_rejected(self, mcp_server):
+    async def test_flat_kwargs_rejected(self, mcp_server) -> None:
         """Passing search/page/page_size as top-level kwargs raises a ToolError
         that specifically mentions the unexpected arguments.
 
@@ -2153,8 +2153,6 @@ class TestListDatasetsRequestWrapper:
         ``list_datasets(search=..., page=..., page_size=...)`` instead of
         ``list_datasets(request={...})``.
         """
-        from fastmcp.exceptions import ToolError
-
         with pytest.raises(ToolError) as exc_info:
             async with Client(mcp_server) as client:
                 await client.call_tool(


(superset) 01/04: fix(mcp): clarify request wrapper pattern in list_datasets, list_charts, list_dashboards

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aminghadersohi pushed a commit to branch fix/mcp-list-datasets-schema-request-wrapper
in repository https://gitbox.apache.org/repos/asf/superset.git

commit e884229367b1dbb3470dd89862b0a59c40027877
Author: Amin Ghadersohi <am...@gmail.com>
AuthorDate: Thu May 7 16:18:25 2026 +0000

    fix(mcp): clarify request wrapper pattern in list_datasets, list_charts, list_dashboards
    
    LLMs consistently passed flat kwargs (search, page, page_size) to list_*
    tools instead of wrapping them in the required `request` object, causing
    pydantic validation errors.
    
    - Add docstring usage examples to list_datasets, list_charts, and
      list_dashboards showing the correct `request={...}` call shape and
      explicitly warning against flat kwargs
    - Enumerate valid filter columns directly in DatasetFilter, ChartFilter,
      and DashboardFilter field descriptions (e.g. `created_by_fk` is not a
      valid dataset filter col)
    - Add TestListDatasetsRequestWrapper tests covering: correct request
      wrapper usage, default values, valid/invalid filter col validation,
      and the flat-kwargs rejection scenario from story #105712
    - Allow E501 in list_*.py tool files (docstring examples need full request
      shapes to be instructive)
---
 pyproject.toml                                     |  1 +
 superset/mcp_service/chart/schemas.py              |  7 ++-
 superset/mcp_service/chart/tool/list_charts.py     | 20 +++++++-
 superset/mcp_service/dashboard/schemas.py          |  5 +-
 .../mcp_service/dashboard/tool/list_dashboards.py  | 20 +++++++-
 superset/mcp_service/dataset/schemas.py            |  7 ++-
 superset/mcp_service/dataset/tool/list_datasets.py | 19 ++++++-
 .../mcp_service/dataset/tool/test_dataset_tools.py | 60 ++++++++++++++++++++++
 8 files changed, 127 insertions(+), 12 deletions(-)

diff --git a/pyproject.toml b/pyproject.toml
index 933e5175971..33e46734a37 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -383,6 +383,7 @@ dummy-variable-rgx = "^(_+|(_+[a-zA-Z0-9_]*[a-zA-Z0-9]+?))$"
 
 [tool.ruff.lint.per-file-ignores]
 "superset/mcp_service/app.py" = ["S608", "E501"]  # LLM instruction text: SQL examples (S608) and long lines in multiline string (E501)
+"superset/mcp_service/*/tool/list_*.py" = ["E501"]  # LLM docstring examples show full request shapes which exceed line length
 "scripts/*" = ["TID251"]
 "setup.py" = ["TID251"]
 "superset/config.py" = ["TID251"]
diff --git a/superset/mcp_service/chart/schemas.py b/superset/mcp_service/chart/schemas.py
index 1fdb4f43ab6..d9f1c6b97e3 100644
--- a/superset/mcp_service/chart/schemas.py
+++ b/superset/mcp_service/chart/schemas.py
@@ -537,8 +537,11 @@ class ChartFilter(ColumnOperator):
         "datasource_name",
     ] = Field(
         ...,
-        description="Column to filter on. Use get_schema(model_type='chart') for "
-        "available filter columns.",
+        description=(
+            "Column to filter on. Valid values: 'slice_name', 'viz_type', "
+            "'datasource_name'. Other column names are not valid filter columns "
+            "and will cause a validation error."
+        ),
     )
     opr: ColumnOperatorEnum = Field(
         ...,
diff --git a/superset/mcp_service/chart/tool/list_charts.py b/superset/mcp_service/chart/tool/list_charts.py
index 2d53afc8d30..66c6909f33f 100644
--- a/superset/mcp_service/chart/tool/list_charts.py
+++ b/superset/mcp_service/chart/tool/list_charts.py
@@ -91,8 +91,24 @@ async def list_charts(
     Returns chart metadata including id, name, viz_type, URL, and last
     modified time.
 
-    Sortable columns for order_column: id, slice_name, viz_type, description,
-    changed_on, created_on
+    **IMPORTANT**: All parameters must be wrapped in a ``request`` object.
+    Do NOT pass ``search``, ``page``, ``page_size``, etc. as top-level
+    keyword arguments — they will be rejected. Use the ``request`` wrapper::
+
+        # Correct usage
+        list_charts(request={"search": "revenue", "page": 1, "page_size": 10})
+        list_charts(request={"filters": [{"col": "slice_name", "opr": "ct", "value": "sales"}]})
+        list_charts()  # no arguments returns first page with defaults
+
+        # Wrong — causes pydantic validation errors
+        list_charts(search="revenue", page=1)  # DO NOT DO THIS
+
+    Valid filter columns for ``filters[].col``:
+        ``slice_name``, ``viz_type``, ``datasource_name``
+
+    Sortable columns for ``order_column``:
+        ``id``, ``slice_name``, ``viz_type``, ``description``,
+        ``changed_on``, ``created_on``
     """
     request = request or _DEFAULT_LIST_CHARTS_REQUEST.model_copy(deep=True)
     await ctx.info(
diff --git a/superset/mcp_service/dashboard/schemas.py b/superset/mcp_service/dashboard/schemas.py
index 8a92d585896..68a680863e5 100644
--- a/superset/mcp_service/dashboard/schemas.py
+++ b/superset/mcp_service/dashboard/schemas.py
@@ -176,8 +176,9 @@ class DashboardFilter(ColumnOperator):
     ] = Field(
         ...,
         description=(
-            "Column to filter on. Use "
-            "get_schema(model_type='dashboard') for available filter columns."
+            "Column to filter on. Valid values: 'dashboard_title', 'published', "
+            "'favorite'. Other column names are not valid filter columns and will "
+            "cause a validation error."
         ),
     )
     opr: ColumnOperatorEnum = Field(
diff --git a/superset/mcp_service/dashboard/tool/list_dashboards.py b/superset/mcp_service/dashboard/tool/list_dashboards.py
index b1bc664c593..ed856dff47d 100644
--- a/superset/mcp_service/dashboard/tool/list_dashboards.py
+++ b/superset/mcp_service/dashboard/tool/list_dashboards.py
@@ -85,8 +85,24 @@ async def list_dashboards(
     including title, slug, URL, and last modified time. Use select_columns to
     request additional fields.
 
-    Sortable columns for order_column: id, dashboard_title, slug, published,
-    changed_on, created_on
+    **IMPORTANT**: All parameters must be wrapped in a ``request`` object.
+    Do NOT pass ``search``, ``page``, ``page_size``, etc. as top-level
+    keyword arguments — they will be rejected. Use the ``request`` wrapper::
+
+        # Correct usage
+        list_dashboards(request={"search": "sales", "page": 1, "page_size": 10})
+        list_dashboards(request={"filters": [{"col": "dashboard_title", "opr": "ct", "value": "exec"}]})
+        list_dashboards()  # no arguments returns first page with defaults
+
+        # Wrong — causes pydantic validation errors
+        list_dashboards(search="sales", page=1)  # DO NOT DO THIS
+
+    Valid filter columns for ``filters[].col``:
+        ``dashboard_title``, ``published``, ``favorite``
+
+    Sortable columns for ``order_column``:
+        ``id``, ``dashboard_title``, ``slug``, ``published``,
+        ``changed_on``, ``created_on``
     """
     request = request or _DEFAULT_LIST_DASHBOARDS_REQUEST.model_copy(deep=True)
     await ctx.info(
diff --git a/superset/mcp_service/dataset/schemas.py b/superset/mcp_service/dataset/schemas.py
index 9d706c84152..b5aa475ff2e 100644
--- a/superset/mcp_service/dataset/schemas.py
+++ b/superset/mcp_service/dataset/schemas.py
@@ -71,8 +71,11 @@ class DatasetFilter(ColumnOperator):
         "database_name",
     ] = Field(
         ...,
-        description="Column to filter on. Use get_schema(model_type='dataset') for "
-        "available filter columns.",
+        description=(
+            "Column to filter on. Valid values: 'table_name', 'schema', "
+            "'database_name'. Other column names (e.g. 'created_by_fk', 'id') "
+            "are not valid filter columns and will cause a validation error."
+        ),
     )
     opr: ColumnOperatorEnum = Field(
         ...,
diff --git a/superset/mcp_service/dataset/tool/list_datasets.py b/superset/mcp_service/dataset/tool/list_datasets.py
index 84b7a71d15f..9679f658316 100644
--- a/superset/mcp_service/dataset/tool/list_datasets.py
+++ b/superset/mcp_service/dataset/tool/list_datasets.py
@@ -96,8 +96,23 @@ async def list_datasets(
     Returns dataset metadata including table name, schema, and last modified
     time.
 
-    Sortable columns for order_column: id, table_name, schema, changed_on,
-    created_on
+    **IMPORTANT**: All parameters must be wrapped in a ``request`` object.
+    Do NOT pass ``search``, ``page``, ``page_size``, etc. as top-level
+    keyword arguments — they will be rejected. Use the ``request`` wrapper::
+
+        # Correct usage
+        list_datasets(request={"search": "sales", "page": 1, "page_size": 10})
+        list_datasets(request={"filters": [{"col": "table_name", "opr": "ct", "value": "orders"}]})
+        list_datasets()  # no arguments returns first page with defaults
+
+        # Wrong — causes pydantic validation errors
+        list_datasets(search="sales", page=1)  # DO NOT DO THIS
+
+    Valid filter columns for ``filters[].col``:
+        ``table_name``, ``schema``, ``database_name``
+
+    Sortable columns for ``order_column``:
+        ``id``, ``table_name``, ``schema``, ``changed_on``, ``created_on``
     """
     if ctx is None:
         raise RuntimeError("FastMCP context is required for list_datasets")
diff --git a/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py b/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
index bfe8410dde9..aa93389921f 100644
--- a/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
+++ b/tests/unit_tests/mcp_service/dataset/tool/test_dataset_tools.py
@@ -2080,3 +2080,63 @@ class TestListDatasetsOwnedByMe:
         request = ListDatasetsRequest(owned_by_me=True, created_by_me=True)
         assert request.owned_by_me is True
         assert request.created_by_me is True
+
+
+class TestListDatasetsRequestWrapper:
+    """
+    Tests verifying that list_datasets requires a ``request`` wrapper object.
+
+    LLMs sometimes pass parameters like ``search``, ``page``, or ``page_size``
+    as flat top-level kwargs instead of nesting them inside a ``request``
+    object.  These tests confirm the correct call shape and that the schema
+    rejects invalid filter column names (e.g. ``created_by_fk``).
+    """
+
+    def test_request_wrapper_with_search(self):
+        """Parameters passed inside request= are accepted."""
+        request = ListDatasetsRequest(search="sales", page=1, page_size=10)
+        assert request.search == "sales"
+        assert request.page == 1
+        assert request.page_size == 10
+
+    def test_request_wrapper_defaults(self):
+        """No-arg constructor produces valid defaults."""
+        request = ListDatasetsRequest()
+        assert request.search is None
+        assert request.page == 1
+        assert request.filters == []
+
+    def test_dataset_filter_valid_col(self):
+        """Valid col values are accepted by DatasetFilter."""
+        for col in ("table_name", "schema", "database_name"):
+            f = DatasetFilter(col=col, opr="ct", value="test")
+            assert f.col == col
+
+    def test_dataset_filter_invalid_col_raises(self):
+        """Column names not in the Literal are rejected with a validation error.
+
+        This guards against LLMs passing ``created_by_fk`` or similar
+        internal column names that are not exposed as filter fields.
+        """
+        from pydantic import ValidationError
+
+        for bad_col in ("created_by_fk", "id", "database_id", "owner"):
+            with pytest.raises(ValidationError):
+                DatasetFilter(col=bad_col, opr="eq", value="1")
+
+    @pytest.mark.asyncio
+    async def test_flat_kwargs_rejected(self, mcp_server):
+        """Passing search/page/page_size as top-level kwargs raises a ToolError.
+
+        This is the exact failure pattern reported in story #105712: LLMs call
+        ``list_datasets(search=..., page=..., page_size=...)`` instead of
+        ``list_datasets(request={...})``.
+        """
+        from fastmcp.exceptions import ToolError
+
+        with pytest.raises(ToolError):
+            async with Client(mcp_server) as client:
+                await client.call_tool(
+                    "list_datasets",
+                    {"search": "sales", "page": 1, "page_size": 10},
+                )


(superset) 03/04: fix(mcp): use valid opr value in docstring filter examples; fix dashboard docstring test

Posted by mi...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

aminghadersohi pushed a commit to branch fix/mcp-list-datasets-schema-request-wrapper
in repository https://gitbox.apache.org/repos/asf/superset.git

commit 88af399d502d39dd32f0c4e25a12f4d70a1539ea
Author: Amin Ghadersohi <am...@gmail.com>
AuthorDate: Thu May 7 16:18:26 2026 +0000

    fix(mcp): use valid opr value in docstring filter examples; fix dashboard docstring test
    
    - Replace opr:"ct" with opr:"sw" in filter examples in list_datasets,
      list_charts, and list_dashboards docstrings — "ct" is not a valid
      ColumnOperatorEnum value, so examples using it produce validation errors
    - Fix TestDashboardSortableColumns.test_sortable_columns_in_docstring:
      assertion checked for "Sortable columns for order_column:" (plain text)
      but docstring uses RST backtick format; split into two substring checks
      matching "Sortable columns for" and "order_column" separately
---
 superset/mcp_service/chart/tool/list_charts.py                      | 2 +-
 superset/mcp_service/dashboard/tool/list_dashboards.py              | 2 +-
 superset/mcp_service/dataset/tool/list_datasets.py                  | 2 +-
 tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py | 3 ++-
 4 files changed, 5 insertions(+), 4 deletions(-)

diff --git a/superset/mcp_service/chart/tool/list_charts.py b/superset/mcp_service/chart/tool/list_charts.py
index 66c6909f33f..bfb2c564540 100644
--- a/superset/mcp_service/chart/tool/list_charts.py
+++ b/superset/mcp_service/chart/tool/list_charts.py
@@ -97,7 +97,7 @@ async def list_charts(
 
         # Correct usage
         list_charts(request={"search": "revenue", "page": 1, "page_size": 10})
-        list_charts(request={"filters": [{"col": "slice_name", "opr": "ct", "value": "sales"}]})
+        list_charts(request={"filters": [{"col": "slice_name", "opr": "sw", "value": "sales"}]})
         list_charts()  # no arguments returns first page with defaults
 
         # Wrong — causes pydantic validation errors
diff --git a/superset/mcp_service/dashboard/tool/list_dashboards.py b/superset/mcp_service/dashboard/tool/list_dashboards.py
index ed856dff47d..8c479df2753 100644
--- a/superset/mcp_service/dashboard/tool/list_dashboards.py
+++ b/superset/mcp_service/dashboard/tool/list_dashboards.py
@@ -91,7 +91,7 @@ async def list_dashboards(
 
         # Correct usage
         list_dashboards(request={"search": "sales", "page": 1, "page_size": 10})
-        list_dashboards(request={"filters": [{"col": "dashboard_title", "opr": "ct", "value": "exec"}]})
+        list_dashboards(request={"filters": [{"col": "dashboard_title", "opr": "sw", "value": "exec"}]})
         list_dashboards()  # no arguments returns first page with defaults
 
         # Wrong — causes pydantic validation errors
diff --git a/superset/mcp_service/dataset/tool/list_datasets.py b/superset/mcp_service/dataset/tool/list_datasets.py
index 9679f658316..099c15231ea 100644
--- a/superset/mcp_service/dataset/tool/list_datasets.py
+++ b/superset/mcp_service/dataset/tool/list_datasets.py
@@ -102,7 +102,7 @@ async def list_datasets(
 
         # Correct usage
         list_datasets(request={"search": "sales", "page": 1, "page_size": 10})
-        list_datasets(request={"filters": [{"col": "table_name", "opr": "ct", "value": "orders"}]})
+        list_datasets(request={"filters": [{"col": "table_name", "opr": "sw", "value": "orders"}]})
         list_datasets()  # no arguments returns first page with defaults
 
         # Wrong — causes pydantic validation errors
diff --git a/tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py b/tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py
index 64d31eb76e1..a2b4e1e5f98 100644
--- a/tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py
+++ b/tests/unit_tests/mcp_service/dashboard/tool/test_dashboard_tools.py
@@ -1349,7 +1349,8 @@ class TestDashboardSortableColumns:
 
         # Check list_dashboards docstring for sortable columns documentation
         assert list_dashboards.__doc__ is not None
-        assert "Sortable columns for order_column:" in list_dashboards.__doc__
+        assert "Sortable columns for" in list_dashboards.__doc__
+        assert "order_column" in list_dashboards.__doc__
         for col in SORTABLE_DASHBOARD_COLUMNS:
             assert col in list_dashboards.__doc__