Home / Function/ addFilesRecursively() — mcp Function Reference

addFilesRecursively() — mcp Function Reference

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

Entity Profile

Dependency Diagram

graph TD
  bb858fdb_9a3b_a551_d94a_ce5beeb5b86f["addFilesRecursively()"]
  b00e0b6e_8e66_44d2_f709_c8c6bbb476c9["zip-repository.ts"]
  bb858fdb_9a3b_a551_d94a_ce5beeb5b86f -->|defined in| b00e0b6e_8e66_44d2_f709_c8c6bbb476c9
  bbbd3356_722d_4bf8_09d2_706412487d25["zipRepository()"]
  bbbd3356_722d_4bf8_09d2_706412487d25 -->|calls| bb858fdb_9a3b_a551_d94a_ce5beeb5b86f
  f7302a04_558c_423c_2b1f_3cfced56f273["warn()"]
  bb858fdb_9a3b_a551_d94a_ce5beeb5b86f -->|calls| f7302a04_558c_423c_2b1f_3cfced56f273
  5c90e8cd_7cb8_59e4_cdeb_8ef1addd217e["error()"]
  bb858fdb_9a3b_a551_d94a_ce5beeb5b86f -->|calls| 5c90e8cd_7cb8_59e4_cdeb_8ef1addd217e
  33bb86df_1268_373b_a74a_77412144612c["debug()"]
  bb858fdb_9a3b_a551_d94a_ce5beeb5b86f -->|calls| 33bb86df_1268_373b_a74a_77412144612c
  c7ef4400_cc66_9f8c_3fec_50f4c76e3cdf["formatBytes()"]
  bb858fdb_9a3b_a551_d94a_ce5beeb5b86f -->|calls| c7ef4400_cc66_9f8c_3fec_50f4c76e3cdf
  style bb858fdb_9a3b_a551_d94a_ce5beeb5b86f fill:#6366f1,stroke:#818cf8,color:#fff

Relationship Graph

Source Code

src/utils/zip-repository.ts lines 588–702

async function addFilesRecursively(
  archive: archiver.Archiver,
  rootDir: string,
  currentDir: string,
  ignoreFilter: Ignore,
  options?: ZipOptions,
  progressState?: ProgressState
): Promise<void> {
  let entries: string[];

  try {
    entries = await fs.readdir(currentDir);
  } catch (error: any) {
    if (error.code === 'EACCES') {
      logger.warn('Permission denied:', currentDir);
      return;
    }
    logger.error('Failed to read directory:', currentDir);
    logger.error('Error:', error.message);
    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;
      }
      console.error('[WARN] Failed to stat:', fullPath, error.message);
      continue;
    }

    // Skip symlinks to prevent following links outside the repository
    if (stats.isSymbolicLink()) {
      logger.warn('Skipping symlink:', fullPath);
      continue;
    }

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

      // Recurse into directory
      await addFilesRecursively(archive, rootDir, fullPath, ignoreFilter, options, progressState);
    } else if (stats.isFile()) {
      // Add file to archive
      try {
        archive.file(fullPath, { name: normalizedRelativePath });

        // Track progress if callback is provided
        if (progressState && options?.onProgress) {
          progressState.filesProcessed++;
          progressState.bytesProcessed += stats.size;
          progressState.lastFile = normalizedRelativePath;

          const progressInterval = options.progressInterval || 100;

          // Report progress every N files
          if (progressState.filesProcessed - progressState.lastReportedCount >= progressInterval) {
            logger.debug(
              `Progress: ${progressState.filesProcessed} files, ${formatBytes(progressState.bytesProcessed)}`
            );

            options.onProgress({

Subdomains

Called By

Frequently Asked Questions

What does addFilesRecursively() do?
addFilesRecursively() is a function in the mcp codebase, defined in src/utils/zip-repository.ts.
Where is addFilesRecursively() defined?
addFilesRecursively() is defined in src/utils/zip-repository.ts at line 588.
What does addFilesRecursively() call?
addFilesRecursively() calls 4 function(s): debug, error, formatBytes, warn.
What calls addFilesRecursively()?
addFilesRecursively() 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