Fix bug that sets message path and sse path to same value

This commit is contained in:
Jeremiah Lowin 2025-05-10 16:10:39 -04:00
commit 84a79ab56e
3 changed files with 14 additions and 5 deletions

View file

@ -869,7 +869,7 @@ class FastMCP(Generic[LifespanResultT]):
elif transport == "sse":
return create_sse_app(
server=self,
message_path=path or self.settings.message_path,
message_path=self.settings.message_path,
sse_path=path or self.settings.sse_path,
auth_server_provider=self._auth_server_provider,
auth_settings=self.settings.auth,

View file

@ -71,7 +71,7 @@ def _run_server(mcp_server: FastMCP, transport: Literal["sse"], port: int) -> No
@contextmanager
def run_server_in_process(
server_fn: Callable[[str, int], None],
server_fn: Callable[[str, int], None], *args
) -> Generator[str, None, None]:
"""
Context manager that runs a Starlette app in a separate process and returns the
@ -88,7 +88,9 @@ def run_server_in_process(
s.bind((host, 0))
port = s.getsockname()[1]
proc = multiprocessing.Process(target=server_fn, args=(host, port), daemon=True)
proc = multiprocessing.Process(
target=server_fn, args=(host, port, *args), daemon=True
)
proc.start()
# Wait for server to be running

View file

@ -56,9 +56,9 @@ def fastmcp_server():
return server
def run_server(host: str, port: int) -> None:
def run_server(host: str, port: int, path: str | None = None) -> None:
try:
app = fastmcp_server().http_app(transport="sse")
app = fastmcp_server().http_app(transport="sse", path=path)
server = uvicorn.Server(
config=uvicorn.Config(app=app, host=host, port=port, log_level="error")
)
@ -109,6 +109,13 @@ def run_nested_server(host: str, port: int) -> None:
sys.exit(0)
async def test_run_server_on_path():
with run_server_in_process(run_server, "/help") as url:
async with Client(transport=SSETransport(f"{url}/help")) as client:
result = await client.ping()
assert result is True
async def test_nested_sse_server_resolves_correctly():
# tests patch for
# https://github.com/modelcontextprotocol/python-sdk/pull/659