Files
wehub-resource-sync 60e0ffc959
Upgrade checks / Notify on failure (push) Has been cancelled
Upgrade checks / Close issue on success (push) Has been cancelled
Schema Crash Test / Real-world schema crash test (232K schemas) (push) Has been cancelled
Run static analysis / static_analysis (push) Has been cancelled
Tests / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Tests / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Tests / Tests with lowest-direct dependencies (push) Has been cancelled
Tests / MCP conformance tests (push) Has been cancelled
Tests / Integration tests (push) Has been cancelled
Tests / Package install smoke (push) Has been cancelled
Upgrade checks / Static analysis (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.13 on ubuntu-latest (push) Has been cancelled
Upgrade checks / Tests: Python 3.10 on windows-latest (push) Has been cancelled
Upgrade checks / Integration tests (push) Has been cancelled
Update MCPServerConfig Schema / update-config-schema (push) Has been cancelled
Update SDK Documentation / update-sdk-docs (push) Has been cancelled
chore: import upstream snapshot with attribution
2026-07-13 12:39:59 +08:00

45 lines
1.4 KiB
Python

import pytest
from fastmcp import Client, Context, FastMCP
@pytest.fixture
def fastmcp_server():
mcp = FastMCP()
@mcp.tool
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:
@pytest.mark.parametrize("roots", [["x"], ["x", "y"]])
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
@pytest.mark.parametrize("roots", [["https://x.com"]])
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
@pytest.mark.parametrize("roots", [["file://x/y/z", "file://x/y/z"]])
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",
]