Enable web services and the REST protocol in Moodle site administration, then create a web service token with the enrol_manual_enrol_users function enabled.
Identify the numeric course ID and the numeric user ID of the user to enrol.
POST to YOUR_MOODLE_SITE/webservice/rest/server.php with fields: wstoken=YOUR_TOKEN, wsfunction=enrol_manual_enrol_users, moodlewsrestformat=json, and enrolments[0][roleid]=YOUR_ROLE_ID, enrolments[0][userid]=YOUR_USER_ID, enrolments[0][courseid]=YOUR_COURSE_ID.
A successful call returns null; any error returns a JSON object with exception and message fields.
Confirm enrolment by calling core_enrol_get_enrolled_users for the course and checking the returned user list.
Optionally set enrolments[0][timestart] and enrolments[0][timeend] as Unix timestamps to restrict enrolment duration.
Known gotchas
The web service token must be granted specifically the enrol_manual_enrol_users capability — a general admin token without this function whitelisted will return a permission error.
A null response body on success is expected behavior; do not treat an empty response as a failure.
The manual enrolment plugin must be enabled for the target course; if it is disabled, the enrolment call will fail even with correct credentials and parameters.
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp