Skip to main content
Glama

memory_export_advanced

Export memory data from DocuMCP server to files in multiple formats with customizable options for documentation workflows.

Instructions

Advanced memory export with multiple formats and options

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
outputPathYesOutput file path
optionsNo

Implementation Reference

  • Core handler implementation for memory_export_advanced tool. The exportMemories method in MemoryExportImportSystem handles advanced export with formats (json,jsonl,csv,xml,yaml,sqlite,archive), compression (gzip,zip), anonymization, encryption, filters, and includes learning/knowledge graph data.
    async exportMemories(
      outputPath: string,
      options: Partial<ExportOptions> = {},
    ): Promise<ExportResult> {
      const defaultOptions: ExportOptions = {
        format: "json",
        compression: "none",
        includeMetadata: true,
        includeLearning: true,
        includeKnowledgeGraph: true,
        anonymize: {
          enabled: false,
          fields: ["userId", "email", "personalInfo"],
          method: "hash",
        },
        encryption: {
          enabled: false,
          algorithm: "aes-256-gcm",
        },
      };
    
      const activeOptions = { ...defaultOptions, ...options };
      const startTime = Date.now();
    
      this.emit("export_started", { outputPath, options: activeOptions });
    
      try {
        // Get filtered entries
        const entries = await this.getFilteredEntries(activeOptions.filters);
    
        // Prepare export data
        const exportData = await this.prepareExportData(entries, activeOptions);
    
        // Apply anonymization if enabled
        if (activeOptions.anonymize?.enabled) {
          this.applyAnonymization(exportData, activeOptions.anonymize);
        }
    
        // Prepare output path - if compression is requested, use temp file first
        let actualOutputPath = outputPath;
        if (activeOptions.compression && activeOptions.compression !== "none") {
          // For compressed exports, export to temp file first
          if (outputPath.endsWith(".gz")) {
            actualOutputPath = outputPath.slice(0, -3); // Remove .gz suffix
          } else if (outputPath.endsWith(".zip")) {
            actualOutputPath = outputPath.slice(0, -4); // Remove .zip suffix
          }
        }
    
        // Export to specified format
        let filePath: string;
        let size = 0;
    
        switch (activeOptions.format) {
          case "json":
            filePath = await this.exportToJSON(
              actualOutputPath,
              exportData,
              activeOptions,
            );
            break;
          case "jsonl":
            filePath = await this.exportToJSONL(
              actualOutputPath,
              exportData,
              activeOptions,
            );
            break;
          case "csv":
            filePath = await this.exportToCSV(
              actualOutputPath,
              exportData,
              activeOptions,
            );
            break;
          case "xml":
            filePath = await this.exportToXML(
              actualOutputPath,
              exportData,
              activeOptions,
            );
            break;
          case "yaml":
            filePath = await this.exportToYAML(
              actualOutputPath,
              exportData,
              activeOptions,
            );
            break;
          case "sqlite":
            filePath = await this.exportToSQLite(
              actualOutputPath,
              exportData,
              activeOptions,
            );
            break;
          case "archive":
            filePath = await this.exportToArchive(
              actualOutputPath,
              exportData,
              activeOptions,
            );
            break;
          default:
            throw new Error(`Unsupported export format: ${activeOptions.format}`);
        }
    
        // Apply compression if specified
        if (activeOptions.compression && activeOptions.compression !== "none") {
          filePath = await this.applyCompression(
            filePath,
            activeOptions.compression,
            outputPath,
          );
        }
    
        // Apply encryption if enabled
        if (activeOptions.encryption?.enabled) {
          filePath = await this.applyEncryption(
            filePath,
            activeOptions.encryption,
          );
        }
    
        // Get file size
        const stats = await fs.stat(filePath);
        size = stats.size;
    
        const result: ExportResult = {
          success: true,
          filePath,
          format: activeOptions.format,
          size,
          entries: entries.length,
          metadata: {
            exportedAt: new Date(),
            version: this.version,
            source: "DocuMCP Memory System",
            includes: this.getIncludedComponents(activeOptions),
            compression:
              activeOptions.compression !== "none"
                ? activeOptions.compression
                : undefined,
            encryption: activeOptions.encryption?.enabled,
          },
          warnings: [],
          errors: [],
        };
    
        this.emit("export_completed", {
          result,
          duration: Date.now() - startTime,
        });
    
        return result;
      } catch (error) {
        const errorMessage =
          error instanceof Error ? error.message : String(error);
        this.emit("export_error", { error: errorMessage });
    
        return {
          success: false,
          format: activeOptions.format,
          size: 0,
          entries: 0,
          metadata: {
            exportedAt: new Date(),
            version: this.version,
            source: "DocuMCP Memory System",
            includes: [],
          },
          warnings: [],
          errors: [errorMessage],
        };
      }
    }
  • Type definition for ExportOptions used in the input schema of memory_export_advanced.
    export interface ExportOptions {
      format: "json" | "jsonl" | "csv" | "xml" | "yaml" | "sqlite" | "archive";
      compression?: "gzip" | "zip" | "none";
      includeMetadata: boolean;
      includeLearning: boolean;
      includeKnowledgeGraph: boolean;
      filters?: {
        types?: string[];
        dateRange?: { start: Date; end: Date };
        projects?: string[];
        tags?: string[];
        outcomes?: string[];
      };
      anonymize?: {
        enabled: boolean;
        fields: string[];
        method: "hash" | "remove" | "pseudonymize";
      };
      encryption?: {
        enabled: boolean;
        algorithm: "aes-256-gcm" | "aes-192-gcm" | "aes-128-gcm";
        password?: string;
      };
    }
  • Tool registration and input schema definition for memory_export_advanced in the memoryTools export array.
    {
      name: "memory_export_advanced",
      description: "Advanced memory export with multiple formats and options",
      inputSchema: {
        type: "object",
        properties: {
          outputPath: { type: "string", description: "Output file path" },
          options: {
            type: "object",
            properties: {
              format: {
                type: "string",
                enum: [
                  "json",
                  "jsonl",
                  "csv",
                  "xml",
                  "yaml",
                  "sqlite",
                  "archive",
                ],
                default: "json",
              },
              compression: {
                type: "string",
                enum: ["gzip", "zip", "none"],
                default: "none",
              },
              includeMetadata: { type: "boolean", default: true },
              includeLearning: { type: "boolean", default: true },
              includeKnowledgeGraph: { type: "boolean", default: true },
              filters: {
                type: "object",
                properties: {
                  types: { type: "array", items: { type: "string" } },
                  dateRange: {
                    type: "object",
                    properties: {
                      start: { type: "string", format: "date-time" },
                      end: { type: "string", format: "date-time" },
                    },
                  },
                  projects: { type: "array", items: { type: "string" } },
                  tags: { type: "array", items: { type: "string" } },
                  outcomes: { type: "array", items: { type: "string" } },
                },
              },
              anonymize: {
                type: "object",
                properties: {
                  enabled: { type: "boolean", default: false },
                  fields: { type: "array", items: { type: "string" } },
                  method: {
                    type: "string",
                    enum: ["hash", "remove", "pseudonymize"],
                    default: "hash",
                  },
                },
              },
              encryption: {
                type: "object",
                properties: {
                  enabled: { type: "boolean", default: false },
                  algorithm: {
                    type: "string",
                    enum: ["aes-256-gcm", "aes-192-gcm", "aes-128-gcm"],
                    default: "aes-256-gcm",
                  },
                  password: { type: "string" },
                },
              },
            },
          },
        },
        required: ["outputPath"],
      },
  • Helper method for filtering memory entries based on export options (types, date range, projects, tags, outcomes).
      filters?: ExportOptions["filters"],
    ): Promise<MemoryEntry[]> {
      let entries = await this.storage.getAll();
    
      if (!filters) return entries;
    
      // Apply type filter
      if (filters.types && filters.types.length > 0) {
        entries = entries.filter((entry) => filters.types!.includes(entry.type));
      }
    
      // Apply date range filter
      if (filters.dateRange) {
        entries = entries.filter((entry) => {
          const entryDate = new Date(entry.timestamp);
          return (
            entryDate >= filters.dateRange!.start &&
            entryDate <= filters.dateRange!.end
          );
        });
      }
    
      // Apply project filter
      if (filters.projects && filters.projects.length > 0) {
        entries = entries.filter((entry) =>
          filters.projects!.some(
            (project) =>
              entry.data.projectPath?.includes(project) ||
              entry.data.projectId === project,
          ),
        );
      }
    
      // Apply tags filter
      if (filters.tags && filters.tags.length > 0) {
        entries = entries.filter(
          (entry) => entry.tags?.some((tag) => filters.tags!.includes(tag)),
        );
      }
    
      // Apply outcomes filter
      if (filters.outcomes && filters.outcomes.length > 0) {
        entries = entries.filter(
          (entry) =>
            filters.outcomes!.includes(entry.data.outcome) ||
            (entry.data.success === true &&
              filters.outcomes!.includes("success")) ||
            (entry.data.success === false &&
              filters.outcomes!.includes("failure")),
        );
      }
    
      return entries;
    }
  • Prepares comprehensive export data including memories, optional learning system data and knowledge graph.
    private async prepareExportData(
      entries: MemoryEntry[],
      options: ExportOptions,
    ): Promise<any> {
      const exportData: any = {
        metadata: {
          version: this.version,
          exportedAt: new Date().toISOString(),
          source: "DocuMCP Memory System",
          entries: entries.length,
          options: {
            includeMetadata: options.includeMetadata,
            includeLearning: options.includeLearning,
            includeKnowledgeGraph: options.includeKnowledgeGraph,
          },
        },
        memories: entries,
      };
    
      // Include learning data if requested
      if (options.includeLearning) {
        const patterns = await this.learningSystem.getPatterns();
        exportData.learning = {
          patterns,
          statistics: await this.learningSystem.getStatistics(),
        };
      }
    
      // Include knowledge graph if requested
      if (options.includeKnowledgeGraph) {
        const nodes = await this.knowledgeGraph.getAllNodes();
        const edges = await this.knowledgeGraph.getAllEdges();
        exportData.knowledgeGraph = {
          nodes,
          edges,
          statistics: await this.knowledgeGraph.getStatistics(),
        };
      }
    
      return exportData;
    }
