From 57adbad3faf95ce90db4f506aedea28b6df8d674 Mon Sep 17 00:00:00 2001 From: Badri Nerella Date: Mon, 26 May 2025 19:26:01 +0530 Subject: [PATCH] Fix root_path duplication in MCP SSE messages endpoint - When FastAPI apps use root_path, the messages_path was incorrectly including the base_path, causing FastAPI to duplicate the root_path in the final URL. This fix removes the base_path from messages_path construction since FastAPI automatically prepends the root_path when serving endpoints. --- fastapi_mcp/server.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/fastapi_mcp/server.py b/fastapi_mcp/server.py index f5c4fc6..9070286 100644 --- a/fastapi_mcp/server.py +++ b/fastapi_mcp/server.py @@ -335,7 +335,9 @@ def mount( else: raise ValueError(f"Invalid router type: {type(router)}") - messages_path = f"{base_path}{mount_path}/messages/" + # For the SSE transport messages_path, we should not include the base_path + # because FastAPI will automatically prepend the root_path when serving the endpoint + messages_path = f"{mount_path}/messages/" sse_transport = FastApiSseTransport(messages_path)