mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-21 13:04:18 +02:00
Merge pull request #404 from jlowin/test-no-prefix
Add test for no prefix when importing
This commit is contained in:
commit
6bb82befa5
2 changed files with 19 additions and 2 deletions
|
|
@ -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}"
|
||||
)
|
||||
|
||||
|
||||
|
|
|
|||
|
|
@ -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."""
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue