The agent no longer asks if they have submitted

The agent no longer asks if they have submitted
ContenidoContents

I am building local_mcpserver. It is a local plugin: Moodle becomes something an assistant, Grok or Cursor, talks to directly. I wrote about it in I built myself an MCP server for Moodle. It signs in as a real user of the site and can do what that user can already do in the interface. See which submissions are still ungraded, which students have not logged in for days, or set up a course’s sections without opening twenty tabs. There is no separate service storing credentials.

With that, the assistant already looks at the site when I ask. The next step is that it should not have to ask whether anything has happened.

The routine came in through that server and asked whether anyone had submitted an assignment, sent a quiz or written in a forum. Each pass loads the tool schema, requests lists, and the model has to conclude something. Often what it concludes is that there is nothing to do.

The expensive token is not the one spent reviewing a submission. It is the one spent on that question.

A shorter interval does not fix it

If the routine runs more often, you hear about it sooner and you pay for more silence. If it runs less often, you reach the submission late. Both buy the same thing: a change Moodle had already recorded when it happened.

The empty pass also stays in the thread. In Grok 4.7 the price doubles once the prompt crosses 200,000 tokens, and the whole request doubles, not just the overflow. A history of “nothing new” pushes you towards that. A notification does not add those turns.

Moodle already had the fact

The events are in core. assessable_submitted is an assignment submission. attempt_submitted is a quiz attempt being sent. A new thread is discussion_created and a reply is post_created. Starting a thread does not fire both: a new thread and a reply are different events.

The plugin does not do the HTTP call inside the student’s click. The observer is internal: false, so it runs once the transaction has committed. If the action is rolled back, nothing is sent. All it does is queue the send_webhook task. Cron does the POST, with a ten-second cap, without following redirects, and with Moodle’s cURL settings. If the receiver does not answer, it retries up to five times. The student’s submission carries on.

The notice carries ids, not the work

The JSON always starts with the same five fields, in this order: event, courseid, userid, time, eventid. Depending on the event it adds ids: actorid, cmid, objectid and little else (quizid, forumid, discussionid). No name, text, answer, grade or file.

 1{
 2  "event": "\\mod_assign\\event\\assessable_submitted",
 3  "courseid": 42,
 4  "userid": 17,
 5  "time": 1795219200,
 6  "eventid": "9f3c0a1b2d4e5f60718293a4b5c6d7e8",
 7  "actorid": 17,
 8  "cmid": 88,
 9  "objectid": 351
10}

Two reasons, and in the end the same one. The receiver might be n8n, a log, or a bot that stores the body. That is no place for a submission. And the model does not need the text in order to wake up. When there is something to look at, it comes in through MCP for that id, as the user, with the permissions that user already has.

Reading the PDF, the thread or the attempt costs what it cost. I have not made that part cheaper. It is the part I want to pay for.

eventid is 32 hex characters and does not change if the same event is retried. If the receiver has already handled it, it does not open another review. That is tokens too, and one less duplicated comment.

Only the courses I watch

There is a master switch, off by default, and a checkbox in the course settings: Send webhooks. Without both, nothing goes out. A whole Moodle does not notify for a course I am not watching. The checkbox needs permission to edit the course and the local/mcpserver:coursewebhooks capability.

In a case like this you use the hooks. The checkbox goes into a core form, is saved with it, and disappears when the course is deleted. That is not done by copying edit_form.php, or with an old lib.php callback, or with a custom field someone can delete from the admin screens. Moodle already publishes the point: after_form_definition, after_form_submission and before_course_deleted. The plugin hooks in there and leaves the form alone.

0.20.0 only reported an enrolment, and the courses came from a list in site administration. On 21 November, PR 3 put 0.21.0 on main. The list became the course checkbox, and unenrolment, submission, quiz and forum came in. A test button sends "event": "test" while the switch is still off, and writes the row to the MCP audit log.

One detail on assignments. With drafts, assessable_submitted is the submit button. Without drafts, Moodle treats every save as a submission and fires the same event. If the assignment does not use drafts, the notice also arrives on an edit.

The door

The URL has to be https. The secret goes in a header, not in the query.

Grok Bot and Cursor routines ask for Authorization: Bearer …. That is two fields: the header name and the value. Pasting the whole line into the name produced a “value not valid” and not much else. Since 0.20.1 the setting explains the split and does not keep the secret in the wrong field.

If I control the receiver, there is a second secret. It signs the raw body, the exact JSON bytes, and sends it as X-Webhook-Signature: sha256= with an HMAC-SHA256. The time goes in X-Webhook-Timestamp and is not part of the signature. To avoid handling the same notice twice I use eventid, not the time. For a bot that only knows how to check Authorization, the HMAC stays empty.

Each attempt is written to the audit log, with the event, the course, the attempt number and the HTTP status. The secret is not stored. Neither is the URL path: it sometimes carries a token, and the log only keeps the host.

What goes away, and what does not

The webhook does not review the work. It says that id exists. Building the course, reading the file and writing the comment are still an MCP call, at the same real cost.

What goes away is the round of “did anything happen?”. The receiver can be n8n or a script. The large model does not have to start until the job already has a name.

local_mcpserver 0.21.0 is on GitHub. It is still in beta. It sends nothing until there is a URL, a secret, selected events and the course checkbox.

CompartirShare