Spaces:
Running
Running
Jeremiah Lowin commited on
Commit ·
3edb3a3
1
Parent(s): 88d77c1
Add test for no prefix
Browse files- src/fastmcp/server/server.py +4 -2
- tests/server/test_mount.py +15 -0
src/fastmcp/server/server.py
CHANGED
|
@@ -1094,11 +1094,13 @@ class FastMCP(Generic[LifespanResultT]):
|
|
| 1094 |
|
| 1095 |
def _validate_resource_prefix(prefix: str) -> None:
|
| 1096 |
valid_resource = "resource://path/to/resource"
|
|
|
|
| 1097 |
try:
|
| 1098 |
-
AnyUrl(
|
| 1099 |
except pydantic.ValidationError as e:
|
| 1100 |
raise ValueError(
|
| 1101 |
-
|
|
|
|
| 1102 |
)
|
| 1103 |
|
| 1104 |
|
|
|
|
| 1094 |
|
| 1095 |
def _validate_resource_prefix(prefix: str) -> None:
|
| 1096 |
valid_resource = "resource://path/to/resource"
|
| 1097 |
+
test_case = f"{prefix}{valid_resource}"
|
| 1098 |
try:
|
| 1099 |
+
AnyUrl(test_case)
|
| 1100 |
except pydantic.ValidationError as e:
|
| 1101 |
raise ValueError(
|
| 1102 |
+
"Resource prefix or separator would result in an "
|
| 1103 |
+
f"invalid resource URI (test case was {test_case!r}): {e}"
|
| 1104 |
)
|
| 1105 |
|
| 1106 |
|
tests/server/test_mount.py
CHANGED
|
@@ -106,6 +106,21 @@ class TestBasicMount:
|
|
| 106 |
with pytest.raises(NotFoundError, match="Unknown tool: sub_sub_tool"):
|
| 107 |
await main_app._mcp_call_tool("sub_sub_tool", {})
|
| 108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 109 |
|
| 110 |
class TestMultipleServerMount:
|
| 111 |
"""Test mounting multiple servers simultaneously."""
|
|
|
|
| 106 |
with pytest.raises(NotFoundError, match="Unknown tool: sub_sub_tool"):
|
| 107 |
await main_app._mcp_call_tool("sub_sub_tool", {})
|
| 108 |
|
| 109 |
+
async def test_mount_with_no_prefix(self):
|
| 110 |
+
main_app = FastMCP("MainApp")
|
| 111 |
+
sub_app = FastMCP("SubApp")
|
| 112 |
+
|
| 113 |
+
@sub_app.tool()
|
| 114 |
+
def sub_tool() -> str:
|
| 115 |
+
return "This is from the sub app"
|
| 116 |
+
|
| 117 |
+
main_app.mount(
|
| 118 |
+
prefix="", server=sub_app, tool_separator="", resource_separator=""
|
| 119 |
+
)
|
| 120 |
+
|
| 121 |
+
tools = await main_app.get_tools()
|
| 122 |
+
assert "sub_tool" in tools
|
| 123 |
+
|
| 124 |
|
| 125 |
class TestMultipleServerMount:
|
| 126 |
"""Test mounting multiple servers simultaneously."""
|