5
5
from mcp .shared .memory import (
6
6
create_connected_server_and_client_session as client_session ,
7
7
)
8
- from mcp .types import TextContent
8
+ from mcp .types import TextContent , TextResourceContents
9
9
10
10
11
11
@pytest .mark .anyio
@@ -41,12 +41,19 @@ async def test_complex_inputs():
41
41
42
42
43
43
@pytest .mark .anyio
44
- async def test_desktop ():
44
+ async def test_desktop (monkeypatch ):
45
45
"""Test the desktop server"""
46
+ from pathlib import Path
47
+
46
48
from pydantic import AnyUrl
47
49
48
50
from examples .fastmcp .desktop import mcp
49
51
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
+
50
57
async with client_session (mcp ._mcp_server ) as client :
51
58
# Test the add function
52
59
result = await client .call_tool ("add" , {"a" : 1 , "b" : 2 })
@@ -59,5 +66,7 @@ async def test_desktop():
59
66
result = await client .read_resource (AnyUrl ("dir://desktop" ))
60
67
assert len (result .contents ) == 1
61
68
content = result .contents [0 ]
62
- assert isinstance (content , TextContent )
69
+ assert isinstance (content , TextResourceContents )
63
70
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