-
Notifications
You must be signed in to change notification settings - Fork 3.1k
fix(mcp-tool): add httpx_client_factory support to SseConnectionParams #4842
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -134,6 +134,49 @@ def test_init_with_sse_connection_params(self): | |
|
|
||
| assert manager._connection_params == sse_params | ||
|
|
||
| @patch("google.adk.tools.mcp_tool.mcp_session_manager.sse_client") | ||
| def test_init_with_sse_custom_httpx_factory(self, mock_sse_client): | ||
| """Test that sse_client is called with custom httpx_client_factory.""" | ||
| custom_httpx_factory = Mock() | ||
|
|
||
| sse_params = SseConnectionParams( | ||
| url="https://example.com/mcp", | ||
| timeout=10.0, | ||
| httpx_client_factory=custom_httpx_factory, | ||
| ) | ||
| manager = MCPSessionManager(sse_params) | ||
|
|
||
| manager._create_client() | ||
|
|
||
| mock_sse_client.assert_called_once_with( | ||
| url="https://example.com/mcp", | ||
| headers=None, | ||
| timeout=10.0, | ||
| sse_read_timeout=300.0, | ||
| httpx_client_factory=custom_httpx_factory, | ||
| ) | ||
|
|
||
| @patch("google.adk.tools.mcp_tool.mcp_session_manager.sse_client") | ||
| def test_init_with_sse_default_httpx_factory(self, mock_sse_client): | ||
| """Test that sse_client is called with default httpx_client_factory.""" | ||
| sse_params = SseConnectionParams( | ||
| url="https://example.com/mcp", | ||
| timeout=10.0, | ||
| ) | ||
| manager = MCPSessionManager(sse_params) | ||
|
|
||
| manager._create_client() | ||
|
|
||
| mock_sse_client.assert_called_once_with( | ||
| url="https://example.com/mcp", | ||
| headers=None, | ||
| timeout=10.0, | ||
| sse_read_timeout=300.0, | ||
| httpx_client_factory=SseConnectionParams.model_fields[ | ||
| "httpx_client_factory" | ||
| ].get_default(), | ||
| ) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To ensure the new functionality doesn't introduce serialization issues, it would be valuable to add a test case that verifies |
||
|
|
||
| def test_init_with_streamable_http_params(self): | ||
| """Test initialization with StreamableHTTPConnectionParams.""" | ||
| http_params = StreamableHTTPConnectionParams( | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
MCPSessionManagersupports pickling, which means its_connection_paramsmust be picklable. Sincehttpx_client_factoryis a callable, it might not be picklable if it's a lambda or a nested function. It would be beneficial to document this constraint for users to prevent potential runtime errors.