aminghadersohi commented on code in PR #40352:
URL: https://github.com/apache/superset/pull/40352#discussion_r3326689467


##########
superset/mcp_service/annotation_layer/tool/update_annotation_layer.py:
##########
@@ -0,0 +1,118 @@
+# 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 (
+    UpdateAnnotationLayerRequest,
+    UpdateAnnotationLayerResponse,
+)
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="Annotation",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Update annotation layer",
+        readOnlyHint=False,
+        destructiveHint=False,
+    ),
+)
+async def update_annotation_layer(
+    request: UpdateAnnotationLayerRequest, ctx: Context
+) -> UpdateAnnotationLayerResponse:
+    """Update an existing annotation layer's name or description.
+
+    Use this tool to rename an annotation layer or update its description.
+    At least one of ``name`` or ``descr`` must be provided.
+
+    Workflow:
+    1. Call this tool with the layer ``id`` and the fields to change
+    2. The updated layer ``id`` and new values are returned on success
+    """
+    await ctx.info(
+        "Updating annotation layer: id=%s, name=%r" % (request.id, 
request.name)
+    )
+
+    try:
+        from superset.commands.annotation_layer.exceptions import (
+            AnnotationLayerInvalidError,
+            AnnotationLayerNotFoundError,
+            AnnotationLayerUpdateFailedError,
+        )
+        from superset.commands.annotation_layer.update import (
+            UpdateAnnotationLayerCommand,
+        )
+
+        properties: dict[str, Any] = {}
+        if request.name is not None:
+            properties["name"] = request.name
+        if request.descr is not None:
+            properties["descr"] = request.descr
+
+        with 
event_logger.log_context(action="mcp.update_annotation_layer.update"):
+            layer = UpdateAnnotationLayerCommand(request.id, properties).run()

Review Comment:
   Fixed. A `@model_validator(mode="after")` has been added to 
`UpdateAnnotationLayerRequest` that raises `ValueError` when both `name` and 
`descr` are `None`. Pydantic rejects the request before the tool runs, so an 
id-only call now fails validation instead of silently succeeding. A 
corresponding schema test 
(`test_update_annotation_layer_request_no_fields_fails`) is included.



##########
superset/mcp_service/annotation_layer/schemas.py:
##########
@@ -0,0 +1,73 @@
+# 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
+
+
+class CreateAnnotationLayerRequest(BaseModel):
+    model_config = ConfigDict(populate_by_name=True)
+
+    name: str = Field(
+        ...,
+        min_length=1,
+        max_length=250,
+        description="Unique name for the annotation layer",
+    )
+    descr: str | None = Field(
+        None, description="Optional description of the annotation layer"
+    )
+
+
+class CreateAnnotationLayerResponse(BaseModel):
+    id: int | None = Field(
+        None,
+        description="ID of the created annotation layer, or None if failed",
+    )
+    name: str = Field(..., description="Name of the annotation layer")
+    descr: str | None = Field(None, description="Description of the annotation 
layer")
+    error: str | None = Field(None, description="Error message if creation 
failed")
+
+
+class UpdateAnnotationLayerRequest(BaseModel):
+    model_config = ConfigDict(populate_by_name=True)
+
+    id: int = Field(..., description="ID of the annotation layer to update")
+    name: str | None = Field(
+        None,
+        min_length=1,
+        max_length=250,
+        description="New name for the annotation layer",
+    )
+    descr: str | None = Field(
+        None, description="New description for the annotation layer"

Review Comment:
   Fixed via `@model_validator(mode="after")` on `UpdateAnnotationLayerRequest` 
— see reply in the sibling thread. The validator rejects requests where both 
`name` and `descr` are `None` before the tool handler is invoked.



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