Home / Function/ estimateDirectorySize() — mcp Function Reference

estimateDirectorySize() — mcp Function Reference

Architecture documentation for the estimateDirectorySize() function in zip-repository.ts from the mcp codebase.

Entity Profile

Dependency Diagram

graph TD
  2551d272_a873_fd1f_63c5_810cf113a32c["estimateDirectorySize()"]
  b00e0b6e_8e66_44d2_f709_c8c6bbb476c9["zip-repository.ts"]
  2551d272_a873_fd1f_63c5_810cf113a32c -->|defined in| b00e0b6e_8e66_44d2_f709_c8c6bbb476c9
  bbbd3356_722d_4bf8_09d2_706412487d25["zipRepository()"]
  bbbd3356_722d_4bf8_09d2_706412487d25 -->|calls| 2551d272_a873_fd1f_63c5_810cf113a32c
  f7302a04_558c_423c_2b1f_3cfced56f273["warn()"]
  2551d272_a873_fd1f_63c5_810cf113a32c -->|calls| f7302a04_558c_423c_2b1f_3cfced56f273
  style 2551d272_a873_fd1f_63c5_810cf113a32c fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/utils/zip-repository.ts lines 346–413

async function estimateDirectorySize(
  rootDir: string,
  ignoreFilter: Ignore
): Promise<number> {
  let totalSize = 0;

  async function walkDirectory(currentDir: string): Promise<void> {
    let entries: string[];

    try {
      entries = await fs.readdir(currentDir);
    } catch (error: any) {
      if (error.code === 'EACCES') {
        logger.warn('Permission denied:', currentDir);
        return;
      }
      throw error;
    }

    for (const entry of entries) {
      const fullPath = join(currentDir, entry);
      const relativePath = relative(rootDir, fullPath);

      // Normalize path for ignore matching (use forward slashes)
      const normalizedRelativePath = relativePath.split(sep).join('/');

      // Check if ignored
      if (ignoreFilter.ignores(normalizedRelativePath)) {
        continue;
      }

      let stats;
      try {
        stats = await fs.lstat(fullPath);
      } catch (error: any) {
        if (error.code === 'ENOENT') {
          // File disappeared, skip
          continue;
        }
        logger.warn('Failed to stat:', fullPath, error.message);
        continue;
      }

      // Skip symlinks to prevent following links outside the repository
      if (stats.isSymbolicLink()) {
        continue;
      }

      if (stats.isDirectory()) {
        // Check if directory itself should be ignored
        const dirPath = normalizedRelativePath + '/';
        if (ignoreFilter.ignores(dirPath)) {
          continue;
        }

        // Recurse into directory
        await walkDirectory(fullPath);
      } else if (stats.isFile()) {
        // Add file size to total
        totalSize += stats.size;
      }
      // Skip other special files (sockets, FIFOs, etc.)
    }
  }

  await walkDirectory(rootDir);
  return totalSize;
}

Subdomains

Calls

Called By

Frequently Asked Questions

What does estimateDirectorySize() do?
estimateDirectorySize() is a function in the mcp codebase, defined in src/utils/zip-repository.ts.
Where is estimateDirectorySize() defined?
estimateDirectorySize() is defined in src/utils/zip-repository.ts at line 346.
What does estimateDirectorySize() call?
estimateDirectorySize() calls 1 function(s): warn.
What calls estimateDirectorySize()?
estimateDirectorySize() is called by 1 function(s): zipRepository.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free