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.
Files changed (2) hide show
  1. package/README.md +156 -151
  2. package/package.json +1 -1
package/README.md CHANGED
@@ -1,108 +1,86 @@
1
- # HANU LMS MCP
1
+ # FIT LMS MCP
2
2
 
3
- A local, read-only MCP server for a student's authorized HANU Moodle data.
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
- ## Quick Setup (Interactive)
5
+ It exposes enrolled courses, course assignments, upcoming deadlines, and course structure over stdio, with **automatic background authentication** and **interactive setup**.
8
6
 
9
- The easiest way to configure and register the MCP server is using the interactive setup assistant:
7
+ ---
10
8
 
11
- ```bash
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
- ### Manual Setup
11
+ Run the interactive setup assistant directly with `npx`:
19
12
 
20
13
  ```bash
21
- npm ci --ignore-scripts
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
- The runtime supports Node.js 18.19+. The `--env-file` examples below require
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
- | Variable | Meaning |
32
- | --- | --- |
33
- | `LMS_BASE_URL` | Required HTTP(S) Moodle base URL, e.g. `https://lms.fit.hanu.vn`; no credentials, query or fragment |
34
- | `LMS_USERNAME` | Student ID / username for automatic login (Option 1) |
35
- | `LMS_PASSWORD` | Password for automatic login (Option 1; automatically logs in and refreshes expired sessions) |
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
- Configuration failures name the invalid setting without printing its value.
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
- ## Tools
27
+ ---
47
28
 
48
- | Tool | Input | Result |
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
- Examples of tool arguments:
31
+ If you prefer to configure manually, copy the template and edit [.env](file:///.env):
56
32
 
57
- ```json
58
- {}
33
+ ```bash
34
+ cp .env.example .env
35
+ npm run build
59
36
  ```
60
37
 
61
- Use `{}` with `get_my_courses` or `get_upcoming_deadlines`. Select a course ID from
62
- the course results for the other two tools:
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
- ```json
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
- ```json
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
- { "from": "2026-11-01T00:00:00+07:00", "to": "2026-11-30T23:59:59+07:00" }
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
- Deadline `from`/`to` bounds are inclusive ISO 8601 timestamps with a timezone.
77
- Explicit bounds override the default window. Without `from`, `includePast: true`
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
- "hanu-lms": {
78
+ "fit-lms": {
101
79
  "type": "local",
102
80
  "command": [
103
81
  "node",
104
- "--env-file=/absolute/path/to/hanu-lms-mcp/.env",
105
- "/absolute/path/to/hanu-lms-mcp/dist/index.js"
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
- For desktop environments without Node on `PATH`, replace `node` with its absolute
115
- executable path. Run `opencode mcp list`, reopen OpenCode after rebuilding, and ask:
116
-
117
- ```text
118
- Use hanu-lms to list my courses, then show what I need to submit in the next 7 days.
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
- For Claude Desktop, the equivalent entry under `mcpServers` is:
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
- "hanu-lms": {
129
+ "fit-lms": {
127
130
  "command": "node",
128
131
  "args": [
129
- "--env-file=/absolute/path/to/hanu-lms-mcp/.env",
130
- "/absolute/path/to/hanu-lms-mcp/dist/index.js"
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
- ## Authentication and session management
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
- ### Option 1: Automatic login (Recommended)
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 2: Manual session refresh (Legacy)
145
- If using `LMS_MOODLE_SESSION` and `LMS_MOODLE_SESSKEY`:
146
- 1. Sign in normally to your own LMS account in your browser.
147
- 2. In browser DevTools, obtain the `MoodleSession` cookie from Application/Storage
148
- and the `sesskey` query value from a normal `/lib/ajax/service.php` Network
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
- Do not paste live values into chat, screenshots, issues, logs or source control.
153
- `AUTH_REQUIRED` means Moodle requested authentication. `INVALID_SESSION_KEY` means
154
- an invalid sesskey and does not prove that the session expired. An empty course list
155
- alone does not prove authentication failure. A remote `missingparam` may concern any
156
- method argument; only a known missing local sesskey maps to `MISSING_SESSION_KEY`.
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
- ## Verification
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
- Default tests use synthetic fixtures and a local HTTP server. They do not contact
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
- Without `LMS_LIVE_SMOKE=1`, the live script exits before connecting. The authorized
181
- smoke test exercises all four tools over stdio for enrolled courses and a two-call
182
- AJAX batch. It prints only check results and counts. See the dated
183
- [MVP verification report](docs/MVP_Verification.md) for actual live evidence.
184
-
185
- ## Retrieval and limits
186
-
187
- - Moodle AJAX calls use a session cookie and sesskey. `callBatch` supports up to
188
- 50 calls, associates results by array position and verifies response count.
189
- A failed call rejects the batch with a safe typed error and its `requestIndex`;
190
- no partial successful list is returned. Nested JSON strings remain strings until
191
- a method-specific adapter explicitly decodes them.
192
- - Requests reject redirects, apply a timeout through body reading, limit responses
193
- to 8 MiB and discard raw server messages/stacks. Authentication failures are not
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)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "fit-lms-mcp",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "Model Context Protocol (MCP) server for HANU Faculty of Information Technology (FIT) Moodle LMS",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",