@@ -144,16 +144,14 @@ def test_init_with_streamable_http_params(self):
144
144
145
145
assert manager ._connection_params == http_params
146
146
147
- @pytest .mark .asyncio
148
- async def test_init_with_streamable_http_custom_httpx_factory (self ):
149
- """Test initialization with StreamableHTTPConnectionParams."""
150
- import httpx
151
- custom_httpx_client = httpx .AsyncClient ()
147
+ @patch ("google.adk.tools.mcp_tool.mcp_session_manager.streamablehttp_client" )
148
+ def test_init_with_streamable_http_custom_httpx_factory (
149
+ self , mock_streamablehttp_client
150
+ ):
151
+ """Test that streamablehttp_client is called with custom httpx_client_factory."""
152
+ from datetime import timedelta
152
153
153
- def _httpx_factory (headers = None , timeout = None , auth = None ):
154
- return custom_httpx_client
155
-
156
- custom_httpx_factory = Mock (side_effect = _httpx_factory )
154
+ custom_httpx_factory = Mock ()
157
155
158
156
http_params = StreamableHTTPConnectionParams (
159
157
url = "https://example.com/mcp" ,
@@ -162,9 +160,16 @@ def _httpx_factory(headers=None, timeout=None, auth=None):
162
160
)
163
161
manager = MCPSessionManager (http_params )
164
162
165
- async with manager ._create_client ():
166
- #assert factory was called
167
- custom_httpx_factory .assert_called_once ()
163
+ manager ._create_client ()
164
+
165
+ mock_streamablehttp_client .assert_called_once_with (
166
+ url = "https://example.com/mcp" ,
167
+ headers = None ,
168
+ timeout = timedelta (seconds = 15.0 ),
169
+ sse_read_timeout = timedelta (seconds = 300.0 ),
170
+ terminate_on_close = True ,
171
+ httpx_client_factory = custom_httpx_factory ,
172
+ )
168
173
169
174
170
175
0 commit comments