Copilot commented on code in PR #40077:
URL: https://github.com/apache/superset/pull/40077#discussion_r3230436923


##########
superset/mcp_service/chart/tool/update_chart_preview.py:
##########
@@ -229,9 +234,35 @@ def update_chart_preview(  # noqa: C901
             high_contrast_available=False,
         )
 
-        # Note: Screenshot-based previews are not supported.
-        # Use the explore_url to view the chart interactively.
         previews: Dict[str, Any] = {}
+        if request.generate_preview:
+            try:
+                with event_logger.log_context(
+                    action="mcp.update_chart_preview.preview"
+                ):
+                    for format_type in request.preview_formats:
+                        # URL previews are represented by 
explore_url/chart.url.
+                        # Screenshot-based previews are not supported.
+                        if format_type not in 
SUPPORTED_FORM_DATA_PREVIEW_FORMATS:
+                            continue
+
+                        preview_result = generate_preview_from_form_data(
+                            form_data=new_form_data,
+                            dataset_id=dataset.id,
+                            preview_format=format_type,
+                        )
+
+                        if isinstance(preview_result, ChartError):
+                            logger.warning(
+                                "Preview '%s' failed: %s",
+                                format_type,
+                                preview_result.error,
+                            )
+                        else:
+                            previews[format_type] = preview_result

Review Comment:
   `generate_preview_from_form_data` returns Pydantic preview models (e.g. 
`TablePreview`, `ASCIIPreview`). Storing them directly in the plain dict 
response (`previews[format_type] = preview_result`) can break/alter JSON 
serialization depending on how FastMCP encodes nested objects, and is 
inconsistent with other response-building paths that explicitly serialize 
models. Consider converting non-error preview results to plain data (e.g. via 
`model_dump()` when available) before putting them in `previews`.
   



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