get_file_ledger
Retrieve the complete change history of a file to understand its modification timeline before making edits.
Instructions
Get all logged changes that touched a specific file path. Use to understand the change history of a file before modifying it.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| filePath | Yes |
Implementation Reference
- src/managers/LedgerManager.ts:67-81 (handler)Core handler: getFileLedger reads the ledger file, filters entries whose filesAffected include the given filePath (normalized), and returns matching entries along with git branch/sha context.
async function getFileLedger(filePath: string): Promise<LedgerQueryResult> { const [entries, context] = await Promise.all([ fs.readLedger(ledgerPath), git.getBranchContext(repoDir), ]); const normalized = filePath.replace(/\\/g, '/'); return { entries: entries.filter((e) => e.filesAffected.some((f) => f.replace(/\\/g, '/').includes(normalized)), ), branch: context.branch, sha: context.shortSha, }; } - src/tools/ledger.tool.ts:20-22 (schema)Zod schema for get_file_ledger: requires filePath (non-empty string).
export const GetFileLedgerSchema = z.object({ filePath: z.string().min(1), }); - src/tools/ledger.tool.ts:43-48 (registration)Registration of the 'get_file_ledger' MCP tool: description, schema binding, and handler that delegates to manager.getFileLedger().
server.tool('get_file_ledger', 'Get all logged changes that touched a specific file path. Use to understand the change history of a file before modifying it.', GetFileLedgerSchema.shape, async (args) => { const result = await manager.getFileLedger(args.filePath); return { content: [{ type: 'text' as const, text: JSON.stringify(result, null, 2) }], }; }); - src/access/FileSystemAccess.ts:49-57 (helper)Helper: readLedger reads the JSONL ledger file and parses each line into a LedgerEntry array. Used by getFileLedger to load all entries.
async function readLedger(ledgerPath: string): Promise<LedgerEntry[]> { if (!existsSync(ledgerPath)) return []; const raw = await readFile(ledgerPath, 'utf8'); return raw .trim() .split('\n') .filter(Boolean) .map((line) => JSON.parse(line) as LedgerEntry); } - src/index.ts:49-50 (registration)Top-level wiring: registerLedgerTools is called with the server and ledgerManager, connecting the tool to the MCP server.
registerCodeSearchTools(server, codeSearchManager, REPO_DIR); registerLedgerTools(server, ledgerManager);