Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
977d2b6
1
Parent(s): c915108
Ensure pickleable args
Browse files
src/fastmcp/utilities/tests.py
CHANGED
|
@@ -10,7 +10,6 @@ from typing import TYPE_CHECKING, Any, Literal
|
|
| 10 |
|
| 11 |
import uvicorn
|
| 12 |
|
| 13 |
-
import fastmcp
|
| 14 |
from fastmcp.settings import settings
|
| 15 |
from fastmcp.utilities.http import find_available_port
|
| 16 |
|
|
@@ -73,19 +72,21 @@ def _run_server(mcp_server: FastMCP, transport: Literal["sse"], port: int) -> No
|
|
| 73 |
|
| 74 |
@contextmanager
|
| 75 |
def run_server_in_process(
|
| 76 |
-
server_fn:
|
| 77 |
*args,
|
| 78 |
provide_host_and_port: bool = True,
|
| 79 |
**kwargs,
|
| 80 |
) -> Generator[str, None, None]:
|
| 81 |
"""
|
| 82 |
-
Context manager that runs a FastMCP server
|
| 83 |
returns the server URL. When the context manager is exited, the server process is killed.
|
| 84 |
|
| 85 |
Args:
|
| 86 |
-
server_fn: The
|
| 87 |
-
|
| 88 |
-
|
|
|
|
|
|
|
| 89 |
|
| 90 |
Returns:
|
| 91 |
The server URL.
|
|
@@ -93,9 +94,6 @@ def run_server_in_process(
|
|
| 93 |
host = "127.0.0.1"
|
| 94 |
port = find_available_port()
|
| 95 |
|
| 96 |
-
if isinstance(server_fn, fastmcp.FastMCP):
|
| 97 |
-
server_fn = server_fn.run
|
| 98 |
-
|
| 99 |
if provide_host_and_port:
|
| 100 |
kwargs |= {"host": host, "port": port}
|
| 101 |
|
|
|
|
| 10 |
|
| 11 |
import uvicorn
|
| 12 |
|
|
|
|
| 13 |
from fastmcp.settings import settings
|
| 14 |
from fastmcp.utilities.http import find_available_port
|
| 15 |
|
|
|
|
| 72 |
|
| 73 |
@contextmanager
|
| 74 |
def run_server_in_process(
|
| 75 |
+
server_fn: Callable[..., None],
|
| 76 |
*args,
|
| 77 |
provide_host_and_port: bool = True,
|
| 78 |
**kwargs,
|
| 79 |
) -> Generator[str, None, None]:
|
| 80 |
"""
|
| 81 |
+
Context manager that runs a FastMCP server in a separate process and
|
| 82 |
returns the server URL. When the context manager is exited, the server process is killed.
|
| 83 |
|
| 84 |
Args:
|
| 85 |
+
server_fn: The function that runs a FastMCP server. FastMCP servers are
|
| 86 |
+
not pickleable, so we need a function that creates and runs one.
|
| 87 |
+
*args: Arguments to pass to the server function.
|
| 88 |
+
provide_host_and_port: Whether to provide the host and port to the server function as kwargs.
|
| 89 |
+
**kwargs: Keyword arguments to pass to the server function.
|
| 90 |
|
| 91 |
Returns:
|
| 92 |
The server URL.
|
|
|
|
| 94 |
host = "127.0.0.1"
|
| 95 |
port = find_available_port()
|
| 96 |
|
|
|
|
|
|
|
|
|
|
| 97 |
if provide_host_and_port:
|
| 98 |
kwargs |= {"host": host, "port": port}
|
| 99 |
|