diff --git a/python/semantic_kernel/connectors/mcp.py b/python/semantic_kernel/connectors/mcp.py index 789461b2c805..4554d6a900a4 100644 --- a/python/semantic_kernel/connectors/mcp.py +++ b/python/semantic_kernel/connectors/mcp.py @@ -886,9 +886,9 @@ def get_mcp_client(self) -> _AsyncGeneratorContextManager[Any, None]: } if self.headers: args["headers"] = self.headers - if self.timeout: + if self.timeout is not None: args["timeout"] = self.timeout - if self.sse_read_timeout: + if self.sse_read_timeout is not None: args["sse_read_timeout"] = self.sse_read_timeout if self.terminate_on_close is not None: args["terminate_on_close"] = self.terminate_on_close diff --git a/python/tests/unit/connectors/mcp/test_mcp.py b/python/tests/unit/connectors/mcp/test_mcp.py index b4623489de12..c8688bc451ac 100644 --- a/python/tests/unit/connectors/mcp/test_mcp.py +++ b/python/tests/unit/connectors/mcp/test_mcp.py @@ -377,6 +377,24 @@ async def test_with_kwargs_streamablehttp(mock_session, mock_client, list_tool_c assert len(loaded_plugin.functions["func2"].parameters) == 0 +@patch("semantic_kernel.connectors.mcp.streamablehttp_client") +def test_streamablehttp_client_forwards_zero_timeouts(mock_streamablehttp_client): + plugin = MCPStreamableHttpPlugin( + name="TestMCPPlugin", + url="http://localhost:8080/mcp", + timeout=0.0, + sse_read_timeout=0.0, + ) + + assert plugin.get_mcp_client() is mock_streamablehttp_client.return_value + + mock_streamablehttp_client.assert_called_once_with( + url="http://localhost:8080/mcp", + timeout=0.0, + sse_read_timeout=0.0, + ) + + async def test_kernel_as_mcp_server(kernel: "Kernel", decorated_native_function, custom_plugin_class): kernel.add_plugin(custom_plugin_class, "test") kernel.add_functions("test", [decorated_native_function])