codeant-ai-for-open-source[bot] commented on code in PR #41497:
URL: https://github.com/apache/superset/pull/41497#discussion_r3540834134


##########
superset/mcp_service/theme/tool/create_theme.py:
##########
@@ -0,0 +1,151 @@
+# 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 theme FastMCP tool
+
+Creates a reusable Superset theme from an antd design-token configuration.
+The supplied json_data is sanitized and validated with the same routine the
+REST API uses before the theme is persisted via ThemeDAO.
+"""
+
+import logging
+from typing import Any
+
+from fastmcp import Context
+from marshmallow import ValidationError
+from sqlalchemy.exc import SQLAlchemyError
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import db, event_logger
+from superset.mcp_service.theme.schemas import CreateThemeRequest, 
CreateThemeResponse
+from superset.themes.schemas import _sanitize_and_validate_theme_config
+from superset.utils import json
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="Theme",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Create theme",
+        readOnlyHint=False,
+        destructiveHint=False,
+    ),
+)
+async def create_theme(
+    request: CreateThemeRequest, ctx: Context
+) -> CreateThemeResponse:
+    """Create a reusable theme from antd design tokens.
+
+    Accepts a theme name and an antd design-token configuration (json_data),
+    supplied either as a JSON object or a JSON string. The configuration is
+    sanitized and validated the same way the REST API validates themes before
+    the theme is persisted.
+
+    Required fields:
+    - theme_name: Human-readable name for the theme
+    - json_data: The antd design-token configuration (dict or JSON string)
+
+    Example:
+    ```json
+    {
+        "theme_name": "Corporate Blue",
+        "json_data": {"token": {"colorPrimary": "#1d4ed8"}}
+    }
+    ```
+
+    Returns CreateThemeResponse with the new theme's id and uuid on success,
+    or an error response (error_type="ValidationError") if the configuration
+    is invalid.
+    """
+    await ctx.info("Creating theme: theme_name=%s" % (request.theme_name,))
+
+    # Parse json_data into a dict (accept dict or JSON string)
+    config_dict: dict[str, Any]
+    if isinstance(request.json_data, str):
+        try:
+            parsed = json.loads(request.json_data)
+        except (TypeError, json.JSONDecodeError) as exc:
+            await ctx.warning("Invalid JSON in json_data: %s" % (str(exc),))
+            return CreateThemeResponse(
+                success=False,
+                error=f"json_data is not valid JSON: {exc}",
+                error_type="ValidationError",
+            )
+        if not isinstance(parsed, dict):
+            await ctx.warning("json_data did not parse to an object")
+            return CreateThemeResponse(
+                success=False,
+                error="json_data must be a JSON object",
+                error_type="ValidationError",
+            )
+        config_dict = parsed
+    else:
+        config_dict = request.json_data
+
+    # Sanitize and validate using the same routine as the REST API
+    try:
+        sanitized = _sanitize_and_validate_theme_config(config_dict)

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag missing type annotations for Python locals when the type is 
already inferable from the assignment, and do not require annotations for 
module-level logger declarations; this codebase follows that convention.
   
   **Applied to:**
     - `**/*.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset/mcp_service/theme/tool/create_theme.py:
##########
@@ -0,0 +1,151 @@
+# 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 theme FastMCP tool
+
+Creates a reusable Superset theme from an antd design-token configuration.
+The supplied json_data is sanitized and validated with the same routine the
+REST API uses before the theme is persisted via ThemeDAO.
+"""
+
+import logging
+from typing import Any
+
+from fastmcp import Context
+from marshmallow import ValidationError
+from sqlalchemy.exc import SQLAlchemyError
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import db, event_logger
+from superset.mcp_service.theme.schemas import CreateThemeRequest, 
CreateThemeResponse
+from superset.themes.schemas import _sanitize_and_validate_theme_config
+from superset.utils import json
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="Theme",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Create theme",
+        readOnlyHint=False,
+        destructiveHint=False,
+    ),
+)
+async def create_theme(
+    request: CreateThemeRequest, ctx: Context
+) -> CreateThemeResponse:
+    """Create a reusable theme from antd design tokens.
+
+    Accepts a theme name and an antd design-token configuration (json_data),
+    supplied either as a JSON object or a JSON string. The configuration is
+    sanitized and validated the same way the REST API validates themes before
+    the theme is persisted.
+
+    Required fields:
+    - theme_name: Human-readable name for the theme
+    - json_data: The antd design-token configuration (dict or JSON string)
+
+    Example:
+    ```json
+    {
+        "theme_name": "Corporate Blue",
+        "json_data": {"token": {"colorPrimary": "#1d4ed8"}}
+    }
+    ```
+
+    Returns CreateThemeResponse with the new theme's id and uuid on success,
+    or an error response (error_type="ValidationError") if the configuration
+    is invalid.
+    """
+    await ctx.info("Creating theme: theme_name=%s" % (request.theme_name,))
+
+    # Parse json_data into a dict (accept dict or JSON string)
+    config_dict: dict[str, Any]
+    if isinstance(request.json_data, str):
+        try:
+            parsed = json.loads(request.json_data)
+        except (TypeError, json.JSONDecodeError) as exc:
+            await ctx.warning("Invalid JSON in json_data: %s" % (str(exc),))
+            return CreateThemeResponse(
+                success=False,
+                error=f"json_data is not valid JSON: {exc}",
+                error_type="ValidationError",
+            )
+        if not isinstance(parsed, dict):
+            await ctx.warning("json_data did not parse to an object")
+            return CreateThemeResponse(
+                success=False,
+                error="json_data must be a JSON object",
+                error_type="ValidationError",
+            )
+        config_dict = parsed
+    else:
+        config_dict = request.json_data
+
+    # Sanitize and validate using the same routine as the REST API
+    try:
+        sanitized = _sanitize_and_validate_theme_config(config_dict)
+    except ValidationError as exc:
+        await ctx.warning("Theme validation failed: %s" % (exc.messages,))
+        return CreateThemeResponse(
+            success=False,
+            error=str(exc.messages),
+            error_type="ValidationError",
+        )
+
+    try:
+        from superset.daos.theme import ThemeDAO
+
+        with event_logger.log_context(action="mcp.create_theme"):
+            theme = ThemeDAO.create(

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not require explicit type annotations for inferable local variables or 
module-level logger declarations in mcp_service modules; follow the existing 
repo convention there.
   
   **Applied to:**
     - `superset/mcp_service/**`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset/mcp_service/theme/tool/get_theme_info.py:
##########
@@ -0,0 +1,111 @@
+# 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.
+
+"""
+Get theme info FastMCP tool
+
+This module contains the FastMCP tool for getting detailed information
+about a specific theme by numeric ID or UUID.
+"""
+
+import logging
+from datetime import datetime, timezone
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.mcp_core import ModelGetInfoCore
+from superset.mcp_service.theme.schemas import (
+    GetThemeInfoRequest,
+    serialize_theme_object,
+    ThemeError,
+    ThemeInfo,
+)
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["discovery"],
+    class_permission_name="Theme",
+    annotations=ToolAnnotations(
+        title="Get theme info",
+        readOnlyHint=True,
+        destructiveHint=False,
+    ),
+)
+async def get_theme_info(
+    request: GetThemeInfoRequest, ctx: Context
+) -> ThemeInfo | ThemeError:
+    """Get theme metadata by numeric ID or UUID.
+
+    Returns theme details including name, system flags, and the antd
+    design-token configuration (json_data).
+
+    The identifier may be a numeric ID or a UUID string. To find a theme
+    ID, use the list_themes tool first.
+
+    Example usage:
+    ```json
+    {
+        "identifier": 1
+    }
+    ```
+    """
+    await ctx.info(
+        "Retrieving theme information: identifier=%s" % (request.identifier,)
+    )
+
+    try:
+        from superset.daos.theme import ThemeDAO
+
+        with event_logger.log_context(action="mcp.get_theme_info.lookup"):
+            get_tool = ModelGetInfoCore(
+                dao_class=ThemeDAO,
+                output_schema=ThemeInfo,
+                error_schema=ThemeError,
+                serializer=serialize_theme_object,
+                supports_slug=False,
+                logger=logger,
+            )

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag inferable local variables or module-level `logger` 
declarations in `superset/mcp_service`; keep the existing repo convention of 
leaving these unannotated.
   
   **Applied to:**
     - `superset/mcp_service/**`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset/mcp_service/theme/tool/create_theme.py:
