Copilot commented on code in PR #40352: URL: https://github.com/apache/superset/pull/40352#discussion_r3285747717
########## superset/mcp_service/annotation_layer/schemas.py: ########## @@ -0,0 +1,50 @@ +# 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. + +""" +Pydantic schemas for annotation layer MCP tools +""" + +from __future__ import annotations + +from pydantic import BaseModel, ConfigDict, Field, field_validator + + +class CreateAnnotationLayerRequest(BaseModel): + model_config = ConfigDict(populate_by_name=True) + + name: str = Field(..., description="Unique name for the annotation layer") + descr: str | None = Field( + None, description="Optional description of the annotation layer" + ) Review Comment: CreateAnnotationLayerRequest doesn't enforce the same name length constraints as the existing AnnotationLayer API/model (name is String(250) and the REST schema validates Length(1, 250)). Without a max length check here, long names can hit DB-level errors and bubble up as an unhandled exception in the tool. Consider adding min_length/max_length (or a validator) to cap name at 250 characters (after stripping). ########## superset/mcp_service/annotation_layer/tool/create_annotation_layer.py: ########## @@ -0,0 +1,105 @@ +# 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. + +import logging +from typing import Any + +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 ( + CreateAnnotationLayerRequest, + CreateAnnotationLayerResponse, +) + +logger = logging.getLogger(__name__) + + +@tool( + tags=["mutate"], + class_permission_name="Annotation", + method_permission_name="write", + annotations=ToolAnnotations( + title="Create annotation layer", + readOnlyHint=False, + destructiveHint=False, + ), +) +async def create_annotation_layer( + request: CreateAnnotationLayerRequest, ctx: Context +) -> CreateAnnotationLayerResponse: + """Create a named annotation layer in Superset. Review Comment: This PR introduces a new MCP mutation tool, but there are no unit tests covering its request validation and tool behavior (success path, uniqueness/validation error, create-failed error), unlike existing MCP mutation tools (e.g. create_virtual_dataset tests under tests/unit_tests/mcp_service/dataset/tool/). Adding similar tests would help prevent regressions and ensure the tool contract is stable. -- 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]
