mem0 Memory System

  • tests
#!/usr/bin/env python3 """ ✨ mem0 MCP Server API Tests ✨ Made with ❤️ by Pink Pixel This script tests the mem0 MCP server API endpoints. """ import os import sys import requests import json import time from typing import Dict, Any, List, Optional # Add parent directory to path to import modules sys.path.insert(0, os.path.abspath(os.path.join(os.path.dirname(__file__), '..'))) # Colors for terminal output class Colors: BLUE = '\033[94m' GREEN = '\033[92m' YELLOW = '\033[93m' RED = '\033[91m' BOLD = '\033[1m' END = '\033[0m' # Base URL for the API BASE_URL = "http://0.0.0.0:8000" def print_header(text: str) -> None: """Print a section header""" print(f"\n{Colors.BOLD}{Colors.YELLOW}{text}{Colors.END}") print(f"{Colors.YELLOW}{'=' * 50}{Colors.END}\n") def call_api(method: str, endpoint: str, data: Optional[Dict[str, Any]] = None, description: str = "") -> Dict[str, Any]: """Make an API call and return the response""" url = f"{BASE_URL}{endpoint}" print(f"{Colors.BLUE}{description}{Colors.END}") print(f"{Colors.GREEN}{method} {url}{Colors.END}") if data: print(f"{Colors.YELLOW}Request Body:{Colors.END}") print(json.dumps(data, indent=2)) print() response = requests.request(method, url, json=data) else: response = requests.request(method, url) print(f"{Colors.YELLOW}Response:{Colors.END}") try: response_json = response.json() print(json.dumps(response_json, indent=2)) print() return response_json except json.JSONDecodeError: print(f"{Colors.RED}Error decoding JSON response: {response.text}{Colors.END}") print() return {} def main(): """Main function to test the mem0 MCP server API""" print(f"{Colors.BOLD}{Colors.BLUE}✨ mem0 MCP Server API Tests ✨{Colors.END}") print(f"{Colors.BOLD}Made with ❤️ by Pink Pixel{Colors.END}\n") # 1. Check server health print_header("1. Checking Server Health") health_response = call_api("GET", "/health", description="Checking if the server is running...") # 2. Configure memory provider print_header("2. Configuring Memory Provider") config_data = { "provider": "ollama", "embedding_provider": "ollama", "model": "phi4", "embedding_model": "nomic-embed-text", "data_dir": "./memory_data" } call_api("POST", "/configure", data=config_data, description="Configuring memory provider with Ollama...") # 3. Store a memory print_header("3. Storing a Memory") memory_data = { "content": "The sky is blue because of Rayleigh scattering of sunlight in the atmosphere.", "metadata": { "source": "science", "importance": "high", "tags": ["sky", "science", "color"] } } memory_response = call_api("POST", "/memory/add", data=memory_data, description="Storing a new memory...") # Extract memory_id from the response memory_id = memory_response.get("memory_id", "") print(f"{Colors.BLUE}Extracted memory_id: {Colors.GREEN}{memory_id}{Colors.END}\n") # 4. Search for memories print_header("4. Searching for Memories") search_data = { "query": "Why is the sky blue?", "limit": 5 } search_response = call_api("POST", "/memory/search", data=search_data, description="Searching for memories about the sky...") # 5. Get memory by ID if memory_id: print_header("5. Getting Memory by ID") memory = call_api("GET", f"/memory/{memory_id}", description=f"Getting the memory with ID: {memory_id}") # 6. Delete memory by ID print_header("6. Deleting Memory by ID") call_api("DELETE", f"/memory/{memory_id}", description=f"Deleting the memory with ID: {memory_id}") else: print(f"{Colors.RED}Could not extract memory_id from previous response.{Colors.END}") print(f"\n{Colors.BOLD}{Colors.GREEN}✅ API Test Complete!{Colors.END}") print(f"{Colors.BLUE}You can modify this script to test different configurations and memory operations.{Colors.END}") if __name__ == "__main__": main()