#3589·python-sdk

DirectoryResource listing uses OS path separators and unstable order

Author: tasnemawawde-afkCreated Sep 27, 2026Updated Sep 29, 2026
Labelsv2v1

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: https://github.com/tasnemawawde-afk/python-sdk/commit/06f76b5c8458cc847425c707a4d75d67ed814c6b 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

Python & MCP Python SDK

Python 3.14.7, Windows 11
MCP Python SDK: main branch at commit f1b6589

Source: modelcontextprotocol/python-sdk