From 01954969333f7aa838f39b35cf3b3e70a68d4d66 Mon Sep 17 00:00:00 2001 From: Hermes Agent Date: Mon, 30 Nov 2026 03:48:10 +0000 Subject: [PATCH] feat(mcp-deploy): add public /mcp reverse-proxy route in Caddyfile, hyperstition-mcp.service systemd unit, and live GET/POST /mcp smoke tests (v2.0.10) --- deploy/Caddyfile | 8 +++++++- deploy/hyperstition-mcp.service | 20 ++++++++++++++++++++ deploy/test-first-deployment.sh | 31 ++++++++++++++++++++++++++++--- 3 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 deploy/hyperstition-mcp.service diff --git a/deploy/Caddyfile b/deploy/Caddyfile index 40debb5..062bb5a 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -81,7 +81,13 @@ hyperstitionstud.io { } redir /ci /ci/ permanent - # 6. Repo Install Dir: hyperstitionstudio-core -> /schemas/* and Root Portal Homepage (/) + # 6. Stateless Read-Only Model Context Protocol (MCP) Streamable HTTP Endpoint -> /mcp & /mcp/* + @mcp_route path /mcp /mcp/* + handle @mcp_route { + reverse_proxy 127.0.0.1:8095 + } + + # 7. Repo Install Dir: hyperstitionstudio-core -> /schemas/*, /learn/*, /gallery/* & Root Portal Homepage (/) handle_path /schemas/* { root * /var/www/hyperstitionstud.io/repos/hyperstitionstudio-core/schemas file_server { diff --git a/deploy/hyperstition-mcp.service b/deploy/hyperstition-mcp.service new file mode 100644 index 0000000..5334801 --- /dev/null +++ b/deploy/hyperstition-mcp.service @@ -0,0 +1,20 @@ +# /etc/systemd/system/hyperstition-mcp.service +[Unit] +Description=Stateless Read-Only Model Context Protocol (MCP) HTTP Server for hyperstitionstud.io (127.0.0.1:8095) +After=network.target local-fs.target hyperstition-tmpfs-sync.service +Before=caddy.service + +[Service] +Type=simple +WorkingDirectory=/srv/hyperstitionstud.io/repos +Environment="HYPERSTITIONSTUDIO_CONFIG=/srv/hyperstitionstud.io/repos/workspace.toml" +Environment="PYTHONPATH=/srv/hyperstitionstud.io/repos/hyperstitionstudio-core/src" +ExecStart=/srv/hyperstitionstud.io/repos/.venv/bin/python3 /srv/hyperstitionstud.io/repos/hyperstitionstudio-core/src/hyperstitionstud_io/mcp/server.py --transport http --host 127.0.0.1 --port 8095 +Restart=always +RestartSec=2 +NoNewPrivileges=true +ProtectSystem=strict +ReadOnlyPaths=/srv/hyperstitionstud.io/repos + +[Install] +WantedBy=multi-user.target diff --git a/deploy/test-first-deployment.sh b/deploy/test-first-deployment.sh index b3eed64..45da042 100755 --- a/deploy/test-first-deployment.sh +++ b/deploy/test-first-deployment.sh @@ -14,26 +14,36 @@ set -euo pipefail SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]:-$0}")" && pwd)" TARGET_BASE_URL="${1:-}" SERVER_PID="" +MCP_PID="" cleanup() { if [[ -n "${SERVER_PID}" ]] && kill -0 "${SERVER_PID}" 2>/dev/null; then kill "${SERVER_PID}" 2>/dev/null || true fi + if [[ -n "${MCP_PID}" ]] && kill -0 "${MCP_PID}" 2>/dev/null; then + kill "${MCP_PID}" 2>/dev/null || true + fi } trap cleanup EXIT if [[ -z "${TARGET_BASE_URL}" ]]; then export LIVE_REPOS="${LIVE_REPOS:-/tmp/hyperstition-live-repos}" rm -rf "${LIVE_REPOS}" - echo "[1/3] Hydrating per-repository webroot at ${LIVE_REPOS} via sync-vps-repos.sh --no-pull..." + echo "[1/4] Hydrating per-repository webroot at ${LIVE_REPOS} via sync-vps-repos.sh --no-pull..." "${SCRIPT_DIR}/sync-vps-repos.sh" --no-pull PORT="${TEST_PORT:-18090}" - echo "[2/3] Starting local HTTP server on http://127.0.0.1:${PORT} serving ${LIVE_REPOS}..." + MCP_PORT="${TEST_MCP_PORT:-18095}" + echo "[2/4] Starting local HTTP server on http://127.0.0.1:${PORT} and MCP HTTP server on http://127.0.0.1:${MCP_PORT}/mcp..." python3 -m http.server "${PORT}" --bind 127.0.0.1 --directory "${LIVE_REPOS}" >/dev/null 2>&1 & SERVER_PID="$!" + PYTHONPATH="${SCRIPT_DIR}/../src" python3 "${SCRIPT_DIR}/../src/hyperstitionstud_io/mcp/server.py" --transport http --host 127.0.0.1 --port "${MCP_PORT}" >/dev/null 2>&1 & + MCP_PID="$!" sleep 0.6 TARGET_BASE_URL="http://127.0.0.1:${PORT}" + MCP_URL="http://127.0.0.1:${MCP_PORT}/mcp" +else + MCP_URL="${TARGET_BASE_URL%/}/mcp" fi echo "[3/3] Verifying all 35 portal, /learn/, /gallery/, graph, encyclopedia, haiperdohp-jemaytreeah (.gitignore artifacts), CI & schema routes against ${TARGET_BASE_URL}..." @@ -89,4 +99,19 @@ for route in "${ROUTES[@]}"; do fi done -echo "[OK] All ${PASS_COUNT}/${#ROUTES[@]} deployment routes verified (HTTP 200 OK)." +echo "[4/4] Verifying stateless read-only MCP Streamable HTTP endpoint (${MCP_URL})..." +mcp_get_code="$(curl -s -o /dev/null -w "%{http_code}" "${MCP_URL}")" +if [[ "${mcp_get_code}" != "200" ]]; then + echo " [FAIL ${mcp_get_code}] GET ${MCP_URL}" >&2 + exit 1 +fi +echo " [200 OK] GET ${MCP_URL} (MCP capability manifest)" + +mcp_post_out="$(curl -s -X POST "${MCP_URL}" -H "Content-Type: application/json" -d '{"jsonrpc":"2.0","id":1,"method":"tools/call","params":{"name":"hs_evaluate_aq_and_ingglish","arguments":{"terms":["capital","capture","folds"]}}}')" +if ! grep -q 'exact_gen1_singularity.*true' <<<"${mcp_post_out}"; then + echo " [FAIL] POST ${MCP_URL} did not return exact_gen1_singularity=true" >&2 + exit 1 +fi +echo " [200 OK] POST ${MCP_URL} (JSON-RPC 2.0 tools/call hs_evaluate_aq_and_ingglish verified)" + +echo "[OK] All ${PASS_COUNT}/${#ROUTES[@]} static routes + 2 MCP HTTP endpoints verified (HTTP 200 OK)."