sernobre-moodle-mcp

sernobre-moodle-mcp

MCP server for Moodle that lets AI agents publish and manage pedagogical content — courses, lessons, quizzes, forums — via Moodle Web Services with idempotency.

Category
访问服务器

README

sernobre-moodle-mcp

Model Context Protocol (MCP) server for Moodle. Lets AI agents (Claude, etc.) publish and manage pedagogical content — lessons, resources, activities, quizzes, forums — directly in Moodle via the Web Services API, with guaranteed idempotency.

This project grew out of marcosnahuel/moodle-mcp. What began as a fork has since been rebuilt from the ground up — translated to English, hardened with bug fixes, and reshaped around our own teaching workflow — so it now stands as an independent codebase while keeping the spirit of the original:

  • Rewritten in English — every tool, parameter and error message (the original project was in Spanish);
  • Bug fixes — hardening across the publishing and question-editing flows;
  • A rewritten companion plugin — the original's local_italiciamcp became local_sernobre_mcp, with its own Web Service endpoints.

Credits — our thanks to Marcos Nahuel for creating the original moodle-mcp, which laid the groundwork for this project: https://github.com/marcosnahuel/moodle-mcp

What is this?

sernobre-moodle-mcp is an MCP server in TypeScript/Node.js that exposes a set of tools that an AI agent can call to interact with a Moodle instance:

  • create / update / duplicate / archive courses;
  • manage sections and reorganize content;
  • publish lessons and resources (idempotent);
  • create quizzes from GIFT files;
  • manage students (enrolment, groups, role changes, password resets);
  • query grades, completion, submissions and attempts;
  • create forums, calendar events and send messages;
  • issue badges and read logs.

Besides the TS wrapper, the repository includes a companion Moodle plugin (local_sernobre_mcp) that adds extra Web Service endpoints (e.g. upsert_quiz, upsert_page, add_questions_gift) needed by some tools.

Project status

Component Version
TypeScript wrapper (sernobre-moodle-mcp) v0.1.0
Moodle plugin (local_sernobre_mcp) v0.1.0

See CHANGELOG.md for the full history of changes and migration notes.

Features

  • Guaranteed idempotency — publishing the same content twice never creates duplicates.
  • Translated to English — all tools, parameters and error messages are in English (the original project was in Spanish).
  • Bugs fixed — several fixes compared to the original project, notably in the upsert_quiz, upsert_page, add_questions_gift flows and in question editing on Moodle 5.x.
  • Configurable rate limiting, retries and timeout.
  • Structured logging (JSON per line) with automatic token redaction.
  • Companion Moodle plugin with its own Web Service endpoints.

Architecture

┌─────────────┐   MCP (stdio)   ┌──────────────────────┐   HTTPS JSON   ┌──────────────┐
│  AI Agent   │ ───────────────► │ sernobre-moodle-mcp │ ─────────────► │   Moodle     │
│ (Claude, …) │                  │  MCP server          │                │ Web Services │
└─────────────┘                  └──────────────────────┘                └──────────────┘
                                          │ HTTPS JSON
                                          ▼
                              ┌──────────────────────────┐
                              │  local_sernobre_mcp      │
                              │  plugin (extra endpoints)│
                              └──────────────────────────┘

Requirements

  • Node.js ≥ 20
  • A Moodle 4.x or 5.x instance with Web Services enabled
  • A Web Service token for a user with editingteacher or manager permissions

Installation & configuration

1. Prerequisites

  • Node.js ≥ 20 (check with node --version)
  • npm (comes with Node.js)
  • A Moodle 4.x or 5.x instance that you administer
  • A Moodle user with editingteacher or manager permissions on the courses you want to manage

2. Install the wrapper

git clone https://github.com/sernobre/moodle-mcp.git
cd moodle-mcp
npm install
npm run build

This produces the compiled server in dist/ and the sernobre-moodle-mcp binary.

3. Configure environment variables

The server reads its configuration from environment variables. At minimum you must set MOODLE_URL and MOODLE_WS_TOKEN; everything else has sensible defaults.

