Skip to main content
Glama

export_memory_bank

Export structured project documentation from Memory Bank MCP in JSON or folder format. Specify the output path to save project knowledge for seamless access and management.

Input Schema

NameRequiredDescriptionDefault
formatNoExport formatfolder
outputPathNo

Input Schema (JSON Schema)

{ "$schema": "http://json-schema.org/draft-07/schema#", "additionalProperties": false, "properties": { "format": { "default": "folder", "description": "Export format", "enum": [ "json", "folder" ], "type": "string" }, "outputPath": { "type": "string" } }, "type": "object" }

Implementation Reference

  • The core handler function that implements the export_memory_bank tool logic. It exports the memory bank directory either as a folder copy or as a JSON file with metadata.
    export async function exportMemoryBank(sourceDir: string, format: string = 'folder', outputPath: string): Promise<string> { try { // Check if source directory exists if (!await fs.pathExists(sourceDir)) { throw new Error(`Source directory not found: ${sourceDir}`); } const exportDir = path.dirname(outputPath); await fs.ensureDir(exportDir); if (format === 'folder') { // Export as folder (copy entire directory structure) const exportFolderPath = path.join(exportDir, path.basename(sourceDir)); await fs.copy(sourceDir, exportFolderPath); console.log(`Memory Bank folder exported to "${exportFolderPath}".`); return exportFolderPath; } else if (format === 'json') { // Export as JSON const documents = await readAllDocuments(sourceDir); // Add metadata const exportData = { exportDate: new Date().toISOString(), memoryBank: documents }; const jsonFilePath = outputPath.endsWith('.json') ? outputPath : `${outputPath}.json`; await fs.writeFile(jsonFilePath, JSON.stringify(exportData, null, 2), 'utf-8'); console.log(`Memory Bank data exported to "${jsonFilePath}" in JSON format.`); return jsonFilePath; } else { throw new Error(`Unsupported format: ${format}. Use 'folder' or 'json'.`); } } catch (error) { console.error('Error exporting:', error); throw new Error(`Failed to export Memory Bank: ${error}`); } }
  • MCP server tool registration for 'export_memory_bank', including input validation schema and thin handler that delegates to the core exportMemoryBank function.
    server.tool( 'export_memory_bank', { format: z.enum(['json', 'folder']).default('folder').describe('Export format'), outputPath: z.string().optional() }, async ({ format, outputPath }) => { try { // Check if Memory Bank has been initialized if (!MEMORY_BANK_DIR) { return { content: [{ type: 'text', text: `ℹ️ Memory Bank not initialized. Please use 'initialize_memory_bank' tool first.` }] }; } // Check if Memory Bank directory exists on disk if (!await fs.pathExists(MEMORY_BANK_DIR)) { return { content: [{ type: 'text', text: `ℹ️ Memory Bank directory (${MEMORY_BANK_DIR}) not found on disk. Please use 'initialize_memory_bank' tool first.` }] }; } // Ensure we have an absolute path for the output const defaultOutputPath = path.resolve(path.join(process.cwd(), 'memory-bank-export')); const targetOutputPath = outputPath ? path.resolve(outputPath) : defaultOutputPath; console.log(`Exporting Memory Bank from ${MEMORY_BANK_DIR} to ${targetOutputPath}`); // Call exportMemoryBank function const exportResult = await exportMemoryBank(MEMORY_BANK_DIR, format, targetOutputPath); // Create message based on format type const formatMessage = format === 'json' ? 'JSON file' : 'folder'; return { content: [{ type: 'text', text: `✅ Memory Bank successfully exported as ${formatMessage}: ${exportResult}` }] }; } catch (error) { console.error('Error exporting Memory Bank:', error); return { content: [{ type: 'text', text: `❌ Error: ${error instanceof Error ? error.message : String(error)}` }], isError: true }; } } );
  • Zod schema defining input parameters for the export_memory_bank tool: format (enum 'json' or 'folder', default 'folder') and optional outputPath.
    { format: z.enum(['json', 'folder']).default('folder').describe('Export format'), outputPath: z.string().optional() },
  • Import statement that brings in the exportMemoryBank helper function from fileManager.
    import { createMemoryBankStructure, saveDocument, readDocument, readAllDocuments, exportMemoryBank } from '../utils/fileManager.js';

Other Tools

Related Tools

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/tuncer-byte/memory-bank-MCP'

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