Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ const ListDirectoryArgsSchema = z.object({

const DirectoryTreeArgsSchema = z.object({
path: z.string(),
exclude: z.array(z.string()).optional().default([]),
});

const MoveFileArgsSchema = z.object({
Expand Down Expand Up @@ -542,9 +543,9 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
children?: TreeEntry[];
}

async function buildTree(currentPath: string): Promise<TreeEntry[]> {
async function buildTree(currentPath: string, exclude: string[]): Promise<TreeEntry[]> {
const validPath = await validatePath(currentPath);
const entries = await fs.readdir(validPath, {withFileTypes: true});
const entries = (await fs.readdir(validPath, { withFileTypes: true })).filter((item) => item.isDirectory() && !(exclude.includes(item.name)));
const result: TreeEntry[] = [];

for (const entry of entries) {
Expand All @@ -555,7 +556,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {

if (entry.isDirectory()) {
const subPath = path.join(currentPath, entry.name);
entryData.children = await buildTree(subPath);
entryData.children = await buildTree(subPath, exclude);
}

result.push(entryData);
Expand All @@ -564,7 +565,7 @@ server.setRequestHandler(CallToolRequestSchema, async (request) => {
return result;
}

const treeData = await buildTree(parsed.data.path);
const treeData = await buildTree(parsed.data.path, parsed.data.exclude);
return {
content: [{
type: "text",
Expand Down