#!/usr/bin/env bash
#
# Load environment variables from .env file into the current shell
#
# Usage:
# source scripts/load-env.sh
# OR
# . scripts/load-env.sh
#
# Note: This script must be sourced, not executed directly, to affect the current shell.
# Compatible with both bash and zsh.
# IMPORTANT: do not use `set -u` here, as it may cause issues with zsh when sourcing.
# Get the directory where this script is located
# Works in both bash (BASH_SOURCE) and zsh (ZSH_VERSION with $0)
if [ -n "${BASH_SOURCE[0]:-}" ]; then
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
elif [ -n "${ZSH_VERSION:-}" ]; then
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
else
SCRIPT_DIR="$(cd "$(dirname "$0")" && pwd)"
fi
# Project root is one level up from scripts directory (resolve to absolute path)
PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
# Path to .env file
ENV_FILE="$PROJECT_ROOT/.env"
# Check if .env file exists
if [ ! -f "$ENV_FILE" ]; then
echo "Error: .env file not found at: $ENV_FILE" >&2
echo "Please create a .env file from example.env:" >&2
echo " cp example.env .env" >&2
return 1 2>/dev/null || exit 1
fi
# Load environment variables from .env file
# Skip empty lines and comments (lines starting with #)
while IFS= read -r line || [ -n "$line" ]; do
# Skip empty lines
if [ -z "$line" ]; then
continue
fi
# Skip comments (lines starting with #)
if [[ "$line" =~ ^[[:space:]]*# ]]; then
continue
fi
# Export the variable
export "$line"
# Extract variable name for display (before the = sign)
var_name="${line%%=*}"
done < "$ENV_FILE"
echo "Environment variables loaded successfully!"
# Clean up temporary variables to avoid polluting the environment
unset SCRIPT_DIR
unset PROJECT_ROOT
unset ENV_FILE
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/sam-artuso/demo-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server