55from mcp .shared .memory import (
66 create_connected_server_and_client_session as client_session ,
77)
8- from mcp .types import TextContent
8+ from mcp .types import TextContent , TextResourceContents
99
1010
1111@pytest .mark .anyio
@@ -41,12 +41,19 @@ async def test_complex_inputs():
4141
4242
4343@pytest .mark .anyio
44- async def test_desktop ():
44+ async def test_desktop (monkeypatch ):
4545 """Test the desktop server"""
46+ from pathlib import Path
47+
4648 from pydantic import AnyUrl
4749
4850 from examples .fastmcp .desktop import mcp
4951
52+ # Mock desktop directory listing
53+ mock_files = [Path ("/fake/path/file1.txt" ), Path ("/fake/path/file2.txt" )]
54+ monkeypatch .setattr (Path , "iterdir" , lambda self : mock_files )
55+ monkeypatch .setattr (Path , "home" , lambda : Path ("/fake/home" ))
56+
5057 async with client_session (mcp ._mcp_server ) as client :
5158 # Test the add function
5259 result = await client .call_tool ("add" , {"a" : 1 , "b" : 2 })
@@ -59,5 +66,7 @@ async def test_desktop():
5966 result = await client .read_resource (AnyUrl ("dir://desktop" ))
6067 assert len (result .contents ) == 1
6168 content = result .contents [0 ]
62- assert isinstance (content , TextContent )
69+ assert isinstance (content , TextResourceContents )
6370 assert isinstance (content .text , str )
71+ assert "/fake/path/file1.txt" in content .text
72+ assert "/fake/path/file2.txt" in content .text
0 commit comments