bito-code-review[bot] commented on code in PR #40301:
URL: https://github.com/apache/superset/pull/40301#discussion_r3287153289


##########
superset/mcp_service/saved_query/tool/list_saved_queries.py:
##########
@@ -0,0 +1,159 @@
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements.  See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership.  The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License.  You may obtain a copy of the License at
+#
+#   http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied.  See the License for the
+# specific language governing permissions and limitations
+# under the License.
+
+"""
+List saved queries FastMCP tool
+
+This module contains the FastMCP tool for listing saved SQL queries
+with filtering, search, and pagination.
+"""
+
+import logging
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.mcp_core import ModelListCore
+from superset.mcp_service.saved_query.schemas import (
+    ALL_SAVED_QUERY_COLUMNS,
+    DEFAULT_SAVED_QUERY_COLUMNS,
+    ListSavedQueriesRequest,
+    SavedQueryError,
+    SavedQueryFilter,
+    SavedQueryInfo,
+    SavedQueryList,
+    serialize_saved_query_object,
+    SORTABLE_SAVED_QUERY_COLUMNS,
+)
+
+logger = logging.getLogger(__name__)
+
+_DEFAULT_LIST_SAVED_QUERIES_REQUEST = ListSavedQueriesRequest()
+
+
+@tool(
+    tags=["core"],
+    class_permission_name="SavedQuery",
+    annotations=ToolAnnotations(
+        title="List saved queries",
+        readOnlyHint=True,
+        destructiveHint=False,
+    ),
+)
+async def list_saved_queries(
+    request: ListSavedQueriesRequest | None = None,
+    ctx: Context | None = None,
+) -> SavedQueryList | SavedQueryError:
+    """List saved SQL queries with filtering and search.
+
+    Returns saved queries owned by the current user, including label, SQL,
+    database ID, and schema.
+
+    Sortable columns for order_column: id, label, db_id, schema,
+    changed_on, created_on
+    """
+    if ctx is None:
+        raise RuntimeError("FastMCP context is required for 
list_saved_queries")
+
+    request = request or 
_DEFAULT_LIST_SAVED_QUERIES_REQUEST.model_copy(deep=True)
+
+    await ctx.info(
+        "Listing saved queries: page=%s, page_size=%s, search=%s"
+        % (
+            request.page,
+            request.page_size,
+            request.search,
+        )
+    )
+    await ctx.debug(
+        "Saved query listing parameters: filters=%s, order_column=%s, "
+        "order_direction=%s, select_columns=%s"
+        % (
+            request.filters,
+            request.order_column,
+            request.order_direction,
+            request.select_columns,
+        )
+    )
+
+    try:
+        from superset.daos.query import SavedQueryDAO
+
+        def _serialize_saved_query(
+            obj: object, cols: list[str] | None
+        ) -> SavedQueryInfo | None:
+            return serialize_saved_query_object(obj)
+
+        list_tool = ModelListCore(
+            dao_class=SavedQueryDAO,
+            output_schema=SavedQueryInfo,
+            item_serializer=_serialize_saved_query,
+            filter_type=SavedQueryFilter,
+            default_columns=DEFAULT_SAVED_QUERY_COLUMNS,
+            search_columns=["label", "description", "sql"],
+            list_field_name="saved_queries",
+            output_list_schema=SavedQueryList,
+            all_columns=ALL_SAVED_QUERY_COLUMNS,
+            sortable_columns=SORTABLE_SAVED_QUERY_COLUMNS,
+            logger=logger,
+        )
+
+        with event_logger.log_context(action="mcp.list_saved_queries.query"):
+            result = list_tool.run_tool(
+                filters=request.filters,
+                search=request.search,
+                select_columns=request.select_columns,
+                order_column=request.order_column,
+                order_direction=request.order_direction,
+                page=max(request.page - 1, 0),
+                page_size=request.page_size,
+            )

Review Comment:
   <div>
   
   
   <div id="suggestion">
   <div id="issue"><b>Missing ownership filter params</b></div>
   <div id="fix">
   
   Add `created_by_me` and `owned_by_me` parameters to the 
`list_tool.run_tool()` call and extend the ListSavedQueriesRequest schema to 
support these flags, enabling ownership-based filtering.
   </div>
   
   
   </div>
   
   
   
   
   <small><i>Code Review Run #a1ef76</i></small>
   </div>
   
   ---
   Should Bito avoid suggestions like this for future reviews? (<a 
href=https://alpha.bito.ai/home/ai-agents/review-rules>Manage Rules</a>)
   - [ ] Yes, avoid them



-- 
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]

Reply via email to