mem0 Memory System
- tests
#!/bin/bash
# mem0 MCP Server API Tests (Shell)
# Made with by Pink Pixel
#
# This script tests the mem0 MCP server API endpoints using curl.
# Add parent directory to path
SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )"
PARENT_DIR="$(dirname "$SCRIPT_DIR")"
cd "$PARENT_DIR"
# Colors for better readability
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[0;33m'
RED='\033[0;31m'
NC='\033[0m' # No Color
BOLD='\033[1m'
# Base URL for the API
BASE_URL="http://0.0.0.0:8000"
echo -e "${BOLD}${BLUE} mem0 MCP Server API Test${NC}"
echo -e "${BOLD}Made with by Pink Pixel${NC}\n"
# Function to print section headers
section() {
echo -e "\n${BOLD}${YELLOW}$1${NC}"
echo -e "${YELLOW}$(printf '=%.0s' {1..50})${NC}\n"
}
# Function to make API calls and display results
call_api() {
local method=$1
local endpoint=$2
local data=$3
local description=$4
echo -e "${BLUE}$description${NC}"
echo -e "${GREEN}$method ${BASE_URL}$endpoint${NC}"
if [ -n "$data" ]; then
echo -e "${YELLOW}Request Body:${NC}"
echo -e "$data\n"
response=$(curl -s -X $method "${BASE_URL}${endpoint}" \
-H "Content-Type: application/json" \
-d "$data")
else
response=$(curl -s -X $method "${BASE_URL}${endpoint}" \
-H "Content-Type: application/json")
fi
echo -e "${YELLOW}Response:${NC}"
echo -e "$response\n"
# Return the response for further processing
echo "$response"
}
# 1. Check server health
section "1. Checking Server Health"
call_api "GET" "/health" "" "Checking if the server is running..."
# 2. Configure memory provider
section "2. Configuring Memory Provider"
config_data='{
"provider": "ollama",
"embedding_provider": "ollama",
"model": "llama3",
"embedding_model": "nomic-embed-text",
"data_dir": "./memory_data"
}'
call_api "POST" "/configure" "$config_data" "Configuring memory provider with Ollama..."
# 3. Store a memory
section "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" "$memory_data" "Storing a new memory...")
# Extract memory_id from the response
memory_id=$(echo $memory_response | grep -o '"memory_id":"[^"]*' | sed 's/"memory_id":"//;s/".*//')
echo -e "${BLUE}Extracted memory_id: ${GREEN}$memory_id${NC}\n"
# 4. Search for memories
section "4. Searching for Memories"
search_data='{
"query": "Why is the sky blue?",
"limit": 5
}'
call_api "POST" "/memory/search" "$search_data" "Searching for memories about the sky..."
# 5. Get memory by ID
if [ -n "$memory_id" ]; then
section "5. Getting Memory by ID"
call_api "GET" "/memory/$memory_id" "" "Getting the memory we just stored..."
else
echo -e "${RED}Could not extract memory_id from previous response.${NC}"
fi
# 6. Delete memory by ID
if [ -n "$memory_id" ]; then
section "6. Deleting Memory by ID"
call_api "DELETE" "/memory/$memory_id" "" "Deleting the memory we just stored..."
else
echo -e "${RED}Could not extract memory_id from previous response.${NC}"
fi
echo -e "\n${BOLD}${GREEN} API Test Complete!${NC}"
echo -e "${BLUE}You can modify this script to test different configurations and memory operations.${NC}"