From 3d454380b15f52aa7626f6a3e8974eb7379be5a4 Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sat, 31 May 2025 19:36:04 -0400 Subject: [PATCH] Fix import and remaining available port --- src/fastmcp/utilities/tests.py | 5 ++--- tests/auth/test_oauth_client.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) 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