Skip to main content
Glama

memory_import_bundle

Import a memory bundle while verifying checksums and skipping duplicates. Each import is recorded as a signed receipt for cryptographic accountability.

Instructions

Import a memory bundle from another Agent Receipts instance. Verifies checksums before importing. Skips memories that already exist locally. The import operation itself is recorded as a signed receipt.

Input Schema

TableJSON Schema
NameRequiredDescriptionDefault
bundleYesThe memory bundle JSON object to import
skip_existingNoSkip entities/observations that already exist (default: true)

Implementation Reference

  • Core importBundle method on MemoryEngine — verifies bundle checksum, imports entities/observations/relationships (skipping existing if configured), records the operation as a signed receipt.
    async importBundle(bundle: MemoryBundle, params?: {
      skipExisting?: boolean
    }): Promise<ImportBundleResult> {
      const { skipExisting = true } = params ?? {}
    
      // Verify checksum
      const checksumPayload = JSON.stringify({
        entities: [...bundle.entities].sort((a, b) => a.entity_id.localeCompare(b.entity_id)),
        observations: [...bundle.observations].sort((a, b) => a.observation_id.localeCompare(b.observation_id)),
        relationships: [...bundle.relationships].sort((a, b) => a.relationship_id.localeCompare(b.relationship_id)),
      })
      const computedChecksum = hashData(checksumPayload)
      if (computedChecksum !== bundle.checksum) {
        throw new Error('Bundle checksum mismatch — data may have been tampered with')
      }
    
      const imported = { entities: 0, observations: 0, relationships: 0 }
      const skipped = { entities: 0, observations: 0, relationships: 0 }
    
      for (const entity of bundle.entities) {
        const existing = this.memoryStore.getEntity(entity.entity_id)
        if (existing && skipExisting) {
          skipped.entities++
          continue
        }
        if (!existing) {
          this.memoryStore.createEntity(entity)
          imported.entities++
        }
      }
    
      for (const obs of bundle.observations) {
        const existing = this.memoryStore.getObservation(obs.observation_id)
        if (existing && skipExisting) {
          skipped.observations++
          continue
        }
        if (!existing) {
          this.memoryStore.addObservation(obs)
          imported.observations++
        }
      }
    
      for (const rel of bundle.relationships) {
        try {
          this.memoryStore.addRelationship(rel)
          imported.relationships++
        } catch {
          skipped.relationships++
        }
      }
    
      const receipt = await this.receiptEngine.create({
        action: 'memory.import_bundle',
        receipt_type: 'memory',
        input_hash: hashData({ bundle_id: bundle.bundle_id }),
        output_hash: hashData(imported),
        status: 'completed',
        metadata: {
          memory: {
            memory_operation: 'create',
            entity_id: null,
            observation_id: null,
            relationship_id: null,
            scope: 'user',
            query: null,
            results_count: imported.entities + imported.observations + imported.relationships,
            confidence: null,
          },
          bundle_id: bundle.bundle_id,
        },
      })
    
      return { imported, skipped, receipt }
    }
  • Zod schema for MemoryBundle — the bundle format validated on import (bundle_id, checksum, entities, observations, relationships, etc.)
    })
    export type MemoryQuery = z.infer<typeof MemoryQuery>
    
    // --- Bundle Types ---
    
    export const MemoryBundle = z.object({
  • ImportBundleResult interface — shape of the result returned by importBundle.
    export interface ImportBundleResult {
      imported: { entities: number; observations: number; relationships: number }
      skipped: { entities: number; observations: number; relationships: number }
      receipt: ActionReceipt
    }
  • MCP tool registration — defines Zod input schema (bundle, skip_existing), calls memoryEngine.importBundle, returns JSON result.
    import { z } from 'zod'
    import type { McpServer } from '@modelcontextprotocol/sdk/server/mcp.js'
    import type { MemoryEngine } from '../engine/memory-engine.js'
    
    export function registerMemoryImportBundle(server: McpServer, memoryEngine: MemoryEngine): void {
      server.tool(
        'memory_import_bundle',
        'Import a memory bundle from another Agent Receipts instance. Verifies checksums before importing. Skips memories that already exist locally. The import operation itself is recorded as a signed receipt.',
        {
          bundle: z.record(z.unknown()).describe('The memory bundle JSON object to import'),
          skip_existing: z.boolean().optional().describe('Skip entities/observations that already exist (default: true)'),
        },
        async (params) => {
          const result = await memoryEngine.importBundle(
            params.bundle as Parameters<typeof memoryEngine.importBundle>[0],
            { skipExisting: params.skip_existing },
          )
    
          return {
            content: [{
              type: 'text' as const,
              text: JSON.stringify({
                imported: result.imported,
                skipped: result.skipped,
                receipt_id: result.receipt.receipt_id,
              }, null, 2),
            }],
          }
        },
      )
    }
  • Import and registration of the memory_import_bundle tool in registerAllTools.
    import { registerMemoryImportBundle } from './memory-import-bundle.js'
    
    export function registerAllTools(
      server: McpServer,
      engine: ReceiptEngine,
      memoryEngine?: MemoryEngine,
      memoryStore?: MemoryStore,
      agentId?: string,
    ): void {
      registerCreateReceipt(server, engine)
      registerCompleteReceipt(server, engine)
      registerTrackAction(server, engine)
      registerVerifyReceipt(server, engine)
      registerGetReceipt(server, engine)
      registerListReceipts(server, engine)
      registerGetChain(server, engine)
      registerGetPublicKey(server, engine)
      registerJudgeReceipt(server, engine)
      registerCompleteJudgment(server, engine)
      registerGetJudgments(server, engine)
      registerCleanup(server, engine, memoryStore)
      registerGenerateInvoice(server, engine)
      registerGetStarted(server, engine)
    
      // Memory tools
      if (memoryEngine && memoryStore && agentId) {
        registerMemoryObserve(server, memoryEngine, agentId, memoryStore)
        registerMemoryRecall(server, memoryEngine, agentId)
        registerMemoryForget(server, memoryEngine, agentId)
        registerMemoryEntities(server, memoryStore)
        registerMemoryRelate(server, memoryEngine, agentId)
        registerMemoryProvenance(server, memoryEngine)
        registerMemoryAudit(server, memoryEngine)
        registerMemoryContext(server, memoryEngine)
        registerMemoryExportBundle(server, memoryEngine)
        registerMemoryImportBundle(server, memoryEngine)
      }
    }
Behavior4/5

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

No annotations are provided, so the description carries the full burden. It discloses checksum verification, skipping existing memories, and recording the import as a signed receipt. This is good for a write operation, though it doesn't mention potential failure modes.

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 three sentences, front-loaded with purpose, and contains no fluff. Every sentence provides essential information.

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

Completeness4/5

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

For a tool with no output schema and no annotations, the description covers purpose, input handling, deduplication, and side effects. It lacks explanation of return values, but that is partially compensated by the schema coverage.

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 coverage is 100%, so baseline is 3. The description adds context for 'bundle' (from another instance) and aligns with 'skip_existing' schema, but doesn't compensate beyond that.

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

Purpose5/5

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

The description clearly states the tool imports a memory bundle from another instance, using specific verbs ('Import') and resources ('memory bundle'). It distinguishes from siblings like 'memory_export_bundle' by focusing on import behavior.

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

Usage Guidelines3/5

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

The description mentions importing from another instance and skipping existing memories, but lacks explicit guidance on when to use this tool versus alternatives (e.g., memory_audit, memory_context). It does not state when not to use it.

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/webaesbyamin/agent-receipts'

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