mirror of
https://github.com/aljazceru/mcp-python-sdk.git
synced 2025-12-19 14:54:24 +01:00
refactor: standardize resource response format
Introduce ReadResourceContents type to properly handle MIME types in resource responses. Breaking change in FastMCP read_resource() return type. Github-Issue:#152
This commit is contained in:
@@ -88,10 +88,10 @@ async def test_list_resources(mcp: FastMCP):
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_read_resource_dir(mcp: FastMCP):
|
||||
files, mime_type = await mcp.read_resource("dir://test_dir")
|
||||
assert mime_type == "text/plain"
|
||||
res = await mcp.read_resource("dir://test_dir")
|
||||
assert res.mime_type == "text/plain"
|
||||
|
||||
files = json.loads(files)
|
||||
files = json.loads(res.content)
|
||||
|
||||
assert sorted([Path(f).name for f in files]) == [
|
||||
"config.json",
|
||||
@@ -102,8 +102,8 @@ async def test_read_resource_dir(mcp: FastMCP):
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_read_resource_file(mcp: FastMCP):
|
||||
result, _ = await mcp.read_resource("file://test_dir/example.py")
|
||||
assert result == "print('hello world')"
|
||||
res = await mcp.read_resource("file://test_dir/example.py")
|
||||
assert res.content == "print('hello world')"
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
@@ -119,5 +119,5 @@ async def test_delete_file_and_check_resources(mcp: FastMCP, test_dir: Path):
|
||||
await mcp.call_tool(
|
||||
"delete_file", arguments=dict(path=str(test_dir / "example.py"))
|
||||
)
|
||||
result, _ = await mcp.read_resource("file://test_dir/example.py")
|
||||
assert result == "File not found"
|
||||
res = await mcp.read_resource("file://test_dir/example.py")
|
||||
assert res.content == "File not found"
|
||||
|
||||
Reference in New Issue
Block a user