--- title: 'Claude Code Integration' description: 'Use T6 Mem0 v2 with Claude Code for AI-powered development' --- # Claude Code Integration Integrate the T6 Mem0 v2 MCP server with Claude Code to give your AI coding assistant persistent memory across sessions. ## Prerequisites - Claude Code CLI installed - T6 Mem0 v2 MCP server installed locally - Python 3.11+ environment - Running Supabase and Neo4j instances ## Installation ### 1. Install Dependencies ```bash cd /path/to/t6_mem0_v2 pip install -r requirements.txt ``` ### 2. Configure Environment Create `.env` file with required credentials: ```bash # OpenAI OPENAI_API_KEY=your_openai_key_here # Supabase (Vector Store) SUPABASE_CONNECTION_STRING=postgresql://user:pass@host:port/database # Neo4j (Graph Store) NEO4J_URI=neo4j://localhost:7687 NEO4J_USER=neo4j NEO4J_PASSWORD=your_neo4j_password # Mem0 Configuration MEM0_COLLECTION_NAME=t6_memories MEM0_EMBEDDING_DIMS=1536 MEM0_VERSION=v1.1 ``` ### 3. Verify MCP Server Test the stdio transport: ```bash echo '{"jsonrpc":"2.0","id":1,"method":"tools/list","params":{}}' | python -m mcp_server.main ``` Expected output: ```json { "jsonrpc": "2.0", "id": 1, "result": { "tools": [ {"name": "add_memory", "description": "Add new memory from messages..."}, {"name": "search_memories", "description": "Search memories by semantic similarity..."}, ... ] } } ``` ## Claude Code Configuration ### Option 1: MCP Server Configuration (Recommended) Add to your Claude Code MCP settings file (`~/.config/claude/mcp.json`): ```json { "mcpServers": { "t6-mem0": { "command": "python", "args": ["-m", "mcp_server.main"], "cwd": "/path/to/t6_mem0_v2", "env": { "OPENAI_API_KEY": "${OPENAI_API_KEY}", "SUPABASE_CONNECTION_STRING": "${SUPABASE_CONNECTION_STRING}", "NEO4J_URI": "neo4j://localhost:7687", "NEO4J_USER": "neo4j", "NEO4J_PASSWORD": "${NEO4J_PASSWORD}", "MEM0_COLLECTION_NAME": "t6_memories", "MEM0_EMBEDDING_DIMS": "1536", "MEM0_VERSION": "v1.1" } } } } ``` ### Option 2: Direct Python Integration Use the MCP SDK directly in Python: ```python from mcp import ClientSession, StdioServerParameters from mcp.client.stdio import stdio_client # Configure server server_params = StdioServerParameters( command="python", args=["-m", "mcp_server.main"], env={ "OPENAI_API_KEY": "your_key_here", "SUPABASE_CONNECTION_STRING": "postgresql://...", "NEO4J_URI": "neo4j://localhost:7687", "NEO4J_USER": "neo4j", "NEO4J_PASSWORD": "your_password" } ) # Connect and use async with stdio_client(server_params) as (read, write): async with ClientSession(read, write) as session: # Initialize session await session.initialize() # List available tools tools = await session.list_tools() print(f"Available tools: {[tool.name for tool in tools.tools]}") # Add a memory result = await session.call_tool( "add_memory", arguments={ "messages": [ {"role": "user", "content": "I prefer TypeScript over JavaScript"}, {"role": "assistant", "content": "Got it, I'll remember that!"} ], "user_id": "developer_123" } ) # Search memories results = await session.call_tool( "search_memories", arguments={ "query": "What languages does the developer prefer?", "user_id": "developer_123", "limit": 5 } ) ``` ## Usage Examples ### Example 1: Storing Code Preferences ```python # User tells Claude Code their preferences User: "I prefer using async/await over callbacks in JavaScript" # Claude Code automatically calls add_memory await session.call_tool( "add_memory", arguments={ "messages": [ { "role": "user", "content": "I prefer using async/await over callbacks in JavaScript" }, { "role": "assistant", "content": "I'll remember your preference for async/await!" } ], "user_id": "developer_123", "metadata": { "category": "coding_preference", "language": "javascript" } } ) ``` ### Example 2: Recalling Project Context ```python # Later in a new session User: "How should I structure this async function?" # Claude Code searches memories first memories = await session.call_tool( "search_memories", arguments={ "query": "JavaScript async preferences", "user_id": "developer_123", "limit": 3 } ) # Claude uses retrieved context to provide personalized response # "Based on your preference for async/await, here's how I'd structure it..." ``` ### Example 3: Project-Specific Memory ```python # Store project-specific information await session.call_tool( "add_memory", arguments={ "messages": [ { "role": "user", "content": "This project uses Supabase for the database and Neo4j for the knowledge graph" }, { "role": "assistant", "content": "Got it! I'll remember the tech stack for this project." } ], "user_id": "developer_123", "agent_id": "project_t6_mem0", "metadata": { "project": "t6_mem0_v2", "category": "tech_stack" } } ) ``` ## Available Tools in Claude Code Once configured, these tools are automatically available: | Tool | Description | Use Case | |------|-------------|----------| | `add_memory` | Store information | Save preferences, project details, learned patterns | | `search_memories` | Semantic search | Find relevant context from past conversations | | `get_all_memories` | Get all memories | Review everything Claude knows about you | | `update_memory` | Modify memory | Correct or update stored information | | `delete_memory` | Remove specific memory | Clear outdated information | | `delete_all_memories` | Clear all memories | Start fresh for new project | ## Best Practices ### 1. Use Meaningful User IDs ```python # Good - descriptive IDs user_id = "developer_john_doe" agent_id = "project_ecommerce_backend" # Avoid - generic IDs user_id = "user1" agent_id = "agent" ``` ### 2. Add Rich Metadata ```python metadata = { "project": "t6_mem0_v2", "category": "bug_fix", "file": "mcp_server/http_server.py", "timestamp": "2025-10-15T10:30:00Z", "session_id": "abc-123-def" } ``` ### 3. Search Before Adding ```python # Check if information already exists existing = await session.call_tool( "search_memories", arguments={ "query": "Python coding style preferences", "user_id": "developer_123" } ) # Only add if not found or needs updating if not existing or needs_update: await session.call_tool("add_memory", ...) ``` ### 4. Regular Cleanup ```python # Periodically clean up old project memories await session.call_tool( "delete_all_memories", arguments={ "agent_id": "old_project_archived" } ) ``` ## Troubleshooting ### MCP Server Won't Start **Error**: `ModuleNotFoundError: No module named 'mcp_server'` **Solution**: Ensure you're running from the correct directory: ```bash cd /path/to/t6_mem0_v2 python -m mcp_server.main ``` ### Database Connection Errors **Error**: `Cannot connect to Supabase/Neo4j` **Solution**: Verify services are running and credentials are correct: ```bash # Test Neo4j curl http://localhost:7474 # Test Supabase connection psql $SUPABASE_CONNECTION_STRING -c "SELECT 1" ``` ### Environment Variables Not Loading **Error**: `KeyError: 'OPENAI_API_KEY'` **Solution**: Load `.env` file or set environment variables: ```bash # Load from .env export $(cat .env | xargs) # Or set directly export OPENAI_API_KEY=your_key_here ``` ### Slow Response Times **Issue**: Tool calls taking longer than expected **Solutions**: - Check network latency to Supabase - Verify Neo4j indexes are created - Reduce `limit` parameter in search queries - Consider caching frequently accessed memories ## Advanced Usage ### Custom Memory Categories ```python # Define custom categories CATEGORIES = { "preferences": "User coding preferences and style", "bugs": "Known bugs and their solutions", "architecture": "System design decisions", "dependencies": "Project dependencies and versions" } # Store with category await session.call_tool( "add_memory", arguments={ "messages": [...], "metadata": { "category": "architecture", "importance": "high" } } ) ``` ### Multi-Agent Collaboration ```python # Different agents for different purposes AGENTS = { "code_reviewer": "Reviews code for best practices", "debugger": "Helps debug issues", "architect": "Provides architectural guidance" } # Store agent-specific knowledge await session.call_tool( "add_memory", arguments={ "messages": [...], "user_id": "developer_123", "agent_id": "code_reviewer", "metadata": {"role": "code_review"} } ) ``` ### Session Management ```python import uuid from datetime import datetime # Create session tracking session_id = str(uuid.uuid4()) session_start = datetime.now().isoformat() # Store with session context metadata = { "session_id": session_id, "session_start": session_start, "context": "debugging_authentication" } ``` ## Next Steps Complete reference for all 7 MCP tools Use MCP in n8n workflows