Skip to main content
Glama
theburgerllc

AI Development Pipeline MCP

by theburgerllc

list_directory_files

Lists files in a workspace directory to help developers navigate project structures and manage code assets within the AI Development Pipeline MCP environment.

Instructions

List files in a workspace directory (restricted to workspace directory)

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
dirYes

Implementation Reference

  • Registration of the 'list_directory_files' tool using server.tool(), including schema and inline handler function.
    server.tool(
      'list_directory_files',
      'List files in a workspace directory (restricted to workspace directory)',
      { dir: z.string() },
      async ({ dir }) => {
        try {
          const safePath = validatePath(dir);
          const files = fs.readdirSync(safePath);
          // Filter out sensitive files
          const filteredFiles = files.filter(file =>
            !file.startsWith('.env') &&
            !file.includes('secret') &&
            !file.includes('key') &&
            !file.includes('password')
          );
          return { content: [{ type: 'text', text: JSON.stringify(filteredFiles, null, 2) }] };
        } catch (err: any) {
          return { content: [{ type: 'text', text: `Directory read error: ${err.message}` }] };
        }
      }
    );
  • Handler function that validates the directory path, reads files using fs.readdirSync, filters sensitive files, and returns JSON list.
    async ({ dir }) => {
      try {
        const safePath = validatePath(dir);
        const files = fs.readdirSync(safePath);
        // Filter out sensitive files
        const filteredFiles = files.filter(file =>
          !file.startsWith('.env') &&
          !file.includes('secret') &&
          !file.includes('key') &&
          !file.includes('password')
        );
        return { content: [{ type: 'text', text: JSON.stringify(filteredFiles, null, 2) }] };
      } catch (err: any) {
        return { content: [{ type: 'text', text: `Directory read error: ${err.message}` }] };
      }
    }
  • Input schema defining 'dir' parameter as string using Zod.
    { dir: z.string() },
  • Helper function validatePath used to secure directory path against traversal attacks.
    function validatePath(filePath: string): string {
      const resolvedPath = path.resolve(WORKSPACE_ROOT, filePath);
      if (!resolvedPath.startsWith(WORKSPACE_ROOT)) {
        throw new Error('Path traversal detected - access denied');
      }
      return resolvedPath;
    }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/theburgerllc/ai-development-pipeline-mcp'

If you have feedback or need assistance with the MCP directory API, please join our Discord server