Merge pull request #404 from jlowin/test-no-prefix

Add test for no prefix when importing
This commit is contained in:
Jeremiah Lowin 2025-05-10 15:52:59 -04:00 committed by GitHub
commit 6bb82befa5
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 2 deletions

View file

@ -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}"
)

View file

@ -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."""