codeant-ai-for-open-source[bot] commented on code in PR #40328:
URL: https://github.com/apache/superset/pull/40328#discussion_r3304569283


##########
superset/mcp_service/dashboard/tool/get_dashboard_layout.py:
##########
@@ -0,0 +1,122 @@
+# 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.
+
+"""
+Get dashboard layout FastMCP tool
+
+Companion to get_dashboard_info: returns the parsed dashboard layout
+(tabs and chart positions) extracted from position_json. Use this
+when get_dashboard_info's omitted_fields hint indicates position_json
+was stripped and structured layout data is needed for analysis.
+"""
+
+import logging
+from datetime import datetime, timezone
+
+from fastmcp import Context
+from sqlalchemy.orm import subqueryload
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.dashboard.schemas import (
+    dashboard_layout_serializer,
+    DashboardError,
+    DashboardLayout,
+    GetDashboardLayoutRequest,
+)
+from superset.mcp_service.mcp_core import ModelGetInfoCore
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["discovery"],
+    class_permission_name="Dashboard",
+    annotations=ToolAnnotations(
+        title="Get dashboard layout",
+        readOnlyHint=True,
+        destructiveHint=False,
+    ),
+)
+async def get_dashboard_layout(
+    request: GetDashboardLayoutRequest, ctx: Context
+) -> DashboardLayout | DashboardError:
+    """
+    Get parsed dashboard layout by ID, UUID, or slug.
+
+    Returns the tabs and chart positions extracted from the dashboard's
+    position_json. get_dashboard_info omits position_json to keep responses
+    small; call this tool when you need the structured layout (e.g. to
+    explain which charts live under which tab, or to locate a chart by
+    its parent tab).
+
+    Example usage:
+    ```json
+    {
+        "identifier": 123
+    }
+    ```
+    """
+    await ctx.info("Retrieving dashboard layout: identifier=%s" % 
(request.identifier,))
+
+    try:
+        from superset.daos.dashboard import DashboardDAO
+        from superset.models.dashboard import Dashboard
+
+        eager_options = [subqueryload(Dashboard.slices)]

Review Comment:
   Yes — this looks like a valid performance issue.
   
   `get_dashboard_layout` only serializes:
   
   - `id`
   - `dashboard_title`
   - `uuid`
   - `position_json`
   
   So `subqueryload(Dashboard.slices)` is unused here and adds avoidable 
query/memory overhead, especially for large dashboards.
   
   ### Suggested fix
   Remove the eager load and stop passing `query_options` for this tool path:
   
   ```python
   # before
   eager_options = [subqueryload(Dashboard.slices)]
   ...
   query_options=eager_options,
   ```
   
   If `ModelGetInfoCore` doesn’t require it for any other behavior, the tool 
can simply rely on the default lookup query.
   
   ### Why this is worth changing
   This keeps `get_dashboard_layout` aligned with its actual payload shape and 
preserves the “lightweight by default” design of the MCP tools. The current 
eager load doesn’t seem necessary for correctness, so dropping it is the 
cleaner and cheaper path.
   
   If you want, I can also review the rest of the PR comments and check whether 
there are any other small fixes worth applying.



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