aminghadersohi commented on code in PR #40352: URL: https://github.com/apache/superset/pull/40352#discussion_r3326688444
########## 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: Fixed in the prior commit — `CreateAnnotationLayerRequest.name` now has `min_length=1, max_length=250`, matching the REST API / model constraint. ########## 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: Unit tests were added in the same commit that introduced schema constraints (`test_create_annotation_layer.py`). They cover the success path, uniqueness/validation error, and create-failed error, mirroring the pattern used for other MCP mutation tools. -- 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]