Behavior2/5

Does the description disclose side effects, auth requirements, rate limits, or destructive behavior?

No annotations are provided, so the description carries full burden. It mentions 'multiple formats and options' but doesn't specify what formats are available, what the options do, whether this is a read-only or destructive operation, or any behavioral traits like rate limits, authentication needs, or output behavior. The description is too vague to provide meaningful behavioral context.

Agents need to know what a tool does to the world before calling it. Descriptions should go beyond structured annotations to explain consequences.

Conciseness5/5

Is the description appropriately sized, front-loaded, and free of redundancy?

The description is a single, efficient sentence that front-loads the key information ('Advanced memory export') and adds necessary qualifiers ('with multiple formats and options'). There's zero wasted text, and it's appropriately sized for a tool with two parameters.

Shorter descriptions cost fewer tokens and are easier for agents to parse. Every sentence should earn its place.

Completeness2/5

Given the tool's complexity, does the description cover enough for an agent to succeed on first attempt?

Given the complexity (advanced export with formats/options), no annotations, 50% schema coverage, no output schema, and a sibling tool ('memory_export'), the description is incomplete. It doesn't explain what 'advanced' entails, what formats are supported, how options work, or differentiate meaningfully from the basic version. For a tool with an undocumented 'options' object and no output schema, more detail is needed.

