Major Changes: - Implemented MCP HTTP/SSE transport server for n8n and web clients - Created mcp_server/http_server.py with FastAPI for JSON-RPC 2.0 over HTTP - Added health check endpoint (/health) for container monitoring - Refactored mcp-server/ to mcp_server/ (Python module structure) - Updated Dockerfile.mcp to run HTTP server with health checks MCP Server Features: - 7 memory tools exposed via MCP (add, search, get, update, delete) - HTTP/SSE transport on port 8765 for n8n integration - stdio transport for Claude Code integration - JSON-RPC 2.0 protocol implementation - CORS support for web clients n8n Integration: - Successfully tested with AI Agent workflows - MCP Client Tool configuration documented - Working webhook endpoint tested and verified - System prompt optimized for automatic user_id usage Documentation: - Created comprehensive Mintlify documentation site - Added docs/mcp/introduction.mdx - MCP server overview - Added docs/mcp/installation.mdx - Installation guide - Added docs/mcp/tools.mdx - Complete tool reference - Added docs/examples/n8n.mdx - n8n integration guide - Added docs/examples/claude-code.mdx - Claude Code setup - Updated README.md with MCP HTTP server info - Updated roadmap to mark Phase 1 as complete Bug Fixes: - Fixed synchronized delete operations across Supabase and Neo4j - Updated memory_service.py with proper error handling - Fixed Neo4j connection issues in delete operations Configuration: - Added MCP_HOST and MCP_PORT environment variables - Updated .env.example with MCP server configuration - Updated docker-compose.yml with MCP container health checks Testing: - Added test scripts for MCP HTTP endpoint verification - Created test workflows in n8n - Verified all 7 memory tools working correctly - Tested synchronized operations across both stores Version: 1.0.0 Status: Phase 1 Complete - Production Ready 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
423 lines
9.8 KiB
Plaintext
423 lines
9.8 KiB
Plaintext
---
|
|
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
|
|
|
|
<CardGroup cols={2}>
|
|
<Card title="Tool Reference" icon="wrench" href="/mcp/tools">
|
|
Complete reference for all 7 MCP tools
|
|
</Card>
|
|
<Card title="n8n Integration" icon="workflow" href="/examples/n8n">
|
|
Use MCP in n8n workflows
|
|
</Card>
|
|
</CardGroup>
|