Files
2026-04-27 22:52:27 +00:00

71 lines
2.1 KiB
Bash
Executable File

#!/usr/bin/env bash
set -euo pipefail
HOST="${MCP_HOST:-0.0.0.0}"
PORT="${MCP_PORT:-8787}"
ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
load_env_file() {
local env_file="$1"
local line key value first last comment_start
[[ -r "${env_file}" ]] || return 0
while IFS= read -r line || [[ -n "${line}" ]]; do
line="${line#"${line%%[![:space:]]*}"}"
line="${line%"${line##*[![:space:]]}"}"
[[ -z "${line}" || "${line}" == \#* || "${line}" != *=* ]] && continue
key="${line%%=*}"
value="${line#*=}"
key="${key%"${key##*[![:space:]]}"}"
value="${value#"${value%%[![:space:]]*}"}"
value="${value%"${value##*[![:space:]]}"}"
[[ "${key}" =~ ^[A-Za-z_][A-Za-z0-9_]*$ ]] || continue
[[ -v "${key}" ]] && continue
first="${value:0:1}"
last="${value: -1}"
if [[ "${#value}" -ge 2 && ( ( "${first}" == "'" && "${last}" == "'" ) || ( "${first}" == '"' && "${last}" == '"' ) ) ]]; then
value="${value:1:${#value}-2}"
else
comment_start="${value%%" #"*}"
if [[ "${comment_start}" != "${value}" ]]; then
value="${comment_start}"
value="${value%"${value##*[![:space:]]}"}"
fi
fi
export "${key}=${value}"
done < "${env_file}"
}
load_env_file "${ROOT}/.env"
HOST="${MCP_HOST:-${HOST}}"
PORT="${MCP_PORT:-${PORT}}"
if [[ "${MCP_ALLOW_UNAUTHENTICATED:-}" != "1" && -z "${MCP_AUTH_TOKEN:-}" ]]; then
MCP_AUTH_TOKEN="$(php -r 'echo bin2hex(random_bytes(24));')"
export MCP_AUTH_TOKEN
echo "Generated MCP_AUTH_TOKEN for this session:"
echo "${MCP_AUTH_TOKEN}"
echo
fi
if [[ -z "${VOIPMS_API_USERNAME:-}" || -z "${VOIPMS_API_PASSWORD:-}" ]]; then
echo "Warning: VOIPMS_API_USERNAME or VOIPMS_API_PASSWORD is not set."
echo "Read-only protocol methods will work, but VoIP.ms tools will fail until credentials are present."
echo
fi
echo "Starting VoIP.ms test MCP server"
echo "URL: http://${HOST}:${PORT}/mcp"
echo "Health: http://${HOST}:${PORT}/health"
echo "Auth: Authorization: Bearer ${MCP_AUTH_TOKEN:-<disabled>}"
echo
exec php -S "${HOST}:${PORT}" -t "${ROOT}/mcp" "${ROOT}/mcp/http-server.php"