codeant-ai-for-open-source[bot] commented on code in PR #41497: URL: https://github.com/apache/superset/pull/41497#discussion_r3545808527
########## superset/mcp_service/theme/tool/create_theme.py: ########## @@ -0,0 +1,157 @@ +# 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.mcp_service.utils.sanitization import sanitize_for_llm_context +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 flag inferable local variables in Python for explicit type annotations; keep following the repository convention unless annotation adds clarity or is required. **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/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__) Review Comment: ✅ **Customized review instruction saved!** **Instruction:** > Do not flag module-level logger declarations without explicit type annotations in mcp_service modules; keep `logger = logging.getLogger(__name__)` to match the repository 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]
