Skip to main content
Glama
mednabouli

MCP Multi-Context Hook Generator

by mednabouli
snap.ts2.18 kB
import fs from 'fs'; import path from 'path'; import crypto from 'crypto'; // -------------------- // Snapshot utilities // -------------------- const SNAPSHOT_DIR = '.mcp-snapshots'; function getSnapshotPath(filePath: string) { const relativePath = path.relative(process.cwd(), filePath); const hash = crypto.createHash('md5').update(relativePath).digest('hex'); return path.join(SNAPSHOT_DIR, `${hash}.snap`); } export function saveSnapshot(filePath: string) { if (!fs.existsSync(SNAPSHOT_DIR)) fs.mkdirSync(SNAPSHOT_DIR, { recursive: true }); const content = fs.readFileSync(filePath, 'utf-8'); fs.writeFileSync(getSnapshotPath(filePath), content, 'utf-8'); } export function compareSnapshot(filePath: string) { const snapPath = getSnapshotPath(filePath); if (!fs.existsSync(snapPath)) return { changed: true, message: 'No snapshot exists' }; const oldContent = fs.readFileSync(snapPath, 'utf-8'); const newContent = fs.readFileSync(filePath, 'utf-8'); if (oldContent !== newContent) { return { changed: true, message: `File changed: ${filePath}` }; } return { changed: false, message: '' }; } // -------------------- // Batch operations // -------------------- export function saveAllSnapshots({ components, pageAnalyses, hooksPath, }: { components: { filePath: string }[]; pageAnalyses: { pagePath: string }[]; hooksPath?: string; }) { components.forEach((c) => saveSnapshot(c.filePath)); pageAnalyses.forEach((p) => saveSnapshot(p.pagePath)); if (hooksPath) saveSnapshot(hooksPath); } export function checkAllSnapshots({ components, pageAnalyses, hooksPath, }: { components: { filePath: string }[]; pageAnalyses: { pagePath: string }[]; hooksPath?: string; }) { const results: string[] = []; components.forEach((c) => { const diff = compareSnapshot(c.filePath); if (diff.changed) results.push(diff.message); }); pageAnalyses.forEach((p) => { const diff = compareSnapshot(p.pagePath); if (diff.changed) results.push(diff.message); }); if (hooksPath) { const diff = compareSnapshot(hooksPath); if (diff.changed) results.push(diff.message); } return results; }

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/mednabouli/MCPV2'

If you have feedback or need assistance with the MCP directory API, please join our Discord server