Skip to main content
Glama
verify-mongodb-config.shβ€’4.44 kB
#!/bin/bash # MongoDB Configuration Verification Script # Detects potential authentication mismatches and URI inconsistencies # Usage: ./scripts/verify-mongodb-config.sh echo "πŸ” MongoDB Configuration Verification" echo "======================================" # Colors for output RED='\033[0;31m' GREEN='\033[0;32m' YELLOW='\033[1;33m' NC='\033[0m' # No Color # Check if MongoDB auth is enabled (not commented out) echo -e "\n1. πŸ“‹ Checking MongoDB Authentication Status..." if grep -E "^[[:space:]]*authorization:[[:space:]]*enabled" config/mongod.conf >/dev/null 2>&1; then echo -e "${YELLOW}⚠️ Authentication ENABLED in mongod.conf${NC}" AUTH_ENABLED=true else echo -e "${GREEN}βœ… Authentication DISABLED in mongod.conf${NC}" AUTH_ENABLED=false fi # Extract all MongoDB URIs from project files echo -e "\n2. πŸ”— Scanning for MongoDB URIs..." MONGO_FILES=( "src/database/mongodb.js" "docker-compose.yml" "config/supervisord.conf" "src/grpc/data-service.js" ) declare -A found_uris inconsistent=false for file in "${MONGO_FILES[@]}"; do if [ -f "$file" ]; then # Look for mongodb:// URIs uri=$(grep -oE 'mongodb://[^"'\''[:space:]]+' "$file" 2>/dev/null | head -1) if [ ! -z "$uri" ]; then found_uris["$file"]="$uri" echo -e "πŸ“„ $file: ${YELLOW}$uri${NC}" # Check if URI has auth credentials if [[ $uri == *"@"* ]]; then if [ "$AUTH_ENABLED" == false ]; then echo -e " ${RED}❌ URI has auth but MongoDB auth is DISABLED${NC}" inconsistent=true fi else if [ "$AUTH_ENABLED" == true ]; then echo -e " ${RED}❌ URI has no auth but MongoDB auth is ENABLED${NC}" inconsistent=true fi fi else echo -e "πŸ“„ $file: ${RED}No MongoDB URI found${NC}" fi else echo -e "πŸ“„ $file: ${RED}File not found${NC}" fi done # Check for URI consistency echo -e "\n3. πŸ”„ Checking URI Consistency..." unique_uris=($(printf '%s\n' "${found_uris[@]}" | sort -u)) if [ ${#unique_uris[@]} -eq 1 ]; then echo -e "${GREEN}βœ… All files use the same URI${NC}" elif [ ${#unique_uris[@]} -eq 0 ]; then echo -e "${RED}❌ No MongoDB URIs found in any file${NC}" inconsistent=true else echo -e "${RED}❌ Inconsistent URIs found:${NC}" for uri in "${unique_uris[@]}"; do echo -e " - $uri" done inconsistent=true fi # Test MongoDB connection echo -e "\n4. πŸ”Œ Testing MongoDB Connection..." if command -v mongosh >/dev/null 2>&1; then # Use the most common URI found test_uri="${unique_uris[0]}" if [ ! -z "$test_uri" ]; then echo "Testing connection to: $test_uri" if timeout 5 mongosh "$test_uri" --eval "db.runCommand('ping')" >/dev/null 2>&1; then echo -e "${GREEN}βœ… MongoDB connection successful${NC}" else echo -e "${RED}❌ MongoDB connection failed${NC}" inconsistent=true fi else echo -e "${YELLOW}⚠️ No URI to test${NC}" fi else echo -e "${YELLOW}⚠️ mongosh not available, skipping connection test${NC}" fi # Health check test echo -e "\n5. πŸ₯ Testing MCP Health Endpoint..." if command -v curl >/dev/null 2>&1; then health_response=$(curl -s -w "%{http_code}" -o /dev/null http://localhost:3001/api/health 2>/dev/null) if [ "$health_response" == "200" ]; then echo -e "${GREEN}βœ… Health endpoint responding (HTTP 200)${NC}" else echo -e "${RED}❌ Health endpoint failed (HTTP $health_response)${NC}" inconsistent=true fi else echo -e "${YELLOW}⚠️ curl not available, skipping health check${NC}" fi # Final summary echo -e "\nπŸ“‹ Summary" echo "==========" if [ "$inconsistent" == false ]; then echo -e "${GREEN}βœ… All checks passed - Configuration appears consistent${NC}" exit 0 else echo -e "${RED}❌ Issues detected - Review configuration${NC}" echo -e "\nπŸ”§ Quick Fix Suggestions:" echo "- If auth is disabled: Use mongodb://localhost:27017/conversations" echo "- If auth is enabled: Create admin user first, then use full auth URI" echo "- Ensure all files use the same URI pattern" echo "- Test connection manually: mongosh [your_uri]" exit 1 fi

Latest Blog Posts

MCP directory API

We provide all the information about MCP servers via our MCP API.

curl -X GET 'https://glama.ai/api/mcp/v1/servers/LucianoRicardo737/claude-conversation-logger'

If you have feedback or need assistance with the MCP directory API, please join our Discord server