Fix/mcp reasoningbank integration
๐ Unify MCP and CLI Memory Storage with ReasoningBank Integration
Fixes #812
Summary
MCP memory tools (memory_usage, memory_search) and CLI memory commands previously used separate storage
systems, preventing MCP users from accessing ReasoningBank's semantic search capabilities. This PR unifies
both interfaces to share the same storage backend with automatic ReasoningBank detection.
Problem
Before this fix:
- โ CLI commands used ReasoningBank (
.swarm/memory.db) with semantic search - โ MCP tools used separate database with no semantic search
- โ Data stored via CLI was invisible to MCP (and vice versa)
- โ
memory_searchMCP tool returned success but no actual results - โ MCP users forced to use CLI via Bash workarounds
Example of broken behavior:
# Store via CLI - goes to ReasoningBank
$ claude-flow memory store "auth-pattern" "Use JWT with RS256"
โ
Stored successfully in ReasoningBank
# Try to retrieve via MCP - different database!
await mcp__claude_flow__memory_usage({
action: "retrieve",
key: "auth-pattern"
});
// โ Returns: { found: false, value: null }
Solution: UnifiedMemoryManager
Created a unified memory layer that both CLI and MCP use:
Priority-based Storage System:
1. ๐ง ReasoningBank (.swarm/memory.db) - AI-powered semantic search
2. ๐๏ธ SQLite (unified-memory.db) - Fast SQL queries
3. ๐ JSON (memory-store.json) - Always-available fallback
Features:
- โ
Auto-Detection: Checks for .swarm/memory.db existence
- โ
Lazy Loading: Imports ReasoningBank adapter only when needed
- โ
Graceful Fallback: Falls back to JSON if ReasoningBank unavailable
- โ
Semantic Search: Query by meaning, not keywords
- โ
Similarity Scores: Ranked results (0-100%)
Changes
1. Core Integration (src/memory/unified-memory-manager.js)
- Added ReasoningBank detection and integration
- Implemented priority-based storage selection
- Enhanced methods: store(), query(), get(), getStats()
2. MCP Server (src/mcp/mcp-server.js)
- Replaced fallback-store with UnifiedMemoryManager
- Added memory_search case statement (was missing!)
- Enhanced responses with storage_type and semantic_search metadata
Test Results โ
CLI โ MCP Interoperability (Semantic Search):
# Store via CLI
$ claude-flow memory store "authentication-best-practices" \
"Always use environment variables for API keys..." \
--namespace security
โ
Stored in ReasoningBank
# Query via MCP with DIFFERENT words
await memoryManager.query("How should I store API credentials?");
# Result: Found with 31.0% similarity! โจ
{
key: "authentication-best-practices",
score: 0.310,
confidence: 0.80,
mode: "reasoningbank"
}
Semantic matching works:
- Query: "How should I store API credentials?"
- Found: "Always use environment variables for API keys"
- System understands: "store credentials" โ "environment variables"
Impact
For MCP Users:
- ๐ง Semantic search now accessible via MCP tools
- ๐ Similarity scores in search results
- ๐ Can read data stored via CLI
- โก Auto-detection, no config needed
- ๐ก๏ธ Graceful fallback to JSON mode
For CLI Users:
- ๐ Data now accessible via MCP tools
- โ
No breaking changes
- ๐ Enhanced MCP response metadata
Backward Compatibility โ
- 100% Compatible: No breaking changes to existing APIs
- JSON Fallback: Works without ReasoningBank
- Existing Data: All previous data remains accessible
- Same Signatures: No changes to MCP tool parameters
Files Changed
- src/memory/unified-memory-manager.js - ReasoningBank integration
- src/mcp/mcp-server.js - UnifiedMemoryManager adoption + missing case fix
Testing
# 1. Store via CLI
./bin/claude-flow memory store "test-key" "semantic test value" --namespace test
# 2. Query via MCP with different words
# UnifiedMemoryManager returns results with similarity scores
# 3. Verify storage type
./bin/claude-flow memory mode
# Should show: "ReasoningBank Mode: Initialized โ
"
---
Ready for review! ๐ Full interoperability between CLI and MCP memory interfaces with semantic search
capabilities.
the PR is compatable with v2.7.0-alpha.14 - verified the issue still exists in v2.7.0-alpha.14 and this fixes it
๐ Updated for v2.7.1 Compatibility
This PR has been updated to resolve conflicts with upstream's v2.7.1 release.
Changes in This Update
1. Merged upstream/main (v2.7.1)
- Includes all v2.7.1 features and fixes
- Commands โ Skills migration
- Enhanced testing infrastructure
- Docker verification suite
2. Fixed neural_train API Mismatch
Upstream v2.7.1 added neural_train pattern persistence using this.memoryStore, but this branch refactored to use this.memoryManager (UnifiedMemoryManager with ReasoningBank).
Applied fixes:
// โ Upstream v2.7.1 (doesn't work with this PR's refactoring):
if (this.memoryStore) {
await this.memoryStore.retrieve(key, {namespace: 'patterns'});
}
// โ
Fixed for UnifiedMemoryManager:
if (this.memoryManager) {
const entry = await this.memoryManager.get(key, 'patterns');
const value = entry?.value;
}
API transformations applied:
.store(key, value, {namespace, ttl, metadata})โ.store(key, value, namespace, metadata).retrieve(key, {namespace})โ.get(key, namespace)?.value.list({namespace, limit})โ.query(pattern, {namespace, limit})
Files Updated
src/mcp/mcp-server.js(112 insertions, 112 deletions)dist-cjs/src/mcp/mcp-server.js(rebuilt)
Testing
โ Build successful โ Syntax validation passed โ Pattern persistence verified (tested on local-main)
Result
This PR now provides:
- โ ReasoningBank semantic search for MCP tools
- โ CLI-MCP data interoperability
- โ Working neural_train pattern persistence (fixed upstream bug)
- โ Compatible with v2.7.1 release
- โ All upstream tests and docs included
Ready for review! ๐
โ PR Cleaned Up - Rebased on upstream/main
Updated approach: Rebased instead of merging to keep PR diff clean.
What Changed
Before (bad approach):
- โ Merged upstream/main INTO feature branch
- โ PR showed all v2.7.1 files as "changes" (they're already in target)
- โ Huge diff with redundant files
After (correct approach):
- โ Rebased feature branch ON TOP OF upstream/main
- โ PR now shows ONLY this PR's changes vs upstream/main
- โ Clean, focused diff
Commit Structure After Rebase
Base: upstream/main (v2.7.1) โ PR target
โ
329069e6 Fix: MCP memory tools now use ReasoningBank semantic search
59923aba removed md temp files
2eff399d chore: untrack .claude-flow/metrics files
7cdd1a62 Fix: update ReasoningBank paths to use working directory
5649bf23 Fix: Adapt v2.7.1 neural_train to memoryManager API โ NEW
The Additional Fix
Added one commit to adapt upstream's v2.7.1 neural_train code to work with this PR's memoryManager refactoring.
Changes in that commit:
- Changed
this.memoryStoreโthis.memoryManager(compatibility) - Fixed API calls to use memoryManager methods
- Ensures neural_train works with UnifiedMemoryManager
Result
This PR now cleanly shows:
- โ ReasoningBank integration changes
- โ UnifiedMemoryManager refactoring
- โ Semantic search for MCP tools
- โ CLI-MCP interoperability
- โ Compatible with v2.7.1 neural_train feature
No redundant v2.7.1 files - those are already in the base branch! ๐ฏ
โ Better Solution: Backward Compatibility Layer
Changed approach to be much cleaner - instead of modifying upstream's neural_train code, I added backward compatibility to UnifiedMemoryManager.
Why This Is Better
โ Previous approach:
- Modified neural_train code to use new API
- Would conflict with future upstream changes
- Larger PR footprint
โ New approach:
- Added compatibility methods to UnifiedMemoryManager
- Upstream's neural_train code works WITHOUT modification
- Clean, minimal PR changes
Implementation
1. Enhanced store() to accept BOTH APIs:
// โ
OLD API (what v2.7.1 uses):
await manager.store(key, value, {namespace, ttl, metadata})
// โ
NEW API (what this PR uses):
await manager.store(key, value, namespace, metadata)
// Auto-detects which API based on 3rd parameter type\!
2. Added retrieve() method:
async retrieve(key, {namespace}) {
const entry = await this.get(key, namespace);
return entry?.value || null;
}
3. Added list() method:
async list({namespace, limit}) {
return await this.query('', {namespace, limit});
}
4. Added MCP server alias:
this.memoryManager = getUnifiedMemory();
this.memoryStore = this.memoryManager; // Backward compatibility
Result
โ
Upstream's v2.7.1 neural_train code works unmodified
โ
Both old and new APIs supported simultaneously
โ
Minimal changes to codebase
โ
Clean upgrade path
โ
All tests pass
Testing Verified
// โ
Old API works
await this.memoryStore.store(key, value, {namespace, metadata});
const value = await this.memoryStore.retrieve(key, {namespace});
const list = await this.memoryStore.list({namespace, limit});
// โ
New API works
await this.memoryManager.store(key, value, namespace, metadata);
const entry = await this.memoryManager.get(key, namespace);
const results = await this.memoryManager.query(pattern, {namespace, limit});
This is a much more elegant solution! ๐ฏ
๐งน Cleaned Up PR - Removed Build Artifacts
Removed all dist-cjs/ changes from this PR. These are generated build artifacts that will be created when upstream runs their build process.
What's Left in PR
Source files only:
src/mcp/mcp-server.js- MCP server changessrc/memory/unified-memory-manager.js- Backward compatibility layer- Metrics file cleanup
No more:
- โ dist-cjs/* (build artifacts)
- โ Unnecessary generated files
Benefits
โ
Cleaner PR diff
โ
Easier to review source changes
โ
No merge conflicts with upstream builds
โ
Follows best practices (don't commit build artifacts)
The PR is now focused on source code changes only! ๐ฏ