mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-28 02:10:38 +02:00
Improve HTTP server startup performance (#4729)
This commit is contained in:
parent
c428a08fea
commit
34bdd480c9
15 changed files with 488 additions and 128 deletions
73
tests/server/http/test_startup_imports.py
Normal file
73
tests/server/http/test_startup_imports.py
Normal file
|
|
@ -0,0 +1,73 @@
|
|||
"""Fresh-interpreter import guards for the default HTTP server path."""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import subprocess
|
||||
import sys
|
||||
import textwrap
|
||||
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.subprocess_heavy
|
||||
def test_default_http_app_does_not_load_opt_in_integrations() -> None:
|
||||
script = textwrap.dedent(
|
||||
"""
|
||||
import sys
|
||||
|
||||
from fastmcp import FastMCP
|
||||
|
||||
server = FastMCP("HTTP import guard")
|
||||
|
||||
@server.tool
|
||||
def echo(value: str) -> str:
|
||||
return value
|
||||
|
||||
app = server.http_app(transport="http", stateless_http=True)
|
||||
assert app is not None
|
||||
|
||||
forbidden = (
|
||||
"fastmcp.server.event_store",
|
||||
"griffe",
|
||||
"jsonref",
|
||||
"key_value",
|
||||
"prefab_ui",
|
||||
)
|
||||
loaded = [
|
||||
name
|
||||
for name in sys.modules
|
||||
if any(name == root or name.startswith(f"{root}.") for root in forbidden)
|
||||
]
|
||||
assert not loaded, loaded
|
||||
"""
|
||||
)
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", script],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
|
||||
|
||||
@pytest.mark.subprocess_heavy
|
||||
def test_fastmcp_server_import_does_not_load_context() -> None:
|
||||
script = textwrap.dedent(
|
||||
"""
|
||||
import sys
|
||||
|
||||
from fastmcp import FastMCP
|
||||
|
||||
assert FastMCP is not None
|
||||
assert "fastmcp.server.context" not in sys.modules
|
||||
"""
|
||||
)
|
||||
|
||||
result = subprocess.run(
|
||||
[sys.executable, "-c", script],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
)
|
||||
|
||||
assert result.returncode == 0, result.stderr
|
||||
Loading…
Add table
Add a link
Reference in a new issue