Skip to main content
Glama
README.md
<div align="center">

# ๐ŸŽ“ Moodle MCP Server

**Model Context Protocol integration for Moodle LMS**

[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
[![TypeScript](https://img.shields.io/badge/TypeScript-5.7-blue.svg)](https://www.typescriptlang.org/)
[![Node.js](https://img.shields.io/badge/Node.js-18+-green.svg)](https://nodejs.org/)
[![MCP](https://img.shields.io/badge/MCP-1.0.4-purple.svg)](https://modelcontextprotocol.io)
[![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg)](http://makeapullrequest.com)

[Features](#-features) โ€ข [Installation](#-installation) โ€ข [Usage](#-usage) โ€ข [Documentation](#-documentation) โ€ข [Contributing](#-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

```bash
# 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**

```bash
cp .env.example .env
```

2. **Configure your credentials**

```bash
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

```bash
# 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`

```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](USAGE.md) for comprehensive tool documentation

## ๐Ÿงช Testing

### Quick Test

```bash
# 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](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

```bash
# 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

- **[USAGE.md](USAGE.md)** - Comprehensive guide to all available tools
- **[TESTING.md](TESTING.md)** - Testing instructions and methods
- **[MCP Documentation](https://modelcontextprotocol.io)** - Learn more about MCP

## ๐Ÿ› 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](LICENSE) file for details.

## ๐Ÿ™ Acknowledgments

- Built with [Model Context Protocol SDK](https://github.com/modelcontextprotocol/sdk)
- Powered by [Moodle LMS](https://moodle.org/)
- TypeScript & Node.js ecosystem

## ๐Ÿ“ž Support

- ๐Ÿ“– [Documentation](USAGE.md)
- ๐Ÿ› [Issue Tracker](../../issues)
- ๐Ÿ’ฌ [Discussions](../../discussions)

---

<div align="center">

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

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

</div>

TDQS

B3.3/5.0

Scored across 5 tools

Disambiguation3/5

The three read tools list_courses and get_course_contents are distinct, but search_resources vs search_files overlap heavily (both search across enrolled courses and return download URLs), and get_course_documents is essentially get_course_contents filtered to files. An agent must guess which of the resource/file/document tools matches its intent, though descriptions give partial guidance.

Naming Consistency5/5

All five tools follow a clean snake_case verb_noun pattern (list_, get_, search_). The verbs are used meaningfully and consistently across the set.

Tool Count4/5

Five tools is a reasonable, focused scope for a read-only course/content browsing server. Slightly thin, but no tool feels trivially redundant enough to pad the count.

Completeness3/5

Coverage of courses, contents, and files/documents is decent, but the surface is entirely read-only with no grades, assignments/submissions, forums, calendar, or user info. For a general Moodle server these are notable gaps, though the file-discovery workflow itself is workable.

Maintenance

ActivityInactive
ResponsivenessNo recent community issues