@teamnetwork-nz/prtg-mcp-server 1.4.0 → 1.5.0
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 +13 -2
- package/dist/http-server.d.ts +14 -0
- package/dist/http-server.d.ts.map +1 -0
- package/dist/http-server.js +115 -0
- package/dist/http-server.js.map +1 -0
- package/dist/index.js +27 -62
- package/dist/index.js.map +1 -1
- package/package.json +12 -3
package/README.md
CHANGED
|
@@ -44,7 +44,11 @@ Set these environment variables before starting the server:
|
|
|
44
44
|
| `PRTG_TZ` | `local` | Timezone for date input/output — see [Timezone handling](#timezone-handling) below |
|
|
45
45
|
| `PRTG_TRANSPORT` | `stdio` | Transport mode: `stdio` (default, local) or `http` (remote agent hosting) |
|
|
46
46
|
| `PRTG_HTTP_PORT` | `3000` | Port to listen on when `PRTG_TRANSPORT=http` |
|
|
47
|
-
| `PRTG_HTTP_HOST` | `
|
|
47
|
+
| `PRTG_HTTP_HOST` | `127.0.0.1` | Bind address when `PRTG_TRANSPORT=http` |
|
|
48
|
+
| `PRTG_HTTP_BEARER_TOKEN` | unset | Token required in `Authorization: Bearer ...`; mandatory for non-loopback binding |
|
|
49
|
+
| `PRTG_HTTP_ALLOWED_HOSTS` | unset | Comma-separated allowed `Host` header values; mandatory for non-loopback binding |
|
|
50
|
+
| `PRTG_HTTP_ALLOWED_ORIGINS` | unset | Comma-separated browser origins permitted to call `/mcp` |
|
|
51
|
+
| `PRTG_HTTP_MAX_BODY_BYTES` | `1048576` | Maximum HTTP request body size |
|
|
48
52
|
|
|
49
53
|
## Timezone handling
|
|
50
54
|
|
|
@@ -100,10 +104,13 @@ PRTG_BASE_URL=https://prtg.example.com:1616 \
|
|
|
100
104
|
PRTG_API_KEY=your-api-key \
|
|
101
105
|
PRTG_TRANSPORT=http \
|
|
102
106
|
PRTG_HTTP_PORT=3000 \
|
|
107
|
+
PRTG_HTTP_BEARER_TOKEN=replace-with-a-long-random-secret \
|
|
103
108
|
PRTG_TZ=Pacific/Auckland \
|
|
104
109
|
node dist/index.js
|
|
105
110
|
```
|
|
106
111
|
|
|
112
|
+
The listener defaults to loopback. To expose it directly or from a container, set `PRTG_HTTP_HOST=0.0.0.0`, `PRTG_HTTP_BEARER_TOKEN`, and `PRTG_HTTP_ALLOWED_HOSTS` (including the port when one appears in the request's `Host` header). TLS should be terminated by a trusted reverse proxy.
|
|
113
|
+
|
|
107
114
|
### Docker
|
|
108
115
|
|
|
109
116
|
```dockerfile
|
|
@@ -114,6 +121,7 @@ RUN npm ci --omit=dev
|
|
|
114
121
|
COPY dist/ ./dist/
|
|
115
122
|
ENV PRTG_TRANSPORT=http
|
|
116
123
|
ENV PRTG_HTTP_PORT=3000
|
|
124
|
+
ENV PRTG_HTTP_HOST=0.0.0.0
|
|
117
125
|
EXPOSE 3000
|
|
118
126
|
CMD ["node", "dist/index.js"]
|
|
119
127
|
```
|
|
@@ -124,6 +132,8 @@ docker build -t prtg-mcp-server .
|
|
|
124
132
|
docker run -p 3000:3000 \
|
|
125
133
|
-e PRTG_BASE_URL=https://prtg.example.com:1616 \
|
|
126
134
|
-e PRTG_API_KEY=your-api-key \
|
|
135
|
+
-e PRTG_HTTP_BEARER_TOKEN=replace-with-a-long-random-secret \
|
|
136
|
+
-e PRTG_HTTP_ALLOWED_HOSTS=your-host:3000 \
|
|
127
137
|
-e PRTG_TZ=Pacific/Auckland \
|
|
128
138
|
prtg-mcp-server
|
|
129
139
|
```
|
|
@@ -135,7 +145,8 @@ docker run -p 3000:3000 \
|
|
|
135
145
|
"mcpServers": {
|
|
136
146
|
"prtg": {
|
|
137
147
|
"type": "http",
|
|
138
|
-
"url": "https://your-host:3000/mcp"
|
|
148
|
+
"url": "https://your-host:3000/mcp",
|
|
149
|
+
"headers": { "Authorization": "Bearer replace-with-a-long-random-secret" }
|
|
139
150
|
}
|
|
140
151
|
}
|
|
141
152
|
}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import http from "node:http";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
export interface HttpServerOptions {
|
|
4
|
+
host: string;
|
|
5
|
+
port: number;
|
|
6
|
+
serverName: string;
|
|
7
|
+
bearerToken?: string;
|
|
8
|
+
allowedHosts?: string[];
|
|
9
|
+
allowedOrigins?: string[];
|
|
10
|
+
maxBodyBytes?: number;
|
|
11
|
+
}
|
|
12
|
+
export declare function validateHttpOptions(options: HttpServerOptions): void;
|
|
13
|
+
export declare function createHttpTransportServer(createServer: () => McpServer, options: HttpServerOptions): http.Server;
|
|
14
|
+
//# sourceMappingURL=http-server.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-server.d.ts","sourceRoot":"","sources":["../src/http-server.ts"],"names":[],"mappings":"AACA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AAGzE,MAAM,WAAW,iBAAiB;IAChC,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC;IACnB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,MAAM,EAAE,CAAC;IACxB,cAAc,CAAC,EAAE,MAAM,EAAE,CAAC;IAC1B,YAAY,CAAC,EAAE,MAAM,CAAC;CACvB;AAgDD,wBAAgB,mBAAmB,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,CAapE;AAED,wBAAgB,yBAAyB,CACvC,YAAY,EAAE,MAAM,SAAS,EAC7B,OAAO,EAAE,iBAAiB,GACzB,IAAI,CAAC,MAAM,CAuDb"}
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
import { timingSafeEqual } from "node:crypto";
|
|
2
|
+
import http from "node:http";
|
|
3
|
+
import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
|
|
4
|
+
const LOOPBACK_HOSTS = new Set(["127.0.0.1", "::1", "localhost"]);
|
|
5
|
+
function json(res, status, body) {
|
|
6
|
+
res.writeHead(status, { "Content-Type": "application/json" });
|
|
7
|
+
res.end(JSON.stringify(body));
|
|
8
|
+
}
|
|
9
|
+
function rpcError(res, status, code, message) {
|
|
10
|
+
json(res, status, { jsonrpc: "2.0", error: { code, message }, id: null });
|
|
11
|
+
}
|
|
12
|
+
function tokenMatches(header, expected) {
|
|
13
|
+
if (!header?.startsWith("Bearer "))
|
|
14
|
+
return false;
|
|
15
|
+
const supplied = Buffer.from(header.slice(7));
|
|
16
|
+
const wanted = Buffer.from(expected);
|
|
17
|
+
return supplied.length === wanted.length && timingSafeEqual(supplied, wanted);
|
|
18
|
+
}
|
|
19
|
+
async function readJsonBody(req, limit) {
|
|
20
|
+
return new Promise((resolve, reject) => {
|
|
21
|
+
const chunks = [];
|
|
22
|
+
let size = 0;
|
|
23
|
+
let tooLarge = false;
|
|
24
|
+
req.on("data", (chunk) => {
|
|
25
|
+
size += chunk.length;
|
|
26
|
+
if (size > limit) {
|
|
27
|
+
tooLarge = true;
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
chunks.push(chunk);
|
|
31
|
+
});
|
|
32
|
+
req.on("end", () => {
|
|
33
|
+
if (tooLarge) {
|
|
34
|
+
reject(Object.assign(new Error("Request body too large"), { statusCode: 413 }));
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
try {
|
|
38
|
+
resolve(JSON.parse(Buffer.concat(chunks).toString("utf8")));
|
|
39
|
+
}
|
|
40
|
+
catch {
|
|
41
|
+
reject(Object.assign(new Error("Invalid JSON body"), { statusCode: 400 }));
|
|
42
|
+
}
|
|
43
|
+
});
|
|
44
|
+
req.on("error", reject);
|
|
45
|
+
});
|
|
46
|
+
}
|
|
47
|
+
export function validateHttpOptions(options) {
|
|
48
|
+
if (!Number.isInteger(options.port) || options.port < 1 || options.port > 65535) {
|
|
49
|
+
throw new Error(`Invalid HTTP port: ${options.port}`);
|
|
50
|
+
}
|
|
51
|
+
if (options.maxBodyBytes !== undefined && (!Number.isInteger(options.maxBodyBytes) || options.maxBodyBytes < 1)) {
|
|
52
|
+
throw new Error(`Invalid HTTP body limit: ${options.maxBodyBytes}`);
|
|
53
|
+
}
|
|
54
|
+
if (!LOOPBACK_HOSTS.has(options.host) && !options.bearerToken) {
|
|
55
|
+
throw new Error("A bearer token is required when the HTTP server binds beyond loopback");
|
|
56
|
+
}
|
|
57
|
+
if (!LOOPBACK_HOSTS.has(options.host) && !options.allowedHosts?.length) {
|
|
58
|
+
throw new Error("HTTP_ALLOWED_HOSTS is required when the HTTP server binds beyond loopback");
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export function createHttpTransportServer(createServer, options) {
|
|
62
|
+
validateHttpOptions(options);
|
|
63
|
+
const allowedHosts = new Set(options.allowedHosts?.map((value) => value.toLowerCase()));
|
|
64
|
+
const allowedOrigins = new Set(options.allowedOrigins?.map((value) => value.toLowerCase()));
|
|
65
|
+
const maxBodyBytes = options.maxBodyBytes ?? 1024 * 1024;
|
|
66
|
+
return http.createServer(async (req, res) => {
|
|
67
|
+
const url = new URL(req.url ?? "/", "http://localhost");
|
|
68
|
+
if (url.pathname === "/health") {
|
|
69
|
+
json(res, 200, { status: "ok", server: options.serverName });
|
|
70
|
+
return;
|
|
71
|
+
}
|
|
72
|
+
if (url.pathname !== "/mcp") {
|
|
73
|
+
res.writeHead(404).end();
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
if (allowedHosts.size && !allowedHosts.has((req.headers.host ?? "").toLowerCase())) {
|
|
77
|
+
rpcError(res, 403, -32000, "Host not allowed");
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
if (req.headers.origin && !allowedOrigins.has(req.headers.origin.toLowerCase())) {
|
|
81
|
+
rpcError(res, 403, -32000, "Origin not allowed");
|
|
82
|
+
return;
|
|
83
|
+
}
|
|
84
|
+
if (options.bearerToken && !tokenMatches(req.headers.authorization, options.bearerToken)) {
|
|
85
|
+
res.setHeader("WWW-Authenticate", "Bearer");
|
|
86
|
+
rpcError(res, 401, -32001, "Unauthorized");
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
if (req.method !== "POST") {
|
|
90
|
+
res.setHeader("Allow", "POST");
|
|
91
|
+
rpcError(res, 405, -32000, "Method not allowed");
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
const server = createServer();
|
|
95
|
+
const transport = new StreamableHTTPServerTransport({ sessionIdGenerator: undefined });
|
|
96
|
+
try {
|
|
97
|
+
const body = await readJsonBody(req, maxBodyBytes);
|
|
98
|
+
await server.connect(transport);
|
|
99
|
+
await transport.handleRequest(req, res, body);
|
|
100
|
+
res.once("close", () => {
|
|
101
|
+
void transport.close();
|
|
102
|
+
void server.close();
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
catch (error) {
|
|
106
|
+
void transport.close();
|
|
107
|
+
void server.close();
|
|
108
|
+
if (!res.headersSent) {
|
|
109
|
+
const status = error.statusCode ?? 500;
|
|
110
|
+
rpcError(res, status, status === 400 ? -32700 : -32603, status < 500 ? error.message : "Internal server error");
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
//# sourceMappingURL=http-server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"http-server.js","sourceRoot":"","sources":["../src/http-server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAC9C,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B,OAAO,EAAE,6BAA6B,EAAE,MAAM,oDAAoD,CAAC;AAYnG,MAAM,cAAc,GAAG,IAAI,GAAG,CAAC,CAAC,WAAW,EAAE,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC;AAElE,SAAS,IAAI,CAAC,GAAwB,EAAE,MAAc,EAAE,IAAa;IACnE,GAAG,CAAC,SAAS,CA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SAAS,GAAG,IAAI,6BAA6B,CAAC,EAAE,kBAAkB,EAAE,SAAS,EAAE,CAAC,CAAC;QACvF,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,MAAM,YAAY,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;YACnD,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;YAChC,MAAM,SAAS,CAAC,aAAa,CAAC,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC,CAAC;YAC9C,GAAG,CAAC,IAAI,CAAC,OAAO,EAAE,GAAG,EAAE;gBACrB,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC;gBACvB,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;YACtB,CAAC,CAAC,CAAC;QACL,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,KAAK,SAAS,CAAC,KAAK,EAAE,CAAC;YACvB,KAAK,MAAM,CAAC,KAAK,EAAE,CAAC;YACpB,IAAI,CAAC,GAAG,CAAC,WAAW,EAAE,CAAC;gBACrB,MAAM,MAAM,GAAI,KAAiC,CAAC,UAAU,IAAI,GAAG,CAAC;gBACpE,QAAQ,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,KAAK,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,CAAC,CAAC,CAAE,KAAe,CAAC,OAAO,CAAC,CAAC,CAAC,uBAAuB,CAAC,CAAC;YAC7H,CAAC;QACH,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import http from "node:http";
|
|
3
2
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
3
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
5
|
-
import {
|
|
4
|
+
import { createHttpTransportServer } from "./http-server.js";
|
|
6
5
|
import { createClient } from "./client.js";
|
|
7
6
|
import { registerSensorTools } from "./tools/sensors.js";
|
|
8
7
|
import { registerDeviceTools } from "./tools/devices.js";
|
|
@@ -11,21 +10,6 @@ import { registerMetricsTools } from "./tools/metrics.js";
|
|
|
11
10
|
import { registerSystemTools } from "./tools/system.js";
|
|
12
11
|
import { registerActionTools } from "./tools/actions.js";
|
|
13
12
|
import { getEffectiveTz } from "./tz.js";
|
|
14
|
-
async function readJsonBody(req) {
|
|
15
|
-
return new Promise((resolve, reject) => {
|
|
16
|
-
const chunks = [];
|
|
17
|
-
req.on("data", (chunk) => chunks.push(chunk));
|
|
18
|
-
req.on("end", () => {
|
|
19
|
-
try {
|
|
20
|
-
resolve(JSON.parse(Buffer.concat(chunks).toString()));
|
|
21
|
-
}
|
|
22
|
-
catch {
|
|
23
|
-
resolve(undefined);
|
|
24
|
-
}
|
|
25
|
-
});
|
|
26
|
-
req.on("error", reject);
|
|
27
|
-
});
|
|
28
|
-
}
|
|
29
13
|
async function main() {
|
|
30
14
|
let client;
|
|
31
15
|
try {
|
|
@@ -74,11 +58,12 @@ async function main() {
|
|
|
74
58
|
else {
|
|
75
59
|
process.stderr.write("[prtg-mcp] Running in read-only mode (set PRTG_READWRITE=true to enable write tools)\n");
|
|
76
60
|
}
|
|
77
|
-
const
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
61
|
+
const createConfiguredServer = () => {
|
|
62
|
+
const server = new McpServer({
|
|
63
|
+
name: "@teamnetwork/prtg-mcp-server",
|
|
64
|
+
version: "1.5.0",
|
|
65
|
+
}, {
|
|
66
|
+
instructions: `
|
|
82
67
|
PRTG Network Monitor MCP server — monitoring data via the PRTG v2 REST API.
|
|
83
68
|
|
|
84
69
|
## Mode
|
|
@@ -113,54 +98,34 @@ PRTG Network Monitor MCP server — monitoring data via the PRTG v2 REST API.
|
|
|
113
98
|
- All tools use PRTG numeric object IDs. These appear as "id" in list results.
|
|
114
99
|
- Use search or get_hierarchy to discover IDs before calling get_sensor, get_channels, or the write tools.
|
|
115
100
|
`.trim(),
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
101
|
+
});
|
|
102
|
+
registerSensorTools(server, client);
|
|
103
|
+
registerDeviceTools(server, client);
|
|
104
|
+
registerNavigationTools(server, client);
|
|
105
|
+
registerMetricsTools(server, client);
|
|
106
|
+
registerSystemTools(server, client);
|
|
107
|
+
if (readwrite)
|
|
108
|
+
registerActionTools(server, client);
|
|
109
|
+
return server;
|
|
110
|
+
};
|
|
124
111
|
if (transportMode === "http") {
|
|
125
112
|
const port = parseInt(process.env["PRTG_HTTP_PORT"] ?? "3000", 10);
|
|
126
|
-
const host = process.env["PRTG_HTTP_HOST"] ?? "
|
|
127
|
-
const
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
res.end(JSON.stringify({ status: "ok", server: "@teamnetwork/prtg-mcp-server" }));
|
|
136
|
-
return;
|
|
137
|
-
}
|
|
138
|
-
if (!url.startsWith("/mcp")) {
|
|
139
|
-
res.writeHead(404);
|
|
140
|
-
res.end();
|
|
141
|
-
return;
|
|
142
|
-
}
|
|
143
|
-
try {
|
|
144
|
-
if (req.method === "POST") {
|
|
145
|
-
const body = await readJsonBody(req);
|
|
146
|
-
await transport.handleRequest(req, res, body);
|
|
147
|
-
}
|
|
148
|
-
else {
|
|
149
|
-
await transport.handleRequest(req, res);
|
|
150
|
-
}
|
|
151
|
-
}
|
|
152
|
-
catch (err) {
|
|
153
|
-
if (!res.headersSent) {
|
|
154
|
-
res.writeHead(500, { "Content-Type": "application/json" });
|
|
155
|
-
res.end(JSON.stringify({ error: err.message }));
|
|
156
|
-
}
|
|
157
|
-
}
|
|
113
|
+
const host = process.env["PRTG_HTTP_HOST"] ?? "127.0.0.1";
|
|
114
|
+
const httpServer = createHttpTransportServer(createConfiguredServer, {
|
|
115
|
+
host,
|
|
116
|
+
port,
|
|
117
|
+
serverName: "@teamnetwork/prtg-mcp-server",
|
|
118
|
+
bearerToken: process.env["PRTG_HTTP_BEARER_TOKEN"],
|
|
119
|
+
allowedHosts: process.env["PRTG_HTTP_ALLOWED_HOSTS"]?.split(",").map((value) => value.trim()).filter(Boolean),
|
|
120
|
+
allowedOrigins: process.env["PRTG_HTTP_ALLOWED_ORIGINS"]?.split(",").map((value) => value.trim()).filter(Boolean),
|
|
121
|
+
maxBodyBytes: parseInt(process.env["PRTG_HTTP_MAX_BODY_BYTES"] ?? "1048576", 10),
|
|
158
122
|
});
|
|
159
123
|
httpServer.listen(port, host, () => {
|
|
160
124
|
process.stderr.write(`[prtg-mcp] HTTP transport listening on ${host}:${port}/mcp\n`);
|
|
161
125
|
});
|
|
162
126
|
}
|
|
163
127
|
else {
|
|
128
|
+
const server = createConfiguredServer();
|
|
164
129
|
const transport = new StdioServerTransport();
|
|
165
130
|
await server.connect(transport);
|
|
166
131
|
}
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AACA,OAAO,EAAE,SAAS,EAAE,MAAM,yCAAyC,CAAC;AACpE,OAAO,EAAE,oBAAoB,EAAE,MAAM,2CAA2C,CAAC;AACjF,OAAO,EAAE,yBAAyB,EAAE,MAAM,kBAAkB,CAAC;AAC7D,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,EAAE,uBAAuB,EAAE,MAAM,uBAAuB,CAAC;AAChE,OAAO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AC,IAAI,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC;YACjH,YAAY,EAAE,QAAQ,CAAC,OAAO,CAAC,GAAG,CAAC,0BAA0B,CAAC,IAAI,SAAS,EAAE,EAAE,CAAC;SACjF,CAAC,CAAC;QAEH,UAAU,CAAC,MAAM,CAAC,IAAI,EAAE,IAAI,EAAE,GAAG,EAAE;YACjC,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,0CAA0C,IAAI,IAAI,IAAI,QAAQ,CAAC,CAAC;QACvF,CAAC,CAAC,CAAC;IACL,CAAC;SAAM,CAAC;QACN,MAAM,MAAM,GAAG,sBAAsB,EAAE,CAAC;QACxC,MAAM,SAAS,GAAG,IAAI,oBAAoB,EAAE,CAAC;QAC7C,MAAM,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IAClC,CAAC;AACH,CAAC;AAED,IAAI,EAAE,CAAC,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;IAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAC,qBAAsB,GAAa,CAAC,OAAO,IAAI,CAAC,CAAC;IACtE,OAAO,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;AAClB,CAAC,CAAC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,17 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@teamnetwork-nz/prtg-mcp-server",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.5.0",
|
|
4
4
|
"description": "MCP server for PRTG Network Monitor — v2 REST API only, no database required",
|
|
5
|
-
"keywords": [
|
|
5
|
+
"keywords": [
|
|
6
|
+
"mcp",
|
|
7
|
+
"prtg",
|
|
8
|
+
"monitoring",
|
|
9
|
+
"network",
|
|
10
|
+
"claude"
|
|
11
|
+
],
|
|
6
12
|
"license": "MIT",
|
|
7
13
|
"type": "module",
|
|
8
14
|
"bin": {
|
|
9
15
|
"prtg-mcp-server": "./dist/index.js"
|
|
10
16
|
},
|
|
11
17
|
"main": "./dist/index.js",
|
|
12
|
-
"files": [
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
13
21
|
"scripts": {
|
|
14
22
|
"build": "tsc",
|
|
23
|
+
"test": "npm run build && node --test tests/*.test.mjs",
|
|
15
24
|
"dev": "tsc --watch",
|
|
16
25
|
"start": "node dist/index.js",
|
|
17
26
|
"prepublishOnly": "npm run build"
|