From a3927ba66ce100eddca5486f83b1d9988406d4dc Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 10 Feb 2026 21:57:07 -0500 Subject: [PATCH] [FIX] Third time the charm --- custom_components/mcp_bridge/__init__.py | 31 +++++++++--------------- 1 file changed, 12 insertions(+), 19 deletions(-) diff --git a/custom_components/mcp_bridge/__init__.py b/custom_components/mcp_bridge/__init__.py index 1c402e0..cb02fd0 100644 --- a/custom_components/mcp_bridge/__init__.py +++ b/custom_components/mcp_bridge/__init__.py @@ -67,8 +67,13 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: async def get_exposed_scripts(call: ServiceCall) -> dict[str, Any]: entity_reg = er.async_get(hass) + script_comp = hass.data.get("script") + scripts: list[dict[str, Any]] = [] + if not script_comp: + return {"scripts": [], "count": 0} + for entity_id in hass.states.async_entity_ids("script"): entity_entry = entity_reg.async_get(entity_id) if not entity_entry: @@ -77,30 +82,17 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: if MCP_ACCESSIBLE_LABEL not in entity_entry.labels: continue - state = hass.states.get(entity_id) - if not state: + script_obj = script_comp.scripts.get(entity_id) + if not script_obj: continue - # Get script name from entity_id - script_name = entity_id.split(".", 1)[1] - - # Get service description which includes field definitions - fields = {} - try: - service_desc = hass.services.async_describe_service("script", script_name) - if service_desc and "fields" in service_desc: - fields = service_desc["fields"] - except Exception as e: - _LOGGER.debug(f"Could not get service description for {entity_id}: {e}") - scripts.append( { "entity_id": entity_id, - "friendly_name": state.attributes.get( - "friendly_name", entity_id - ), - "description": state.attributes.get("description", ""), - "fields": fields, + "friendly_name": script_obj.name or entity_id, + "description": script_obj.description or "", + "fields": script_obj.fields or {}, + "mode": script_obj.mode, } ) @@ -109,6 +101,7 @@ async def async_setup(hass: HomeAssistant, config: ConfigType) -> bool: "count": len(scripts), } + async def get_entity_metadata(call: ServiceCall) -> dict[str, Any]: entity_id = call.data.get(CONF_ENTITY_ID) if not entity_id: