spoonbobo/moodle-mcp-server
If you are the rightful owner of moodle-mcp-server and would like to certify it and/or have it hosted online, please leave a comment on the right or send an email to henry@mcphub.com.
The Moodle MCP Server is a Model Context Protocol server implementation designed to facilitate interaction with the Moodle Learning Management System (LMS) through its Web Services API.
get_course
Get detailed information about a specific course
get_courses
List courses with optional category filtering
create_course
Create new courses in Moodle
get_course_enrollments
Get users enrolled in a course
get_user
Get user information by ID, username, or email
Moodle MCP Server
A Model Context Protocol (MCP) server implementation that provides tools and resources for interacting with Moodle Learning Management System (LMS) via its Web Services API.
Features
This MCP server provides comprehensive tools for Moodle integration:
Course Management
- get_course: Get detailed information about a specific course
- get_courses: List courses with optional category filtering
- create_course: Create new courses in Moodle
- get_course_enrollments: Get users enrolled in a course
- get_course_assignments: Get assignments from a course
- get_course_forums: Get forums from a course
User Management
- get_user: Get user information by ID, username, or email
- search_users: Search for users by name, username, or email
- enroll_user: Enroll a user in a course with specified role
System Information
- get_site_info: Get general site information and capabilities
Resources
moodle://course/{course_id}
- Course data with web interface linksmoodle://user/{user_id}
- User data with web interface linksmoodle://course/{course_id}/enrollments
- Course enrollment datamoodle://course/{course_id}/assignments
- Course assignmentsmoodle://courses
- List of courses
Installation
Prerequisites
- Python 3.10 or higher
- A Moodle instance with Web Services enabled
- A valid Moodle Web Service token
Setup
-
Clone or download this MCP server
-
Install dependencies using UV:
uv sync
Or using pip:
pip install -e .
Environment Configuration
Set the required environment variables:
# Required
export MOODLE_BASE_URL="http://localhost:8080"
export MOODLE_TOKEN="e6e5019748dd95f7380bc25b1be120ba"
# Optional
export MOODLE_VERIFY_SSL="true" # Set to "false" for self-signed certificates
Or for PowerShell:
$env:MOODLE_BASE_URL="http://localhost:8080"
$env:MOODLE_TOKEN="e6e5019748dd95f7380bc25b1be120ba"
You can also copy env.example
to .env
and modify it with your credentials.
Moodle Configuration
-
Enable Web Services in your Moodle site:
- Go to Administration ā Site administration ā Advanced features
- Enable "Enable web services"
-
Create a Web Service Token:
- Go to Administration ā Site administration ā Server ā Web services ā Manage tokens
- Create a new token for a user with appropriate permissions
-
Configure Web Service Functions (if using restricted tokens):
- Ensure the following functions are enabled:
core_course_get_courses_by_field
core_course_get_courses
core_course_create_courses
core_user_get_users_by_field
core_user_get_users
core_enrol_get_enrolled_users
enrol_manual_enrol_users
mod_assign_get_assignments
mod_forum_get_forums_by_courses
core_webservice_get_site_info
- Ensure the following functions are enabled:
Usage
Running the Server
Using UV:
uv run moodle-mcp-server
Or using Python:
python -m moodle_mcp.main
Or if installed globally:
moodle-mcp-server
Integration with MCP Clients
Add to your MCP client configuration:
{
"moodle": {
"command": "moodle-mcp-server",
"env": {
"MOODLE_BASE_URL": "http://localhost:8080",
"MOODLE_TOKEN": "e6e5019748dd95f7380bc25b1be120ba"
}
}
}
Example Usage
Get Course Information
# Get course with ID 123
course = await get_course(course_id=123)
print(f"Course: {course['courses'][0]['fullname']}")
print(f"Web URL: {course['courses'][0]['web_url']}")
Search for Users
# Search for users named "John"
users = await search_users(query="John", limit=10)
for user in users['users']:
print(f"User: {user['fullname']} ({user['email']})")
print(f"Profile URL: {user['web_url']}")
Get Course Enrollments
# Get enrollments for course 123
enrollments = await get_course_enrollments(course_id=123)
print(f"Total enrolled: {enrollments['total_count']}")
for user in enrollments['enrolled_users']:
print(f"- {user['fullname']} ({user['email']})")
Create a New Course
# Create a new course
new_course = await create_course(
fullname="Introduction to Python",
shortname="PYTHON101",
category_id=1,
summary="Learn Python programming basics"
)
print(f"Created course: {new_course[0]['web_url']}")
API Functions
Authentication
All API requests use token-based authentication. The token is automatically included in all requests using the MOODLE_TOKEN
environment variable.
Error Handling
The server includes comprehensive error handling and will return detailed error messages for debugging. All responses include web interface URLs where applicable for easy navigation to the Moodle web interface.
Web Interface Integration
All returned data includes direct web interface URLs for:
- Course pages
- User profiles
- Assignment pages
- Forum pages
This allows seamless integration between API access and web interface navigation.
Development
Project Structure
mcp/moodle-mcp-server/
āāā src/moodle_mcp/
ā āāā __init__.py
ā āāā server.py # Main server implementation
ā āāā main.py # Entry point
āāā pyproject.toml # Project configuration
āāā README.md # This file
Adding New Tools
To add new Moodle Web Service functions:
- Add the function to
server.py
using the@mcp.tool
decorator - Use
make_moodle_api_request()
for API calls - Add appropriate web interface URLs using the helper functions
- Update the available operations list in
main.py
Testing
The project includes comprehensive tests:
# Run all tests
uv run pytest tests/ -v
# Run simple working tests
uv run python tests/test_simple.py
# Run connectivity tests
uv run python tests/test_connectivity.py
Set up a test environment with:
- A Moodle development instance
- Test user accounts with appropriate permissions
- Sample courses and content for testing
Test files included:
test_simple.py
- Basic functionality tests (always pass)test_connectivity.py
- Import and connectivity teststest_basic.py
- Unit tests for individual componentstest_moodle_api.py
- Comprehensive API and tool tests
Troubleshooting
Common Issues
-
403 Forbidden Errors:
- Run the diagnostic tool:
uv run python tests/test_moodle_connection.py
- Check that web services are enabled in Moodle
- Verify the token has required permissions
- Ensure required web service functions are enabled
- Run the diagnostic tool:
-
Authentication Errors: Verify your token and ensure it has the required permissions
-
SSL Verification: Set
MOODLE_VERIFY_SSL=false
for self-signed certificates -
Missing Functions: Ensure all required web service functions are enabled in Moodle
-
Permission Errors: Verify the token user has appropriate capabilities
Debug Mode
Enable debug logging by setting environment variable:
export MOODLE_DEBUG=true
License
MIT License - see LICENSE file for details.
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
Support
For issues related to:
- MCP Server: Create an issue in this repository
- Moodle Configuration: Consult Moodle documentation
- Web Services: Check Moodle Web Services documentation