You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@superset.apache.org by "aminghadersohi (via GitHub)" <gi...@apache.org> on 2026/05/30 04:41:21 UTC

Re: [PR] feat(mcp): add create_user and update_user tools [superset]

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


##########
superset/mcp_service/user/tool/create_user.py:
##########
@@ -0,0 +1,114 @@
+# 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 fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.user.schemas import CreateUserRequest, CreateUserResponse
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="User",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Create a new user account",
+        readOnlyHint=False,
+        destructiveHint=False,
+    ),
+)
+async def create_user(request: CreateUserRequest, ctx: Context) -> CreateUserResponse:
+    """Create a new Superset user account. Admin access is required.
+
+    Use this tool to provision a new user with a username, name, email,
+    password, and one or more roles. After creation, the user can log in

Review Comment:
   Tests have been added in `tests/unit_tests/mcp_service/user/tool/test_user_tools.py` covering all the branches mentioned: missing roles, `add_user` failure, successful creation with sensitive field omission checks, and equivalent tests for `update_user`.



##########
superset/mcp_service/user/schemas.py:
##########
@@ -0,0 +1,102 @@
+# 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 user-related MCP tools."""
+
+from __future__ import annotations
+
+from pydantic import BaseModel, ConfigDict, EmailStr, Field, field_validator
+
+
+class CreateUserRequest(BaseModel):
+    """Request schema for create_user."""
+
+    model_config = ConfigDict(populate_by_name=True)
+
+    username: str = Field(
+        ...,
+        min_length=1,
+        max_length=64,
+        description="Unique username for the new account.",
+    )
+    first_name: str = Field(
+        ...,
+        min_length=1,
+        max_length=64,
+        description="First name of the user.",
+    )
+    last_name: str = Field(
+        ...,
+        min_length=1,
+        max_length=64,
+        description="Last name of the user.",
+    )
+    email: EmailStr = Field(
+        ...,
+        description="Email address for the user account.",
+    )
+    password: str = Field(
+        ...,
+        min_length=1,
+        description="Plain-text password; will be hashed before storage.",
+    )

Review Comment:
   The `_sanitize_params` function in `middleware.py` already recurses into nested dicts (`else _sanitize_params(v) if isinstance(v, dict) else v`), so `request.password` is redacted even when the `request` object is a nested dict in the logged params. The `password` key is in `_SENSITIVE_PARAM_KEYS` and will be replaced with `[REDACTED]` at all nesting levels.



-- 
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: notifications-unsubscribe@superset.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@superset.apache.org
For additional commands, e-mail: notifications-help@superset.apache.org