I built myself an MCP server for Moodle
ContenidoContents
I built myself an MCP server for Moodle. It is called local_mcpserver, it is a local plugin, and it turns Moodle into something an AI assistant, such as Grok or Cursor, can talk to directly.
It is at version 0.8.6, still in beta. It works, but some things are missing and it may change. I am writing about it now because the important decisions are already made, and those are what I want to explain.
Why my own
With LiftCoach I had already built an MCP connector (post in Spanish) and I liked working that way: you ask the assistant for something and it uses your real data, no copy and paste.
I wanted the same for Moodle. Ask which submissions I have not graded, which students have not logged in for days, or set up a course’s sections from Cursor, without opening twenty tabs.
And I wanted it to run inside Moodle, as just another plugin. No separate service storing credentials or sitting in the middle. The assistant connects as a real Moodle user and can do what that user can already do in the interface. No more, no less.
How it connects
My server exposes a single Streamable HTTP endpoint:
{wwwroot}/local/mcpserver/server.php
The MCP client connects there, asks for the tool list and uses it. There are 63 tools in total. It runs on Moodle 4.5 to 5.2 and it is free software, GPLv3.
OAuth 2.1 from day one
The easy path would have been to start with a token pasted into the client config and leave sign-in “for later”. I did not.
An assistant that gets into Moodle gets in as someone. If that part is wrong at the start, everything you build on top inherits the problem. So my server has had OAuth 2.1 since the first version: authorisation code flow with PKCE S256 and dynamic client registration.
In practice, the user signs in to their Moodle as usual and authorises the client. Access tokens are short-lived, refresh tokens rotate on every use and everything can be revoked. Only the token’s hash is stored.
For clients that do not speak OAuth there are personal tokens. Each user creates them from My MCP tokens, picks the scopes their role allows and a lifetime of 30, 90 or 365 days. The token is shown once. The admin has a panel to see them all, without their value, and revoke them. Moodle’s web service token stays as an optional fallback, off by default.
On top of that, every call goes to the Moodle event log and requests are rate limited per user per minute.
Read, write and admin
Reading a course’s status and deleting a section are not the same thing. So the tools are split into three scopes:
- read (26 tools): courses, activities, grades, deadlines, progress, forums, calendar, ungraded work, inactive students…
- write (26 tools): create and edit courses, sections and activities, quizzes, grading, enrolment, groups, forums and messages.
- admin (11 tools): user accounts and site policies.
Any authenticated user can read. Editing teachers and managers can write. Admin is for site administrators. And on top of that, each user’s Moodle permissions in each context always apply.
Writes ship off
A fresh install does not allow writes. The Allow write tools setting is off and, while it is, write tools do not even show up in the list the assistant sees. The admin turns it on when they want.
There is also a switch per tool: tool_<name>, for example tool_delete_section. That is 63 checkboxes. If you do not want anyone deleting sections from an assistant, you untick it and that tool disappears. The rest stay.
Two details worth knowing:
search_usershas the admin scope, but it works with writes off. Searching users is reading.list_policiesandget_policy_acceptancesonly read, but they carry the admin scope. Who accepted which policy is not something everyone should see, so they sit with the admin tools and need writes on.
The delicate stuff has a safety net. Deletes and grades run as a dry run (dryRun) first and are only saved when the call confirms. I explain that in Grading with dryRun.
Prompts and skills
Handing an assistant 63 tools is not enough for it to build a good course. So my server ships three MCP prompts: design_course, grade_assignment and create_quiz_from_content. They guide the assistant step by step, with a dry run before saving.
For clients that load skills, the plugin includes two: moodle-course-design, with the order of work and what a good course looks like, and moodle-grading, which tells the agent to wait for the teacher’s confirmation before saving a grade.
Where to find it
Everything is on the local_mcpserver page and in the documentation: installation, settings, security and the reference for all 63 tools.
Download and source are marked “coming soon”. When they are out, I will write about it here.