From 6b0e63568a293f047239504407819ad446b9ff61 Mon Sep 17 00:00:00 2001 From: Franck Nijhof Date: Sat, 29 Aug 2026 13:17:04 +0200 Subject: [PATCH] Ask MCP authorization servers for a refresh token (#180604) --- homeassistant/components/mcp/config_flow.py | 6 +++++- tests/components/mcp/test_config_flow.py | 4 +++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/homeassistant/components/mcp/config_flow.py b/homeassistant/components/mcp/config_flow.py index d0b0747494e6..8d01a016d487 100644 --- a/homeassistant/components/mcp/config_flow.py +++ b/homeassistant/components/mcp/config_flow.py @@ -315,7 +315,11 @@ class ModelContextProtocolConfigFlow(AbstractOAuth2FlowHandler, domain=DOMAIN): @override def extra_authorize_data(self) -> dict: """Extra data that needs to be appended to the authorize url.""" - data = {} + data = { + # Add params to ensure we get back a refresh token + "access_type": "offline", + "prompt": "consent", + } if self.data and (scopes := self.data[CONF_SCOPE]) is not None: data[CONF_SCOPE] = " ".join(scopes) data.update(super().extra_authorize_data) diff --git a/tests/components/mcp/test_config_flow.py b/tests/components/mcp/test_config_flow.py index 17303fe0bf7a..048593e258ec 100644 --- a/tests/components/mcp/test_config_flow.py +++ b/tests/components/mcp/test_config_flow.py @@ -341,7 +341,9 @@ async def perform_oauth_flow( assert result["url"] == ( f"{authorize_url}?response_type=code&client_id={CLIENT_ID}" f"&redirect_uri={OAUTH_CALLBACK_URL}" - f"&state={state}{scope_param}" + f"&state={state}" + # Asked for so the server hands back a refresh token + f"&access_type=offline&prompt=consent{scope_param}" ) client = await hass_client_no_auth()