mem0 Memory System

  • examples
#!/usr/bin/env python3 """ ✨ mem0 MCP Server Example Integration ✨ Made with ❤️ by Pink Pixel This script demonstrates how to integrate the mem0 MCP server with an application. """ import os import sys import requests import json # Add parent directory to path to import modules sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) """ Example integration of mem0 MCP server with an application """ import argparse from client import Mem0Client def main(): """Example application using mem0 MCP server""" parser = argparse.ArgumentParser(description="mem0 MCP Client Example") parser.add_argument( "--server-url", type=str, default="http://localhost:8000", help="URL of the mem0 MCP server" ) parser.add_argument( "--provider", type=str, default="openai", choices=["openai", "anthropic", "google", "deepseek", "openrouter", "ollama"], help="LLM provider to use" ) parser.add_argument( "--user-id", type=str, default="example_user", help="User ID for memory operations" ) args = parser.parse_args() print(f"✨ mem0 MCP Client Example ✨") print(f"Made with ❤️ by Pink Pixel") print(f"\nConnecting to server: {args.server_url}") print(f"Using provider: {args.provider}") # Initialize the client client = Mem0Client(base_url=args.server_url) # Check if the server is running if not client.health_check(): print("Error: Could not connect to the mem0 MCP server") print("Make sure the server is running with: python server.py") return # Configure the memory provider print("\nConfiguring memory provider...") client.configure( provider=args.provider, data_dir=f"./memory_data_{args.provider}", embedding_provider="openai" if args.provider != "ollama" else "ollama" ) # Interactive mode print("\n--- Memory Operations ---") print("1. Add a memory") print("2. Search memories") print("3. Chat with memories") print("4. Exit") while True: choice = input("\nEnter your choice (1-4): ") if choice == "1": content = input("Enter memory content: ") memory_id = client.add_memory(content, user_id=args.user_id) print(f"Memory added with ID: {memory_id}") elif choice == "2": query = input("Enter search query: ") results = client.search_memories(query, user_id=args.user_id) print("\nSearch results:") if not results["results"]: print("No results found") else: for i, result in enumerate(results["results"], 1): print(f"{i}. {result['memory']} (Score: {result['score']:.2f})") elif choice == "3": message = input("Enter your message: ") print("Thinking...") response = client.chat(message, user_id=args.user_id) print(f"\nAI: {response}") elif choice == "4": print("Goodbye!") break else: print("Invalid choice, please try again") if __name__ == "__main__": main()