From 456db4db63bba16ba286bc55aac188723b228faa Mon Sep 17 00:00:00 2001 From: Jeremiah Lowin <153965+jlowin@users.noreply.github.com> Date: Sat, 10 May 2025 15:50:03 -0400 Subject: [PATCH] Add test for no prefix --- src/fastmcp/server/server.py | 6 ++++-- tests/server/test_mount.py | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/fastmcp/server/server.py b/src/fastmcp/server/server.py index 143631b06..4ea5822fc 100644 --- a/src/fastmcp/server/server.py +++ b/src/fastmcp/server/server.py @@ -1094,11 +1094,13 @@ class FastMCP(Generic[LifespanResultT]): def _validate_resource_prefix(prefix: str) -> None: valid_resource = "resource://path/to/resource" + test_case = f"{prefix}{valid_resource}" try: - AnyUrl(f"{prefix}{valid_resource}") + AnyUrl(test_case) except pydantic.ValidationError as e: raise ValueError( - f"Resource prefix or separator would result in an invalid resource URI: {e}" + "Resource prefix or separator would result in an " + f"invalid resource URI (test case was {test_case!r}): {e}" ) diff --git a/tests/server/test_mount.py b/tests/server/test_mount.py index a07e40e81..2d8d37c07 100644 --- a/tests/server/test_mount.py +++ b/tests/server/test_mount.py @@ -106,6 +106,21 @@ class TestBasicMount: with pytest.raises(NotFoundError, match="Unknown tool: sub_sub_tool"): await main_app._mcp_call_tool("sub_sub_tool", {}) + async def test_mount_with_no_prefix(self): + main_app = FastMCP("MainApp") + sub_app = FastMCP("SubApp") + + @sub_app.tool() + def sub_tool() -> str: + return "This is from the sub app" + + main_app.mount( + prefix="", server=sub_app, tool_separator="", resource_separator="" + ) + + tools = await main_app.get_tools() + assert "sub_tool" in tools + class TestMultipleServerMount: """Test mounting multiple servers simultaneously."""