Skip to content

Write tools

Scope write (or admin) and capability local/mcp:write. Write mode must be on and the tool enabled; otherwise write tools are not listed. See Enabling write mode. Each tool also checks the Moodle capability below.

create_course

Creates a blank course, or queues a background copy when templateCourseId is set. A copy returns taskId and status: pending at once; poll get_task_status. Cron must be running.

Parameter Type Required Default Description
fullName string yes — Full name (max 254).
shortName string yes — Unique short name (max 255).
categoryId integer no 1 Category id.
summary string no "" Summary HTML.
format string no topics Course format, e.g. topics, weeks.
visible boolean no true Visible to students.
numSections integer no 1 Sections for a blank course (0–52). Ignored for a copy.
startDate integer no — Start (Unix timestamp).
endDate integer no — End (Unix timestamp); 0 = none.
templateCourseId integer no — Course to copy. Activities are copied.
includeUserData boolean no false Copy enrolments and user data. Needs moodle/backup:userinfo.
dryRun boolean no false Check permissions and names only.

Returns: Blank: courseId, shortName, fullName, url. Copy: taskId, status (pending), queued. With dryRun: dryRun: true.

Moodle permissions: moodle/course:create in the category. A copy also needs moodle/backup:backupcourse and moodle/backup:backuptargetimport.

Example arguments:

{"fullName": "Statistics 102", "shortName": "STAT102", "templateCourseId": 42}

build_course

Builds a course from a JSON plan of sections, activities and quiz questions, as a background task. Returns taskId and status: pending at once; poll get_task_status. If the build fails after creating a new course, that course is deleted and the task is failed. With courseId, a failure deletes only the activities this build created.

Parameter Type Required Default Description
dryRun boolean no false Validate and return the plan; create nothing.
courseId integer no — Build inside this existing course instead of creating one.
fullName string for a new course — Full name (max 254).
shortName string for a new course — Short name (max 255).
categoryId integer no 1 Category.
summary string no "" Summary HTML.
format string no topics Course format.
visible boolean no true Visible.
sections array no [] Up to 52 sections {number, name, summary, activities[]}; up to 40 activities each. An activity takes the add_activity fields (except fileBase64 and gradingDueDate) plus, for quizzes, category, questions[] (as in add_quiz_questions), gift or xml.

Returns: dryRun, taskId, status, course, sections[] (the plan on a dry run).

Moodle permissions: New course: moodle/course:create in the category. Existing course (courseId): moodle/course:manageactivities. Plus the capabilities of each activity and question it creates.

Example arguments:

{"fullName": "Field biology", "shortName": "BIOFIELD", "sections": [{"number": 1, "name": "Week 1", "activities": [{"type": "page", "name": "Welcome", "content": "<p>Start here.</p>"}]}]}

add_section

Adds a section at the end of a course, with optional name and summary.

Parameter Type Required Default Description
courseId integer yes — Moodle course id.
name string no — Section name (max 255).
summary string no "" Summary HTML.

Returns: courseId, section, name.

Moodle permissions: moodle/course:update.

Example arguments:

{"courseId": 42, "name": "Week 5"}

add_activity

Adds a page, url, label, resource (file), assign, quiz or forum to a section. Assignments accept dates, a maximum grade, submission types and a basic rubric.

Parameter Type Required Default Description
courseId integer yes — Moodle course id.
section integer yes — Section number (0 = general).
type string yes — page, url, label, resource, assign, quiz, forum.
name string no* — Name (max 255). May be omitted for a label.
intro string no "" Description HTML. Body of a label.
content string no — Page HTML content (also label body if intro is empty).
externalUrl string for url — URL for a url activity (max 1333).
dueDate integer no — Assignment due date (Unix timestamp).
timeOpen integer no — Quiz open time (Unix timestamp).
timeClose integer no — Quiz close time (Unix timestamp).
grade integer no — Maximum grade, assign or quiz (0–100000).
forumType string no general general, eachuser, single, qanda, blog, news.
visible boolean no true Whether the activity is visible.
allowSubmissionsFromDate integer no — Assignment open date (Unix timestamp).
cutoffDate integer no — Assignment cut-off date.
gradingDueDate integer no — Date by which grading should be done.
submissionTypes array no — Assignment submission plugins: file and/or onlinetext.
rubric array no — Up to 20 criteria, each {description, levels[]} with at least two levels {definition, score} (max 10).
fileName string for resource — File name for a resource.
fileUrl string resource: one of the two — Public http(s) URL of the file.
fileBase64 string resource: one of the two — Base64 file contents, 2 MiB maximum decoded.
timeLimit integer no — Quiz time limit in seconds.
attempts integer no — Quiz attempts (0–10, 0 = unlimited).
gradeMethod string no — highest, average, first, last.
navMethod string no — free or sequential.
questionsPerPage integer no — 0–50; 0 = all on one page.
shuffleAnswers boolean no — Shuffle quiz answers.
review string no — immediately, later, afterclose, never.

Returns: cmid, instanceId, courseId, type, name, section, visible, url.

Moodle permissions: moodle/course:manageactivities and mod/<type>:addinstance.

Example arguments:

{"courseId": 42, "section": 1, "type": "assign", "name": "Essay", "dueDate": 1798761600, "submissionTypes": ["onlinetext"], "rubric": [{"description": "Argument", "levels": [{"definition": "Weak", "score": 0}, {"definition": "Strong", "score": 5}]}]}

create_quiz

Creates a quiz in a section.

