zipRepository() — mcp Function Reference
Architecture documentation for the zipRepository() function in zip-repository.ts from the mcp codebase.
Entity Profile
Dependency Diagram
graph TD 52a097f2_598d_df67_e422_55b20a202d95["zipRepository()"] b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb["resolveOrFetchGraph()"] b9fca090_95d0_4cf7_0bb0_7a7efcc55ccb -->|calls| 52a097f2_598d_df67_e422_55b20a202d95 966fdd0a_509a_01b0_865e_32cfde84f964["precacheForDirectory()"] 966fdd0a_509a_01b0_865e_32cfde84f964 -->|calls| 52a097f2_598d_df67_e422_55b20a202d95 7676d97e_3407_e9fb_36e4_f3398b574ec2["error()"] 52a097f2_598d_df67_e422_55b20a202d95 -->|calls| 7676d97e_3407_e9fb_36e4_f3398b574ec2 44adfa8b_2ebc_f147_11ab_97c37a623907["buildIgnoreFilter()"] 52a097f2_598d_df67_e422_55b20a202d95 -->|calls| 44adfa8b_2ebc_f147_11ab_97c37a623907 b8971bfc_ba3c_23a9_1f17_5d613ac67105["debug()"] 52a097f2_598d_df67_e422_55b20a202d95 -->|calls| b8971bfc_ba3c_23a9_1f17_5d613ac67105 36639085_56c2_b6be_fa5a_bce73400fd8c["estimateDirectorySize()"] 52a097f2_598d_df67_e422_55b20a202d95 -->|calls| 36639085_56c2_b6be_fa5a_bce73400fd8c e2a45e09_2506_abe8_d09f_d033416cdd84["formatBytes()"] 52a097f2_598d_df67_e422_55b20a202d95 -->|calls| e2a45e09_2506_abe8_d09f_d033416cdd84 dfe11f52_4dd3_db89_9717_941d05bae091["warn()"] 52a097f2_598d_df67_e422_55b20a202d95 -->|calls| dfe11f52_4dd3_db89_9717_941d05bae091 3a4a51ae_b292_2750_c894_60a641d584b1["addFilesRecursively()"] 52a097f2_598d_df67_e422_55b20a202d95 -->|calls| 3a4a51ae_b292_2750_c894_60a641d584b1 style 52a097f2_598d_df67_e422_55b20a202d95 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/utils/zip-repository.ts lines 176–340
export async function zipRepository(
directoryPath: string,
options: ZipOptions = {}
): Promise<ZipResult> {
const maxSizeBytes = options.maxSizeBytes || MAX_ZIP_SIZE_BYTES;
// Validate directory exists
try {
const stats = await fs.stat(directoryPath);
if (!stats.isDirectory()) {
const errorMsg = `Path is not a directory: ${directoryPath}`;
logger.error(errorMsg);
throw new Error(errorMsg);
}
} catch (error: any) {
if (error.code === 'ENOENT') {
const errorMsg = `Directory does not exist: ${directoryPath}`;
logger.error(errorMsg);
throw new Error(errorMsg);
}
if (error.code === 'EACCES') {
const errorMsg = `Permission denied accessing directory: ${directoryPath}`;
logger.error(errorMsg);
throw new Error(errorMsg);
}
// Re-throw unknown errors with logging
logger.error('Failed to validate directory:', directoryPath);
logger.error('Error:', error.message);
throw error;
}
// Parse gitignore files
const ignoreFilter = await buildIgnoreFilter(
directoryPath,
options.additionalExclusions,
options.includeGitignore
);
// Estimate directory size before starting ZIP creation
logger.debug('Estimating directory size...');
const estimatedSize = await estimateDirectorySize(directoryPath, ignoreFilter);
logger.debug('Estimated size:', formatBytes(estimatedSize));
// Check if estimated size exceeds limit
if (estimatedSize > maxSizeBytes) {
throw new Error(
`Directory size (${formatBytes(estimatedSize)}) exceeds maximum allowed size (${formatBytes(maxSizeBytes)}). ` +
`Consider excluding more directories or analyzing a subdirectory.`
);
}
// Create temp file path
const tempDir = tmpdir();
const zipFileName = `supermodel-${randomBytes(8).toString('hex')}.zip`;
const zipPath = join(tempDir, zipFileName);
logger.debug('Creating ZIP:', zipPath);
logger.debug('Source directory:', directoryPath);
// Create ZIP archive
let fileCount = 0;
let totalSize = 0;
const output = createWriteStream(zipPath);
const archive = archiver('zip', {
zlib: { level: 6 } // Balanced compression
});
// Track errors
let archiveError: Error | null = null;
archive.on('error', (err) => {
logger.error('Archive error:', err.message);
archiveError = err;
});
archive.on('warning', (err) => {
if (err.code === 'ENOENT') {
logger.warn('File not found (skipping):', err.message);
} else {
logger.warn('Archive warning:', err.message);
}
});
// Track progress
archive.on('entry', (entry) => {
fileCount++;
totalSize += entry.stats?.size || 0;
// Check size limit
if (totalSize > maxSizeBytes) {
const errorMsg =
`ZIP size exceeds limit (${formatBytes(maxSizeBytes)}). ` +
`Current size: ${formatBytes(totalSize)}. ` +
`Consider excluding more directories or analyzing a subdirectory.`;
logger.error(errorMsg);
archive.abort();
archiveError = new Error(errorMsg);
}
});
// Pipe to file
archive.pipe(output);
// Add files recursively with filtering
// Initialize progress state if progress callback is provided
const progressState: ProgressState | undefined = options.onProgress
? { filesProcessed: 0, bytesProcessed: 0, lastReportedCount: 0, lastFile: '' }
: undefined;
await addFilesRecursively(archive, directoryPath, directoryPath, ignoreFilter, options, progressState);
// Finalize archive
await archive.finalize();
// Wait for output stream to finish
await new Promise<void>((resolve, reject) => {
output.on('close', () => {
if (archiveError) {
reject(archiveError);
} else {
resolve();
}
});
output.on('error', (err) => {
logger.error('Output stream error:', err.message);
reject(err);
});
});
// Check for errors during archiving
if (archiveError) {
logger.error('Archiving failed, cleaning up partial ZIP');
// Clean up partial ZIP
await fs.unlink(zipPath).catch(() => {});
throw archiveError;
}
// Get final file size
const zipStats = await fs.stat(zipPath);
const zipSizeBytes = zipStats.size;
logger.debug('ZIP created successfully');
logger.debug('Files included:', fileCount);
logger.debug('ZIP size:', formatBytes(zipSizeBytes));
// Create cleanup function
const cleanup = async () => {
try {
await fs.unlink(zipPath);
logger.debug('Cleaned up ZIP:', zipPath);
} catch (error: any) {
if (error.code !== 'ENOENT') {
logger.warn('Failed to cleanup ZIP:', error.message);
}
}
};
return {
path: zipPath,
cleanup,
fileCount,
sizeBytes: zipSizeBytes,
};
}
Domain
Subdomains
Calls
Source
Frequently Asked Questions
What does zipRepository() do?
zipRepository() is a function in the mcp codebase.
What does zipRepository() call?
zipRepository() calls 7 function(s): addFilesRecursively, buildIgnoreFilter, debug, error, estimateDirectorySize, formatBytes, warn.
What calls zipRepository()?
zipRepository() is called by 2 function(s): precacheForDirectory, resolveOrFetchGraph.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free