fit-lms-mcp 1.0.0 โ 1.0.1
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.
- package/README.md +156 -151
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,108 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# FIT LMS MCP
|
|
2
2
|
|
|
3
|
-
A
|
|
4
|
-
It exposes enrolled courses, course assignments, upcoming deadlines and course
|
|
5
|
-
structure over stdio, using an existing Moodle session.
|
|
3
|
+
A Model Context Protocol (MCP) server providing authorized, read-only access to a student's HANU Faculty of Information Technology (FIT) Moodle LMS (`https://lms.fit.hanu.vn`).
|
|
6
4
|
|
|
7
|
-
|
|
5
|
+
It exposes enrolled courses, course assignments, upcoming deadlines, and course structure over stdio, with **automatic background authentication** and **interactive setup**.
|
|
8
6
|
|
|
9
|
-
|
|
7
|
+
---
|
|
10
8
|
|
|
11
|
-
|
|
12
|
-
npm install
|
|
13
|
-
npm run setup
|
|
14
|
-
```
|
|
15
|
-
|
|
16
|
-
The script will prompt for your LMS student ID and password, test the connection, save `.env`, and optionally register the MCP server directly into **Claude Desktop** and **Cursor**.
|
|
9
|
+
## ๐ Quick Start
|
|
17
10
|
|
|
18
|
-
|
|
11
|
+
Run the interactive setup assistant directly with `npx`:
|
|
19
12
|
|
|
20
13
|
```bash
|
|
21
|
-
|
|
22
|
-
cp .env.example .env
|
|
23
|
-
# Fill in your LMS credentials in .env.
|
|
24
|
-
npm run build
|
|
14
|
+
npx fit-lms-setup
|
|
25
15
|
```
|
|
26
16
|
|
|
27
|
-
|
|
28
|
-
Node.js 20.6+; with older Node versions, supply the variables through your MCP
|
|
29
|
-
client's environment instead. The server itself does not automatically load `.env`.
|
|
17
|
+
*(Or if you already have the local workspace, simply run `npm install && npm run setup`)*
|
|
30
18
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
| `LMS_MOODLE_SESSION` | MoodleSession cookie value (Option 2 - Manual session) |
|
|
37
|
-
| `LMS_MOODLE_SESSKEY` | sesskey query value (Option 2 - Manual session) |
|
|
38
|
-
| `TIMEOUT_MS` | Optional request timeout in milliseconds, including response-body reading; default `5000`, maximum `2147483647` |
|
|
19
|
+
The interactive setup assistant will:
|
|
20
|
+
1. Prompt for your LMS student ID and password (safely masked).
|
|
21
|
+
2. Test the connection against HANU LMS immediately.
|
|
22
|
+
3. Save your `.env` configuration file securely with `0600` permissions.
|
|
23
|
+
4. Automatically register the MCP server into **Claude Code**, **OpenCode**, **Codex**, or **Antigravity**.
|
|
39
24
|
|
|
40
|
-
|
|
41
|
-
Provide either `LMS_USERNAME` and `LMS_PASSWORD` for automatic login, or
|
|
42
|
-
`LMS_MOODLE_SESSION` and `LMS_MOODLE_SESSKEY` for manual session configuration.
|
|
43
|
-
Cookie delimiters/control characters and unsafe sesskeys are rejected. Real
|
|
44
|
-
`.env*` files are ignored by Git; `.env.example` contains placeholders only.
|
|
25
|
+
After running setup, you can use the MCP server directly in your AI client with `npx -y fit-lms-mcp`.
|
|
45
26
|
|
|
46
|
-
|
|
27
|
+
---
|
|
47
28
|
|
|
48
|
-
|
|
49
|
-
| --- | --- | --- |
|
|
50
|
-
| `get_my_courses` | Optional `classification`: `all` (default), `inprogress`, `future`, `past` | Normalized enrolled courses, including IDs, names and optional dates/progress/URLs |
|
|
51
|
-
| `get_course_assignments` | Required positive `courseId` | Visible assignments with `id`, `idType`, `name`, `courseId`, `courseName`, `url` |
|
|
52
|
-
| `get_upcoming_deadlines` | Optional `daysAhead` (1โ365, default **7**), `includePast` (default false), `from`, `to`, `courseId` | Assignment due events sorted by due date, with course names and identifiers |
|
|
53
|
-
| `get_course_contents` | Required positive `courseId` | `{courseId, courseName, sections}`; each section contains its number, title, visibility and accessible module metadata |
|
|
29
|
+
## โ๏ธ Manual Configuration
|
|
54
30
|
|
|
55
|
-
|
|
31
|
+
If you prefer to configure manually, copy the template and edit [.env](file:///.env):
|
|
56
32
|
|
|
57
|
-
```
|
|
58
|
-
|
|
33
|
+
```bash
|
|
34
|
+
cp .env.example .env
|
|
35
|
+
npm run build
|
|
59
36
|
```
|
|
60
37
|
|
|
61
|
-
|
|
62
|
-
|
|
38
|
+
| Variable | Description |
|
|
39
|
+
| :--- | :--- |
|
|
40
|
+
| `LMS_BASE_URL` | Required Moodle base URL, e.g. `https://lms.fit.hanu.vn` (no credentials, query or fragment) |
|
|
41
|
+
| `LMS_USERNAME` | Student ID / username for automatic login (Option 1 - Recommended) |
|
|
42
|
+
| `LMS_PASSWORD` | Password for automatic login (Option 1; automatically logs in and refreshes expired sessions) |
|
|
43
|
+
| `TIMEOUT_MS` | Optional request timeout in milliseconds (default: `5000`, maximum: `2147483647`) |
|
|
44
|
+
| `LMS_MOODLE_SESSION` | MoodleSession cookie value (Option 2 - Manual legacy session) |
|
|
45
|
+
| `LMS_MOODLE_SESSKEY` | sesskey query parameter from the same session (Option 2 - Manual legacy session) |
|
|
63
46
|
|
|
64
|
-
|
|
65
|
-
{ "courseId": 900001 }
|
|
66
|
-
```
|
|
47
|
+
*Configuration failures name the invalid setting without printing sensitive credential values. Saved `.env` files are ignored by Git.*
|
|
67
48
|
|
|
68
|
-
|
|
69
|
-
{ "daysAhead": 14, "courseId": 900001 }
|
|
70
|
-
```
|
|
49
|
+
---
|
|
71
50
|
|
|
51
|
+
## ๐ค AI Client Integration
|
|
52
|
+
|
|
53
|
+
### 1. Claude Code
|
|
54
|
+
Register via CLI:
|
|
55
|
+
```bash
|
|
56
|
+
claude mcp add fit-lms -- node --env-file=/absolute/path/to/fit-lms-mcp/.env /absolute/path/to/fit-lms-mcp/dist/index.js
|
|
57
|
+
```
|
|
58
|
+
Or add to `~/.claude.json`:
|
|
72
59
|
```json
|
|
73
|
-
{
|
|
60
|
+
{
|
|
61
|
+
"mcpServers": {
|
|
62
|
+
"fit-lms": {
|
|
63
|
+
"command": "node",
|
|
64
|
+
"args": [
|
|
65
|
+
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
66
|
+
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
67
|
+
]
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
74
71
|
```
|
|
75
72
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
starts at Unix time zero; otherwise the lower bound is now. Without `to`, the
|
|
79
|
-
upper bound is now plus `daysAhead` ร 24 hours. Dates are returned as UTC ISO 8601.
|
|
80
|
-
|
|
81
|
-
Assignment `id` and course-content module `id` identify **course modules**, not
|
|
82
|
-
assignment database records; assignment results state `idType: "courseModule"`.
|
|
83
|
-
Deadlines include `eventId`, `title`, `courseId`, `courseName`, `dueDate`, `url` and
|
|
84
|
-
`courseModuleId` (or `null` when a verified view link is unavailable). Unverified
|
|
85
|
-
open/cutoff dates and submission state are omitted rather than inferred.
|
|
86
|
-
|
|
87
|
-
The existing `assignments` and `deadlines` tools remain available for compatibility.
|
|
88
|
-
`assignments` accepts an optional course ID and keeps its `courseModuleId`/`title`
|
|
89
|
-
output. `deadlines` keeps its explicit date filters and unbounded future default;
|
|
90
|
-
use `get_upcoming_deadlines` for the seven-day default.
|
|
91
|
-
|
|
92
|
-
## Connect OpenCode
|
|
93
|
-
|
|
94
|
-
Merge this entry into `mcp` in `~/.config/opencode/opencode.jsonc` for global use,
|
|
95
|
-
or `opencode.json` in a project. Replace both absolute paths with your checkout.
|
|
96
|
-
|
|
73
|
+
### 2. OpenCode
|
|
74
|
+
Add to `~/.config/opencode/opencode.jsonc` (or project `opencode.json`):
|
|
97
75
|
```json
|
|
98
76
|
{
|
|
99
77
|
"mcp": {
|
|
100
|
-
"
|
|
78
|
+
"fit-lms": {
|
|
101
79
|
"type": "local",
|
|
102
80
|
"command": [
|
|
103
81
|
"node",
|
|
104
|
-
"--env-file=/absolute/path/to/
|
|
105
|
-
"/absolute/path/to/
|
|
82
|
+
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
83
|
+
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
106
84
|
],
|
|
107
85
|
"enabled": true,
|
|
108
86
|
"timeout": 60000
|
|
@@ -111,107 +89,134 @@ or `opencode.json` in a project. Replace both absolute paths with your checkout.
|
|
|
111
89
|
}
|
|
112
90
|
```
|
|
113
91
|
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
92
|
+
### 3. Antigravity
|
|
93
|
+
Add to `~/.gemini/config/mcp_config.json`:
|
|
94
|
+
```json
|
|
95
|
+
{
|
|
96
|
+
"mcpServers": {
|
|
97
|
+
"fit-lms": {
|
|
98
|
+
"command": "node",
|
|
99
|
+
"args": [
|
|
100
|
+
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
101
|
+
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
102
|
+
]
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
119
106
|
```
|
|
120
107
|
|
|
121
|
-
|
|
108
|
+
### 4. Cursor
|
|
109
|
+
Add to `~/.cursor/mcp.json` or `.cursor/mcp.json` in your project:
|
|
110
|
+
```json
|
|
111
|
+
{
|
|
112
|
+
"mcpServers": {
|
|
113
|
+
"fit-lms": {
|
|
114
|
+
"command": "node",
|
|
115
|
+
"args": [
|
|
116
|
+
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
117
|
+
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
118
|
+
]
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
```
|
|
122
123
|
|
|
124
|
+
### 5. Claude Desktop
|
|
125
|
+
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
123
126
|
```json
|
|
124
127
|
{
|
|
125
128
|
"mcpServers": {
|
|
126
|
-
"
|
|
129
|
+
"fit-lms": {
|
|
127
130
|
"command": "node",
|
|
128
131
|
"args": [
|
|
129
|
-
"--env-file=/absolute/path/to/
|
|
130
|
-
"/absolute/path/to/
|
|
132
|
+
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
133
|
+
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
131
134
|
]
|
|
132
135
|
}
|
|
133
136
|
}
|
|
134
137
|
}
|
|
135
138
|
```
|
|
136
139
|
|
|
137
|
-
|
|
140
|
+
> [!TIP]
|
|
141
|
+
> On macOS with NVM, if your GUI application does not inherit terminal `$PATH`, replace `"node"` with your full Node executable path (e.g. `which node`).
|
|
142
|
+
|
|
143
|
+
---
|
|
144
|
+
|
|
145
|
+
## ๐ ๏ธ MCP Tools
|
|
146
|
+
|
|
147
|
+
| Tool | Input | Output |
|
|
148
|
+
| :--- | :--- | :--- |
|
|
149
|
+
| `get_my_courses` | Optional `classification`: `all` (default), `inprogress`, `future`, `past` | Enrolled courses with ID, course name, short name, start/end dates, progress percentage, and LMS URL |
|
|
150
|
+
| `get_course_assignments` | Required positive integer `courseId` | List of visible assignments in the course with module ID, name, course ID, course name, and view link |
|
|
151
|
+
| `get_upcoming_deadlines` | Optional `daysAhead` (1โ365, default **7**), `includePast` (default false), `from`, `to`, `courseId` | Due events sorted in ascending order by due date, with verified course module ID and direct submission link |
|
|
152
|
+
| `get_course_contents` | Required positive integer `courseId` | Course sections, module structure, activity titles, and resource metadata (excludes hidden/restricted items) |
|
|
153
|
+
|
|
154
|
+
### Tool Argument Examples
|
|
155
|
+
|
|
156
|
+
- List all enrolled courses:
|
|
157
|
+
```json
|
|
158
|
+
{}
|
|
159
|
+
```
|
|
160
|
+
- Upcoming deadlines for the next 7 days:
|
|
161
|
+
```json
|
|
162
|
+
{}
|
|
163
|
+
```
|
|
164
|
+
- Deadlines for the next 14 days for a specific course:
|
|
165
|
+
```json
|
|
166
|
+
{ "courseId": 660, "daysAhead": 14 }
|
|
167
|
+
```
|
|
168
|
+
- Get assignments for course ID 660:
|
|
169
|
+
```json
|
|
170
|
+
{ "courseId": 660 }
|
|
171
|
+
```
|
|
172
|
+
|
|
173
|
+
*Compatibility tools `assignments` and `deadlines` remain available for backwards compatibility.*
|
|
174
|
+
|
|
175
|
+
---
|
|
138
176
|
|
|
139
|
-
|
|
140
|
-
Configure `LMS_USERNAME` and `LMS_PASSWORD` in your `.env`. The server automatically performs
|
|
141
|
-
the form login on Moodle, caches the session and sesskey in memory, and transparently
|
|
142
|
-
re-authenticates whenever the session expires. No manual session copying is required.
|
|
177
|
+
## ๐ Authentication & Session Management
|
|
143
178
|
|
|
144
|
-
### Option
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
request. Copy both from the same current login into your local `.env`.
|
|
150
|
-
3. Restart/reconnect the MCP server in the client.
|
|
179
|
+
### Option 1: Automatic Login (Recommended)
|
|
180
|
+
Set `LMS_USERNAME` and `LMS_PASSWORD` in your `.env`.
|
|
181
|
+
- When called, the server automatically executes the 3-step Moodle authentication flow (`logintoken` CSRF retrieval โ POST credentials โ extract `MoodleSession` cookie โ extract `sesskey`).
|
|
182
|
+
- Credentials and session tokens are cached in memory.
|
|
183
|
+
- If a session expires during use, `MoodleClient` **transparently re-authenticates and retries the request once** in the background.
|
|
151
184
|
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
185
|
+
### Option 2: Manual Session Cookies (Legacy)
|
|
186
|
+
If you prefer not to store student credentials in `.env`, provide `LMS_MOODLE_SESSION` and `LMS_MOODLE_SESSKEY`:
|
|
187
|
+
1. Log in to `https://lms.fit.hanu.vn` in your browser.
|
|
188
|
+
2. In DevTools (F12) โ Application/Storage โ Cookies, copy `MoodleSession`.
|
|
189
|
+
3. In DevTools โ Network, filter for `/lib/ajax/service.php` and copy the `sesskey` parameter.
|
|
190
|
+
4. Paste both into `.env`.
|
|
157
191
|
|
|
158
|
-
|
|
192
|
+
---
|
|
193
|
+
|
|
194
|
+
## ๐งช Verification & Testing
|
|
195
|
+
|
|
196
|
+
Run the automated test suite (synthetic fixtures, local HTTP server, zero network credentials needed):
|
|
159
197
|
|
|
160
198
|
```bash
|
|
161
199
|
npm test
|
|
162
200
|
npm run build
|
|
163
201
|
```
|
|
164
202
|
|
|
165
|
-
|
|
166
|
-
HANU or require credentials. They cover ordered batches, root/array errors,
|
|
167
|
-
malformed responses, response-size limits, timeouts, schema validation, date
|
|
168
|
-
filtering, hidden resources and actual stdio calls to all four canonical tools.
|
|
169
|
-
|
|
170
|
-
Live verification is opt-in and excluded from the default test command/CI:
|
|
203
|
+
To run the opt-in live smoke verification against HANU LMS:
|
|
171
204
|
|
|
172
205
|
```bash
|
|
173
|
-
# After building; Node.js 20.6+ for --env-file.
|
|
174
206
|
LMS_LIVE_SMOKE=1 node --env-file=.env scripts/smoke-live.mjs
|
|
175
|
-
|
|
176
|
-
# When the required environment variables are already supplied:
|
|
177
|
-
LMS_LIVE_SMOKE=1 npm run test:live
|
|
178
207
|
```
|
|
179
208
|
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
retried. Returned links use the configured LMS and omit session keys/actions.
|
|
195
|
-
- Courses follow `nextoffset`, with deduplication and a 100-page safety limit.
|
|
196
|
-
- Assignment lists and course contents use authenticated HTML. The tested LMS does
|
|
197
|
-
not expose `mod_assign_get_assignments` or `core_course_get_contents` through
|
|
198
|
-
session AJAX. Supported Moodle page structures are checked explicitly; other
|
|
199
|
-
layouts fail rather than silently report an empty course. Hidden/restricted
|
|
200
|
-
resources are omitted. No resource files are downloaded automatically.
|
|
201
|
-
- Deadlines scan calendar action events from zero, advance both `timesort` and
|
|
202
|
-
event ID, deduplicate and filter on actual due time (`timestart`). Stalled cursors
|
|
203
|
-
or more than 100 pages fail explicitly. Events without usable dates are omitted.
|
|
204
|
-
Calendar action events are not an exhaustive assignment/submission history.
|
|
205
|
-
- Student/group overrides and cutoff-date semantics remain unverified. Browser
|
|
206
|
-
capture confirms a displayed due date, not every possible override scenario.
|
|
207
|
-
|
|
208
|
-
## Source layout and contracts
|
|
209
|
-
|
|
210
|
-
`src/config` validates environment configuration; `src/moodle` owns transport,
|
|
211
|
-
authentication and parsing; `src/services` normalizes results; `src/tools` and
|
|
212
|
-
`src/mcp/tools` expose MCP schemas. `src/mcp/server.ts` registers the tools.
|
|
213
|
-
|
|
214
|
-
- [Authentication and request contract](docs/Moodle_Authentication_Request_Contract.md)
|
|
215
|
-
- [Assignment and deadline discovery](docs/Moodle_Assignment_Deadline_Endpoint_Discovery.md)
|
|
216
|
-
- [MVP verification and known limitations](docs/MVP_Verification.md)
|
|
217
|
-
- [Implementation plan and Linear issue index](tasks/plan.md)
|
|
209
|
+
---
|
|
210
|
+
|
|
211
|
+
## ๐ Source Layout
|
|
212
|
+
|
|
213
|
+
- `src/config/env.ts`: Validates environment settings and credentials.
|
|
214
|
+
- `src/moodle/auth/`: Contains `AutoLoginAuthProvider`, `ManualSessionProvider`, and `provider-factory.ts`.
|
|
215
|
+
- `src/moodle/client.ts`: Reusable Moodle HTTP client with batching and transparent auth retry.
|
|
216
|
+
- `src/services/`: Course, assignment, deadline, and course content services.
|
|
217
|
+
- `src/tools/` & `src/mcp/tools/`: MCP tool definitions and schemas.
|
|
218
|
+
- `scripts/setup.mjs`: Interactive setup assistant.
|
|
219
|
+
|
|
220
|
+
## ๐ License
|
|
221
|
+
|
|
222
|
+
MIT ยฉ [DwaftPainter](https://github.com/DwaftPainter)
|