Skip to content

Commit f1b6cc2

Browse files
committed
Code review feedback
1 parent cf53991 commit f1b6cc2

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

dash/mcp/primitives/tools/tool_get_dash_component.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,13 +61,16 @@ def list_tools(cls) -> list[Tool]:
6161
def call_tool(cls, tool_name: str, arguments: dict[str, Any]) -> CallToolResult:
6262
comp_id = arguments.get("component_id", "")
6363
if not comp_id:
64-
raise ValueError("component_id is required")
64+
return CallToolResult(
65+
content=[TextContent(type="text", text="component_id is required")],
66+
isError=True,
67+
)
6568

6669
prop_filter = arguments.get("property", "")
6770
component = find_component(comp_id)
71+
callback_map = get_app().mcp_callback_map
6872

6973
if component is None:
70-
callback_map = get_app().mcp_callback_map
7174
rendering_tools = [
7275
cb.tool_name
7376
for cb in callback_map
@@ -84,29 +87,24 @@ def call_tool(cls, tool_name: str, arguments: dict[str, Any]) -> CallToolResult:
8487
isError=True,
8588
)
8689

87-
callback_map = get_app().mcp_callback_map
88-
8990
properties: dict[str, ComponentPropertyInfo] = {}
9091
for prop_name in getattr(component, "_prop_names", []):
9192
if prop_filter and prop_name != prop_filter:
9293
continue
9394

94-
value = callback_map.get_initial_value(f"{comp_id}.{prop_name}")
95+
id_and_prop = f"{comp_id}.{prop_name}"
96+
value = callback_map.get_initial_value(id_and_prop)
9597
if value is None:
9698
value = getattr(component, prop_name, None)
9799
if value is None:
98100
continue
99101

100-
modified_by: list[str] = []
101-
input_to: list[str] = []
102-
id_and_prop = f"{comp_id}.{prop_name}"
103-
for cb in callback_map:
104-
for out in cb.outputs:
105-
if out["id_and_prop"] == id_and_prop:
106-
modified_by.append(cb.tool_name)
107-
for inp in cb.inputs:
108-
if inp["id_and_prop"] == id_and_prop:
109-
input_to.append(cb.tool_name)
102+
modified_by = [
103+
cb.tool_name for cb in callback_map.outputs_by_prop.get(id_and_prop, [])
104+
]
105+
input_to = [
106+
cb.tool_name for cb in callback_map.inputs_by_prop.get(id_and_prop, [])
107+
]
110108

111109
properties[prop_name] = ComponentPropertyInfo(
112110
initial_value=value,

0 commit comments

Comments
 (0)