---
name: iblai-connect-moodle
description: "Read and write Moodle LMS data through the Moodle Web Services (External Services API) and expose it to an ibl.ai agent as an MCP tool. Use when the user asks an agent to work with Moodle LMS data, or to set up a Moodle LMS MCP connection on ibl.ai."
metadata:
  kind: guide
---

# Moodle LMS connector for AI agents

> A starting point maintained on ibl.ai at https://ibl.ai/developer/connectors/moodle — not part of the iblai/vibe repository. Checked against Moodle HQ's documentation on October 20, 2026; test it against your own Moodle LMS setup before you rely on it.

Moodle LMS is an open-source learning management system that schools, universities and organisations run on their own servers or through a host. It holds courses, enrolments, assignments, quizzes, grades, messages and files.

## Auth & conventions

- **API:** Moodle Web Services (External Services API) (REST). One endpoint, /webservice/rest/server.php, dispatches named functions (wsfunction) such as core_course_get_courses. Each site lists its own functions under Site administration > Server > Web services > API Documentation.
- **Access:** Issued by your administrator. A site admin enables web services and the REST protocol, defines an external service with the allowed functions, then issues a token per user under Manage tokens. Users with moodle/webservice:createtoken can create their own.
- **Auth:** API token (wstoken); Username and password exchanged for a token at /login/token.php. Pass wstoken, wsfunction and moodlewsrestformat=json (default is XML). /login/token.php takes username, password and a service short name. Files use /webservice/upload.php and /webservice/pluginfile.php with the token.
- Keep Moodle LMS credentials in environment variables or the ibl.ai credential store. Never print a token in chat and never commit one to a file.
- Destructive or outward-facing calls are marked **Confirm with the user first** — do.

## Reads

- **Courses** — core_course_get_courses returns course records; core_course_get_contents returns a course's sections and activities.
- **Enrolled users** — core_enrol_get_enrolled_users returns participants of a course (takes courseid).
- **Grade items** — gradereport_user_get_grade_items returns grade items and grades for users in a course.
- **Assignment submissions** — mod_assign_get_assignments and mod_assign_get_submissions return assignments and their submissions.
- **Users** — core_user_get_users_by_field looks up users by a field such as id, username or email.
- **Site info** — core_webservice_get_site_info returns the calling user, the site and the functions the token can call.

## Writes

- **Grades** — mod_assign_save_grade saves a grade and feedback on an assignment submission. **Confirm with the user first.**
- **Enrolments** — enrol_manual_enrol_users enrols users; enrol_manual_unenrol_users removes them. **Confirm with the user first.**
- **Users and courses** — core_user_create_users and core_course_create_courses create records; core_course_delete_courses deletes courses. **Confirm with the user first.**
- **Messages** — core_message_send_instant_messages sends messages to users. **Confirm with the user first.**
- **Calendar events** — core_calendar_create_calendar_events adds calendar events.

## Expose it to an ibl.ai agent (MCP)

Moodle HQ did not publish an MCP server of its own when this skill was checked. Host a small MCP server that wraps the calls above, then register it below.

First install the ibl.ai platform skills and connect your organization (writes `IBLAI_ORG`, `IBLAI_USERNAME` and `IBLAI_API_KEY` to `.env`):

```bash
npx skills add iblai/vibe --all
# then, in your coding agent:
/iblai-api-login
```

Every call below sends `Authorization: Api-Token $IBLAI_API_KEY`.

1. **Register the server** — `POST https://api.iblai.app/dm/api/ai-mentor/orgs/$IBLAI_ORG/users/$IBLAI_USERNAME/mcp-servers/` with `name`, `url`, `transport` (`sse` | `websocket` | `streamable_http`) and `auth_type` (`none` | `token` | `oauth2`). Capture the returned `id`.
   - For an API key or service credential use `auth_type=token` with `auth_scope=platform` for one key across the organization, or scope it to a single agent for one key per agent.
2. **Create the connection** — `POST https://api.iblai.app/dm/api/ai-mentor/orgs/$IBLAI_ORG/users/$IBLAI_USERNAME/mcp-server-connections/` with `server`, `scope` (`platform` | `mentor` | `user`), `auth_type`, and either `credentials` + `authorization_scheme` or a `connected_service` id for OAuth. Credentials are masked on read; never send a masked value back.
3. **Enable it on the agent** — `GET https://api.iblai.app/dm/api/ai-mentor/orgs/$IBLAI_ORG/users/$IBLAI_USERNAME/mentors/{agent_id}/settings/`, add `mcp-tool` to `tool_slugs` and the server id to `mcp_servers`, then `PATCH` the full lists back. They are replaced, not merged.

Full reference: https://ibl.ai/developer/platform/mcp/mcp-connections and the `/iblai-api-agent-mcp` skill.

## Example prompts

- "List everyone enrolled in Algebra I who has no grade on the unit 3 assignment."
- "Enrol these five students into the Biology 2 course as students."
- "Show the grade items and my students' scores for Physics 101."
- "Add a calendar event for the course review session next Tuesday."

## Guardrails

- Grades, submissions and enrolment records held by a school are FERPA-protected education records.
- Request the narrowest Moodle LMS scopes or role the task needs, and prefer a read-only credential for agents that only answer questions.
- Return the fields the user asked for, not whole records; do not paste personal data into chat that the user did not request.
- Before any write, show the user exactly what will change and wait for a yes.
- Page through large result sets and back off on rate-limit responses instead of retrying in a loop.

## References

- Moodle Developer Resources: External Services: https://moodledev.io/docs/5.1/apis/subsystems/external
- Moodle web services file handling: https://moodledev.io/docs/5.1/apis/subsystems/external/files
- MoodleDocs: Using web services: https://docs.moodle.org/503/en/Using_web_services
- This connector on ibl.ai: https://ibl.ai/developer/connectors/moodle
- ibl.ai MCP server connections: https://ibl.ai/developer/platform/mcp/mcp-connections
