Skip to content
Closed
Show file tree
Hide file tree
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
3 changes: 2 additions & 1 deletion src/everything/tools/get-resource-reference.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ import {
const GetResourceReferenceSchema = z.object({
resourceType: z
.enum([RESOURCE_TYPE_TEXT, RESOURCE_TYPE_BLOB])
.default(RESOURCE_TYPE_TEXT),
.default(RESOURCE_TYPE_TEXT)
.describe("Type of resource — must be 'Text' or 'Blob'."),
resourceId: z
.number()
.default(1)
Expand Down
29 changes: 24 additions & 5 deletions src/filesystem/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ const CreateDirectoryArgsSchema = z.object({

const ListDirectoryArgsSchema = z.object({
path: z.string(),
depth: z.number().optional().describe('Maximum directory depth to list (default: 1, max: 10)')
});

const ListDirectoryWithSizesArgsSchema = z.object({
Expand Down Expand Up @@ -427,17 +428,35 @@ server.registerTool(
"prefixes. This tool is essential for understanding directory structure and " +
"finding specific files within a directory. Only works within allowed directories.",
inputSchema: {
path: z.string()
path: z.string(),
depth: z.number().optional().describe('Maximum directory depth to list (default: 1, max: 10)')
},
outputSchema: { content: z.string() },
annotations: { readOnlyHint: true }
},
async (args: z.infer<typeof ListDirectoryArgsSchema>) => {
const validPath = await validatePath(args.path);
const entries = await fs.readdir(validPath, { withFileTypes: true });
const formatted = entries
.map((entry) => `${entry.isDirectory() ? "[DIR]" : "[FILE]"} ${entry.name}`)
.join("\n");
const maxDepth = Math.min(args.depth ?? 1, 10);

async function listDirRecursive(currentPath: string, currentDepth: number): Promise<string[]> {
const entries = await fs.readdir(currentPath, { withFileTypes: true });
const lines: string[] = [];

for (const entry of entries) {
const indent = ' '.repeat(currentDepth - 1);
lines.push(`${indent}${entry.isDirectory() ? "[DIR]" : "[FILE]"} ${entry.name}`);

if (entry.isDirectory() && currentDepth < maxDepth) {
const subPath = path.join(currentPath, entry.name);
const subEntries = await listDirRecursive(subPath, currentDepth + 1);
lines.push(...subEntries);
}
}

return lines;
}

const formatted = (await listDirRecursive(validPath, 1)).join("\n");
return {
content: [{ type: "text" as const, text: formatted }],
structuredContent: { content: formatted }
Expand Down
Loading