fit-lms-mcp 1.0.1 → 2.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 +109 -37
- package/dist/index.js +69 -5
- package/package.json +6 -6
- package/scripts/setup.mjs +89 -32
package/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# FIT LMS MCP
|
|
1
|
+
# HANU FIT LMS MCP
|
|
2
2
|
|
|
3
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`).
|
|
4
4
|
|
|
@@ -8,19 +8,27 @@ It exposes enrolled courses, course assignments, upcoming deadlines, and course
|
|
|
8
8
|
|
|
9
9
|
## 🚀 Quick Start
|
|
10
10
|
|
|
11
|
+
Requires **Node.js 22 or later**. Node.js 24 LTS is recommended. CI tests Node.js 22, 24, and 26 on Linux and macOS.
|
|
12
|
+
|
|
11
13
|
Run the interactive setup assistant directly with `npx`:
|
|
12
14
|
|
|
13
15
|
```bash
|
|
14
|
-
npx fit-lms-setup
|
|
16
|
+
npx fit-lms-mcp setup
|
|
15
17
|
```
|
|
16
18
|
|
|
17
|
-
|
|
19
|
+
Or, from a local workspace:
|
|
20
|
+
|
|
21
|
+
```bash
|
|
22
|
+
npm install
|
|
23
|
+
npm run setup
|
|
24
|
+
```
|
|
18
25
|
|
|
19
26
|
The interactive setup assistant will:
|
|
27
|
+
|
|
20
28
|
1. Prompt for your LMS student ID and password (safely masked).
|
|
21
29
|
2. Test the connection against HANU LMS immediately.
|
|
22
|
-
3. Save your
|
|
23
|
-
4.
|
|
30
|
+
3. Save your configuration securely with `0600` permissions to `~/.fit-lms-mcp/.env` when run via `npx`, or the workspace `.env` when run from the package root.
|
|
31
|
+
4. Offer to register the MCP server with detected AI clients (**Claude Code**, **OpenCode**, **Codex**, or **Antigravity**). For Codex, use the manual configuration below.
|
|
24
32
|
|
|
25
33
|
After running setup, you can use the MCP server directly in your AI client with `npx -y fit-lms-mcp`.
|
|
26
34
|
|
|
@@ -28,13 +36,15 @@ After running setup, you can use the MCP server directly in your AI client with
|
|
|
28
36
|
|
|
29
37
|
## ⚙️ Manual Configuration
|
|
30
38
|
|
|
31
|
-
|
|
39
|
+
For a local workspace, copy the template, edit `.env`, and build:
|
|
32
40
|
|
|
33
41
|
```bash
|
|
34
42
|
cp .env.example .env
|
|
35
43
|
npm run build
|
|
36
44
|
```
|
|
37
45
|
|
|
46
|
+
For use via `npx`, create `~/.fit-lms-mcp/.env` with the settings below and restrict its permissions to `0600`.
|
|
47
|
+
|
|
38
48
|
| Variable | Description |
|
|
39
49
|
| :--- | :--- |
|
|
40
50
|
| `LMS_BASE_URL` | Required Moodle base URL, e.g. `https://lms.fit.hanu.vn` (no credentials, query or fragment) |
|
|
@@ -44,44 +54,47 @@ npm run build
|
|
|
44
54
|
| `LMS_MOODLE_SESSION` | MoodleSession cookie value (Option 2 - Manual legacy session) |
|
|
45
55
|
| `LMS_MOODLE_SESSKEY` | sesskey query parameter from the same session (Option 2 - Manual legacy session) |
|
|
46
56
|
|
|
47
|
-
*Configuration failures name the invalid setting without printing sensitive credential values.
|
|
57
|
+
*Configuration failures name the invalid setting without printing sensitive credential values. Workspace `.env` files are ignored by Git.*
|
|
58
|
+
|
|
59
|
+
When credentials are not already supplied through the environment, the server looks for `.env` in its working directory, then `~/.fit-lms-mcp/.env`. The first readable file is used. You can also provide settings through your AI client's environment configuration.
|
|
48
60
|
|
|
49
61
|
---
|
|
50
62
|
|
|
51
63
|
## 🤖 AI Client Integration
|
|
52
64
|
|
|
65
|
+
The following examples use the credentials saved by the `npx` setup flow.
|
|
66
|
+
|
|
53
67
|
### 1. Claude Code
|
|
68
|
+
|
|
54
69
|
Register via CLI:
|
|
70
|
+
|
|
55
71
|
```bash
|
|
56
|
-
claude mcp add fit-lms --
|
|
72
|
+
claude mcp add fit-lms -- npx -y fit-lms-mcp
|
|
57
73
|
```
|
|
74
|
+
|
|
58
75
|
Or add to `~/.claude.json`:
|
|
76
|
+
|
|
59
77
|
```json
|
|
60
78
|
{
|
|
61
79
|
"mcpServers": {
|
|
62
80
|
"fit-lms": {
|
|
63
|
-
"command": "
|
|
64
|
-
"args": [
|
|
65
|
-
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
66
|
-
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
67
|
-
]
|
|
81
|
+
"command": "npx",
|
|
82
|
+
"args": ["-y", "fit-lms-mcp"]
|
|
68
83
|
}
|
|
69
84
|
}
|
|
70
85
|
}
|
|
71
86
|
```
|
|
72
87
|
|
|
73
88
|
### 2. OpenCode
|
|
89
|
+
|
|
74
90
|
Add to `~/.config/opencode/opencode.jsonc` (or project `opencode.json`):
|
|
91
|
+
|
|
75
92
|
```json
|
|
76
93
|
{
|
|
77
94
|
"mcp": {
|
|
78
95
|
"fit-lms": {
|
|
79
96
|
"type": "local",
|
|
80
|
-
"command": [
|
|
81
|
-
"node",
|
|
82
|
-
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
83
|
-
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
84
|
-
],
|
|
97
|
+
"command": ["npx", "-y", "fit-lms-mcp"],
|
|
85
98
|
"enabled": true,
|
|
86
99
|
"timeout": 60000
|
|
87
100
|
}
|
|
@@ -89,56 +102,87 @@ Add to `~/.config/opencode/opencode.jsonc` (or project `opencode.json`):
|
|
|
89
102
|
}
|
|
90
103
|
```
|
|
91
104
|
|
|
92
|
-
### 3.
|
|
105
|
+
### 3. Codex
|
|
106
|
+
|
|
107
|
+
Register via CLI:
|
|
108
|
+
|
|
109
|
+
```bash
|
|
110
|
+
codex mcp add fit-lms -- npx -y fit-lms-mcp
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
Or add to `~/.codex/config.toml`:
|
|
114
|
+
|
|
115
|
+
```toml
|
|
116
|
+
[mcp_servers.fit-lms]
|
|
117
|
+
command = "npx"
|
|
118
|
+
args = ["-y", "fit-lms-mcp"]
|
|
119
|
+
```
|
|
120
|
+
|
|
121
|
+
See the [Codex MCP documentation](https://developers.openai.com/codex/mcp/). The setup assistant currently writes a JSON configuration for Codex; use the CLI command or TOML configuration above instead.
|
|
122
|
+
|
|
123
|
+
### 4. Antigravity
|
|
124
|
+
|
|
93
125
|
Add to `~/.gemini/config/mcp_config.json`:
|
|
126
|
+
|
|
94
127
|
```json
|
|
95
128
|
{
|
|
96
129
|
"mcpServers": {
|
|
97
130
|
"fit-lms": {
|
|
98
|
-
"command": "
|
|
99
|
-
"args": [
|
|
100
|
-
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
101
|
-
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
102
|
-
]
|
|
131
|
+
"command": "npx",
|
|
132
|
+
"args": ["-y", "fit-lms-mcp"]
|
|
103
133
|
}
|
|
104
134
|
}
|
|
105
135
|
}
|
|
106
136
|
```
|
|
107
137
|
|
|
108
|
-
###
|
|
138
|
+
### 5. Cursor
|
|
139
|
+
|
|
109
140
|
Add to `~/.cursor/mcp.json` or `.cursor/mcp.json` in your project:
|
|
141
|
+
|
|
110
142
|
```json
|
|
111
143
|
{
|
|
112
144
|
"mcpServers": {
|
|
113
145
|
"fit-lms": {
|
|
114
|
-
"command": "
|
|
115
|
-
"args": [
|
|
116
|
-
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
117
|
-
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
118
|
-
]
|
|
146
|
+
"command": "npx",
|
|
147
|
+
"args": ["-y", "fit-lms-mcp"]
|
|
119
148
|
}
|
|
120
149
|
}
|
|
121
150
|
}
|
|
122
151
|
```
|
|
123
152
|
|
|
124
|
-
###
|
|
153
|
+
### 6. Claude Desktop
|
|
154
|
+
|
|
125
155
|
Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
156
|
+
|
|
126
157
|
```json
|
|
127
158
|
{
|
|
128
159
|
"mcpServers": {
|
|
129
160
|
"fit-lms": {
|
|
130
|
-
"command": "
|
|
131
|
-
"args": [
|
|
132
|
-
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
133
|
-
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
134
|
-
]
|
|
161
|
+
"command": "npx",
|
|
162
|
+
"args": ["-y", "fit-lms-mcp"]
|
|
135
163
|
}
|
|
136
164
|
}
|
|
137
165
|
}
|
|
138
166
|
```
|
|
139
167
|
|
|
168
|
+
### Local Workspace Configuration
|
|
169
|
+
|
|
170
|
+
To run a local build with an explicit credentials file, replace the `npx` command and arguments with:
|
|
171
|
+
|
|
172
|
+
```json
|
|
173
|
+
{
|
|
174
|
+
"command": "node",
|
|
175
|
+
"args": [
|
|
176
|
+
"--env-file=/absolute/path/to/fit-lms-mcp/.env",
|
|
177
|
+
"/absolute/path/to/fit-lms-mcp/dist/index.js"
|
|
178
|
+
]
|
|
179
|
+
}
|
|
180
|
+
```
|
|
181
|
+
|
|
182
|
+
For OpenCode, use these values as a single command array. For Codex, use them as the `command` and `args` values in the TOML table above.
|
|
183
|
+
|
|
140
184
|
> [!TIP]
|
|
141
|
-
> On macOS with NVM, if your GUI application does not inherit terminal `$PATH`, replace `"node"` with
|
|
185
|
+
> On macOS with NVM, if your GUI application does not inherit terminal `$PATH`, replace `"npx"` or `"node"` with its full executable path (for example, the output of `which npx` or `which node`).
|
|
142
186
|
|
|
143
187
|
---
|
|
144
188
|
|
|
@@ -174,6 +218,16 @@ Add to `~/Library/Application Support/Claude/claude_desktop_config.json`:
|
|
|
174
218
|
|
|
175
219
|
---
|
|
176
220
|
|
|
221
|
+
### Example Prompts
|
|
222
|
+
|
|
223
|
+
Once connected to your AI assistant, you can ask:
|
|
224
|
+
|
|
225
|
+
- "List my enrolled courses on HANU FIT LMS."
|
|
226
|
+
- "Show all assignments and upcoming deadlines for the next 7 days."
|
|
227
|
+
- "What topics and materials are in course 660?"
|
|
228
|
+
|
|
229
|
+
---
|
|
230
|
+
|
|
177
231
|
## 🔐 Authentication & Session Management
|
|
178
232
|
|
|
179
233
|
### Option 1: Automatic Login (Recommended)
|
|
@@ -217,6 +271,24 @@ LMS_LIVE_SMOKE=1 node --env-file=.env scripts/smoke-live.mjs
|
|
|
217
271
|
- `src/tools/` & `src/mcp/tools/`: MCP tool definitions and schemas.
|
|
218
272
|
- `scripts/setup.mjs`: Interactive setup assistant.
|
|
219
273
|
|
|
274
|
+
## Publishing Releases
|
|
275
|
+
|
|
276
|
+
Version 2.0.0 requires Node.js 22 or later; Node.js 18 and 20 are no longer supported.
|
|
277
|
+
|
|
278
|
+
The `publish.yml` workflow publishes on a `v*` Git tag push or a manual workflow run. Creating a GitHub Release does not trigger a second publish. Update `package.json` and `package-lock.json` before tagging a release, and make the tag match the package version (for example, `v2.0.0`). Published npm versions cannot be reused, even after unpublishing.
|
|
279
|
+
|
|
280
|
+
For manual runs, the `tag` input selects the npm distribution channel: `latest`, `beta`, or `next`. To publish the stable version `2.0.0` from `package.json`, select `latest`. The package version (`2.0.0`), Git tag (`v2.0.0`), and npm channel (`latest`) are separate values.
|
|
281
|
+
|
|
282
|
+
Publishing uses npm trusted publishing (OIDC) from a GitHub-hosted runner with Node.js 24 and npm 11. No `NPM_TOKEN` secret is required. Configure the package's Trusted Publisher on npm with:
|
|
283
|
+
|
|
284
|
+
- **Organization or user:** `DwaftPainter`
|
|
285
|
+
- **Repository:** `fit-lms-mcp` (without `@`)
|
|
286
|
+
- **Workflow filename:** `publish.yml`
|
|
287
|
+
- **Environment name:** leave empty; this workflow does not select an environment
|
|
288
|
+
- **Allowed actions:** enable `Allow npm publish`
|
|
289
|
+
|
|
290
|
+
Required fields in an existing trusted publisher cannot be edited; recreate the connection if they are incorrect. See the [npm trusted publishing documentation](https://docs.npmjs.com/trusted-publishers/).
|
|
291
|
+
|
|
220
292
|
## 📄 License
|
|
221
293
|
|
|
222
294
|
MIT © [DwaftPainter](https://github.com/DwaftPainter)
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,69 @@
|
|
|
1
|
-
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import fs from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import os from "node:os";
|
|
5
|
+
function tryLoadEnv() {
|
|
6
|
+
if (process.env.LMS_USERNAME || process.env.LMS_MOODLE_SESSION) {
|
|
7
|
+
return;
|
|
8
|
+
}
|
|
9
|
+
const candidatePaths = [
|
|
10
|
+
path.resolve(process.cwd(), ".env"),
|
|
11
|
+
path.join(os.homedir(), ".fit-lms-mcp", ".env"),
|
|
12
|
+
];
|
|
13
|
+
for (const envPath of candidatePaths) {
|
|
14
|
+
if (fs.existsSync(envPath)) {
|
|
15
|
+
if (typeof process.loadEnvFile === "function") {
|
|
16
|
+
try {
|
|
17
|
+
process.loadEnvFile(envPath);
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
catch {
|
|
21
|
+
// fallback to manual parse if loadEnvFile fails
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
try {
|
|
25
|
+
const content = fs.readFileSync(envPath, "utf8");
|
|
26
|
+
for (const line of content.split("\n")) {
|
|
27
|
+
const trimmed = line.trim();
|
|
28
|
+
if (!trimmed || trimmed.startsWith("#"))
|
|
29
|
+
continue;
|
|
30
|
+
const eqIdx = trimmed.indexOf("=");
|
|
31
|
+
if (eqIdx === -1)
|
|
32
|
+
continue;
|
|
33
|
+
const key = trimmed.slice(0, eqIdx).trim();
|
|
34
|
+
let val = trimmed.slice(eqIdx + 1).trim();
|
|
35
|
+
if ((val.startsWith('"') && val.endsWith('"')) || (val.startsWith("'") && val.endsWith("'"))) {
|
|
36
|
+
val = val.slice(1, -1);
|
|
37
|
+
}
|
|
38
|
+
if (key && !(key in process.env)) {
|
|
39
|
+
process.env[key] = val;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
catch {
|
|
45
|
+
// ignore read errors
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
async function main() {
|
|
51
|
+
const args = process.argv.slice(2);
|
|
52
|
+
if (args.includes("setup") || args.includes("--setup")) {
|
|
53
|
+
// Dynamic import to execute setup assistant
|
|
54
|
+
// @ts-expect-error setup.mjs is an ES script without TS definitions
|
|
55
|
+
const { runSetup } = await import("../scripts/setup.mjs");
|
|
56
|
+
await runSetup();
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
tryLoadEnv();
|
|
60
|
+
const { loadConfig } = await import("./config/env.js");
|
|
61
|
+
const { createServer } = await import("./mcp/server.js");
|
|
62
|
+
loadConfig();
|
|
63
|
+
const server = createServer();
|
|
64
|
+
server.start();
|
|
65
|
+
}
|
|
66
|
+
main().catch((err) => {
|
|
67
|
+
console.error(err instanceof Error ? err.message : String(err));
|
|
68
|
+
process.exit(1);
|
|
69
|
+
});
|
package/package.json
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "fit-lms-mcp",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.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",
|
|
7
7
|
"bin": {
|
|
8
|
-
"fit-lms-mcp": "
|
|
9
|
-
"fit-lms-setup": "
|
|
10
|
-
"hanu-lms-mcp": "
|
|
11
|
-
"hanu-lms-setup": "
|
|
8
|
+
"fit-lms-mcp": "dist/index.js",
|
|
9
|
+
"fit-lms-setup": "scripts/setup.mjs",
|
|
10
|
+
"hanu-lms-mcp": "dist/index.js",
|
|
11
|
+
"hanu-lms-setup": "scripts/setup.mjs"
|
|
12
12
|
},
|
|
13
13
|
"files": [
|
|
14
14
|
"dist",
|
|
@@ -59,6 +59,6 @@
|
|
|
59
59
|
"typescript": "^5.3.3"
|
|
60
60
|
},
|
|
61
61
|
"engines": {
|
|
62
|
-
"node": ">=
|
|
62
|
+
"node": ">=22"
|
|
63
63
|
}
|
|
64
64
|
}
|
package/scripts/setup.mjs
CHANGED
|
@@ -81,12 +81,16 @@ export function stripJsonComments(text) {
|
|
|
81
81
|
const end = text.indexOf("*/", i + 2);
|
|
82
82
|
if (end === -1) break;
|
|
83
83
|
i = end + 1;
|
|
84
|
+
} else if (char === "}" || char === "]") {
|
|
85
|
+
// Strip trailing commas only outside strings, after skipping comments.
|
|
86
|
+
result = result.replace(/,(\s*)$/, "$1");
|
|
87
|
+
result += char;
|
|
84
88
|
} else {
|
|
85
89
|
result += char;
|
|
86
90
|
}
|
|
87
91
|
}
|
|
88
92
|
}
|
|
89
|
-
return result
|
|
93
|
+
return result;
|
|
90
94
|
}
|
|
91
95
|
|
|
92
96
|
export function updateJsonConfigFile(configPath, serverConfig, key = "mcpServers") {
|
|
@@ -119,10 +123,20 @@ export function updateJsonConfigFile(configPath, serverConfig, key = "mcpServers
|
|
|
119
123
|
return false;
|
|
120
124
|
}
|
|
121
125
|
|
|
122
|
-
if (
|
|
126
|
+
if (Object.hasOwn(json, key) &&
|
|
127
|
+
(json[key] === null || typeof json[key] !== "object" || Array.isArray(json[key]))) {
|
|
128
|
+
console.error(`\n❌ Cấu trúc ${key} không hợp lệ (không phải JSON object): ${configPath}`);
|
|
129
|
+
console.error(` ⚠️ Đã HỦY thao tác ghi để bảo vệ file của bạn.`);
|
|
130
|
+
return false;
|
|
131
|
+
}
|
|
132
|
+
if (!Object.hasOwn(json, key)) {
|
|
123
133
|
json[key] = {};
|
|
124
134
|
}
|
|
125
|
-
|
|
135
|
+
// Reuse the legacy name when present so setup does not add a second server.
|
|
136
|
+
const serverName = !Object.hasOwn(json[key], "fit-lms") && Object.hasOwn(json[key], "hanu-lms")
|
|
137
|
+
? "hanu-lms"
|
|
138
|
+
: "fit-lms";
|
|
139
|
+
json[key][serverName] = serverConfig;
|
|
126
140
|
|
|
127
141
|
try {
|
|
128
142
|
fs.mkdirSync(path.dirname(configPath), { recursive: true });
|
|
@@ -221,26 +235,40 @@ export function saveEnvFile(envPath, { baseUrl, timeoutMs, username, password })
|
|
|
221
235
|
}
|
|
222
236
|
}
|
|
223
237
|
|
|
224
|
-
async function
|
|
238
|
+
export async function runSetup() {
|
|
225
239
|
console.log("\n=================================================");
|
|
226
|
-
console.log(" HANU LMS MCP — Interactive Setup Assistant");
|
|
240
|
+
console.log(" HANU FIT LMS MCP — Interactive Setup Assistant");
|
|
227
241
|
console.log("=================================================\n");
|
|
228
242
|
|
|
229
|
-
const
|
|
230
|
-
const
|
|
231
|
-
const
|
|
243
|
+
const scriptDir = path.dirname(fileURLToPath(import.meta.url));
|
|
244
|
+
const packageRoot = path.resolve(scriptDir, "..");
|
|
245
|
+
const isLocalDev = path.resolve(process.cwd()) === packageRoot;
|
|
246
|
+
|
|
247
|
+
let envPath;
|
|
248
|
+
const distIndexPath = path.resolve(packageRoot, "dist/index.js");
|
|
232
249
|
const nodePath = process.execPath;
|
|
233
250
|
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
251
|
+
if (isLocalDev) {
|
|
252
|
+
envPath = path.resolve(packageRoot, ".env");
|
|
253
|
+
// 1. Ensure build exists in local dev
|
|
254
|
+
if (!fs.existsSync(distIndexPath)) {
|
|
255
|
+
console.log("📦 Chưa tìm thấy bản build, đang tiến hành build TypeScript sang dist/...");
|
|
256
|
+
try {
|
|
257
|
+
execSync("npm run build", { cwd: packageRoot, stdio: "inherit" });
|
|
258
|
+
console.log("✅ Build hoàn tất.\n");
|
|
259
|
+
} catch {
|
|
260
|
+
console.error("❌ Lỗi khi build project. Vui lòng kiểm tra lại npm run build.");
|
|
261
|
+
process.exit(1);
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
} else {
|
|
265
|
+
const configDir = path.join(os.homedir(), ".fit-lms-mcp");
|
|
237
266
|
try {
|
|
238
|
-
|
|
239
|
-
console.log("✅ Build hoàn tất.\n");
|
|
267
|
+
fs.mkdirSync(configDir, { recursive: true, mode: 0o700 });
|
|
240
268
|
} catch {
|
|
241
|
-
|
|
242
|
-
process.exit(1);
|
|
269
|
+
// Ignore directory creation errors if already exists
|
|
243
270
|
}
|
|
271
|
+
envPath = path.join(configDir, ".env");
|
|
244
272
|
}
|
|
245
273
|
|
|
246
274
|
// 2. Load existing .env if present
|
|
@@ -257,6 +285,19 @@ async function main() {
|
|
|
257
285
|
} catch {
|
|
258
286
|
// Ignore read errors
|
|
259
287
|
}
|
|
288
|
+
} else if (!isLocalDev) {
|
|
289
|
+
// Check if local dev .env exists as fallback
|
|
290
|
+
const localEnv = path.resolve(process.cwd(), ".env");
|
|
291
|
+
if (fs.existsSync(localEnv)) {
|
|
292
|
+
try {
|
|
293
|
+
const parsed = parseEnvContent(fs.readFileSync(localEnv, "utf8"));
|
|
294
|
+
if (parsed.LMS_BASE_URL) existingBaseUrl = parsed.LMS_BASE_URL;
|
|
295
|
+
if (parsed.LMS_USERNAME) existingUsername = parsed.LMS_USERNAME;
|
|
296
|
+
if (parsed.TIMEOUT_MS) existingTimeout = parsed.TIMEOUT_MS;
|
|
297
|
+
} catch {
|
|
298
|
+
// Ignore read errors
|
|
299
|
+
}
|
|
300
|
+
}
|
|
260
301
|
}
|
|
261
302
|
|
|
262
303
|
// 3. Ask user for inputs
|
|
@@ -314,17 +355,29 @@ async function main() {
|
|
|
314
355
|
console.log(`\n🎉 Đã lưu cấu hình an toàn (permissions: 0600) vào: ${envPath}`);
|
|
315
356
|
|
|
316
357
|
// 6. Define configurations for clients
|
|
317
|
-
const mcpServerConfig =
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
358
|
+
const mcpServerConfig = isLocalDev
|
|
359
|
+
? {
|
|
360
|
+
command: nodePath,
|
|
361
|
+
args: [`--env-file=${envPath}`, distIndexPath],
|
|
362
|
+
}
|
|
363
|
+
: {
|
|
364
|
+
command: "npx",
|
|
365
|
+
args: ["-y", "fit-lms-mcp"],
|
|
366
|
+
};
|
|
367
|
+
|
|
368
|
+
const openCodeConfig = isLocalDev
|
|
369
|
+
? {
|
|
370
|
+
type: "local",
|
|
371
|
+
command: [nodePath, `--env-file=${envPath}`, distIndexPath],
|
|
372
|
+
enabled: true,
|
|
373
|
+
timeout: 60000,
|
|
374
|
+
}
|
|
375
|
+
: {
|
|
376
|
+
type: "local",
|
|
377
|
+
command: ["npx", "-y", "fit-lms-mcp"],
|
|
378
|
+
enabled: true,
|
|
379
|
+
timeout: 60000,
|
|
380
|
+
};
|
|
328
381
|
|
|
329
382
|
// 7. Auto-detect and configure: Claude Code, OpenCode, Codex, Antigravity
|
|
330
383
|
console.log("\n-------------------------------------------------");
|
|
@@ -407,25 +460,29 @@ async function main() {
|
|
|
407
460
|
console.log(" Cấu hình MCP cho các AI Client (Copy thủ công)");
|
|
408
461
|
console.log("=================================================\n");
|
|
409
462
|
|
|
463
|
+
const cliExample = isLocalDev
|
|
464
|
+
? `claude mcp add fit-lms -- ${nodePath} --env-file=${envPath} ${distIndexPath}`
|
|
465
|
+
: `claude mcp add fit-lms -- npx -y fit-lms-mcp`;
|
|
466
|
+
|
|
410
467
|
console.log("1. Claude Code:");
|
|
411
|
-
console.log(` Lệnh CLI:
|
|
468
|
+
console.log(` Lệnh CLI: ${cliExample}`);
|
|
412
469
|
console.log(" Hoặc trong ~/.claude.json:");
|
|
413
|
-
console.log(JSON.stringify({ mcpServers: { "
|
|
470
|
+
console.log(JSON.stringify({ mcpServers: { "fit-lms": mcpServerConfig } }, null, 2));
|
|
414
471
|
|
|
415
472
|
console.log("\n2. OpenCode (~/.config/opencode/opencode.jsonc):");
|
|
416
|
-
console.log(JSON.stringify({ mcp: { "
|
|
473
|
+
console.log(JSON.stringify({ mcp: { "fit-lms": openCodeConfig } }, null, 2));
|
|
417
474
|
|
|
418
475
|
console.log("\n3. Codex (~/.codex/config.json):");
|
|
419
|
-
console.log(JSON.stringify({ mcpServers: { "
|
|
476
|
+
console.log(JSON.stringify({ mcpServers: { "fit-lms": mcpServerConfig } }, null, 2));
|
|
420
477
|
|
|
421
478
|
console.log("\n4. Antigravity (~/.gemini/config/mcp_config.json):");
|
|
422
|
-
console.log(JSON.stringify({ mcpServers: { "
|
|
479
|
+
console.log(JSON.stringify({ mcpServers: { "fit-lms": mcpServerConfig } }, null, 2));
|
|
423
480
|
|
|
424
481
|
console.log("\n✨ Setup hoàn tất! Bạn có thể khởi động AI Client của mình để bắt đầu.");
|
|
425
482
|
}
|
|
426
483
|
|
|
427
484
|
if (process.argv[1] && path.resolve(process.argv[1]) === path.resolve(fileURLToPath(import.meta.url))) {
|
|
428
|
-
|
|
485
|
+
runSetup().catch((err) => {
|
|
429
486
|
console.error("Lỗi:", err);
|
|
430
487
|
process.exit(1);
|
|
431
488
|
});
|