Initial Checks
Release line
2.x (current stable)
Description
What happened
DirectoryResource.read() returns str(path.relative_to(...)), so on Windows a
recursive listing contains sub\c.txt, while Linux/macOS return sub/c.txt.
The file order also follows glob(), which depends on the filesystem, so the
same directory can produce a different JSON listing on different machines.
Expected
Resource content is sent to clients, so the listing should be the same on every
platform: / separators and a stable (sorted) order.
Reproduce (on Windows)
import anyio, tempfile
from pathlib import Path
from mcp.server.mcpserver.resources import DirectoryResource
root = Path(tempfile.mkdtemp())
(root / "sub").mkdir()
(root / "sub" / "c.txt").write_text("c", encoding="utf-8")
r = DirectoryResource(uri="dir://x", name="x", path=root, recursive=True)
print(anyio.run(r.read)) # {"files": ["sub\\c.txt"]}
Possible fix
Use Path.as_posix() and sorted(...) in read(). I have a tested fix with
tests on my fork: tasnemawawde-afk@06f76b5
Happy to open a PR if a maintainer wants one.
(I used Claude to help find and write this fix; I reviewed it and ran the tests myself.)
Example Code
Python & MCP Python SDK
Python 3.14.7, Windows 11
MCP Python SDK: main branch at commit f1b6589
Initial Checks
Release line
2.x (current stable)
Description
What happened
DirectoryResource.read()returnsstr(path.relative_to(...)), so on Windows arecursive listing contains
sub\c.txt, while Linux/macOS returnsub/c.txt.The file order also follows
glob(), which depends on the filesystem, so thesame directory can produce a different JSON listing on different machines.
Expected
Resource content is sent to clients, so the listing should be the same on every
platform:
/separators and a stable (sorted) order.Reproduce (on Windows)
import anyio, tempfile
from pathlib import Path
from mcp.server.mcpserver.resources import DirectoryResource
Possible fix
Use
Path.as_posix()andsorted(...)inread(). I have a tested fix withtests on my fork: tasnemawawde-afk@06f76b5
Happy to open a PR if a maintainer wants one.
(I used Claude to help find and write this fix; I reviewed it and ran the tests myself.)
Example Code
Python & MCP Python SDK