Parameter Type Required Default Description
courseId integer yes — Moodle course id.
section integer yes — Section number.
name string yes — Name (1–255).
intro string no "" Description HTML.
timeOpen integer no — Open time.
timeClose integer no — Close time.
timeLimit integer no — Seconds; 0 = no limit.
attempts integer no — 0–10; 0 = unlimited.
grade integer no 10 Maximum grade (0–100000).
gradeMethod string no — highest, average, first, last.
navMethod string no — free, sequential.
questionsPerPage integer no — 0–50.
shuffleAnswers boolean no — Shuffle answers.
review string no — immediately, later, afterclose, never.
visible boolean no — Visible.

Returns: Activity summary: cmid, courseId, name, url (and the other add_activity fields).

Moodle permissions: moodle/course:manageactivities and mod/quiz:addinstance.

Example arguments:

{"courseId": 42, "section": 2, "name": "Unit 2 check", "attempts": 2, "timeLimit": 1200}

add_quiz_questions

Creates questions in the course question bank and adds them to a quiz (up to 50 per call). On Moodle 4.5 the bank is the course context; on 5.0+ it is the mod_qbank activity, created if missing.

Parameter Type Required Default Description
cmid integer yes — Quiz course module id.
category string no — Question bank category name; omit for the default.
questions array yes — Each question: type (multichoice, truefalse, shortanswer, numerical, match, essay), name, text, optional mark; plus correct (truefalse), choices[] {text, correct} (multichoice, one or several correct), answers[] and caseSensitive (shortanswer), answer and tolerance (numerical), pairs[] {question, answer} (match).

Returns: cmid, categoryId, questions[].

Moodle permissions: mod/quiz:manage and moodle/question:add (moodle/question:managecategory to create a category).

Example arguments:

{"cmid": 315, "questions": [{"type": "truefalse", "name": "Sun", "text": "<p>The Sun is a star.</p>", "correct": true, "mark": 1}]}

import_questions

Imports GIFT or Moodle XML into a question bank category with Moodle's core importers, and optionally adds the questions to a quiz.

Parameter Type Required Default Description
courseId integer yes — Moodle course id.
format string yes — gift or xml.
content string yes — The GIFT or XML text.
category string no — Category name (max 254).
cmid integer no — Quiz to add the imported questions to.

Returns: courseId, categoryId, questionIds[], added.

Moodle permissions: moodle/question:add (mod/quiz:manage to add them to a quiz).

Example arguments:

{"courseId": 42, "format": "gift", "content": "::Capital::Where is Paris?{=France ~Spain}"}

update_activity

Updates an existing page, url, label, assign, quiz or forum. Only the fields you send change.

Parameter Type Required Default Description
cmid integer yes — Course module id.
name string no — New name (1–255).
intro string no — Description HTML. Body of a label.
content string no — Page HTML content (also label body if intro is empty).
externalUrl string no — URL for a url activity (max 1333).
dueDate integer no — Assignment due date (Unix timestamp).
timeOpen integer no — Quiz open time (Unix timestamp).
timeClose integer no — Quiz close time (Unix timestamp).
grade integer no — Maximum grade, assign or quiz (0–100000).
forumType string no — general, eachuser, single, qanda, blog, news.
visible boolean no — Whether the activity is visible.

Returns: cmid, instanceId, courseId, type, name, section, visible, url.

Moodle permissions: Moodle's normal activity update check (moodle/course:manageactivities); moodle/course:activityvisibility to change visible.

Example arguments:

{"cmid": 314, "name": "Q&A"}

enrol_user

Enrols a user with manual enrolment. Give userId or username.

Parameter Type Required Default Description
courseId integer yes — Moodle course id.
userId integer one of the two — User id.
username string one of the two — Username, used when userId is omitted.
role string no student Role shortname, e.g. student, teacher, editingteacher.

Returns: courseId, userId, role, enrolled.

Moodle permissions: enrol/manual:enrol. The course needs a manual enrolment instance.

Example arguments:

{"courseId": 42, "username": "ada", "role": "student"}

create_group

Creates a group in a course.

Parameter Type Required Default Description
courseId integer yes — Moodle course id.
name string yes — Group name (max 254).
description string no "" Description HTML.

Returns: groupId, courseId, name.

Moodle permissions: moodle/course:managegroups.

Example arguments:

{"courseId": 42, "name": "Team A"}

set_visibility

Shows or hides a course (courseId), a section (courseId + section) or an activity (cmid).

Parameter Type Required Default Description
target string yes — course, section or activity.
visible boolean yes — true = show, false = hide.
courseId integer for course/section — Course id.
section integer for section — Section number.
cmid integer for activity — Course module id.

Returns: target, visible.

Moodle permissions: moodle/course:visibility, moodle/course:sectionvisibility or moodle/course:activityvisibility, depending on the target.

Example arguments:

{"target": "section", "courseId": 42, "section": 5, "visible": false}

delete_activity

Deletes an activity. Dry run unless dryRun: false and confirm: true.

Parameter Type Required Default Description
cmid integer yes — Course module id.
dryRun boolean no true When true, only report what would be deleted.
confirm boolean no false Must be true with dryRun: false to delete.

Returns: dryRun, deleted, target (the activity).

Moodle permissions: moodle/course:manageactivities.

Example arguments:

{"cmid": 314, "dryRun": false, "confirm": true}

delete_section

Deletes a section and its activities. Section 0 cannot be deleted. Dry run unless confirmed.

Parameter Type Required Default Description
courseId integer yes — Moodle course id.
section integer yes — Section number (not 0).
dryRun boolean no true When true, only report what would be deleted.
confirm boolean no false Must be true with dryRun: false to delete.

Returns: dryRun, deleted, target (the section).

Moodle permissions: moodle/course:update.

Example arguments:

{"courseId": 42, "section": 6}