Skip to main content
Glama
MausRundung

Project Explorer MCP Server

by MausRundung

explore_project

Analyze project directories to list files with sizes and import/export details, excluding common build folders for JavaScript/TypeScript codebases.

Instructions

Lists all files in a directory with their sizes and imports/exports. Analyzes JavaScript/TypeScript files for import/export statements and provides detailed file information including size formatting. Excludes common build directories like node_modules, .git, dist, etc.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
directoryYesThe directory path to analyze
subDirectoryNoOptional subdirectory within the main directory to analyze
includeHiddenNoWhether to include hidden files and directories (starting with .)

Implementation Reference

  • Main handler function executing the tool logic: validates args, checks permissions, scans directory recursively, analyzes code files for imports/exports, formats and returns markdown results.
    export async function handleExploreProject(args: any, allowedDirectories: string[]) {
      const directory = args.directory as string;
      const subDirectory = args.subDirectory as string || "";
      const includeHidden = (args.includeHidden as boolean) || false;
      
      if (!directory) {
        throw new McpError(
          ErrorCode.InvalidRequest, 
          "Directory parameter is required"
        );
      }
      
      try {
        // Construct the full directory path
        let fullDirPath = directory;
        if (subDirectory) {
          fullDirPath = path.join(directory, subDirectory);
        }
        
        // Normalize path for comparison
        fullDirPath = path.normalize(fullDirPath);
        
        // Check if the path is allowed
        if (!isPathAllowed(fullDirPath, allowedDirectories)) {
          throw new McpError(
            ErrorCode.InvalidRequest, 
            `Access denied: The path '${fullDirPath}' is not in the list of allowed directories: ${allowedDirectories.join(', ')}`
          );
        }
        
        // Validate that the directory exists
        const dirStats = await getFileStats(fullDirPath);
        if (!dirStats || !dirStats.isDirectory) {
          throw new McpError(
            ErrorCode.InvalidRequest, 
            `The path '${fullDirPath}' does not exist or is not a directory.`
          );
        }
        
        const files = await scanDirectory(fullDirPath, fullDirPath);
        
        // Filter out hidden files if not includeHidden
        const filteredFiles = includeHidden 
          ? files 
          : files.filter(file => !path.basename(file.path).startsWith('.'));
        
        if (filteredFiles.length === 0) {
          const emptyResult = `# Project Analysis Results for: ${fullDirPath}\n\nNo files found in the directory.\n\n**Note:** This could mean:\n- The directory is empty\n- All files are hidden (use includeHidden=true to see hidden files)\n- All files are in excluded directories (${EXCLUDED_DIRS.join(', ')})`;
          return {
            content: [
              {
                type: "text",
                text: emptyResult
              }
            ]
          };
        }
        
        const formattedResults = formatResults(filteredFiles, fullDirPath);
        
        return {
          content: [
            {
              type: "text",
              text: formattedResults
            }
          ]
        };
      } catch (error) {
        if (error instanceof McpError) {
          throw error;
        }
        
        throw new McpError(
          ErrorCode.InternalError, 
          `Error analyzing project: ${error instanceof Error ? error.message : String(error)}`
        );
      }
    }
  • Tool definition object with name, description, and inputSchema defining parameters: directory (required), subDirectory (optional), includeHidden (optional boolean).
    export const exploreProjectTool = {
      name: "explore_project",
      description: "Lists all files in a directory with their sizes and imports/exports. Analyzes JavaScript/TypeScript files for import/export statements and provides detailed file information including size formatting. Excludes common build directories like node_modules, .git, dist, etc.",
      inputSchema: {
        type: "object",
        properties: {
          directory: { 
            type: "string",
            description: "The directory path to analyze"
          },
          subDirectory: {
            type: "string",
            description: "Optional subdirectory within the main directory to analyze",
            default: ""
          },
          includeHidden: { 
            type: "boolean", 
            description: "Whether to include hidden files and directories (starting with .)",
            default: false
          }
        },
        required: ["directory"]
      }
    };
  • src/index.ts:33-44 (registration)
    Registration of the exploreProjectTool in the MCP server's listTools handler, making it discoverable.
    server.setRequestHandler(ListToolsRequestSchema, async () => {
      return {
        tools: [
          exploreProjectTool,
          listAllowedTool,
          searchTool,
          renameFileTool,
          deleteFileTool,
          checkOutdatedTool
        ]
      };
    });
  • src/index.ts:52-77 (registration)
    Registration of the tool handler in the MCP server's CallToolRequestSchema switch statement, routing 'explore_project' calls to handleExploreProject.
      switch (request.params.name) {
        case "list_allowed_directories":
          return await handleListAllowed(args, ALLOWED_DIRECTORIES);
          
        case "explore_project":
          return await handleExploreProject(args, ALLOWED_DIRECTORIES);
          
        case "search_files":
          return await handleSearch(args, ALLOWED_DIRECTORIES);
          
        case "rename_file":
          return await handleRenameFile(args, ALLOWED_DIRECTORIES);
          
        case "delete_file":
          return await handleDeleteFile(args, ALLOWED_DIRECTORIES);
          
        case "check_outdated":
          return await handleCheckOutdated(args, ALLOWED_DIRECTORIES);
          
        default:
          throw new McpError(
            ErrorCode.InvalidRequest, 
            `Unknown tool: ${request.params.name}`
          );
      }
    });
  • Core recursive directory scanning helper that collects file info, skips excluded dirs, extracts imports/exports from code files.
    async function scanDirectory(dirPath: string, rootPath: string): Promise<FileInfo[]> {
      const results: FileInfo[] = [];
      
      try {
        const entries = await fs.promises.readdir(dirPath, { withFileTypes: true });
        
        for (const entry of entries) {
          const entryPath = path.join(dirPath, entry.name);
          
          // Skip excluded directories
          if (entry.isDirectory() && shouldExcludePath(entryPath)) {
            continue;
          }
          
          if (entry.isDirectory()) {
            // Recursively scan subdirectories
            const subdirResults = await scanDirectory(entryPath, rootPath);
            results.push(...subdirResults);
          } else if (entry.isFile()) {
            const stats = await getFileStats(entryPath);
            
            if (!stats) continue;
            
            const fileInfo: FileInfo = {
              path: entryPath,
              size: stats.size,
              sizeFormatted: formatFileSize(stats.size),
              isEmpty: stats.isEmpty
            };
            
            // Check if this is a file type we should analyze for imports/exports
            const ext = path.extname(entryPath).toLowerCase();
            if (ANALYZED_EXTENSIONS.includes(ext)) {
              if (CODE_FILE_EXTENSIONS.includes(ext)) {
                const { imports, exports } = await extractImportsAndExports(entryPath);
                fileInfo.imports = imports;
                fileInfo.exports = exports;
              } else if (CONFIG_FILE_EXTENSIONS.includes(ext)) {
                fileInfo.fileType = 'config';
              }
            }
            
            results.push(fileInfo);
          }
        }
      } catch (error) {
        // Error scanning directory, skip
      }
      
      return results;
    }
