Skip to content

Commit f53415e

Browse files
ianliuyCopilot
andcommitted
fix(filesystem): normalize path separators in search_files results
On Windows, path.relative() returns backslash-separated paths (e.g., src\index.ts), but minimatch expects forward slashes for glob pattern matching (e.g., **/*.ts). This causes search_files and directory_tree exclude patterns to fail on Windows. Fix by normalizing relativePath to use forward slashes via .split(path.sep).join('/') before passing to minimatch in both searchFilesWithValidation (lib.ts) and buildTree (index.ts). Fixes modelcontextprotocol#3517 Co-authored-by: Copilot <[email protected]> Signed-off-by: Yiyang Liu <[email protected]>
1 parent d5bfe34 commit f53415e

2 files changed

Lines changed: 4 additions & 2 deletions

File tree

‎src/filesystem/index.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -554,7 +554,8 @@ server.registerTool(
554554
const result: TreeEntry[] = [];
555555

556556
for (const entry of entries) {
557-
const relativePath = path.relative(rootPath, path.join(currentPath, entry.name));
557+
// Normalize to forward slashes for consistent cross-platform glob matching
558+
const relativePath = path.relative(rootPath, path.join(currentPath, entry.name)).split(path.sep).join('/');
558559
const shouldExclude = excludePatterns.some(pattern => {
559560
if (pattern.includes('*')) {
560561
return minimatch(relativePath, pattern, { dot: true });

‎src/filesystem/lib.ts‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,8 @@ export async function searchFilesWithValidation(
389389
try {
390390
await validatePath(fullPath);
391391

392-
const relativePath = path.relative(rootPath, fullPath);
392+
// Normalize to forward slashes for consistent cross-platform glob matching
393+
const relativePath = path.relative(rootPath, fullPath).split(path.sep).join('/');
393394
const shouldExclude = excludePatterns.some(excludePattern =>
394395
minimatch(relativePath, excludePattern, { dot: true })
395396
);

0 commit comments

Comments
 (0)