feat: Add comprehensive Mem0 MCP integration#2
Open
krzemienski wants to merge 1 commit into
Open
Conversation
This commit adds intelligent memory capabilities using Mem0 MCP server as an alternative to the standard memory server. Key improvements: - Dynamic MCP configuration based on MEM0_API_KEY environment variable - Automatic fallback to standard memory when Mem0 not configured - Updated init_project and start_project functions for Mem0 compatibility - Dynamic memory tool name resolution for both memory systems - User preferences storage in Mem0 for cross-session continuity - Enhanced parse_claude_stream to handle Mem0 tool names - Comprehensive documentation updates in CLAUDE.md and README.md Mem0 provides semantic search, intelligent extraction, and persistent storage across sessions, significantly improving the builder's ability to maintain context and make informed decisions throughout the build process. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
Reviewer's GuideThis PR integrates the Mem0 MCP server as an optional, intelligent memory layer driven by the MEM0_API_KEY environment variable, refactors memory tool selection and prompts across build phases, adds user preference storage, enhances memory stream parsing, and updates documentation to reflect the new semantic memory capabilities. Sequence Diagram for Conditional MCP Server SetupsequenceDiagram
actor User
participant Script as builder-claude-code-builder.sh
User->>Script: Optionally sets MEM0_API_KEY
User->>Script: Executes script
Script->>Script: setup_mcp_servers()
alt MEM0_API_KEY is set
Script->>Script: Writes .mcp.json with Mem0 MCP config
else MEM0_API_KEY is not set
Script->>Script: Writes .mcp.json with Standard Memory MCP config
end
Sequence Diagram for Memory Interaction in
|
| Change | Details | Files |
|---|---|---|
| Dynamic MCP server configuration with Mem0 fallback |
|
builder-claude-code-builder.sh |
| Introduce Mem0 memory tool resolution |
|
builder-claude-code-builder.sh |
| Implement user preference storage via Mem0 |
|
builder-claude-code-builder.sh |
| Enhance initialization and research prompts for Mem0 |
|
builder-claude-code-builder.sh |
| Extend parse_claude_stream() for Mem0 tool events |
|
builder-claude-code-builder.sh |
| Refactor phase prompt memory context for semantic memory |
|
builder-claude-code-builder.sh |
| Update documentation for Mem0 integration |
|
README.mdCLAUDE.md |
Tips and commands
Interacting with Sourcery
- Trigger a new review: Comment
@sourcery-ai reviewon the pull request. - Continue discussions: Reply directly to Sourcery's review comments.
- Generate a GitHub issue from a review comment: Ask Sourcery to create an
issue from a review comment by replying to it. You can also reply to a
review comment with@sourcery-ai issueto create an issue from it. - Generate a pull request title: Write
@sourcery-aianywhere in the pull
request title to generate a title at any time. You can also comment
@sourcery-ai titleon the pull request to (re-)generate the title at any time. - Generate a pull request summary: Write
@sourcery-ai summaryanywhere in
the pull request body to generate a PR summary at any time exactly where you
want it. You can also comment@sourcery-ai summaryon the pull request to
(re-)generate the summary at any time. - Generate reviewer's guide: Comment
@sourcery-ai guideon the pull
request to (re-)generate the reviewer's guide at any time. - Resolve all Sourcery comments: Comment
@sourcery-ai resolveon the
pull request to resolve all Sourcery comments. Useful if you've already
addressed all the comments and don't want to see them anymore. - Dismiss all Sourcery reviews: Comment
@sourcery-ai dismisson the pull
request to dismiss all existing Sourcery reviews. Especially useful if you
want to start fresh with a new review - don't forget to comment
@sourcery-ai reviewto trigger a new review!
Customizing Your Experience
Access your dashboard to:
- Enable or disable review features such as the Sourcery-generated pull request
summary, the reviewer's guide, and others. - Change the review language.
- Add, remove or edit custom review instructions.
- Adjust other review settings.
Getting Help
- Contact our support team for questions or feedback.
- Visit our documentation for detailed guides and information.
- Keep in touch with the Sourcery team by following us on X/Twitter, LinkedIn or GitHub.
There was a problem hiding this comment.
Hey @krzemienski - I've reviewed your changes - here's some feedback:
- Validate the generated .mcp.json to ensure correct comma placement when injecting MEMORY_SERVER_CONFIG to avoid invalid JSON formatting.
- Refactor the duplicated MEM0 vs standard-memory prompt construction into shared helper functions or templates to reduce code repetition and improve maintainability.
- The get_memory_tool function relies on positional array indices, which is brittle—consider using an explicit mapping (e.g. associative array) for tool name resolution instead.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- Validate the generated .mcp.json to ensure correct comma placement when injecting MEMORY_SERVER_CONFIG to avoid invalid JSON formatting.
- Refactor the duplicated MEM0 vs standard-memory prompt construction into shared helper functions or templates to reduce code repetition and improve maintainability.
- The get_memory_tool function relies on positional array indices, which is brittle—consider using an explicit mapping (e.g. associative array) for tool name resolution instead.
## Individual Comments
### Comment 1
<location> `builder-claude-code-builder.sh:478` </location>
<code_context>
+These preferences will help maintain consistency across sessions."
+
+ # Run Claude to store preferences
+ run_claude_auto "$preferences_prompt" "User Preferences" >/dev/null 2>&1
+ fi
+}
</code_context>
<issue_to_address>
Avoid silencing errors when storing user preferences
Capturing and logging errors instead of redirecting output will help identify issues during preference storage.
</issue_to_address>
<suggested_fix>
<<<<<<< SEARCH
# Run Claude to store preferences
run_claude_auto "$preferences_prompt" "User Preferences" >/dev/null 2>&1
=======
# Run Claude to store preferences
preferences_output=$(run_claude_auto "$preferences_prompt" "User Preferences" 2>&1)
preferences_status=$?
if [ $preferences_status -ne 0 ]; then
log_error "Failed to store user preferences: $preferences_output"
fi
>>>>>>> REPLACE
</suggested_fix>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Comment on lines
+477
to
+478
| # Run Claude to store preferences | ||
| run_claude_auto "$preferences_prompt" "User Preferences" >/dev/null 2>&1 |
There was a problem hiding this comment.
suggestion (bug_risk): Avoid silencing errors when storing user preferences
Capturing and logging errors instead of redirecting output will help identify issues during preference storage.
Suggested change
| # Run Claude to store preferences | |
| run_claude_auto "$preferences_prompt" "User Preferences" >/dev/null 2>&1 | |
| # Run Claude to store preferences | |
| preferences_output=$(run_claude_auto "$preferences_prompt" "User Preferences" 2>&1) | |
| preferences_status=$? | |
| if [ $preferences_status -ne 0 ]; then | |
| log_error "Failed to store user preferences: $preferences_output" | |
| fi |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Key Features
🧠 Intelligent Memory with Mem0
When
MEM0_API_KEYis set, the builder uses Mem0's advanced memory system:🔧 Technical Implementation
setup_mcp_servers()get_memory_tools()andget_memory_tool()init_project()andstart_project()for both memory systemsparse_claude_stream()to handle Mem0 tool namesstore_user_preferences()📖 Documentation
Test Plan
Backward Compatibility
🤖 Generated with Claude Code
Summary by Sourcery
Add dynamic integration of the Mem0 MCP memory server driven by the MEM0_API_KEY environment variable, providing an LLM-powered, semantic memory fallback while preserving the existing standard memory flow.
New Features:
Enhancements:
Documentation: