UNPKG

@rip-user/rls-debugger-mcp

Version:

AI-powered MCP server for debugging Supabase Row Level Security policies with Claude structured outputs

91 lines 2.39 kB
import { promises as fs } from 'fs'; import path from 'path'; export class MemoryStore { memoryDir; memoryFile; constructor(memoryDir = './.rls-memory') { this.memoryDir = memoryDir; this.memoryFile = path.join(memoryDir, 'policy_knowledge.json'); } /** * Initialize the memory directory */ async initialize() { try { await fs.mkdir(this.memoryDir, { recursive: true }); } catch (error) { // Directory might already exist, that's fine } } /** * Load all knowledge from memory */ async loadAll() { try { const data = await fs.readFile(this.memoryFile, 'utf-8'); return JSON.parse(data); } catch { return []; } } /** * Load knowledge for specific tables */ async loadForTables(tables) { const allKnowledge = await this.loadAll(); return allKnowledge.filter(k => k.tables.some(t => tables.includes(t))); } /** * Load knowledge by type */ async loadByType(type) { const allKnowledge = await this.loadAll(); return allKnowledge.filter(k => k.type === type); } /** * Save new knowledge */ async save(knowledge) { await this.initialize(); const existing = await this.loadAll(); const newKnowledge = { ...knowledge, timestamp: new Date().toISOString() }; existing.push(newKnowledge); await fs.writeFile(this.memoryFile, JSON.stringify(existing, null, 2)); } /** * Clear all memory (use with caution) */ async clear() { try { await fs.unlink(this.memoryFile); } catch { // File might not exist, that's fine } } /** * Get memory summary */ async getSummary() { const allKnowledge = await this.loadAll(); const byType = {}; const byTable = {}; allKnowledge.forEach(k => { byType[k.type] = (byType[k.type] || 0) + 1; k.tables.forEach(table => { byTable[table] = (byTable[table] || 0) + 1; }); }); return { total: allKnowledge.length, byType, byTable }; } } //# sourceMappingURL=memory.js.map