Complex tools with many parameters or behaviors need more documentation. Simple tools need less. This dimension scales expectations accordingly.

Parameters3/5

Does the description clarify parameter syntax, constraints, interactions, or defaults beyond what the schema provides?

Schema description coverage is 50% (only 'outputPath' has a description). The description mentions 'multiple formats and options', which hints at the 'options' parameter's purpose, but doesn't explain what those options are or how they affect the export. It adds some meaning beyond the schema but doesn't fully compensate for the undocumented 'options' parameter.

Input schemas describe structure but not intent. Descriptions should explain non-obvious parameter relationships and valid value ranges.

Purpose4/5

Does the description clearly state what the tool does and how it differs from similar tools?

The description clearly states the tool's purpose as 'Advanced memory export with multiple formats and options', which includes a specific verb ('export') and resource ('memory'). It distinguishes from the simpler 'memory_export' sibling tool by specifying 'advanced' with 'multiple formats and options'. However, it doesn't specify what makes it 'advanced' beyond formats/options.

Agents choose between tools based on descriptions. A clear purpose with a specific verb and resource helps agents select the right tool.

Usage Guidelines2/5

Does the description explain when to use this tool, when not to, or what alternatives exist?

The description provides no guidance on when to use this tool versus alternatives. It doesn't mention when to choose this over the basic 'memory_export' tool or other memory-related tools like 'memory_migration' or 'memory_visualization'. No context about prerequisites, typical use cases, or exclusions is provided.

Agents often have multiple tools that could apply. Explicit usage guidance like "use X instead of Y when Z" prevents misuse.

Install Server

Other 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/tosin2013/documcp'

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