Skip to content

Commit e73cd17

Browse files
committed
Use TABULAR/PLOTLY_FIGURE PropRole.matches() in formatters
1 parent bb9b4c7 commit e73cd17

3 files changed

Lines changed: 6 additions & 11 deletions

File tree

dash/mcp/primitives/tools/prop_roles.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def _compute_dropdown_value_schema(param: MCPInput) -> dict[str, Any]:
100100
description="Returns formatted text",
101101
)
102102

103-
GENERIC_FIGURE = PropRole(
103+
PLOTLY_FIGURE = PropRole(
104104
identifiers={(ANY_COMPONENT, "figure")},
105105
description="Returns chart/visualization data",
106106
input_schema={

dash/mcp/primitives/tools/results/result_dataframe.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,11 @@
1313

1414
from dash.mcp.types import MCPOutput
1515

16+
from ..prop_roles import TABULAR
1617
from .base import ResultFormatter
1718

1819
MAX_ROWS = 50
1920

20-
_TABULAR_PROPS = {
21-
("DataTable", "data"),
22-
("AgGrid", "rowData"),
23-
}
24-
2521

2622
def _to_markdown_table(rows: list[dict], max_rows: int = MAX_ROWS) -> str:
2723
"""Render a list of row dicts as a markdown table."""
@@ -54,8 +50,7 @@ class DataFrameResult(ResultFormatter):
5450
def format(
5551
cls, output: MCPOutput, returned_output_value: Any
5652
) -> list[TextContent | ImageContent]:
57-
key = (output.get("component_type"), output.get("property"))
58-
if key not in _TABULAR_PROPS:
53+
if not TABULAR.matches(output.get("component_type"), output.get("property")):
5954
return []
6055
if (
6156
not isinstance(returned_output_value, list)

dash/mcp/primitives/tools/results/result_plotly_figure.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111

1212
from dash.mcp.types import MCPOutput
1313

14+
from ..prop_roles import PLOTLY_FIGURE
1415
from .base import ResultFormatter
1516

1617
logger = logging.getLogger(__name__)
@@ -45,9 +46,8 @@ class PlotlyFigureResult(ResultFormatter):
4546
def format(
4647
cls, output: MCPOutput, returned_output_value: Any
4748
) -> list[TextContent | ImageContent]:
48-
if (
49-
output.get("component_type") != "Graph"
50-
or output.get("property") != "figure"
49+
if not PLOTLY_FIGURE.matches(
50+
output.get("component_type"), output.get("property")
5151
):
5252
return []
5353
if not isinstance(returned_output_value, dict):

0 commit comments

Comments
 (0)