Moodle MCP Server

linomck/moodle-mcp
0 starsCommunity

Install to Claude Code

This server doesn't publish a one-line install command. Follow the setup in the source repository.

Summary

A powerful Model Context Protocol (MCP) server that seamlessly integrates AI assistants with Moodle Learning Management System.

README.md

<div align="center">

๐ŸŽ“ Moodle MCP Server

Model Context Protocol integration for Moodle LMS

![License: MIT](https://opensource.org/licenses/MIT) ![TypeScript](https://www.typescriptlang.org/) ![Node.js](https://nodejs.org/) ![MCP](https://modelcontextprotocol.io) ![PRs Welcome](http://makeapullrequest.com)

Features โ€ข Installation โ€ข Usage โ€ข Documentation โ€ข Contributing

</div>

---

๐Ÿ“– Overview

A powerful Model Context Protocol (MCP) server that seamlessly integrates AI assistants with Moodle Learning Management System. Enable your AI assistant to access courses, retrieve educational content, download resources, and search through your learning materials.

๐Ÿ”Œ Compatible with: Claude Desktop, and any MCP-compatible AI assistant

โœจ Features

  • ๐Ÿ” Secure Authentication - Token-based auth using Moodle Web Services
  • ๐Ÿ“š Course Management - List and access all enrolled courses
  • ๐Ÿ“„ Content Retrieval - Get sections, modules, and resources from courses
  • ๐Ÿ’พ Document Access - Download files and documents with proper authentication
  • ๐Ÿ” Smart Search - Find resources by name across all enrolled courses
  • ๐Ÿ›ก๏ธ Error Handling - Comprehensive error handling with automatic token refresh
  • ๐Ÿš€ TypeScript - Fully typed for better developer experience

๐ŸŽฏ Use Cases

  • Study Assistant: Let AI help you navigate course materials
  • Content Organization: Search and organize learning resources
  • Course Overview: Get quick summaries of course structures
  • Resource Discovery: Find specific documents across multiple courses
  • Learning Analytics: Analyze course content and structure

๐Ÿ“‹ Prerequisites

  • Node.js 18 or higher
  • Moodle Instance with Web Services enabled
  • Valid Credentials with API access to your Moodle instance

๐Ÿš€ Installation

Quick Start

# Clone the repository
git clone <repository-url>
cd moodle-mcp

# Install dependencies
npm install

# Build the project
npm run build

Configuration

  1. Create environment file
cp .env.example .env
  1. Configure your credentials
MOODLE_URL=https://your-moodle-instance.com
MOODLE_USERNAME=your_username
MOODLE_PASSWORD=your_password
MOODLE_SERVICE=moodle_mobile_app  # Optional

Moodle Web Services Setup

Your Moodle instance must have Web Services enabled. If you're a Moodle administrator:

  1. Navigate to Site administration โ†’ Server โ†’ Web services โ†’ Overview
  2. Follow the setup wizard to enable web services
  3. Create or use the built-in moodle_mobile_app service
  4. Ensure these functions are enabled:
  • core_webservice_get_site_info
  • core_enrol_get_users_courses
  • core_course_get_courses
  • core_course_get_contents

๐ŸŽฎ Usage

Running the Server

# Production
node dist/index.js

# Development with auto-reload
npm run dev

Integration with Claude Desktop

Add to your Claude Desktop configuration:

macOS: ~/Library/Application Support/Claude/claude_desktop_config.json Windows: %APPDATA%/Claude/claude_desktop_config.json Linux: ~/.config/Claude/claude_desktop_config.json

{
  "mcpServers": {
    "moodle": {
      "command": "node",
      "args": ["/absolute/path/to/moodle-mcp/dist/index.js"],
      "env": {
        "MOODLE_URL": "https://your-moodle-instance.com",
        "MOODLE_USERNAME": "your_username",
        "MOODLE_PASSWORD": "your_password"
      }
    }
  }
}

Available Tools

| Tool | Description | |------|-------------| | list_courses | List all enrolled courses with details | | get_course_contents | Retrieve complete course structure with sections and modules | | get_course_documents | Get all downloadable files from a course with direct URLs | | search_resources | Search for resources by name across all courses |

๐Ÿ“š Detailed documentation: See USAGE.md for comprehensive tool documentation

๐Ÿงช Testing

Quick Test

# Run the complete test suite
npm test

Testing Options

| Method | Description | |--------|-------------| | Automated Tests | npm test - Full test suite | | MCP Inspector | Interactive web-based tool testing | | Standalone Script | Direct API testing without MCP | | Manual cURL | Test Moodle API endpoints directly |

๐Ÿ“˜ Full testing guide: See TESTING.md

๐Ÿ—๏ธ Development

Project Structure

moodle-mcp/
โ”œโ”€โ”€ src/
โ”‚   โ”œโ”€โ”€ index.ts          # MCP server implementation
โ”‚   โ”œโ”€โ”€ moodle-client.ts  # Moodle API client
โ”‚   โ”œโ”€โ”€ types.ts          # TypeScript type definitions
โ”‚   โ””โ”€โ”€ test.ts           # Standalone test script
โ”œโ”€โ”€ dist/                 # Compiled JavaScript
โ”œโ”€โ”€ .env.example          # Environment template
โ”œโ”€โ”€ README.md             # This file
โ”œโ”€โ”€ USAGE.md              # Tool usage guide
โ””โ”€โ”€ TESTING.md            # Testing guide

Commands

# Build the project
npm run build

# Watch mode (auto-rebuild)
npm run watch

# Run tests
npm test

# Development mode
npm run dev

๐Ÿ”ง API Architecture

Authentication Flow

1. Token Generation โ†’ POST /login/token.php
2. API Calls        โ†’ GET/POST /webservice/rest/server.php?wstoken={token}
3. File Downloads   โ†’ GET /pluginfile.php/...?token={token}

Moodle Web Services

  • core_webservice_get_site_info - User and site information
  • core_enrol_get_users_courses - Enrolled courses list
  • core_course_get_courses - All available courses
  • core_course_get_contents - Course structure and resources

๐Ÿ“š Documentation

๐Ÿ› Troubleshooting

<details> <summary><strong>Authentication Errors</strong></summary>

  • โœ… Verify credentials are correct in .env
  • โœ… Ensure Web Services are enabled in Moodle
  • โœ… Check service name matches your Moodle configuration
  • โœ… Verify user has appropriate API access permissions

</details>

<details> <summary><strong>Permission Errors</strong></summary>

  • โœ… Verify user has appropriate role permissions in Moodle
  • โœ… Some resources may be restricted based on enrollment
  • โœ… Check course visibility settings

</details>

<details> <summary><strong>Connection Errors</strong></summary>

  • โœ… Verify Moodle URL is correct and accessible
  • โœ… Check network connection and firewall settings
  • โœ… Ensure Moodle instance accepts API requests
  • โœ… Try accessing Moodle URL directly in browser

</details>

๐Ÿ”’ Security

  • ๐Ÿ” Store credentials securely using environment variables
  • ๐ŸŒ Use HTTPS for Moodle connections in production
  • ๐Ÿ”„ Regularly rotate passwords and tokens
  • ๐Ÿ“‹ Follow your organization's security policies
  • โš ๏ธ Never commit .env file to version control

๐Ÿค Contributing

Contributions are welcome! Here's how you can help:

  1. ๐Ÿด Fork the repository
  2. ๐Ÿ”จ Create a feature branch (git checkout -b feature/amazing-feature)
  3. ๐Ÿ’พ Commit your changes (git commit -m 'Add amazing feature')
  4. ๐Ÿ“ค Push to the branch (git push origin feature/amazing-feature)
  5. ๐ŸŽ‰ Open a Pull Request

Please ensure your PR:

  • โœ… Includes tests for new features
  • โœ… Updates documentation as needed
  • โœ… Follows existing code style
  • โœ… Passes all tests

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿ™ Acknowledgments

๐Ÿ“ž Support

---

<div align="center">

Made with โค๏ธ for the Moodle and AI community

โญ Star this repo if you find it helpful!

</div>

Related MCP servers

Browse all โ†’