Variable Required Description
MOODLE_URL Yes URL of the Moodle instance (must be HTTPS, except in development)
MOODLE_WS_TOKEN Yes Moodle Web Service token (see step 4)
MOODLE_WS_TIMEOUT_MS No Timeout per request (default: 30000)
MOODLE_WS_MAX_RETRIES No Number of retries (default: 3)
MOODLE_WS_RATE_LIMIT_PER_SEC No Requests per second limit (default: 10)
MCP_LOG_LEVEL No error | warn | info | debug (default: info)
MOODLE_ALLOW_INSECURE No true allows HTTP URLs (development only)

Set them in your shell before starting the server:

PowerShell (Windows):

$env:MOODLE_URL = "https://your-moodle.example.com"
$env:MOODLE_WS_TOKEN = "paste-your-token-here"
$env:MCP_LOG_LEVEL = "info"

bash / zsh (Linux, macOS):

export MOODLE_URL="https://your-moodle.example.com"
export MOODLE_WS_TOKEN="paste-your-token-here"
export MCP_LOG_LEVEL="info"

Or create a .env file and load it in your shell (the project does not auto-load .env files — use a dotenv launcher or export them yourself).

4. Configure Moodle (Web Services) — one-time

Follow these steps on the Moodle side before first use:

  1. Site administration → Server → Web services — tick Enable web services and save.
  2. Advanced features — make sure Enable web services is on.
  3. Under External services, create a new dedicated service (recommended for audit clarity) and add the functions below to it. Tick the Authorized users only option.
  4. Add at least these core functions:
    • core_webservice_get_site_info
    • core_course_get_courses_by_field
    • core_course_get_contents
    • core_enrol_get_enrolled_users
    • core_course_edit_section
    • core_course_edit_module
    • the local_sernobre_mcp_* functions from the companion plugin (step 6)
  5. Under Manage tokens, generate a token for a user with editingteacher or manager permissions. Copy the token — it is your MOODLE_WS_TOKEN.

Audit tip: create a dedicated user (e.g. moodle-mcp-bot) with editingteacher on the relevant courses and generate the token for that user, so Moodle logs clearly distinguish human vs MCP actions.

5. Start the server

npm start

The server starts, emits a server.start log line, and waits for MCP traffic over stdio. Logs are JSON per line on stderr; tokens are automatically redacted.

6. Install the companion plugin

Some tools need the local_sernobre_mcp Moodle plugin (plugin-companion/local_sernobre_mcp.zip):

  1. Unzip the archive into <moodle-root>/local/.
  2. Go to Site administration → Notifications to complete the install/update (a version bump triggers the upgrade flow).
  3. Re-enter the external service created in step 4 and add all local_sernobre_mcp_* functions (e.g. upsert_quiz, upsert_page, upsert_assignment, upsert_url, upsert_forum, add_questions_gift, upload_file, delete_module_by_idnumber, duplicate_section, create_sections, delete_sections, move_section, get_sections, update_sections, …).
  4. If the server is already running, restart it after updating the plugin.

7. Smoke test

Run the wrapper in a terminal and ask your MCP client to call ws_raw with core_webservice_get_site_info. If you get back your Moodle site name, the wiring is correct. A token error means step 4 needs checking; an HTTP 404 usually means MOODLE_URL has a trailing slash or a /webservice/... suffix (the wrapper appends that itself).

8. Connect an MCP client

Claude Desktop — add this to claude_desktop_config.json (Windows: %APPDATA%\Claude\claude_desktop_config.json; macOS: ~/Library/Application Support/Claude/claude_desktop_config.json):

{
  "mcpServers": {
    "moodle": {
      "command": "npx",
      "args": ["-y", "sernobre-moodle-mcp"],
      "env": {
        "MOODLE_URL": "https://your-moodle.example.com",
        "MOODLE_WS_TOKEN": "paste-your-token-here",
        "MCP_LOG_LEVEL": "info"
      }
    }
  }
}

To use your local build instead of the published package, point command at node with args: ["K:\\Formação\\moodle\\moodle-mcp-sernobre\\dist\\index.js"].

Restart Claude Desktop and confirm the moodle server is listed as connected. See the full guide in examples/setup-claude-desktop.md.

