@teamnetwork-nz/sonicwall-api-mcp-server 0.9.2 → 0.10.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 CHANGED
@@ -1,5 +1,7 @@
1
1
  # SonicWall NSA MCP Server
2
2
 
3
+ Both TypeScript and Python tools accept optional `outputFormat: "json"` for client consistency. The TypeScript server returns valid JSON text when requested; the Python server already returns structured data that FastMCP serializes as JSON. In both implementations the option is handled locally and is never sent to the SonicWall appliance.
4
+
3
5
  ## Streamable HTTP
4
6
 
5
7
  Set `SONICWALL_TRANSPORT=http` to serve stateless MCP at `/mcp`. It binds to `127.0.0.1` by default; remote binding requires `SONICWALL_HTTP_BEARER_TOKEN` and `SONICWALL_HTTP_ALLOWED_HOSTS`. Optional controls include `SONICWALL_HTTP_PORT`, `SONICWALL_HTTP_ALLOWED_ORIGINS`, and `SONICWALL_HTTP_MAX_BODY_BYTES`; `/health` is available for health checks.
package/dist/index.js CHANGED
@@ -2317,11 +2317,40 @@ function strictSchema(schema) {
2317
2317
  if (isSchema(schema) && typeof schema.strict === "function") return schema.strict();
2318
2318
  return schema;
2319
2319
  }
2320
+ function addOutputFormat(schema) {
2321
+ const strict = strictSchema(schema);
2322
+ if (typeof strict.extend !== "function") return strict;
2323
+ return strict.extend({
2324
+ outputFormat: import_v317.z.enum(["json"]).optional().describe("Return the result as valid JSON text without Markdown wrappers.")
2325
+ }).strict?.() ?? strict;
2326
+ }
2327
+ function toJsonValue(text2) {
2328
+ const fenced = text2.match(/\x60\x60\x60json\s*([\s\S]*?)\s*\x60\x60\x60/i)?.[1];
2329
+ const candidate = fenced ?? text2;
2330
+ try {
2331
+ return JSON.parse(candidate);
2332
+ } catch {
2333
+ return text2;
2334
+ }
2335
+ }
2320
2336
  function enforceStrictToolInputs(server) {
2321
2337
  const mutable = server;
2322
2338
  const createRegisteredTool = mutable._createRegisteredTool.bind(server);
2323
2339
  mutable._createRegisteredTool = (...args) => {
2324
- args[3] = strictSchema(args[3]);
2340
+ args[3] = addOutputFormat(args[3]);
2341
+ const handler = args[8];
2342
+ if (typeof handler === "function") {
2343
+ args[8] = async (input, ...rest) => {
2344
+ const values = input && typeof input === "object" ? input : {};
2345
+ const { outputFormat, ...toolArgs } = values;
2346
+ const result = await handler(toolArgs, ...rest);
2347
+ if (outputFormat !== "json" || result?.isError || !Array.isArray(result?.content)) return result;
2348
+ const textItems = result.content.filter((item) => item.type === "text" && typeof item.text === "string");
2349
+ if (textItems.length === 0) return result;
2350
+ const data = result.structuredContent !== void 0 ? result.structuredContent : textItems.length === 1 ? toJsonValue(textItems[0]?.text ?? "") : textItems.map((item) => toJsonValue(item.text));
2351
+ return { ...result, content: [{ type: "text", text: JSON.stringify(data, null, 2) }], ...result.structuredContent === void 0 && data && typeof data === "object" ? { structuredContent: data } : {} };
2352
+ };
2353
+ }
2325
2354
  return createRegisteredTool(...args);
2326
2355
  };
2327
2356
  }
@@ -39,11 +39,40 @@ function strictSchema(schema) {
39
39
  if (isSchema(schema) && typeof schema.strict === "function") return schema.strict();
40
40
  return schema;
41
41
  }
42
+ function addOutputFormat(schema) {
43
+ const strict = strictSchema(schema);
44
+ if (typeof strict.extend !== "function") return strict;
45
+ return strict.extend({
46
+ outputFormat: import_v3.z.enum(["json"]).optional().describe("Return the result as valid JSON text without Markdown wrappers.")
47
+ }).strict?.() ?? strict;
48
+ }
49
+ function toJsonValue(text) {
50
+ const fenced = text.match(/\x60\x60\x60json\s*([\s\S]*?)\s*\x60\x60\x60/i)?.[1];
51
+ const candidate = fenced ?? text;
52
+ try {
53
+ return JSON.parse(candidate);
54
+ } catch {
55
+ return text;
56
+ }
57
+ }
42
58
  function enforceStrictToolInputs(server) {
43
59
  const mutable = server;
44
60
  const createRegisteredTool = mutable._createRegisteredTool.bind(server);
45
61
  mutable._createRegisteredTool = (...args) => {
46
- args[3] = strictSchema(args[3]);
62
+ args[3] = addOutputFormat(args[3]);
63
+ const handler = args[8];
64
+ if (typeof handler === "function") {
65
+ args[8] = async (input, ...rest) => {
66
+ const values = input && typeof input === "object" ? input : {};
67
+ const { outputFormat, ...toolArgs } = values;
68
+ const result = await handler(toolArgs, ...rest);
69
+ if (outputFormat !== "json" || result?.isError || !Array.isArray(result?.content)) return result;
70
+ const textItems = result.content.filter((item) => item.type === "text" && typeof item.text === "string");
71
+ if (textItems.length === 0) return result;
72
+ const data = result.structuredContent !== void 0 ? result.structuredContent : textItems.length === 1 ? toJsonValue(textItems[0]?.text ?? "") : textItems.map((item) => toJsonValue(item.text));
73
+ return { ...result, content: [{ type: "text", text: JSON.stringify(data, null, 2) }], ...result.structuredContent === void 0 && data && typeof data === "object" ? { structuredContent: data } : {} };
74
+ };
75
+ }
47
76
  return createRegisteredTool(...args);
48
77
  };
49
78
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@teamnetwork-nz/sonicwall-api-mcp-server",
3
- "version": "0.9.2",
3
+ "version": "0.10.0",
4
4
  "description": "MCP server for SonicWall appliance configuration and diagnostics — objects, rules, NAT, routing, reachability, and GeoIP lookup",
5
5
  "keywords": [
6
6
  "mcp",