Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

DirectoryResource listing uses OS path separators and unstable order

未关闭 适合新手
#3,589 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
86/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
python
领域
backend

调研方向

从 mcp.server.mcpserver.resources.DirectoryResource.read() 开始,查看 issue 中的 Windows 复现情况,以及报告中链接的经过测试的修复方案。完成的标准是递归列表在所有平台上都使用 / 作为分隔符,并保持稳定的排序顺序,同时通过测试覆盖该行为。

由索引模型根据 Issue 内容生成。

描述

v1 v2
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 & 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

环境准备

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

modelcontextprotocol/python-sdk 的其他 Issue

查看 modelcontextprotocol/python-sdk 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。