Codex (CLI) — Codex configures MCP servers as TOML tables in ~/.codex/config.toml (user-wide) or .codex/config.toml (project-scoped, trusted projects only). You do not run npm start yourself — Codex launches the server as a subprocess.

Run the published package from npm:

[mcp_servers.moodle]
command = "npx"
args = ["-y", "sernobre-moodle-mcp"]
env = { MOODLE_URL = "https://your-moodle.example.com", MOODLE_WS_TOKEN = "paste-your-token-here", MCP_LOG_LEVEL = "info" }
startup_timeout_sec = 20

Or add it with the Codex CLI (recommended — it writes the TOML for you):

codex mcp add moodle --env MOODLE_URL=https://your-moodle.example.com --env MOODLE_WS_TOKEN=your-token -- npx -y sernobre-moodle-mcp

To use your local build instead of the published package, set command = "node" with args = ["K:\\Formação\\moodle\\moodle-mcp-sernobre\\dist\\index.js"].

Notes:

  • Rebuild with npm run build after any source change if you use the local dist/index.js path.
  • Use an absolute path to node if Codex cannot find it on PATH.
  • Rather than hardcoding the token in env, you can forward it from your shell with env_vars = ["MOODLE_WS_TOKEN"] and export it before launching Codex.
  • Verify with codex mcp list; raise startup_timeout_sec if the server boots slowly.

Other MCP clients — configure the client to launch npx -y sernobre-moodle-mcp (or node dist/index.js for a local build) over stdio with the same environment variables. The server exposes its tools via the standard MCP tools/list and tools/call capabilities.

Available tools

Courses

create_course, update_course, duplicate_course, archive_course, list_my_courses, get_course_context

Sections

create_section, update_section, create_sections, delete_sections, move_section, get_sections, update_sections, duplicate_section, reorder_sections, hide_section, release_section

Content

publish_class_lesson, create_activity, update_activity, publish_preview, confirm_preview, delete_resource, generate_video

Assessment

configure_quiz, create_quiz, update_quiz, import_gift, modify_question, get_quiz_questions, publish_exam_lesson

Communication

create_forum, create_forum_announcement, send_moodle_message, get_site_info, get_course_logs

Gradebook

get_grades, get_assign_submissions, get_completion, get_quiz_attempts, grade_manually

Students

list_students, enrol_csv, unenrol_student, change_role, groups, reset_password

Other

list_user_badges, create_calendar_event, update_event, delete_event, list_calendar_events, ws_raw

Lesson example

The repository includes a Markdown lesson example in examples/lesson-example.md, used with the publish_class_lesson tool.

Development

npm run dev          # watch build
npm run typecheck    # type checking
npm run test         # unit tests
npm run test:integration  # integration tests (requires Moodle)
npm run build        # production build

Repository structure

src/                    # TypeScript wrapper (MCP server)
  tools/                # tool implementations
  client/               # Moodle Web Services API client
  schemas/              # validation (zod)
  utils/                # idempotency, logging, rate limit, markdown→HTML
plugin-companion/       # Moodle plugin local_sernobre_mcp (PHP)
docs/                   # technical docs and roadmap
examples/               # examples (lesson, Claude Desktop setup)
tests/                  # tests

License

MIT — see LICENSE.

The original code this project is based on belongs to marcosnahuel/moodle-mcp.

推荐服务器

Baidu Map

Baidu Map

百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。

官方
精选
JavaScript
Playwright MCP Server

Playwright MCP Server

一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。

官方
精选
TypeScript
Magic Component Platform (MCP)

Magic Component Platform (MCP)

一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。

官方
精选
本地
TypeScript
Audiense Insights MCP Server

Audiense Insights MCP Server

通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。

官方
精选
本地
TypeScript
VeyraX

VeyraX

一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。

官方
精选
本地
graphlit-mcp-server

graphlit-mcp-server

模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。

官方
精选
TypeScript
Kagi MCP Server

Kagi MCP Server

一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。

官方
精选
Python
e2b-mcp-server

e2b-mcp-server

使用 MCP 通过 e2b 运行代码。

官方
精选
Neon MCP Server

Neon MCP Server

用于与 Neon 管理 API 和数据库交互的 MCP 服务器

官方
精选
Exa MCP Server

Exa MCP Server

模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。

官方
精选