##########
@@ -0,0 +1,151 @@
+# 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 theme FastMCP tool
+
+Creates a reusable Superset theme from an antd design-token configuration.
+The supplied json_data is sanitized and validated with the same routine the
+REST API uses before the theme is persisted via ThemeDAO.
+"""
+
+import logging
+from typing import Any
+
+from fastmcp import Context
+from marshmallow import ValidationError
+from sqlalchemy.exc import SQLAlchemyError
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import db, event_logger
+from superset.mcp_service.theme.schemas import CreateThemeRequest, 
CreateThemeResponse
+from superset.themes.schemas import _sanitize_and_validate_theme_config
+from superset.utils import json
+
+logger = logging.getLogger(__name__)
+
+
+@tool(
+    tags=["mutate"],
+    class_permission_name="Theme",
+    method_permission_name="write",
+    annotations=ToolAnnotations(
+        title="Create theme",
+        readOnlyHint=False,
+        destructiveHint=False,
+    ),
+)
+async def create_theme(
+    request: CreateThemeRequest, ctx: Context
+) -> CreateThemeResponse:
+    """Create a reusable theme from antd design tokens.
+
+    Accepts a theme name and an antd design-token configuration (json_data),
+    supplied either as a JSON object or a JSON string. The configuration is
+    sanitized and validated the same way the REST API validates themes before
+    the theme is persisted.
+
+    Required fields:
+    - theme_name: Human-readable name for the theme
+    - json_data: The antd design-token configuration (dict or JSON string)
+
+    Example:
+    ```json
+    {
+        "theme_name": "Corporate Blue",
+        "json_data": {"token": {"colorPrimary": "#1d4ed8"}}
+    }
+    ```
+
+    Returns CreateThemeResponse with the new theme's id and uuid on success,
+    or an error response (error_type="ValidationError") if the configuration
+    is invalid.
+    """
+    await ctx.info("Creating theme: theme_name=%s" % (request.theme_name,))
+
+    # Parse json_data into a dict (accept dict or JSON string)
+    config_dict: dict[str, Any]
+    if isinstance(request.json_data, str):
+        try:
+            parsed = json.loads(request.json_data)

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not require explicit type annotations for locals whose types are 
already inferable from their assignments; keep the existing Python codebase 
convention.
   
   **Applied to:**
     - `**/*.py`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset/mcp_service/theme/tool/get_theme_info.py:
##########
@@ -0,0 +1,111 @@
+# 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.
+
+"""
+Get theme info FastMCP tool
+
+This module contains the FastMCP tool for getting detailed information
+about a specific theme by numeric ID or UUID.
+"""
+
+import logging
+from datetime import datetime, timezone
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.mcp_core import ModelGetInfoCore
+from superset.mcp_service.theme.schemas import (
+    GetThemeInfoRequest,
+    serialize_theme_object,
+    ThemeError,
+    ThemeInfo,
+)
+
+logger = logging.getLogger(__name__)

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not require explicit type annotations for module-level `logger` 
variables in `mcp_service` modules; keep the existing repository convention of 
using `logger = logging.getLogger(__name__)` without annotations.
   
   **Applied to:**
     - `superset/mcp_service/**`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



##########
superset/mcp_service/theme/tool/list_themes.py:
##########
@@ -0,0 +1,163 @@
+# 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.
+
+"""
+List themes FastMCP tool
+
+This module contains the FastMCP tool for listing themes with filtering,
+search, and pagination support.
+"""
+
+import logging
+
+from fastmcp import Context
+from superset_core.mcp.decorators import tool, ToolAnnotations
+
+from superset.extensions import event_logger
+from superset.mcp_service.mcp_core import ModelListCore
+from superset.mcp_service.theme.schemas import (
+    ListThemesRequest,
+    serialize_theme_object,
+    ThemeError,
+    ThemeFilter,
+    ThemeInfo,
+    ThemeList,
+)
+
+logger = logging.getLogger(__name__)
+
+DEFAULT_THEME_COLUMNS = [
+    "id",
+    "theme_name",
+    "is_system_default",
+    "is_system_dark",
+]
+SORTABLE_THEME_COLUMNS = ["id", "theme_name", "changed_on", "created_on"]

Review Comment:
   ✅ **Customized review instruction saved!**
   
   **Instruction:**
   > Do not flag unannotated module-level constants in the mcp_service package; 
mypy inference is acceptable and this matches the existing repo convention.
   
   **Applied to:**
     - `superset/mcp_service/**`
   
   ---
   💡 *To manage or update this instruction, visit: [CodeAnt AI 
Settings](https://app.codeant.ai/org/settings/learnings)*



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