codeant-ai-for-open-source[bot] commented on code in PR #40342: URL: https://github.com/apache/superset/pull/40342#discussion_r3311936065
########## superset/mcp_service/annotation_layer/tool/list_annotation_layers.py: ########## @@ -0,0 +1,123 @@ +# 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 annotation layers FastMCP tool.""" + +import logging + +from fastmcp import Context +from superset_core.mcp.decorators import tool, ToolAnnotations + +from superset.extensions import event_logger +from superset.mcp_service.annotation_layer.schemas import ( + AnnotationLayerError, + AnnotationLayerFilter, + AnnotationLayerInfo, + AnnotationLayerList, + DEFAULT_LAYER_COLUMNS, + ListAnnotationLayersRequest, + serialize_annotation_layer, +) +from superset.mcp_service.mcp_core import ModelListCore + +logger = logging.getLogger(__name__) + +_DEFAULT_REQUEST = ListAnnotationLayersRequest() + +_ALL_LAYER_COLUMNS = ["id", "name", "descr", "changed_on", "created_on"] +_SORTABLE_LAYER_COLUMNS = ["id", "name", "changed_on", "created_on"] + + +@tool( + tags=["core"], + class_permission_name="Annotation", + annotations=ToolAnnotations( + title="List annotation layers", + readOnlyHint=True, + destructiveHint=False, + ), +) +async def list_annotation_layers( + request: ListAnnotationLayersRequest | None = None, + ctx: Context | None = None, +) -> AnnotationLayerList | AnnotationLayerError: + """List annotation layers with filtering, search, and pagination. + + Returns annotation layer metadata including name and description. + + Sortable columns for order_column: id, name, changed_on, created_on + """ + if ctx is None: + raise RuntimeError("FastMCP context is required for list_annotation_layers") + + request = request or _DEFAULT_REQUEST.model_copy(deep=True) + + await ctx.info( + "Listing annotation layers: page=%s, page_size=%s, search=%s" + % (request.page, request.page_size, request.search) + ) + + try: + from superset.daos.annotation_layer import AnnotationLayerDAO + + def _serialize( + obj: object, cols: list[str] | None + ) -> AnnotationLayerInfo | None: + return serialize_annotation_layer(obj) Review Comment: **Suggestion:** `select_columns` is not actually honored in item serialization because the serializer ignores the `cols` argument and always builds a full `AnnotationLayerInfo`. This breaks the column-selection contract (clients requesting a narrow projection still receive all fields, often as nulls) and can cause incorrect downstream behavior for callers that rely on selected fields only. [incomplete implementation] <details> <summary><b>Severity Level:</b> Major ⚠️</summary> ```mdx - ⚠️ Annotation layer MCP tool ignores select_columns response filtering. - ⚠️ Clients see unrequested fields, sometimes null-populated. - ⚠️ Inconsistent projection versus chart/dataset MCP list tools. ``` </details> <details> <summary><b>Steps of Reproduction ✅ </b></summary> ```mdx 1. Start the MCP server used in tests via `mcp` from `superset.mcp_service.app` (imported and exposed in `tests/unit_tests/mcp_service/annotation_layer/tool/test_annotation_layer_tools.py:31` as the `mcp_server` fixture at lines 77-81). 2. Patch `AnnotationLayerDAO.list` as done in `test_list_annotation_layers_basic` (`tests/unit_tests/mcp_service/annotation_layer/tool/test_annotation_layer_tools.py:139-147`) to return a layer object with all fields set (e.g., `make_layer()` from lines 43-52). 3. Using `fastmcp.Client` as in `test_list_annotation_layers_basic`, call the `list_annotation_layers` tool (`list_annotation_layers.py:54-57`) with a request that narrows `select_columns`, for example `{"request": {"select_columns": ["id"], "page": 1, "page_size": 10}}`; this is passed into `ModelListCore.run_tool` at `list_annotation_layers.py:96-105`, which computes `columns_requested=["id"]` and `columns_to_load=["id"]` (`mcp_core.py:100-112, 191-193`). 4. Inspect the JSON response body parsed with `superset.utils.json` (as in `test_list_annotation_layers_basic`, lines 152-157) and observe that each `annotation_layers` entry contains all fields from `AnnotationLayerInfo` (`schemas.py:72-79`), including `name`, `descr`, `changed_on`, and `created_on`, even though only `"id"` was requested. This happens because `_serialize` in `list_annotation_layers.py:77-80` ignores its `cols` argument and always calls `serialize_annotation_layer(obj)`, which unconditionally populates every field (`schemas.py:30-39`), and `AnnotationLayerInfo` has no `_filter_fields_by_context` serializer like charts/dashboards/datasets, so `select_columns` is not honored in the response shape. ``` </details> [Fix in Cursor](https://app.codeant.ai/fix-in-ide?tool=cursor&prompt_id=192b4154e4ba4bb1b26a76593277a973&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) | [Fix in VSCode Claude](https://app.codeant.ai/fix-in-ide?tool=vscode-claude&prompt_id=192b4154e4ba4bb1b26a76593277a973&service=github&base_url=https%3A%2F%2Fgithub.com&org=apache&repo=apache%2Fsuperset) *(Use Cmd/Ctrl + Click for best experience)* <details> <summary><b>Prompt for AI Agent 🤖 </b></summary> ```mdx This is a comment left during a code review. **Path:** superset/mcp_service/annotation_layer/tool/list_annotation_layers.py **Line:** 77:80 **Comment:** *Incomplete Implementation: `select_columns` is not actually honored in item serialization because the serializer ignores the `cols` argument and always builds a full `AnnotationLayerInfo`. This breaks the column-selection contract (clients requesting a narrow projection still receive all fields, often as nulls) and can cause incorrect downstream behavior for callers that rely on selected fields only. Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise. Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix ``` </details> <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40342&comment_hash=616c997de8ebd9dbb8496ca07a93c820108419763aadfcd764bb1d69ceb1d4ec&reaction=like'>👍</a> | <a href='https://app.codeant.ai/feedback?pr_url=https%3A%2F%2Fgithub.com%2Fapache%2Fsuperset%2Fpull%2F40342&comment_hash=616c997de8ebd9dbb8496ca07a93c820108419763aadfcd764bb1d69ceb1d4ec&reaction=dislike'>👎</a> -- 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]
