Spaces:
Running
Running
| import pytest | |
| from fastmcp import Client, Context, FastMCP | |
| def fastmcp_server(): | |
| mcp = FastMCP() | |
| async def list_roots(context: Context) -> list[str]: | |
| roots = await context.list_roots() | |
| return [str(r.uri) for r in roots] | |
| return mcp | |
| class TestClientRoots: | |
| async def test_invalid_roots(self, fastmcp_server: FastMCP, roots: list[str]): | |
| """ | |
| Roots must be URIs | |
| """ | |
| with pytest.raises(ValueError, match="Input should be a valid URL"): | |
| async with Client(fastmcp_server, roots=roots): | |
| pass | |
| async def test_invalid_urls(self, fastmcp_server: FastMCP, roots: list[str]): | |
| """ | |
| At this time, root URIs must start with file:// | |
| """ | |
| with pytest.raises(ValueError, match="URL scheme should be 'file'"): | |
| async with Client(fastmcp_server, roots=roots): | |
| pass | |
| async def test_valid_roots(self, fastmcp_server: FastMCP, roots: list[str]): | |
| async with Client(fastmcp_server, roots=roots) as client: | |
| result = await client.call_tool("list_roots", {}) | |
| assert result.data == [ | |
| "file://x/y/z", | |
| "file://x/y/z", | |
| ] | |