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


##########
superset/mcp_service/dataset/tool/create_dataset.py:
##########
@@ -0,0 +1,143 @@
+# 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.
+
+"""
+Create dataset FastMCP tool
+
+Registers a physical table as a Superset dataset against an existing
+database connection — the programmatic equivalent of Data → Datasets → 
+Dataset.
+Returns the same DatasetInfo shape as get_dataset_info so the caller can feed
+the resulting dataset_id directly into generate_chart.
+"""
+
+import logging
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.dataset.schemas import (
+    CreateDatasetRequest,
+    DatasetError,
+    DatasetInfo,
+    serialize_dataset_object,
+)
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="Dataset",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Register physical table as dataset",
+        readOnlyHint=False,
+        destructiveHint=False,
+    ),
+)
+async def create_dataset(

Review Comment:
   Thanks for the Bito review!
   
   Regarding the additional suggestions in the run summary:
   
   **Function too many return statements / complexity**: Addressed in 
b44e9b9065 — extracted _classify_invalid_error() helper to reduce cyclomatic 
complexity from 12 to within the 10 limit.
   
   **Missing DatasetInvalidError test coverage**: Added 
test_create_dataset_invalid_error in b44e9b9065 covering the generic 
ValidationError case.
   
   **_make_mock_dataset duplication**: Intentional — test_create_dataset.py is 
a new separate test file for the create_dataset tool, with its own focused 
fixture. Merging with test_dataset_tools.py's create_mock_dataset would create 
an import dependency between test files. Keeping them separate is the right 
tradeoff.
   
   **Bito primary actionable suggestion (missing 
@requires_data_model_metadata_access)**: Already addressed by aminghadersohi 
above — create_dataset is a write/mutation tool, not a metadata-read tool, so 
that decorator does not apply. Write access is gated via 
class_permission_name="Dataset" + method_permission_name="write" on the @tool 
decorator.
   



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