@marcelo-ochoa/server-qnap 1.0.1 → 1.0.2
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/CHANGELOG.md +10 -0
- package/Demos.md +43 -0
- package/LICENSE +216 -0
- package/README.md +4 -4
- package/dist/server.js +1 -1
- package/dist/tools/report.js +143 -22
- package/package.json +1 -1
- package/server.json +2 -2
- package/server.ts +1 -1
- package/tools/report.ts +161 -25
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
|
4
4
|
|
|
5
|
+
## [1.0.2] - 2026-02-10
|
|
6
|
+
|
|
7
|
+
### Added
|
|
8
|
+
- **Enhanced qnap-report Tool**: Completely rewritten in native TypeScript for better performance and reliability.
|
|
9
|
+
- Replaced Python-based report collector with native Node.js implementation.
|
|
10
|
+
- Returns structured **JSON format** instead of plain text, perfect for AI parsing.
|
|
11
|
+
- Added detailed **Disk Health** (model, serial, capacity, temperature, health status).
|
|
12
|
+
- Added granular **Resource Usage** (CPU load, memory breakdown, uptime, system temperature).
|
|
13
|
+
- Added comprehensive **Storage Info** (volume labels, total/used/free space, usage percentages).
|
|
14
|
+
|
|
5
15
|
## [1.0.1] - 2026-02-09
|
|
6
16
|
|
|
7
17
|
### Changed
|
package/Demos.md
CHANGED
|
@@ -146,6 +146,49 @@ Using this sample settings.json file at ~/.gemini/ directory:
|
|
|
146
146
|
- qnap-report
|
|
147
147
|
- analyze backup files in several subdirectories of `/backup/stacks` on the QNAP NAS. For each subdirectory compare the two most recent backups (daily or weekly, identified by filenames like `alldb_backup-2.sql.gz` for weekly and `alldb_backup-09.sql.gz` for daily). The comparison should be based on file size, considering backups with similar sizes as correct. Generate a report indicating the status (OK or Error) for each directory based on this comparison.
|
|
148
148
|
|
|
149
|
+
### qnap-report JSON Output Example
|
|
150
|
+
|
|
151
|
+
The `qnap-report` tool now returns a structured JSON object, making it easy for AI models to analyze the system state.
|
|
152
|
+
|
|
153
|
+
```json
|
|
154
|
+
{
|
|
155
|
+
"timestamp": "2026-02-10T15:29:38.124Z",
|
|
156
|
+
"host": "http://10.1.1.241:8080",
|
|
157
|
+
"diskHealth": [
|
|
158
|
+
{
|
|
159
|
+
"alias": "3.5\" SATA HDD 1",
|
|
160
|
+
"model": "WD20EFRX-68EUZN0",
|
|
161
|
+
"serial": "WD-WCC4M1RXUCRS",
|
|
162
|
+
"capacity": "1.82 TB",
|
|
163
|
+
"health": "OK",
|
|
164
|
+
"temperature": "39°C"
|
|
165
|
+
},
|
|
166
|
+
...
|
|
167
|
+
],
|
|
168
|
+
"resourceUsage": {
|
|
169
|
+
"cpuUsage": "21.5 %",
|
|
170
|
+
"memory": {
|
|
171
|
+
"totalMB": 1000,
|
|
172
|
+
"freeMB": 529,
|
|
173
|
+
"usedMB": 471,
|
|
174
|
+
"usedPercent": "47.1%"
|
|
175
|
+
},
|
|
176
|
+
"uptime": "29 days, 0 hours, 27 minutes",
|
|
177
|
+
"systemTemperature": "39°C"
|
|
178
|
+
},
|
|
179
|
+
"storageInfo": [
|
|
180
|
+
{
|
|
181
|
+
"name": "Backup",
|
|
182
|
+
"totalGB": "1218.42",
|
|
183
|
+
"usedGB": "1029.01",
|
|
184
|
+
"freeGB": "189.42",
|
|
185
|
+
"usedPercent": "84.5%"
|
|
186
|
+
},
|
|
187
|
+
...
|
|
188
|
+
]
|
|
189
|
+
}
|
|
190
|
+
```
|
|
191
|
+
|
|
149
192
|
## Using Antigravity Code Editor
|
|
150
193
|
|
|
151
194
|
Put this in `~/.gemini/antigravity/mcp_config.json`
|
package/LICENSE
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
The MCP project is undergoing a licensing transition from the MIT License to the Apache License, Version 2.0 ("Apache-2.0"). All new code and specification contributions to the project are licensed under Apache-2.0. Documentation contributions (excluding specifications) are licensed under CC-BY-4.0.
|
|
2
|
+
|
|
3
|
+
Contributions for which relicensing consent has been obtained are licensed under Apache-2.0. Contributions made by authors who originally licensed their work under the MIT License and who have not yet granted explicit permission to relicense remain licensed under the MIT License.
|
|
4
|
+
|
|
5
|
+
No rights beyond those granted by the applicable original license are conveyed for such contributions.
|
|
6
|
+
|
|
7
|
+
---
|
|
8
|
+
|
|
9
|
+
Apache License
|
|
10
|
+
Version 2.0, January 2004
|
|
11
|
+
http://www.apache.org/licenses/
|
|
12
|
+
|
|
13
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
|
14
|
+
|
|
15
|
+
1. Definitions.
|
|
16
|
+
|
|
17
|
+
"License" shall mean the terms and conditions for use, reproduction,
|
|
18
|
+
and distribution as defined by Sections 1 through 9 of this document.
|
|
19
|
+
|
|
20
|
+
"Licensor" shall mean the copyright owner or entity authorized by
|
|
21
|
+
the copyright owner that is granting the License.
|
|
22
|
+
|
|
23
|
+
"Legal Entity" shall mean the union of the acting entity and all
|
|
24
|
+
other entities that control, are controlled by, or are under common
|
|
25
|
+
control with that entity. For the purposes of this definition,
|
|
26
|
+
"control" means (i) the power, direct or indirect, to cause the
|
|
27
|
+
direction or management of such entity, whether by contract or
|
|
28
|
+
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
|
29
|
+
outstanding shares, or (iii) beneficial ownership of such entity.
|
|
30
|
+
|
|
31
|
+
"You" (or "Your") shall mean an individual or Legal Entity
|
|
32
|
+
exercising permissions granted by this License.
|
|
33
|
+
|
|
34
|
+
"Source" form shall mean the preferred form for making modifications,
|
|
35
|
+
including but not limited to software source code, documentation
|
|
36
|
+
source, and configuration files.
|
|
37
|
+
|
|
38
|
+
"Object" form shall mean any form resulting from mechanical
|
|
39
|
+
transformation or translation of a Source form, including but
|
|
40
|
+
not limited to compiled object code, generated documentation,
|
|
41
|
+
and conversions to other media types.
|
|
42
|
+
|
|
43
|
+
"Work" shall mean the work of authorship, whether in Source or
|
|
44
|
+
Object form, made available under the License, as indicated by a
|
|
45
|
+
copyright notice that is included in or attached to the work
|
|
46
|
+
(an example is provided in the Appendix below).
|
|
47
|
+
|
|
48
|
+
"Derivative Works" shall mean any work, whether in Source or Object
|
|
49
|
+
form, that is based on (or derived from) the Work and for which the
|
|
50
|
+
editorial revisions, annotations, elaborations, or other modifications
|
|
51
|
+
represent, as a whole, an original work of authorship. For the purposes
|
|
52
|
+
of this License, Derivative Works shall not include works that remain
|
|
53
|
+
separable from, or merely link (or bind by name) to the interfaces of,
|
|
54
|
+
the Work and Derivative Works thereof.
|
|
55
|
+
|
|
56
|
+
"Contribution" shall mean any work of authorship, including
|
|
57
|
+
the original version of the Work and any modifications or additions
|
|
58
|
+
to that Work or Derivative Works thereof, that is intentionally
|
|
59
|
+
submitted to the Licensor for inclusion in the Work by the copyright
|
|
60
|
+
owner or by an individual or Legal Entity authorized to submit on behalf
|
|
61
|
+
of the copyright owner. For the purposes of this definition, "submitted"
|
|
62
|
+
means any form of electronic, verbal, or written communication sent
|
|
63
|
+
to the Licensor or its representatives, including but not limited to
|
|
64
|
+
communication on electronic mailing lists, source code control systems,
|
|
65
|
+
and issue tracking systems that are managed by, or on behalf of, the
|
|
66
|
+
Licensor for the purpose of discussing and improving the Work, but
|
|
67
|
+
excluding communication that is conspicuously marked or otherwise
|
|
68
|
+
designated in writing by the copyright owner as "Not a Contribution."
|
|
69
|
+
|
|
70
|
+
"Contributor" shall mean Licensor and any individual or Legal Entity
|
|
71
|
+
on behalf of whom a Contribution has been received by Licensor and
|
|
72
|
+
subsequently incorporated within the Work.
|
|
73
|
+
|
|
74
|
+
2. Grant of Copyright License. Subject to the terms and conditions of
|
|
75
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
76
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
77
|
+
copyright license to reproduce, prepare Derivative Works of,
|
|
78
|
+
publicly display, publicly perform, sublicense, and distribute the
|
|
79
|
+
Work and such Derivative Works in Source or Object form.
|
|
80
|
+
|
|
81
|
+
3. Grant of Patent License. Subject to the terms and conditions of
|
|
82
|
+
this License, each Contributor hereby grants to You a perpetual,
|
|
83
|
+
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
|
84
|
+
(except as stated in this section) patent license to make, have made,
|
|
85
|
+
use, offer to sell, sell, import, and otherwise transfer the Work,
|
|
86
|
+
where such license applies only to those patent claims licensable
|
|
87
|
+
by such Contributor that are necessarily infringed by their
|
|
88
|
+
Contribution(s) alone or by combination of their Contribution(s)
|
|
89
|
+
with the Work to which such Contribution(s) was submitted. If You
|
|
90
|
+
institute patent litigation against any entity (including a
|
|
91
|
+
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
|
92
|
+
or a Contribution incorporated within the Work constitutes direct
|
|
93
|
+
or contributory patent infringement, then any patent licenses
|
|
94
|
+
granted to You under this License for that Work shall terminate
|
|
95
|
+
as of the date such litigation is filed.
|
|
96
|
+
|
|
97
|
+
4. Redistribution. You may reproduce and distribute copies of the
|
|
98
|
+
Work or Derivative Works thereof in any medium, with or without
|
|
99
|
+
modifications, and in Source or Object form, provided that You
|
|
100
|
+
meet the following conditions:
|
|
101
|
+
|
|
102
|
+
(a) You must give any other recipients of the Work or
|
|
103
|
+
Derivative Works a copy of this License; and
|
|
104
|
+
|
|
105
|
+
(b) You must cause any modified files to carry prominent notices
|
|
106
|
+
stating that You changed the files; and
|
|
107
|
+
|
|
108
|
+
(c) You must retain, in the Source form of any Derivative Works
|
|
109
|
+
that You distribute, all copyright, patent, trademark, and
|
|
110
|
+
attribution notices from the Source form of the Work,
|
|
111
|
+
excluding those notices that do not pertain to any part of
|
|
112
|
+
the Derivative Works; and
|
|
113
|
+
|
|
114
|
+
(d) If the Work includes a "NOTICE" text file as part of its
|
|
115
|
+
distribution, then any Derivative Works that You distribute must
|
|
116
|
+
include a readable copy of the attribution notices contained
|
|
117
|
+
within such NOTICE file, excluding those notices that do not
|
|
118
|
+
pertain to any part of the Derivative Works, in at least one
|
|
119
|
+
of the following places: within a NOTICE text file distributed
|
|
120
|
+
as part of the Derivative Works; within the Source form or
|
|
121
|
+
documentation, if provided along with the Derivative Works; or,
|
|
122
|
+
within a display generated by the Derivative Works, if and
|
|
123
|
+
wherever such third-party notices normally appear. The contents
|
|
124
|
+
of the NOTICE file are for informational purposes only and
|
|
125
|
+
do not modify the License. You may add Your own attribution
|
|
126
|
+
notices within Derivative Works that You distribute, alongside
|
|
127
|
+
or as an addendum to the NOTICE text from the Work, provided
|
|
128
|
+
that such additional attribution notices cannot be construed
|
|
129
|
+
as modifying the License.
|
|
130
|
+
|
|
131
|
+
You may add Your own copyright statement to Your modifications and
|
|
132
|
+
may provide additional or different license terms and conditions
|
|
133
|
+
for use, reproduction, or distribution of Your modifications, or
|
|
134
|
+
for any such Derivative Works as a whole, provided Your use,
|
|
135
|
+
reproduction, and distribution of the Work otherwise complies with
|
|
136
|
+
the conditions stated in this License.
|
|
137
|
+
|
|
138
|
+
5. Submission of Contributions. Unless You explicitly state otherwise,
|
|
139
|
+
any Contribution intentionally submitted for inclusion in the Work
|
|
140
|
+
by You to the Licensor shall be under the terms and conditions of
|
|
141
|
+
this License, without any additional terms or conditions.
|
|
142
|
+
Notwithstanding the above, nothing herein shall supersede or modify
|
|
143
|
+
the terms of any separate license agreement you may have executed
|
|
144
|
+
with Licensor regarding such Contributions.
|
|
145
|
+
|
|
146
|
+
6. Trademarks. This License does not grant permission to use the trade
|
|
147
|
+
names, trademarks, service marks, or product names of the Licensor,
|
|
148
|
+
except as required for reasonable and customary use in describing the
|
|
149
|
+
origin of the Work and reproducing the content of the NOTICE file.
|
|
150
|
+
|
|
151
|
+
7. Disclaimer of Warranty. Unless required by applicable law or
|
|
152
|
+
agreed to in writing, Licensor provides the Work (and each
|
|
153
|
+
Contributor provides its Contributions) on an "AS IS" BASIS,
|
|
154
|
+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
|
155
|
+
implied, including, without limitation, any warranties or conditions
|
|
156
|
+
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
|
157
|
+
PARTICULAR PURPOSE. You are solely responsible for determining the
|
|
158
|
+
appropriateness of using or redistributing the Work and assume any
|
|
159
|
+
risks associated with Your exercise of permissions under this License.
|
|
160
|
+
|
|
161
|
+
8. Limitation of Liability. In no event and under no legal theory,
|
|
162
|
+
whether in tort (including negligence), contract, or otherwise,
|
|
163
|
+
unless required by applicable law (such as deliberate and grossly
|
|
164
|
+
negligent acts) or agreed to in writing, shall any Contributor be
|
|
165
|
+
liable to You for damages, including any direct, indirect, special,
|
|
166
|
+
incidental, or consequential damages of any character arising as a
|
|
167
|
+
result of this License or out of the use or inability to use the
|
|
168
|
+
Work (including but not limited to damages for loss of goodwill,
|
|
169
|
+
work stoppage, computer failure or malfunction, or any and all
|
|
170
|
+
other commercial damages or losses), even if such Contributor
|
|
171
|
+
has been advised of the possibility of such damages.
|
|
172
|
+
|
|
173
|
+
9. Accepting Warranty or Additional Liability. While redistributing
|
|
174
|
+
the Work or Derivative Works thereof, You may choose to offer,
|
|
175
|
+
and charge a fee for, acceptance of support, warranty, indemnity,
|
|
176
|
+
or other liability obligations and/or rights consistent with this
|
|
177
|
+
License. However, in accepting such obligations, You may act only
|
|
178
|
+
on Your own behalf and on Your sole responsibility, not on behalf
|
|
179
|
+
of any other Contributor, and only if You agree to indemnify,
|
|
180
|
+
defend, and hold each Contributor harmless for any liability
|
|
181
|
+
incurred by, or claims asserted against, such Contributor by reason
|
|
182
|
+
of your accepting any such warranty or additional liability.
|
|
183
|
+
|
|
184
|
+
END OF TERMS AND CONDITIONS
|
|
185
|
+
|
|
186
|
+
---
|
|
187
|
+
|
|
188
|
+
MIT License
|
|
189
|
+
|
|
190
|
+
Copyright (c) 2024-2025 Model Context Protocol a Series of LF Projects, LLC.
|
|
191
|
+
|
|
192
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
193
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
194
|
+
in the Software without restriction, including without limitation the rights
|
|
195
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
196
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
197
|
+
furnished to do so, subject to the following conditions:
|
|
198
|
+
|
|
199
|
+
The above copyright notice and this permission notice shall be included in all
|
|
200
|
+
copies or substantial portions of the Software.
|
|
201
|
+
|
|
202
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
203
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
204
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
205
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
206
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
207
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
208
|
+
SOFTWARE.
|
|
209
|
+
|
|
210
|
+
---
|
|
211
|
+
|
|
212
|
+
Creative Commons Attribution 4.0 International (CC-BY-4.0)
|
|
213
|
+
|
|
214
|
+
Documentation in this project (excluding specifications) is licensed under
|
|
215
|
+
CC-BY-4.0. See https://creativecommons.org/licenses/by/4.0/legalcode for
|
|
216
|
+
the full license text.
|
package/README.md
CHANGED
|
@@ -8,7 +8,7 @@ An MCP server implementation for QNAP NAS devices, providing tools to monitor sy
|
|
|
8
8
|
- `host`: The QNAP NAS URL (e.g., `http://10.1.1.241:8080`).
|
|
9
9
|
- `username`: Your admin username.
|
|
10
10
|
- `password`: Your admin password.
|
|
11
|
-
- `qnap-report`: Generate a system report including CPU, memory, disks, and volume status.
|
|
11
|
+
- `qnap-report`: Generate a system report in **JSON format** including CPU, memory, disks, and volume status. Perfect for AI analysis and automated monitoring.
|
|
12
12
|
- `qnap-dir`: List the contents of a directory.
|
|
13
13
|
- `path`: The path to list (e.g., `/Public`).
|
|
14
14
|
- `qnap-file-info`: Get detailed information about a specific file.
|
|
@@ -82,8 +82,8 @@ docker run -i --rm -e QNAP_USER=admin -e QNAP_PASSWORD=password mochoa/mcp-qnap
|
|
|
82
82
|
|
|
83
83
|
## Change Log
|
|
84
84
|
|
|
85
|
-
See [Change Log](CHANGELOG.md) for the history of changes.
|
|
85
|
+
See [Change Log](https://github.com/marcelo-ochoa/servers/blob/main/src/qnap/CHANGELOG.md) for the history of changes.
|
|
86
86
|
|
|
87
|
-
## License
|
|
87
|
+
## 📜 License
|
|
88
88
|
|
|
89
|
-
MIT
|
|
89
|
+
This project is licensed under the Apache License, Version 2.0 for new contributions, with existing code under MIT - see the [LICENSE](https://github.com/marcelo-ochoa/servers/blob/main/src/qnap/LICENSE) file for details.
|
package/dist/server.js
CHANGED
package/dist/tools/report.js
CHANGED
|
@@ -1,38 +1,159 @@
|
|
|
1
1
|
import { getNasHost, getNasSid, fetchWithTimeout } from "./connect.js";
|
|
2
|
+
/**
|
|
3
|
+
* Parses disk health information from QNAP XML response.
|
|
4
|
+
*/
|
|
5
|
+
function parseDiskHealth(xml) {
|
|
6
|
+
const disks = [];
|
|
7
|
+
// Extract individual disk entries
|
|
8
|
+
const entryRegex = /<entry>(.*?)<\/entry>/gs;
|
|
9
|
+
let match;
|
|
10
|
+
while ((match = entryRegex.exec(xml)) !== null) {
|
|
11
|
+
const entry = match[1];
|
|
12
|
+
const alias = entry.match(/<Disk_Alias><!\[CDATA\[(.*?)\]\]><\/Disk_Alias>/)?.[1] || "";
|
|
13
|
+
const health = entry.match(/<Health><!\[CDATA\[(.*?)\]\]><\/Health>/)?.[1] || "";
|
|
14
|
+
const capacity = entry.match(/<Capacity><!\[CDATA\[(.*?)\]\]><\/Capacity>/)?.[1] || "";
|
|
15
|
+
const tempC = entry.match(/<oC><!\[CDATA\[(.*?)\]\]><\/oC>/)?.[1] || "";
|
|
16
|
+
const model = entry.match(/<Model><!\[CDATA\[(.*?)\]\]><\/Model>/)?.[1] || "";
|
|
17
|
+
const serial = entry.match(/<Serial><!\[CDATA\[(.*?)\]\]><\/Serial>/)?.[1] || "";
|
|
18
|
+
if (alias) {
|
|
19
|
+
disks.push({
|
|
20
|
+
alias,
|
|
21
|
+
model,
|
|
22
|
+
serial,
|
|
23
|
+
capacity,
|
|
24
|
+
health,
|
|
25
|
+
temperature: tempC ? `${tempC}°C` : ""
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
return disks;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Parses resource usage information from QNAP XML response.
|
|
33
|
+
*/
|
|
34
|
+
function parseResourceUsage(xml) {
|
|
35
|
+
const cpuUsage = xml.match(/<cpu_usage><!\[CDATA\[(.*?)\]\]><\/cpu_usage>/)?.[1]?.trim() || "";
|
|
36
|
+
const memTotalStr = xml.match(/<total_memory><!\[CDATA\[(.*?)\]\]><\/total_memory>/)?.[1];
|
|
37
|
+
const memFreeStr = xml.match(/<free_memory><!\[CDATA\[(.*?)\]\]><\/free_memory>/)?.[1];
|
|
38
|
+
let memory = null;
|
|
39
|
+
if (memTotalStr && memFreeStr) {
|
|
40
|
+
const total = parseFloat(memTotalStr);
|
|
41
|
+
const free = parseFloat(memFreeStr);
|
|
42
|
+
const used = total - free;
|
|
43
|
+
const usedPct = total > 0 ? (used / total) * 100 : 0;
|
|
44
|
+
memory = {
|
|
45
|
+
totalMB: total,
|
|
46
|
+
freeMB: free,
|
|
47
|
+
usedMB: used,
|
|
48
|
+
usedPercent: usedPct.toFixed(1) + "%"
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
const day = xml.match(/<uptime_day><!\[CDATA\[(.*?)\]\]><\/uptime_day>/)?.[1];
|
|
52
|
+
const hour = xml.match(/<uptime_hour><!\[CDATA\[(.*?)\]\]><\/uptime_hour>/)?.[1];
|
|
53
|
+
const min = xml.match(/<uptime_min><!\[CDATA\[(.*?)\]\]><\/uptime_min>/)?.[1];
|
|
54
|
+
let uptime = "";
|
|
55
|
+
if (day !== undefined && hour !== undefined && min !== undefined) {
|
|
56
|
+
uptime = `${day} days, ${hour} hours, ${min} minutes`;
|
|
57
|
+
}
|
|
58
|
+
const sysTemp = xml.match(/<sys_tempc>([^<]+)<\/sys_tempc>/)?.[1];
|
|
59
|
+
return {
|
|
60
|
+
cpuUsage,
|
|
61
|
+
memory,
|
|
62
|
+
uptime,
|
|
63
|
+
systemTemperature: sysTemp ? `${sysTemp}°C` : ""
|
|
64
|
+
};
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Parses storage/volume information from QNAP XML response.
|
|
68
|
+
*/
|
|
69
|
+
function parseStorageInfo(xml) {
|
|
70
|
+
const volumes = [];
|
|
71
|
+
// Create mapping of volumeValue to volumeLabel
|
|
72
|
+
const volLabels = {};
|
|
73
|
+
const volRegex = /<volume>(.*?)<\/volume>/gs;
|
|
74
|
+
let volMatch;
|
|
75
|
+
while ((volMatch = volRegex.exec(xml)) !== null) {
|
|
76
|
+
const vol = volMatch[1];
|
|
77
|
+
const val = vol.match(/<volumeValue><!\[CDATA\[(.*?)\]\]><\/volumeValue>/)?.[1];
|
|
78
|
+
const label = vol.match(/<volumeLabel><!\[CDATA\[(.*?)\]\]><\/volumeLabel>/)?.[1];
|
|
79
|
+
if (val && label) {
|
|
80
|
+
volLabels[val] = label;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
// Parse volume usage
|
|
84
|
+
const useRegex = /<volumeUse>(.*?)<\/volumeUse>/gs;
|
|
85
|
+
let useMatch;
|
|
86
|
+
while ((useMatch = useRegex.exec(xml)) !== null) {
|
|
87
|
+
const volUse = useMatch[1];
|
|
88
|
+
const val = volUse.match(/<volumeValue><!\[CDATA\[(.*?)\]\]><\/volumeValue>/)?.[1];
|
|
89
|
+
const totalStr = volUse.match(/<total_size><!\[CDATA\[(.*?)\]\]><\/total_size>/)?.[1];
|
|
90
|
+
const freeStr = volUse.match(/<free_size><!\[CDATA\[(.*?)\]\]><\/free_size>/)?.[1];
|
|
91
|
+
if (val) {
|
|
92
|
+
const name = volLabels[val] || `Volume ${val}`;
|
|
93
|
+
let usage = { name };
|
|
94
|
+
if (totalStr && freeStr) {
|
|
95
|
+
try {
|
|
96
|
+
const total = parseFloat(totalStr);
|
|
97
|
+
const free = parseFloat(freeStr);
|
|
98
|
+
const used = total - free;
|
|
99
|
+
const usedPct = total > 0 ? (used / total) * 100 : 0;
|
|
100
|
+
usage = {
|
|
101
|
+
...usage,
|
|
102
|
+
totalGB: (total / (1024 ** 3)).toFixed(2),
|
|
103
|
+
usedGB: (used / (1024 ** 3)).toFixed(2),
|
|
104
|
+
freeGB: (free / (1024 ** 3)).toFixed(2),
|
|
105
|
+
usedPercent: usedPct.toFixed(1) + "%"
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
catch {
|
|
109
|
+
usage = { ...usage, totalBytes: totalStr, freeBytes: freeStr };
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
volumes.push(usage);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
return volumes;
|
|
116
|
+
}
|
|
117
|
+
/**
|
|
118
|
+
* Handle qnap-report tool call.
|
|
119
|
+
*/
|
|
2
120
|
export async function reportHandler(request) {
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
if (!
|
|
121
|
+
const host = getNasHost();
|
|
122
|
+
const sid = getNasSid();
|
|
123
|
+
if (!host || !sid) {
|
|
6
124
|
return {
|
|
7
|
-
content: [{ type: "text", text: "Not connected to QNAP NAS. Use qnap-connect first." }],
|
|
125
|
+
content: [{ type: "text", text: JSON.stringify({ error: "Not connected to QNAP NAS. Use qnap-connect first." }) }],
|
|
8
126
|
isError: true
|
|
9
127
|
};
|
|
10
128
|
}
|
|
11
129
|
try {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
const
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
130
|
+
const results = {
|
|
131
|
+
timestamp: new Date().toISOString(),
|
|
132
|
+
host: host
|
|
133
|
+
};
|
|
134
|
+
// 1. Disk Health
|
|
135
|
+
const diskUrl = `${host}/cgi-bin/disk/qsmart.cgi?func=all_hd_data&sid=${sid}`;
|
|
136
|
+
const diskResp = await fetchWithTimeout(diskUrl);
|
|
137
|
+
const diskXml = await diskResp.text();
|
|
138
|
+
results.diskHealth = parseDiskHealth(diskXml);
|
|
139
|
+
// 2. Resource Usage
|
|
140
|
+
const resUrl = `${host}/cgi-bin/management/manaRequest.cgi?subfunc=sysinfo&hd=no&multicpu=1&sid=${sid}`;
|
|
141
|
+
const resResp = await fetchWithTimeout(resUrl);
|
|
142
|
+
const resXml = await resResp.text();
|
|
143
|
+
results.resourceUsage = parseResourceUsage(resXml);
|
|
144
|
+
// 3. Storage Info
|
|
145
|
+
const storageUrl = `${host}/cgi-bin/management/chartReq.cgi?chart_func=disk_usage&disk_select=all&include=all&sid=${sid}`;
|
|
146
|
+
const storageResp = await fetchWithTimeout(storageUrl);
|
|
147
|
+
const storageXml = await storageResp.text();
|
|
148
|
+
results.storageInfo = parseStorageInfo(storageXml);
|
|
28
149
|
return {
|
|
29
|
-
content: [{ type: "text", text:
|
|
150
|
+
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
|
|
30
151
|
isError: false,
|
|
31
152
|
};
|
|
32
153
|
}
|
|
33
154
|
catch (error) {
|
|
34
155
|
return {
|
|
35
|
-
content: [{ type: "text", text: `Error generating report: ${error.message}` }],
|
|
156
|
+
content: [{ type: "text", text: JSON.stringify({ error: `Error generating report: ${error.message}` }) }],
|
|
36
157
|
isError: true
|
|
37
158
|
};
|
|
38
159
|
}
|
package/package.json
CHANGED
package/server.json
CHANGED
|
@@ -7,12 +7,12 @@
|
|
|
7
7
|
"source": "github",
|
|
8
8
|
"subfolder": "src/qnap"
|
|
9
9
|
},
|
|
10
|
-
"version": "1.0.
|
|
10
|
+
"version": "1.0.2",
|
|
11
11
|
"packages": [
|
|
12
12
|
{
|
|
13
13
|
"registryType": "npm",
|
|
14
14
|
"identifier": "@marcelo-ochoa/server-qnap",
|
|
15
|
-
"version": "1.0.
|
|
15
|
+
"version": "1.0.2",
|
|
16
16
|
"transport": {
|
|
17
17
|
"type": "stdio"
|
|
18
18
|
}
|
package/server.ts
CHANGED
package/tools/report.ts
CHANGED
|
@@ -1,45 +1,181 @@
|
|
|
1
1
|
import { CallToolRequest } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import { getNasHost, getNasSid, fetchWithTimeout } from "./connect.js";
|
|
3
3
|
|
|
4
|
+
/**
|
|
5
|
+
* Parses disk health information from QNAP XML response.
|
|
6
|
+
*/
|
|
7
|
+
function parseDiskHealth(xml: string): any[] {
|
|
8
|
+
const disks: any[] = [];
|
|
9
|
+
// Extract individual disk entries
|
|
10
|
+
const entryRegex = /<entry>(.*?)<\/entry>/gs;
|
|
11
|
+
let match;
|
|
12
|
+
|
|
13
|
+
while ((match = entryRegex.exec(xml)) !== null) {
|
|
14
|
+
const entry = match[1];
|
|
15
|
+
|
|
16
|
+
const alias = entry.match(/<Disk_Alias><!\[CDATA\[(.*?)\]\]><\/Disk_Alias>/)?.[1] || "";
|
|
17
|
+
const health = entry.match(/<Health><!\[CDATA\[(.*?)\]\]><\/Health>/)?.[1] || "";
|
|
18
|
+
const capacity = entry.match(/<Capacity><!\[CDATA\[(.*?)\]\]><\/Capacity>/)?.[1] || "";
|
|
19
|
+
const tempC = entry.match(/<oC><!\[CDATA\[(.*?)\]\]><\/oC>/)?.[1] || "";
|
|
20
|
+
const model = entry.match(/<Model><!\[CDATA\[(.*?)\]\]><\/Model>/)?.[1] || "";
|
|
21
|
+
const serial = entry.match(/<Serial><!\[CDATA\[(.*?)\]\]><\/Serial>/)?.[1] || "";
|
|
22
|
+
|
|
23
|
+
if (alias) {
|
|
24
|
+
disks.push({
|
|
25
|
+
alias,
|
|
26
|
+
model,
|
|
27
|
+
serial,
|
|
28
|
+
capacity,
|
|
29
|
+
health,
|
|
30
|
+
temperature: tempC ? `${tempC}°C` : ""
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
return disks;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* Parses resource usage information from QNAP XML response.
|
|
39
|
+
*/
|
|
40
|
+
function parseResourceUsage(xml: string): any {
|
|
41
|
+
const cpuUsage = xml.match(/<cpu_usage><!\[CDATA\[(.*?)\]\]><\/cpu_usage>/)?.[1]?.trim() || "";
|
|
42
|
+
const memTotalStr = xml.match(/<total_memory><!\[CDATA\[(.*?)\]\]><\/total_memory>/)?.[1];
|
|
43
|
+
const memFreeStr = xml.match(/<free_memory><!\[CDATA\[(.*?)\]\]><\/free_memory>/)?.[1];
|
|
44
|
+
|
|
45
|
+
let memory: any = null;
|
|
46
|
+
if (memTotalStr && memFreeStr) {
|
|
47
|
+
const total = parseFloat(memTotalStr);
|
|
48
|
+
const free = parseFloat(memFreeStr);
|
|
49
|
+
const used = total - free;
|
|
50
|
+
const usedPct = total > 0 ? (used / total) * 100 : 0;
|
|
51
|
+
memory = {
|
|
52
|
+
totalMB: total,
|
|
53
|
+
freeMB: free,
|
|
54
|
+
usedMB: used,
|
|
55
|
+
usedPercent: usedPct.toFixed(1) + "%"
|
|
56
|
+
};
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const day = xml.match(/<uptime_day><!\[CDATA\[(.*?)\]\]><\/uptime_day>/)?.[1];
|
|
60
|
+
const hour = xml.match(/<uptime_hour><!\[CDATA\[(.*?)\]\]><\/uptime_hour>/)?.[1];
|
|
61
|
+
const min = xml.match(/<uptime_min><!\[CDATA\[(.*?)\]\]><\/uptime_min>/)?.[1];
|
|
62
|
+
|
|
63
|
+
let uptime = "";
|
|
64
|
+
if (day !== undefined && hour !== undefined && min !== undefined) {
|
|
65
|
+
uptime = `${day} days, ${hour} hours, ${min} minutes`;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
const sysTemp = xml.match(/<sys_tempc>([^<]+)<\/sys_tempc>/)?.[1];
|
|
69
|
+
|
|
70
|
+
return {
|
|
71
|
+
cpuUsage,
|
|
72
|
+
memory,
|
|
73
|
+
uptime,
|
|
74
|
+
systemTemperature: sysTemp ? `${sysTemp}°C` : ""
|
|
75
|
+
};
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
/**
|
|
79
|
+
* Parses storage/volume information from QNAP XML response.
|
|
80
|
+
*/
|
|
81
|
+
function parseStorageInfo(xml: string): any[] {
|
|
82
|
+
const volumes: any[] = [];
|
|
83
|
+
|
|
84
|
+
// Create mapping of volumeValue to volumeLabel
|
|
85
|
+
const volLabels: Record<string, string> = {};
|
|
86
|
+
const volRegex = /<volume>(.*?)<\/volume>/gs;
|
|
87
|
+
let volMatch;
|
|
88
|
+
while ((volMatch = volRegex.exec(xml)) !== null) {
|
|
89
|
+
const vol = volMatch[1];
|
|
90
|
+
const val = vol.match(/<volumeValue><!\[CDATA\[(.*?)\]\]><\/volumeValue>/)?.[1];
|
|
91
|
+
const label = vol.match(/<volumeLabel><!\[CDATA\[(.*?)\]\]><\/volumeLabel>/)?.[1];
|
|
92
|
+
if (val && label) {
|
|
93
|
+
volLabels[val] = label;
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
// Parse volume usage
|
|
98
|
+
const useRegex = /<volumeUse>(.*?)<\/volumeUse>/gs;
|
|
99
|
+
let useMatch;
|
|
100
|
+
while ((useMatch = useRegex.exec(xml)) !== null) {
|
|
101
|
+
const volUse = useMatch[1];
|
|
102
|
+
const val = volUse.match(/<volumeValue><!\[CDATA\[(.*?)\]\]><\/volumeValue>/)?.[1];
|
|
103
|
+
const totalStr = volUse.match(/<total_size><!\[CDATA\[(.*?)\]\]><\/total_size>/)?.[1];
|
|
104
|
+
const freeStr = volUse.match(/<free_size><!\[CDATA\[(.*?)\]\]><\/free_size>/)?.[1];
|
|
105
|
+
|
|
106
|
+
if (val) {
|
|
107
|
+
const name = volLabels[val] || `Volume ${val}`;
|
|
108
|
+
let usage: any = { name };
|
|
109
|
+
|
|
110
|
+
if (totalStr && freeStr) {
|
|
111
|
+
try {
|
|
112
|
+
const total = parseFloat(totalStr);
|
|
113
|
+
const free = parseFloat(freeStr);
|
|
114
|
+
const used = total - free;
|
|
115
|
+
const usedPct = total > 0 ? (used / total) * 100 : 0;
|
|
116
|
+
|
|
117
|
+
usage = {
|
|
118
|
+
...usage,
|
|
119
|
+
totalGB: (total / (1024 ** 3)).toFixed(2),
|
|
120
|
+
usedGB: (used / (1024 ** 3)).toFixed(2),
|
|
121
|
+
freeGB: (free / (1024 ** 3)).toFixed(2),
|
|
122
|
+
usedPercent: usedPct.toFixed(1) + "%"
|
|
123
|
+
};
|
|
124
|
+
} catch {
|
|
125
|
+
usage = { ...usage, totalBytes: totalStr, freeBytes: freeStr };
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
volumes.push(usage);
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
return volumes;
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
/**
|
|
135
|
+
* Handle qnap-report tool call.
|
|
136
|
+
*/
|
|
4
137
|
export async function reportHandler(request: CallToolRequest) {
|
|
5
|
-
const
|
|
6
|
-
const
|
|
138
|
+
const host = getNasHost();
|
|
139
|
+
const sid = getNasSid();
|
|
7
140
|
|
|
8
|
-
if (!
|
|
141
|
+
if (!host || !sid) {
|
|
9
142
|
return {
|
|
10
|
-
content: [{ type: "text", text: "Not connected to QNAP NAS. Use qnap-connect first." }],
|
|
143
|
+
content: [{ type: "text", text: JSON.stringify({ error: "Not connected to QNAP NAS. Use qnap-connect first." }) }],
|
|
11
144
|
isError: true
|
|
12
145
|
};
|
|
13
146
|
}
|
|
14
147
|
|
|
15
148
|
try {
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
const
|
|
23
|
-
const
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
149
|
+
const results: any = {
|
|
150
|
+
timestamp: new Date().toISOString(),
|
|
151
|
+
host: host
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
// 1. Disk Health
|
|
155
|
+
const diskUrl = `${host}/cgi-bin/disk/qsmart.cgi?func=all_hd_data&sid=${sid}`;
|
|
156
|
+
const diskResp = await fetchWithTimeout(diskUrl);
|
|
157
|
+
const diskXml = await diskResp.text();
|
|
158
|
+
results.diskHealth = parseDiskHealth(diskXml);
|
|
159
|
+
|
|
160
|
+
// 2. Resource Usage
|
|
161
|
+
const resUrl = `${host}/cgi-bin/management/manaRequest.cgi?subfunc=sysinfo&hd=no&multicpu=1&sid=${sid}`;
|
|
162
|
+
const resResp = await fetchWithTimeout(resUrl);
|
|
163
|
+
const resXml = await resResp.text();
|
|
164
|
+
results.resourceUsage = parseResourceUsage(resXml);
|
|
165
|
+
|
|
166
|
+
// 3. Storage Info
|
|
167
|
+
const storageUrl = `${host}/cgi-bin/management/chartReq.cgi?chart_func=disk_usage&disk_select=all&include=all&sid=${sid}`;
|
|
168
|
+
const storageResp = await fetchWithTimeout(storageUrl);
|
|
169
|
+
const storageXml = await storageResp.text();
|
|
170
|
+
results.storageInfo = parseStorageInfo(storageXml);
|
|
35
171
|
|
|
36
172
|
return {
|
|
37
|
-
content: [{ type: "text", text:
|
|
173
|
+
content: [{ type: "text", text: JSON.stringify(results, null, 2) }],
|
|
38
174
|
isError: false,
|
|
39
175
|
};
|
|
40
176
|
} catch (error: any) {
|
|
41
177
|
return {
|
|
42
|
-
content: [{ type: "text", text: `Error generating report: ${error.message}` }],
|
|
178
|
+
content: [{ type: "text", text: JSON.stringify({ error: `Error generating report: ${error.message}` }) }],
|
|
43
179
|
isError: true
|
|
44
180
|
};
|
|
45
181
|
}
|