diff --git a/src/fastmcp/utilities/tests.py b/src/fastmcp/utilities/tests.py index cb697129f..4fa73006e 100644 --- a/src/fastmcp/utilities/tests.py +++ b/src/fastmcp/utilities/tests.py @@ -11,6 +11,7 @@ from typing import TYPE_CHECKING, Any, Literal import uvicorn from fastmcp.settings import settings +from fastmcp.utilities.http import find_available_port if TYPE_CHECKING: from fastmcp.server.server import FastMCP @@ -84,9 +85,7 @@ def run_server_in_process( The server URL. """ host = "127.0.0.1" - with socket.socket() as s: - s.bind((host, 0)) - port = s.getsockname()[1] + port = find_available_port() proc = multiprocessing.Process( target=server_fn, args=(host, port, *args), daemon=True diff --git a/tests/auth/test_oauth_client.py b/tests/auth/test_oauth_client.py index e743e25c3..2a1fd4c23 100644 --- a/tests/auth/test_oauth_client.py +++ b/tests/auth/test_oauth_client.py @@ -11,7 +11,7 @@ import fastmcp.client.auth # Import module, not the function directly from fastmcp.client import Client from fastmcp.client.transports import StreamableHttpTransport from fastmcp.server.auth.auth import ClientRegistrationOptions -from fastmcp.server.auth.providers.in_memory import InMemory +from fastmcp.server.auth.in_memory_provider import InMemoryOAuthProvider as InMemory from fastmcp.server.server import FastMCP from fastmcp.utilities.tests import run_server_in_process