Moodle Connector
Enterprise-ready Moodle REST API client with SSO authentication, batch downloading, and MCP protocol support for Claude Code and OpenCode.
Features
Complete Moodle API Access
- - List courses, check grades, track assignments
- Fetch materials, deadlines, announcements
- Download files with aggressive caching
🆕 Enterprise SSO Support (v2.0.0)
- - Azure AD / Entra ID — Full OAuth2 integration
- Google OAuth — Google Workspace and personal accounts
- SAML — Generic SAML provider support
- Mobile Launch Flow — Seamless SSO for mobile apps
- Token rotation and automatic refresh
Multiple Integration Modes
- - CLI: INLINECODE0
- Python Library: INLINECODE1
- MCP Protocol: Native integration with Claude Code, OpenCode
- Headless Mode — Tampermonkey helper for CI/CD and automation
Generic Batch Downloader
- - JSON-driven configuration (zero code modification)
- Works with any Moodle module
- Auto-organized by course name
Security
- - Encrypted credentials (PBKDF2 + Fernet)
- Token management built-in
- No secrets in git history
- MIT licensed
- Safe for headless environments (CI/CD compatible)
Installation
Once installed via clawhub install moodle-connector:
CODEBLOCK0
Quick Start
1. Setup Moodle Token
CODEBLOCK1
2. Use CLI
CODEBLOCK2
🆕 SSO Authentication (v2.0.0)
Azure AD / Entra ID
CODEBLOCK3
Google OAuth
CODEBLOCK4
SAML Provider
CODEBLOCK5
Headless/CI-CD Deployment
Use Tampermonkey helper script for automated workflows:
CODEBLOCK6
3. Use Python Library
CODEBLOCK7
4. Batch Download (Any Module)
CODEBLOCK8
Output Structure:
CODEBLOCK9
MCP Integration (Claude Code / OpenCode)
REQUIRED: Set MOODLE_CRED_PASSWORD environment variable before starting Claude Code.
Add to your claude_desktop_config.json:
CODEBLOCK10
Important: Replace your-encryption-password with your actual encryption password used in config.json.
Restart Claude Code. All 8 Moodle functions are now available as native MCP tools:
- -
courses() — List enrolled courses - INLINECODE8 — Get grades
- INLINECODE9 — Get assignments
- INLINECODE10 — Get course materials
- INLINECODE11 — Get upcoming deadlines
- INLINECODE12 — Get course news
- INLINECODE13 — Download files
- INLINECODE14 — Get complete data export
Configuration
Moodle Token (config.json)
CODEBLOCK11
Batch Downloader (downloads.json)
CODEBLOCK12
Requirements
- - Python 3.10+
- requests ≥2.31.0
- cryptography ≥41.0.0
- playwright ≥1.40.0
- mcp ≥0.1.0 (for MCP server)
Supported Moodle Instances
Tested with:
- - Taylor's University (mytimes.taylors.edu.my)
- Should work with any Moodle 3.x+ instance
Security Notes
- - Environment-enforced:
MOODLE_CRED_PASSWORD is required — no hardcoded defaults - Error sanitization: MCP server sanitizes errors, no internal details leaked to clients
- Encrypted credentials: PBKDF2 (480K iterations) + Fernet encryption
- Safe for headless: Use
MOODLE_CRED_PASSWORD env var for automation - Git-safe: Never commit
config.json with real tokens - No telemetry: No external data transmission or logging
Troubleshooting
"Invalid parameter value detected" for calendar API
Use
assignments() instead — gets same deadline info.
Browser MFA not triggering
Run:
python moodle_connector.py login for manual token retrieval.
File download stuck
Check network. Increase timeout in code or clear cache: INLINECODE22
License
MIT — See LICENSE file for details. You are free to use, modify, and distribute this software.
Contributing
Contributions welcome! Please:
- 1. Fork the repository
- Create a feature branch
- Submit a pull request
- Agree to license your work under GPLv3
Author
Jabir Iliyas Suraj-Deen
- - GitHub: https://github.com/Jabir-Srj
- Email: jabirsrj8@protonmail.com
- Taylor's University, Kuala Lumpur, Malaysia
GitHub: https://github.com/Jabir-Srj/moodle-connector
Release: v2.0.0 (March 30, 2026)
What's New in v2.0.0
✨ Enterprise SSO Support
- - Azure AD, Google OAuth, and SAML authentication
- Mobile Launch Flow integration
- Headless deployment with Tampermonkey support
- Bilingual documentation (English & Spanish)
- Enhanced security with token rotation
Moodle 连接器
企业级 Moodle REST API 客户端,支持 SSO 认证、批量下载以及适用于 Claude Code 和 OpenCode 的 MCP 协议。
功能特性
完整的 Moodle API 访问
- - 列出课程、查看成绩、追踪作业
- 获取资料、截止日期、公告通知
- 下载文件并支持强力缓存
🆕 企业级 SSO 支持 (v2.0.0)
- - Azure AD / Entra ID — 完整的 OAuth2 集成
- Google OAuth — Google Workspace 和个人账户
- SAML — 通用 SAML 提供商支持
- 移动端启动流程 — 移动应用无缝 SSO
- 令牌轮换与自动刷新
多种集成模式
- - CLI: python moodleconnector.py courses
- Python 库: from moodleconnector import MoodleConnector
- MCP 协议: 原生集成 Claude Code、OpenCode
- 无头模式 — Tampermonkey 辅助脚本,适用于 CI/CD 和自动化
通用批量下载器
- - JSON 驱动配置(无需修改代码)
- 适用于任何 Moodle 模块
- 按课程名称自动整理
安全性
- - 加密凭据(PBKDF2 + Fernet)
- 内置令牌管理
- Git 历史中无秘密信息
- MIT 许可证
- 适用于无头环境(兼容 CI/CD)
安装
通过 clawhub install moodle-connector 安装后:
bash
cd ./skills/moodle-connector
pip install -r requirements.txt
playwright install chromium
快速开始
1. 设置 Moodle 令牌
bash
cp config.template.json config.json
使用你的 Moodle 网络服务令牌编辑 config.json
2. 使用 CLI
bash
python moodle_connector.py courses # 列出所有课程
python moodle_connector.py grades # 查看成绩
python moodle_connector.py assignments # 查看作业
python moodle_connector.py materials --course-id 44864
python moodle_connector.py download https://mytimes.taylors.edu.my/... --output myfile.pdf
python moodle_connector.py summary # 完整 Markdown 导出
🆕 SSO 认证 (v2.0.0)
Azure AD / Entra ID
bash
设置环境变量
export MOODLE
SSOPROVIDER=azure
export MOODLE
SSOTENANT_ID=your-tenant-id
export MOODLE
SSOCLIENT_ID=your-client-id
export MOODLE
SSOCLIENT_SECRET=your-client-secret
使用 SSO 运行
python moodle_connector.py courses
浏览器会自动打开进行登录
Google OAuth
bash
export MOODLESSOPROVIDER=google
export MOODLESSOCLIENT_ID=your-client-id.apps.googleusercontent.com
export MOODLESSOCLIENT_SECRET=your-client-secret
python moodle_connector.py courses
SAML 提供商
bash
export MOODLESSOPROVIDER=saml
export MOODLESSOIDP_URL=https://your-idp.example.com
export MOODLESSOENTITY_ID=your-moodle-entity-id
python moodle_connector.py courses
无头/CI-CD 部署
使用 Tampermonkey 辅助脚本实现自动化工作流:
bash
export MOODLE_HEADLESS=true
export MOODLESSOPROVIDER=azure
令牌会自动保存到 config.json
在 CI/CD 中运行
python moodle_connector.py summary > report.md
3. 使用 Python 库
python
from moodle_connector import MoodleConnector
from pathlib import Path
connector = MoodleConnector(
config_path=Path(config.json),
password=encryption-password
)
courses = connector.courses()
grades = connector.grades()
assignments = connector.assignments()
materials = connector.materials()
deadlines = connector.deadlines()
announcements = connector.announcements()
content = connector.summary()
带缓存的下载
file_content = connector.download(https://...)
4. 批量下载(任意模块)
bash
cp downloads.example.json downloads.json
编辑 downloads.json 添加模块和文件 URL
python batch_downloader.py
输出结构:
downloads/
├── YourModuleName_1/
│ ├── file1.pdf
│ ├── file2.zip
│ └── ...
└── YourModuleName_2/
├── lecture.pdf
└── ...
MCP 集成 (Claude Code / OpenCode)
必需: 在启动 Claude Code 之前设置 MOODLECREDPASSWORD 环境变量。
添加到你的 claudedesktopconfig.json:
json
{
mcpServers: {
moodle-connector: {
command: python,
args: [./skills/moodle-connector/mcp_server.py],
env: {
MOODLECREDPASSWORD: your-encryption-password
}
}
}
}
重要提示: 将 your-encryption-password 替换为你在 config.json 中使用的实际加密密码。
重启 Claude Code。所有 8 个 Moodle 功能现在可作为原生 MCP 工具使用:
- - courses() — 列出已注册课程
- grades() — 获取成绩
- assignments() — 获取作业
- materials() — 获取课程资料
- deadlines() — 获取即将到来的截止日期
- announcements() — 获取课程通知
- download(url, output?) — 下载文件
- summary() — 获取完整数据导出
配置
Moodle 令牌 (config.json)
json
{
moodle: {
base_url: https://mytimes.taylors.edu.my,
web
servicetoken: YOUR
TOKENHERE
},
cache: {
api
ttlseconds: 300
}
}
批量下载器 (downloads.json)
json
{
downloads: [
{
module: Machine Learning,
course_id: 44864,
files: [
{
name: Week1.zip,
url: https://mytimes.taylors.edu.my/webservice/pluginfile.php/...
}
]
}
]
}
系统要求
- - Python 3.10+
- requests ≥2.31.0
- cryptography ≥41.0.0
- playwright ≥1.40.0
- mcp ≥0.1.0(用于 MCP 服务器)
支持的 Moodle 实例
测试环境: