@teamnetwork-nz/prtg-mcp-server 1.5.3 → 1.6.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 +2 -0
- package/dist/strict-tools.js +39 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
# @teamnetwork/prtg-mcp-server
|
|
2
2
|
|
|
3
|
+
Tools accept optional `outputFormat: "json"` to return valid JSON text. The option is removed locally and is never sent to the PRTG API.
|
|
4
|
+
|
|
3
5
|
An MCP server for [PRTG Network Monitor](https://www.paessler.com/prtg) that uses the **PRTG v2 REST API exclusively** — no database, no Data Exporter add-on required.
|
|
4
6
|
|
|
5
7
|
Compatible with Claude Desktop, Claude Code, Cursor, Cline, and any MCP-capable client.
|
package/dist/strict-tools.js
CHANGED
|
@@ -17,13 +17,50 @@ function strictSchema(schema) {
|
|
|
17
17
|
return schema.strict();
|
|
18
18
|
return schema;
|
|
19
19
|
}
|
|
20
|
+
function addOutputFormat(schema) {
|
|
21
|
+
const strict = strictSchema(schema);
|
|
22
|
+
if (typeof strict.extend !== "function")
|
|
23
|
+
return strict;
|
|
24
|
+
return strict.extend({
|
|
25
|
+
outputFormat: z.enum(["json"]).optional().describe("Return the result as valid JSON text without Markdown wrappers."),
|
|
26
|
+
}).strict?.() ?? strict;
|
|
27
|
+
}
|
|
28
|
+
function toJsonValue(text) {
|
|
29
|
+
const fenced = text.match(/\x60\x60\x60json\s*([\s\S]*?)\s*\x60\x60\x60/i)?.[1];
|
|
30
|
+
const candidate = fenced ?? text;
|
|
31
|
+
try {
|
|
32
|
+
return JSON.parse(candidate);
|
|
33
|
+
}
|
|
34
|
+
catch {
|
|
35
|
+
return text;
|
|
36
|
+
}
|
|
37
|
+
}
|
|
20
38
|
/** Make every tool object reject undeclared arguments, including no-argument tools. */
|
|
21
39
|
export function enforceStrictToolInputs(server) {
|
|
22
40
|
const mutable = server;
|
|
23
41
|
const createRegisteredTool = mutable._createRegisteredTool.bind(server);
|
|
24
42
|
mutable._createRegisteredTool = (...args) => {
|
|
25
|
-
//
|
|
26
|
-
args[3] =
|
|
43
|
+
// The MCP-only output option is stripped here so it cannot leak into vendor API parameters.
|
|
44
|
+
args[3] = addOutputFormat(args[3]);
|
|
45
|
+
const handler = args[8];
|
|
46
|
+
if (typeof handler === "function") {
|
|
47
|
+
args[8] = async (input, ...rest) => {
|
|
48
|
+
const values = input && typeof input === "object" ? input : {};
|
|
49
|
+
const { outputFormat, ...toolArgs } = values;
|
|
50
|
+
const result = await handler(toolArgs, ...rest);
|
|
51
|
+
if (outputFormat !== "json" || result?.isError || !Array.isArray(result?.content))
|
|
52
|
+
return result;
|
|
53
|
+
const textItems = result.content.filter((item) => item.type === "text" && typeof item.text === "string");
|
|
54
|
+
if (textItems.length === 0)
|
|
55
|
+
return result;
|
|
56
|
+
const data = result.structuredContent !== undefined
|
|
57
|
+
? result.structuredContent
|
|
58
|
+
: textItems.length === 1
|
|
59
|
+
? toJsonValue((textItems[0]?.text ?? ''))
|
|
60
|
+
: textItems.map((item) => toJsonValue(item.text));
|
|
61
|
+
return { ...result, content: [{ type: "text", text: JSON.stringify(data, null, 2) }], ...(result.structuredContent === undefined && data && typeof data === "object" ? { structuredContent: data } : {}) };
|
|
62
|
+
};
|
|
63
|
+
}
|
|
27
64
|
return createRegisteredTool(...args);
|
|
28
65
|
};
|
|
29
66
|
}
|