Skip to content

MCP memory tools (memory_usage, memory_search) don't use ReasoningBank semantic search despite initialization #812

@dshep

Description

@dshep

Description

The MCP memory tools and CLI memory commands use separate storage systems, preventing MCP users from accessing ReasoningBank's semantic search capabilities even when ReasoningBank is initialized and active.

Current Behavior

CLI Commands (work with ReasoningBank):

$ claude-flow memory mode
ReasoningBank Mode: Initialized ✅ (will be used by default)

$ claude-flow memory store "auth-pattern" "Use JWT with RS256"
🧠 Using ReasoningBank mode...
✅ Stored successfully in ReasoningBank
🔍 Semantic search: enabled

$ claude-flow memory query "JWT security"
✅ Found 5 results (semantic search):
📌 auth-pattern
   Match Score: 95.3%
   Confidence: 80.0%

MCP Tools (don't use ReasoningBank):

// Store via MCP
await mcp__claude_flow__memory_usage({
  action: "store",
  key: "auth-pattern",
  value: "Use JWT with RS256",
  namespace: "default"
});
// ✅ Success - but stored in DIFFERENT database

// Try to retrieve CLI-stored data via MCP
await mcp__claude_flow__memory_usage({
  action: "retrieve",
  key: "auth-pattern",
  namespace: "default"
});
// ❌ Returns: { found: false, value: null }

// Try semantic search via MCP
await mcp__claude_flow__memory_search({
  pattern: "JWT security",
  namespace: "default"
});
// ❌ Returns: { success: true } but NO actual search results

Root Cause

Two Separate Code Paths:

  1. CLI Commands (src/cli/simple-commands/memory.js):

    • Uses src/reasoningbank/reasoningbank-adapter.js
    • Stores in .swarm/memory.db (ReasoningBank SQLite)
    • Supports semantic search via agentic-flow
    • Has --reasoningbank flag and auto-detection
  2. MCP Tools (MCP server implementation):

    • Uses different memory manager
    • Stores in separate SQLite database
    • NO semantic search capability
    • NO access to ReasoningBank features

Data Isolation:

  • Items stored via CLI are invisible to MCP tools
  • Items stored via MCP are invisible to CLI commands
  • Users cannot leverage ReasoningBank features from MCP clients

Impact

This affects any application using MCP tools (like Claude Code, IDEs, etc.):

  1. No Semantic Search - Cannot query by meaning/intent via MCP
  2. Data Fragmentation - Must choose CLI or MCP, can't use both
  3. Feature Inequality - CLI has advanced features, MCP doesn't
  4. Breaking Workflows - SPARC commands using MCP can't access ReasoningBank
  5. Confusing UX - memory mode says ReasoningBank is active, but MCP doesn't use it

Steps to Reproduce

  1. Initialize ReasoningBank:

    claude-flow memory init --reasoningbank
  2. Verify it's active:

    claude-flow memory mode
    # Shows: "ReasoningBank Mode: Initialized ✅"
  3. Store data via CLI:

    claude-flow memory store "test-key" "test value" --namespace default
  4. Try to retrieve via MCP:

    await mcp__claude_flow__memory_usage({
      action: "retrieve",
      key: "test-key",
      namespace: "default"
    });
  5. Expected: Returns { found: true, value: "test value" }

  6. Actual: Returns { found: false, value: null }

Expected Behavior

Option A: Unified Storage (Recommended)

MCP tools should use the same storage backend as CLI commands:

  • If ReasoningBank is initialized → MCP uses .swarm/memory.db
  • If not initialized → MCP uses fallback storage
  • Data stored via CLI is accessible via MCP and vice versa

Option B: Semantic Search MCP Tool

Add a new MCP tool for semantic queries:

await mcp__claude_flow__semantic_search({
  query: "JWT security patterns",
  namespace: "default",
  limit: 10,
  minConfidence: 0.7
});

// Returns:
{
  success: true,
  results: [
    {
      key: "auth-pattern",
      value: "Use JWT with RS256...",
      matchScore: 0.953,
      confidence: 0.80,
      usageCount: 5
    }
  ]
}

Option C: Auto-Detection in MCP

Update MCP memory_usage and memory_search to auto-detect ReasoningBank:

  • Check if .swarm/memory.db exists
  • If yes → use ReasoningBank adapter
  • If no → use basic storage
  • Same behavior as CLI's AUTO mode

Proposed Solution

Phase 1: Shared Storage Layer

Create a unified memory manager that both CLI and MCP use:

// src/memory/unified-reasoningbank-manager.js
export class UnifiedMemoryManager {
  async detectMode() {
    // Auto-detect ReasoningBank like CLI does
    const rbInitialized = await fileExists('.swarm/memory.db');
    return rbInitialized ? 'reasoningbank' : 'basic';
  }

  async store(key, value, options) {
    const mode = await this.detectMode();
    if (mode === 'reasoningbank') {
      return await this.reasoningBankStore(key, value, options);
    } else {
      return await this.basicStore(key, value, options);
    }
  }

  async query(search, options) {
    const mode = await this.detectMode();
    if (mode === 'reasoningbank') {
      // Semantic search!
      return await this.reasoningBankQuery(search, options);
    } else {
      // Keyword search
      return await this.basicQuery(search, options);
    }
  }
}

Phase 2: Update MCP Tools

Update MCP server to use unified manager:

// MCP memory_usage tool
case 'store':
  const manager = new UnifiedMemoryManager();
  const result = await manager.store(key, value, { namespace });
  return {
    success: true,
    stored: true,
    mode: await manager.detectMode(), // 'reasoningbank' or 'basic'
    semanticSearch: await manager.detectMode() === 'reasoningbank'
  };

Phase 3: Enhanced MCP memory_search

Return actual search results instead of just success:

// MCP memory_search tool
const manager = new UnifiedMemoryManager();
const results = await manager.query(pattern, { namespace, limit });

return {
  success: true,
  mode: await manager.detectMode(),
  results: results.map(r => ({
    key: r.key,
    value: r.value,
    score: r.score,        // Semantic similarity (if ReasoningBank)
    confidence: r.confidence,
    namespace: r.namespace
  }))
};

Environment

  • claude-flow version: 2.7.0-alpha.10
  • agentic-flow version: 1.5.13
  • Node version: v22.19.0
  • Platform: macOS (Darwin 24.6.0)
  • Installation: Global (npm install -g claude-flow@alpha)

Additional Context

Current Workaround:

Applications using MCP must use CLI commands via Bash to access ReasoningBank:

// Can't use MCP for semantic search - must use CLI
const results = await Bash(`claude-flow memory query "JWT patterns"`);
const parsed = parseCliOutput(results); // Parse formatted text output

This is suboptimal because:

  1. CLI output is formatted text, not structured JSON
  2. Requires parsing with regex/string manipulation
  3. Adds shell command overhead
  4. Error handling is more complex

Related Issues:

  • Memory fragmentation between CLI and MCP
  • memory_search returns success but no data
  • ReasoningBank features not accessible via MCP

Use Case:

We're building SPARC workflow commands that use MCP memory tools for persistence. We want to add semantic discovery ("find similar architecture patterns to this task") but can't access ReasoningBank features through MCP, forcing us to use CLI workarounds.

Checklist

  • ReasoningBank is initialized (.swarm/memory.db exists)
  • CLI commands use ReasoningBank successfully
  • MCP tools don't access ReasoningBank storage
  • Data stored via CLI is not accessible via MCP
  • memory_search returns success but no results
  • Workaround using CLI via Bash works but is suboptimal

Would love to see MCP tools gain parity with CLI features! 🙏

The ReasoningBank semantic search is incredibly powerful - it should be accessible to all claude-flow users, not just CLI users.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions