Files
computer-playbook/roles/web-app-moodle/files/build/install/webservice-mcp.sh
kevinveenbirkenbachandClaude Opus 5 f2fe5e94b1 feat(moodle): serve MCP through the build-time webservice plugin
Install the protocol plugin during the image build, because a Moodle
plugin must match the pinned release and installing it at runtime would
leave the two free to drift.

Provision the webservice and its token through PHP, and attach only
read-only functions, so the read-only tool policy is enforced by the
service definition rather than declared in metadata.

Address the endpoint as its canonical origin. Moodle compares every
request against wwwroot, so a probe over the internal HTTP origin was
answered with an HTML redirect instead of JSON and every retry hit the
same wall; the verify step now sends the canonical Host and the
forwarded-proto header.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
2026-08-02 22:21:04 +02:00

24 lines
910 B
Bash

#!/bin/bash
set -euxo pipefail
: "${MOODLE_SOURCE_DIR:?required}"
: "${MOODLE_WEBSERVICE_SUBDIR:?required}"
: "${MOODLE_MCP_PLUGIN_RELPATH:?required}"
: "${MOODLE_MCP_PLUGIN_ARCHIVE_URL:?required}"
PLUGIN_DIR="${MOODLE_SOURCE_DIR}/${MOODLE_MCP_PLUGIN_RELPATH}"
ZIP_PATH="$(mktemp -t webservice-mcp.XXXXXX.zip)"
EXTRACT_DIR="$(mktemp -d -t webservice-mcp-extract.XXXXXX)"
trap 'rm -rf "${ZIP_PATH}" "${EXTRACT_DIR}"' EXIT
test -d "${MOODLE_SOURCE_DIR}/${MOODLE_WEBSERVICE_SUBDIR}"
curl --connect-timeout 5 --max-time 300 --retry 3 --retry-all-errors --retry-delay 2 -fSL -o "${ZIP_PATH}" "${MOODLE_MCP_PLUGIN_ARCHIVE_URL}"
unzip -q "${ZIP_PATH}" -d "${EXTRACT_DIR}"
rm -rf "${PLUGIN_DIR}"
SRC="$(find "${EXTRACT_DIR}" -maxdepth 1 -type d -name 'moodle-webservice_mcp-*' | sort | head -n1)"
[ -n "${SRC}" ] || { echo "webservice_mcp unpack produced no directory" >&2; exit 1; }
mv "${SRC}" "${PLUGIN_DIR}"