moodle-mcp 0.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- moodle_mcp-0.1.0/PKG-INFO +39 -0
- moodle_mcp-0.1.0/README.md +27 -0
- moodle_mcp-0.1.0/pyproject.toml +18 -0
- moodle_mcp-0.1.0/setup.cfg +4 -0
- moodle_mcp-0.1.0/src/moodle_mcp/__init__.py +0 -0
- moodle_mcp-0.1.0/src/moodle_mcp/api.py +49 -0
- moodle_mcp-0.1.0/src/moodle_mcp/logger.py +9 -0
- moodle_mcp-0.1.0/src/moodle_mcp/moodle.py +46 -0
- moodle_mcp-0.1.0/src/moodle_mcp/server.py +17 -0
- moodle_mcp-0.1.0/src/moodle_mcp/utils.py +24 -0
- moodle_mcp-0.1.0/src/moodle_mcp.egg-info/PKG-INFO +39 -0
- moodle_mcp-0.1.0/src/moodle_mcp.egg-info/SOURCES.txt +14 -0
- moodle_mcp-0.1.0/src/moodle_mcp.egg-info/dependency_links.txt +1 -0
- moodle_mcp-0.1.0/src/moodle_mcp.egg-info/entry_points.txt +2 -0
- moodle_mcp-0.1.0/src/moodle_mcp.egg-info/requires.txt +4 -0
- moodle_mcp-0.1.0/src/moodle_mcp.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moodle-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Model Context Protocol (MCP) server implementation that provides capabilities to interact with Moodle LMS.
|
|
5
|
+
Project-URL: Homepage, https://github.com/loyaniu/moodle-mcp
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: glom>=24.11.0
|
|
9
|
+
Requires-Dist: mcp[cli]>=1.6.0
|
|
10
|
+
Requires-Dist: python-dotenv>=1.1.0
|
|
11
|
+
Requires-Dist: requests>=2.32.3
|
|
12
|
+
|
|
13
|
+
# Moodle-MCP
|
|
14
|
+
|
|
15
|
+
> A Model Context Protocol (MCP) server implementation that provides capabilities to interact with Moodle LMS.
|
|
16
|
+
>
|
|
17
|
+
> **Warning:** This project is still in development, only some functions are available.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- [x] Get upcoming events from Moodle
|
|
22
|
+
|
|
23
|
+
## API Reference
|
|
24
|
+
|
|
25
|
+
For available Moodle API functions, please refer to the [official documentation](https://docs.moodle.org/dev/Web_service_API_functions).
|
|
26
|
+
|
|
27
|
+
## Setup Instructions
|
|
28
|
+
|
|
29
|
+
1. Create your own `.env` file from `.env.example`
|
|
30
|
+
2. Assume you have `uv` installed, run `uv add "mcp[cli]"` to install the MCP CLI tools
|
|
31
|
+
3. Run `mcp install server.py -f .env` to add the moodle-mcp server to Claude app
|
|
32
|
+
|
|
33
|
+
## Authentication
|
|
34
|
+
|
|
35
|
+
### Getting your Moodle token
|
|
36
|
+
|
|
37
|
+
1. Navigate to your Moodle token management page `https://{your-moodle-url}/user/managetoken.php`
|
|
38
|
+
2. Use the token with `Moodle mobile web service` in the `Service` column
|
|
39
|
+
3. Add this token to your `.env` file
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
# Moodle-MCP
|
|
2
|
+
|
|
3
|
+
> A Model Context Protocol (MCP) server implementation that provides capabilities to interact with Moodle LMS.
|
|
4
|
+
>
|
|
5
|
+
> **Warning:** This project is still in development, only some functions are available.
|
|
6
|
+
|
|
7
|
+
## Features
|
|
8
|
+
|
|
9
|
+
- [x] Get upcoming events from Moodle
|
|
10
|
+
|
|
11
|
+
## API Reference
|
|
12
|
+
|
|
13
|
+
For available Moodle API functions, please refer to the [official documentation](https://docs.moodle.org/dev/Web_service_API_functions).
|
|
14
|
+
|
|
15
|
+
## Setup Instructions
|
|
16
|
+
|
|
17
|
+
1. Create your own `.env` file from `.env.example`
|
|
18
|
+
2. Assume you have `uv` installed, run `uv add "mcp[cli]"` to install the MCP CLI tools
|
|
19
|
+
3. Run `mcp install server.py -f .env` to add the moodle-mcp server to Claude app
|
|
20
|
+
|
|
21
|
+
## Authentication
|
|
22
|
+
|
|
23
|
+
### Getting your Moodle token
|
|
24
|
+
|
|
25
|
+
1. Navigate to your Moodle token management page `https://{your-moodle-url}/user/managetoken.php`
|
|
26
|
+
2. Use the token with `Moodle mobile web service` in the `Service` column
|
|
27
|
+
3. Add this token to your `.env` file
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = "moodle-mcp"
|
|
3
|
+
version = "0.1.0"
|
|
4
|
+
description = "A Model Context Protocol (MCP) server implementation that provides capabilities to interact with Moodle LMS."
|
|
5
|
+
readme = "README.md"
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
|
+
dependencies = [
|
|
8
|
+
"glom>=24.11.0",
|
|
9
|
+
"mcp[cli]>=1.6.0",
|
|
10
|
+
"python-dotenv>=1.1.0",
|
|
11
|
+
"requests>=2.32.3",
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[project.scripts]
|
|
15
|
+
moodle-mcp = "moodle_mcp.server:main"
|
|
16
|
+
|
|
17
|
+
[project.urls]
|
|
18
|
+
Homepage = "https://github.com/loyaniu/moodle-mcp"
|
|
File without changes
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
from typing import TypedDict
|
|
2
|
+
|
|
3
|
+
from glom import glom
|
|
4
|
+
|
|
5
|
+
from .logger import logger
|
|
6
|
+
from .moodle import APIFunction, get_moodle_api_data
|
|
7
|
+
from .utils import to_json_file
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class UpcomingEvent(TypedDict):
|
|
11
|
+
id: int
|
|
12
|
+
name: str
|
|
13
|
+
formattedtime: str
|
|
14
|
+
url: str
|
|
15
|
+
description: str
|
|
16
|
+
popupname: str
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
def get_upcoming_events() -> list[UpcomingEvent]:
|
|
20
|
+
data = get_moodle_api_data(APIFunction.core_calendar_get_calendar_upcoming_view)
|
|
21
|
+
|
|
22
|
+
to_json_file(data, "calendar_upcoming_view.json")
|
|
23
|
+
|
|
24
|
+
# define the extraction specification to get the required fields
|
|
25
|
+
upcoming_events_spec = (
|
|
26
|
+
"events",
|
|
27
|
+
[
|
|
28
|
+
{
|
|
29
|
+
"id": "id",
|
|
30
|
+
"name": "name",
|
|
31
|
+
"formattedtime": "formattedtime",
|
|
32
|
+
"url": "url",
|
|
33
|
+
"description": "description",
|
|
34
|
+
"popupname": "popupname",
|
|
35
|
+
}
|
|
36
|
+
],
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
# use glom to extract the data
|
|
40
|
+
upcoming_events = glom(data, upcoming_events_spec)
|
|
41
|
+
|
|
42
|
+
logger.info(f"Extracted {len(upcoming_events)} upcoming events")
|
|
43
|
+
|
|
44
|
+
return upcoming_events
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
if __name__ == "__main__":
|
|
48
|
+
upcoming_events = get_upcoming_events()
|
|
49
|
+
to_json_file(upcoming_events, "upcoming_events.json")
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
from enum import Enum
|
|
2
|
+
|
|
3
|
+
import requests
|
|
4
|
+
from glom import delete
|
|
5
|
+
|
|
6
|
+
from .logger import logger
|
|
7
|
+
from .utils import getenv
|
|
8
|
+
|
|
9
|
+
MOODLE_URL = getenv("MOODLE_URL")
|
|
10
|
+
MOODLE_TOKEN = getenv("MOODLE_TOKEN")
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class APIFunction(Enum):
|
|
14
|
+
core_calendar_get_calendar_upcoming_view = (
|
|
15
|
+
"core_calendar_get_calendar_upcoming_view"
|
|
16
|
+
)
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
# Fields not needed for specific API functions
|
|
20
|
+
# Using `glom` to extract fields not needed
|
|
21
|
+
DELETE_FIELDS = {
|
|
22
|
+
APIFunction.core_calendar_get_calendar_upcoming_view: [
|
|
23
|
+
"events.*.course.courseimage"
|
|
24
|
+
]
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
|
|
28
|
+
def get_moodle_api_data(function: APIFunction, use_original_data=True):
|
|
29
|
+
params = {
|
|
30
|
+
"wstoken": MOODLE_TOKEN,
|
|
31
|
+
"wsfunction": function.value,
|
|
32
|
+
"moodlewsrestformat": "json",
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
logger.info(f"Getting moodle data for `{function.value}`")
|
|
36
|
+
rsp = requests.get(MOODLE_URL, params=params)
|
|
37
|
+
|
|
38
|
+
data = rsp.json()
|
|
39
|
+
|
|
40
|
+
if use_original_data:
|
|
41
|
+
return data
|
|
42
|
+
|
|
43
|
+
for field_path in DELETE_FIELDS.get(function, []):
|
|
44
|
+
delete(data, field_path)
|
|
45
|
+
|
|
46
|
+
return data
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from mcp.server.fastmcp import FastMCP
|
|
2
|
+
|
|
3
|
+
from . import api
|
|
4
|
+
from .logger import logger
|
|
5
|
+
|
|
6
|
+
mcp = FastMCP("moodle-mcp", dependencies=["glom", "requests"])
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
@mcp.tool()
|
|
10
|
+
def get_upcoming_events() -> list[api.UpcomingEvent]:
|
|
11
|
+
"""Get upcoming events from moodle"""
|
|
12
|
+
return api.get_upcoming_events()
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def main():
|
|
16
|
+
logger.info("Starting moodle-mcp server")
|
|
17
|
+
mcp.run()
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import json
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
from dotenv import load_dotenv
|
|
5
|
+
|
|
6
|
+
ENV_LOADED = False
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def to_json_file(data, filename, folder="output"):
|
|
10
|
+
if not os.path.exists(folder):
|
|
11
|
+
os.makedirs(folder)
|
|
12
|
+
|
|
13
|
+
with open(f"{folder}/{filename}", "w", encoding="utf-8") as f:
|
|
14
|
+
json.dump(data, f, ensure_ascii=False, indent=4)
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def getenv(key: str, default: str = None) -> str:
|
|
18
|
+
global ENV_LOADED
|
|
19
|
+
|
|
20
|
+
if not ENV_LOADED:
|
|
21
|
+
load_dotenv()
|
|
22
|
+
ENV_LOADED = True
|
|
23
|
+
|
|
24
|
+
return os.getenv(key, default)
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: moodle-mcp
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: A Model Context Protocol (MCP) server implementation that provides capabilities to interact with Moodle LMS.
|
|
5
|
+
Project-URL: Homepage, https://github.com/loyaniu/moodle-mcp
|
|
6
|
+
Requires-Python: >=3.10
|
|
7
|
+
Description-Content-Type: text/markdown
|
|
8
|
+
Requires-Dist: glom>=24.11.0
|
|
9
|
+
Requires-Dist: mcp[cli]>=1.6.0
|
|
10
|
+
Requires-Dist: python-dotenv>=1.1.0
|
|
11
|
+
Requires-Dist: requests>=2.32.3
|
|
12
|
+
|
|
13
|
+
# Moodle-MCP
|
|
14
|
+
|
|
15
|
+
> A Model Context Protocol (MCP) server implementation that provides capabilities to interact with Moodle LMS.
|
|
16
|
+
>
|
|
17
|
+
> **Warning:** This project is still in development, only some functions are available.
|
|
18
|
+
|
|
19
|
+
## Features
|
|
20
|
+
|
|
21
|
+
- [x] Get upcoming events from Moodle
|
|
22
|
+
|
|
23
|
+
## API Reference
|
|
24
|
+
|
|
25
|
+
For available Moodle API functions, please refer to the [official documentation](https://docs.moodle.org/dev/Web_service_API_functions).
|
|
26
|
+
|
|
27
|
+
## Setup Instructions
|
|
28
|
+
|
|
29
|
+
1. Create your own `.env` file from `.env.example`
|
|
30
|
+
2. Assume you have `uv` installed, run `uv add "mcp[cli]"` to install the MCP CLI tools
|
|
31
|
+
3. Run `mcp install server.py -f .env` to add the moodle-mcp server to Claude app
|
|
32
|
+
|
|
33
|
+
## Authentication
|
|
34
|
+
|
|
35
|
+
### Getting your Moodle token
|
|
36
|
+
|
|
37
|
+
1. Navigate to your Moodle token management page `https://{your-moodle-url}/user/managetoken.php`
|
|
38
|
+
2. Use the token with `Moodle mobile web service` in the `Service` column
|
|
39
|
+
3. Add this token to your `.env` file
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
README.md
|
|
2
|
+
pyproject.toml
|
|
3
|
+
src/moodle_mcp/__init__.py
|
|
4
|
+
src/moodle_mcp/api.py
|
|
5
|
+
src/moodle_mcp/logger.py
|
|
6
|
+
src/moodle_mcp/moodle.py
|
|
7
|
+
src/moodle_mcp/server.py
|
|
8
|
+
src/moodle_mcp/utils.py
|
|
9
|
+
src/moodle_mcp.egg-info/PKG-INFO
|
|
10
|
+
src/moodle_mcp.egg-info/SOURCES.txt
|
|
11
|
+
src/moodle_mcp.egg-info/dependency_links.txt
|
|
12
|
+
src/moodle_mcp.egg-info/entry_points.txt
|
|
13
|
+
src/moodle_mcp.egg-info/requires.txt
|
|
14
|
+
src/moodle_mcp.egg-info/top_level.txt
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
moodle_mcp
|