handlePrecache() — mcp Function Reference
Architecture documentation for the handlePrecache() function in index.ts from the mcp codebase.
Entity Profile
Dependency Diagram
graph TD 8f9bd40a_a38b_c157_ad49_822975099f71["handlePrecache()"] a8b6f9ab_3b5e_37b9_6276_9a5fda5bb2c4["index.ts"] 8f9bd40a_a38b_c157_ad49_822975099f71 -->|defined in| a8b6f9ab_3b5e_37b9_6276_9a5fda5bb2c4 9b0f2e33_56dd_6b97_6fd4_a4a2c45675d5["main()"] 9b0f2e33_56dd_6b97_6fd4_a4a2c45675d5 -->|calls| 8f9bd40a_a38b_c157_ad49_822975099f71 5c90e8cd_7cb8_59e4_cdeb_8ef1addd217e["error()"] 8f9bd40a_a38b_c157_ad49_822975099f71 -->|calls| 5c90e8cd_7cb8_59e4_cdeb_8ef1addd217e style 8f9bd40a_a38b_c157_ad49_822975099f71 fill:#6366f1,stroke:#818cf8,color:#fff
Relationship Graph
Source Code
src/index.ts lines 52–203
async function handlePrecache(args: string[]) {
if (args.length === 0) {
console.error('Usage: supermodel-mcp precache <directory> [--output-dir <dir>] [--name <repo-name>]');
console.error('');
console.error('Pre-compute a code graph for a repository and save it to disk.');
console.error('');
console.error('Options:');
console.error(' --output-dir <dir> Directory to save the cache file (default: ./supermodel-cache)');
console.error(' --name <name> Repository name for the cache key (default: directory basename)');
console.error('');
console.error('Environment:');
console.error(' SUPERMODEL_API_KEY Required. API key for the Supermodel service.');
console.error(' SUPERMODEL_CACHE_DIR Alternative to --output-dir.');
process.exit(1);
}
// Parse args
let directory = '';
let outputDir = process.env.SUPERMODEL_CACHE_DIR || './supermodel-cache';
let repoName = '';
for (let i = 0; i < args.length; i++) {
if (args[i] === '--output-dir' && i + 1 < args.length) {
outputDir = args[++i];
} else if (args[i] === '--name' && i + 1 < args.length) {
repoName = args[++i];
} else if (!args[i].startsWith('--')) {
directory = args[i];
}
}
if (!directory) {
console.error('Error: directory argument is required');
process.exit(1);
}
if (!process.env.SUPERMODEL_API_KEY) {
console.error('Error: SUPERMODEL_API_KEY environment variable is required');
process.exit(1);
}
const { resolve, basename, join } = require('path');
const { execSync } = require('child_process');
const { existsSync } = require('fs');
const resolvedDir = resolve(directory);
// Detect repo name from git remote, falling back to directory basename
let detectedName = basename(resolvedDir);
try {
const remote = execSync('git remote get-url origin', {
cwd: resolvedDir, encoding: 'utf-8', timeout: 2000,
}).trim();
const match = remote.match(/\/([^\/]+?)(?:\.git)?$/);
if (match) detectedName = match[1];
} catch {}
// Get commit hash for commit-specific caching
let commitHash = '';
try {
commitHash = execSync('git rev-parse --short HEAD', {
cwd: resolvedDir, encoding: 'utf-8', timeout: 2000,
}).trim();
} catch {}
const name = repoName || (commitHash ? `${detectedName}_${commitHash}` : detectedName);
// Check if cache file already exists (skip redundant API calls)
const { saveCacheToDisk, buildIndexes, sanitizeFileName } = require('./cache/graph-cache');
const expectedPath = join(outputDir, `${sanitizeFileName(name)}.json`);
if (existsSync(expectedPath)) {
console.error(`Cache already exists: ${expectedPath}`);
console.error('Skipping precache (graph already generated for this commit).');
return;
}
console.error(`Pre-computing graph for: ${resolvedDir}`);
console.error(`Repository name: ${detectedName}, commit: ${commitHash || 'unknown'}`);
console.error(`Cache file: ${expectedPath}`);
console.error('');
// Import what we need
Domain
Subdomains
Defined In
Calls
Called By
Source
Frequently Asked Questions
What does handlePrecache() do?
handlePrecache() is a function in the mcp codebase, defined in src/index.ts.
Where is handlePrecache() defined?
handlePrecache() is defined in src/index.ts at line 52.
What does handlePrecache() call?
handlePrecache() calls 1 function(s): error.
What calls handlePrecache()?
handlePrecache() is called by 1 function(s): main.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free