Skip to content

πŸš€ The fast, Pythonic way to build MCP servers and clients.

Add test for no prefix

Jeremiah Lowin456db4db63bb
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."""