DirectoryResource listing uses OS path separators and unstable order
維護者通常 1 天內回覆
還沒有人認領這個 Issue。
評估
研究方向
從 mcp.server.mcpserver.resources.DirectoryResource.read() 開始,查看 issue 中的 Windows 重現情況,以及報告中連結的經過測試的修正方案。完成的標準是遞迴列表在所有平台上都使用 / 作為分隔符,並保持穩定的排序順序,同時透過測試涵蓋此行為。
由索引模型根據 Issue 內容生成。
描述
Initial Checks
- I confirm that I'm using the newest release of my line (the latest 2.x, or the latest 1.x if I'm still on v1)
- I confirm that I searched for my issue in https://github.com/modelcontextprotocol/python-sdk/issues before opening this issue
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 & MCP Python SDK
Python 3.14.7, Windows 11
MCP Python SDK: main branch at commit f1b6589
- 主要語言
- Python
- 星號
- 24.4k
- 分支
- 4k
- 平均合併
- 1 天 7 小時
- 30 天內合併 PR
- 18
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/python-sdk 的其他 Issue
-
難度 2/5 1-3 小時 新手友好度 78/100
modelcontextprotocol/python-sdk#3597 ·
維護者通常 1 天內回覆
-
v1 v2
難度 2/5 1-3 小時 新手友好度 68/100
modelcontextprotocol/python-sdk#3592 · 1 則留言 ·
維護者通常 1 天內回覆
-
難度 1/5 1-3 小時 新手友好度 88/100
modelcontextprotocol/python-sdk#3590 ·
維護者通常 1 天內回覆
-
v1 v2
難度 2/5 1-3 小時 新手友好度 84/100
modelcontextprotocol/python-sdk#3585 · 1 則留言 ·
維護者通常 1 天內回覆
-
v1 v2
難度 2/5 1-3 小時 新手友好度 70/100
modelcontextprotocol/python-sdk#3578 · 1 則留言 ·
維護者通常 1 天內回覆
查看 modelcontextprotocol/python-sdk 的全部 Issue
相似的 Issue
-
[Bug] @deck.gl/arcgis dist import resolves to unpublished @deck.gl/core source path (9.3.11, 9.4.0)未關閉
難度 2/5 1-3 小時 新手友好度 72/100
維護者通常 1 天內回覆
-
workflow: a tick's dispatch counts as 'only this step', and no review self-grants a round unattended未關閉workflow
難度 2/5 1-3 小時 新手友好度 85/100
kristofdegrave/homeassistant-smart-charging#1505 ·
維護者通常 1 天內回覆
-
metadata submission
難度 2/5 1-3 小時 新手友好度 82/100
-
bug
難度 2/5 1-3 小時 新手友好度 65/100
canonical/content-cache-operator#163 · 1 則留言 ·
維護者通常 1 天內回覆
-
[submission]未關閉submission
難度 1/5 1 小時以內 新手友好度 65/100
leanprover/lean-eval-submissions#1852 ·
維護者通常 1 天內回覆