Behavior3/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

With no annotations provided, the description carries the full burden of behavioral disclosure. It effectively describes key behaviors like excluding common build directories and analyzing specific file types, but doesn't cover important aspects like performance characteristics, error handling, or whether this is a read-only operation (though 'lists' and 'analyzes' imply non-destructive).

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is efficiently structured in two sentences that each earn their place: the first establishes the core functionality, and the second adds important behavioral details about exclusions. There's no wasted language or redundancy.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness4/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

For a tool with no annotations and no output schema, the description provides good coverage of what the tool does and key behaviors. However, it doesn't describe the output format or structure, which would be helpful given the lack of output schema. The description compensates well for missing annotations but could better address the output gap.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

With 100% schema description coverage, the schema already documents all three parameters thoroughly. The description doesn't add any parameter-specific information beyond what's in the schema, so it meets the baseline of 3 for high schema coverage without providing additional parameter context.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose5/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose with specific verbs ('lists', 'analyzes', 'provides') and resources ('files in a directory', 'JavaScript/TypeScript files'), distinguishing it from siblings like 'search_files' or 'list_allowed_directories' by focusing on file analysis rather than searching or listing permissions.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines4/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides clear context for when to use this tool (analyzing files with import/export details) and implicitly excludes alternatives by specifying its unique analysis capabilities. However, it doesn't explicitly state when NOT to use it or name specific sibling alternatives for comparison.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other Tools

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/MausRundung/mcp-explorer'

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