@@ -176,7 +176,7 @@ def __init__(
176176 The factory receives (tool_name, callback_context, **kwargs) and
177177 returns a ProgressFnT or None. This allows callbacks to access
178178 and modify runtime context like session state.
179-
179+
180180 use_isolated_event_loop: When ``True``, each tool call runs in a
181181 dedicated thread with an isolated ``asyncio`` event loop. This avoids
182182 the anyio ``CancelScope`` cross-task error that occurs on Vertex AI
@@ -210,7 +210,7 @@ def __init__(
210210 else None ,
211211 )
212212 if use_isolated_event_loop and not isinstance (
213- mcp_session_manager .connection_params , StreamableHTTPConnectionParams
213+ mcp_session_manager ._connection_params , StreamableHTTPConnectionParams
214214 ):
215215 raise ValueError (
216216 "use_isolated_event_loop=True is only supported with"
@@ -223,11 +223,11 @@ def __init__(
223223 self ._header_provider = header_provider
224224 self ._progress_callback = progress_callback
225225 self ._use_isolated_event_loop = use_isolated_event_loop
226- self ._server_url : Optional [str ] = (
227- mcp_session_manager . connection_params . url
228- if use_isolated_event_loop
229- else None
230- )
226+ self ._server_url : Optional [str ] = None
227+ if use_isolated_event_loop and isinstance (
228+ mcp_session_manager . _connection_params , StreamableHTTPConnectionParams
229+ ):
230+ self . _server_url = mcp_session_manager . _connection_params . url
231231
232232 @override
233233 def _get_declaration (self ) -> FunctionDeclaration :
@@ -429,6 +429,7 @@ async def _run_async_impl(
429429 # See mcp_thread_utils.py for the full explanation.
430430 from .mcp_thread_utils import call_tool_in_thread # pylint: disable=g-import-not-at-top
431431
432+ assert self ._server_url is not None
432433 return await asyncio .to_thread (
433434 call_tool_in_thread ,
434435 self ._server_url ,
@@ -616,7 +617,8 @@ async def _get_headers(
616617 )
617618 }
618619 elif credential .service_account :
619- # Service accounts should be exchanged for access tokens before reaching this point
620+ # Service accounts should be exchanged for access tokens before
621+ # reaching this point
620622 logger .warning (
621623 "Service account credentials should be exchanged before MCP"
622624 " session creation"
0 commit comments