@teamnetwork-nz/sonicwall-api-mcp-server 0.7.0 → 0.8.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 CHANGED
@@ -1,5 +1,9 @@
1
1
  # SonicWall NSA MCP Server
2
2
 
3
+ ## Streamable HTTP
4
+
5
+ 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.
6
+
3
7
  A [Model Context Protocol](https://modelcontextprotocol.io/) server that provides full read/write access to SonicWall NSA series appliances via the SonicOS REST API.
4
8
 
5
9
  ## Features
@@ -54,7 +58,9 @@ uv pip install sonicwall-mcp-server
54
58
  | `SONICWALL_PASSWORD` | Yes | — | Admin password |
55
59
  | `SONICWALL_PORT` | No | `443` | HTTPS management port |
56
60
  | `SONICWALL_SSL_VERIFY` | No | `true` | Set `false` for self-signed certificates |
57
- | `SONICWALL_READ_ONLY` | No | `true` | Set `false` to allow write operations |
61
+ | `SONICWALL_READWRITE` | No | `false` | Set `true` to allow write operations |
62
+
63
+ `SONICWALL_READ_ONLY=false` remains a deprecated compatibility alias for one release. `SONICWALL_READWRITE` takes precedence when both are set.
58
64
  | `SONICWALL_DEVICES_FILE` | No | — | Path to JSON file for multi-device config |
59
65
  | `SONICWALL_REQUEST_TIMEOUT` | No | `30.0` | Per-request timeout in seconds |
60
66
 
@@ -77,7 +83,7 @@ Add to your MCP config (`claude_desktop_config.json` or `.claude/settings.json`)
77
83
  "SONICWALL_USERNAME": "admin",
78
84
  "SONICWALL_PASSWORD": "your_password",
79
85
  "SONICWALL_SSL_VERIFY": "false",
80
- "SONICWALL_READ_ONLY": "false"
86
+ "SONICWALL_READWRITE": "true"
81
87
  }
82
88
  }
83
89
  }
@@ -97,7 +103,7 @@ Add to your MCP config (`claude_desktop_config.json` or `.claude/settings.json`)
97
103
  "SONICWALL_USERNAME": "admin",
98
104
  "SONICWALL_PASSWORD": "your_password",
99
105
  "SONICWALL_SSL_VERIFY": "false",
100
- "SONICWALL_READ_ONLY": "false"
106
+ "SONICWALL_READWRITE": "true"
101
107
  }
102
108
  }
103
109
  }
@@ -116,7 +122,7 @@ Add to your MCP config (`claude_desktop_config.json` or `.claude/settings.json`)
116
122
  "SONICWALL_USERNAME": "admin",
117
123
  "SONICWALL_PASSWORD": "your_password",
118
124
  "SONICWALL_SSL_VERIFY": "false",
119
- "SONICWALL_READ_ONLY": "false"
125
+ "SONICWALL_READWRITE": "true"
120
126
  }
121
127
  }
122
128
  }
package/dist/env.js ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __export = (target, all) => {
8
+ for (var name in all)
9
+ __defProp(target, name, { get: all[name], enumerable: true });
10
+ };
11
+ var __copyProps = (to, from, except, desc) => {
12
+ if (from && typeof from === "object" || typeof from === "function") {
13
+ for (let key of __getOwnPropNames(from))
14
+ if (!__hasOwnProp.call(to, key) && key !== except)
15
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
16
+ }
17
+ return to;
18
+ };
19
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
20
+
21
+ // src/env.ts
22
+ var env_exports = {};
23
+ __export(env_exports, {
24
+ parsePositiveInt: () => parsePositiveInt
25
+ });
26
+ module.exports = __toCommonJS(env_exports);
27
+ function parsePositiveInt(name, raw, fallback, maximum) {
28
+ if (raw === void 0 || raw.trim() === "") return fallback;
29
+ if (!/^\d+$/.test(raw.trim())) {
30
+ throw new Error(`${name} must be an integer from 1 to ${maximum}`);
31
+ }
32
+ const value = Number(raw);
33
+ if (!Number.isSafeInteger(value) || value < 1 || value > maximum) {
34
+ throw new Error(`${name} must be an integer from 1 to ${maximum}`);
35
+ }
36
+ return value;
37
+ }
38
+ // Annotate the CommonJS export names for ESM import in node:
39
+ 0 && (module.exports = {
40
+ parsePositiveInt
41
+ });
@@ -0,0 +1,119 @@
1
+ #!/usr/bin/env node
2
+ "use strict";
3
+ var __create = Object.create;
4
+ var __defProp = Object.defineProperty;
5
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
6
+ var __getOwnPropNames = Object.getOwnPropertyNames;
7
+ var __getProtoOf = Object.getPrototypeOf;
8
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
9
+ var __export = (target, all) => {
10
+ for (var name in all)
11
+ __defProp(target, name, { get: all[name], enumerable: true });
12
+ };
13
+ var __copyProps = (to, from, except, desc) => {
14
+ if (from && typeof from === "object" || typeof from === "function") {
15
+ for (let key of __getOwnPropNames(from))
16
+ if (!__hasOwnProp.call(to, key) && key !== except)
17
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
18
+ }
19
+ return to;
20
+ };
21
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
22
+ // If the importer is in node compatibility mode or this is not an ESM
23
+ // file that has been converted to a CommonJS file using a Babel-
24
+ // compatible transform (i.e. "__esModule" has not been set), then set
25
+ // "default" to the CommonJS "module.exports" for node compatibility.
26
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
27
+ mod
28
+ ));
29
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
30
+
31
+ // src/http-server.ts
32
+ var http_server_exports = {};
33
+ __export(http_server_exports, {
34
+ createHttpServer: () => createHttpServer,
35
+ validateHttpOptions: () => validateHttpOptions
36
+ });
37
+ module.exports = __toCommonJS(http_server_exports);
38
+ var import_node_crypto = require("crypto");
39
+ var import_node_http = __toESM(require("http"));
40
+ var import_streamableHttp = require("@modelcontextprotocol/sdk/server/streamableHttp.js");
41
+ var loopback = /* @__PURE__ */ new Set(["127.0.0.1", "::1", "localhost"]);
42
+ var send = (res, status, body) => {
43
+ res.writeHead(status, { "Content-Type": "application/json" }).end(JSON.stringify(body));
44
+ };
45
+ var error = (res, status, code, message) => send(res, status, { jsonrpc: "2.0", error: { code, message }, id: null });
46
+ var matches = (value, expected) => {
47
+ if (!value?.startsWith("Bearer ")) return false;
48
+ const supplied = Buffer.from(value.slice(7));
49
+ const wanted = Buffer.from(expected);
50
+ return supplied.length === wanted.length && (0, import_node_crypto.timingSafeEqual)(supplied, wanted);
51
+ };
52
+ var readBody = (req, limit) => new Promise((resolve, reject) => {
53
+ const chunks = [];
54
+ let size = 0;
55
+ let oversized = false;
56
+ req.on("data", (chunk) => {
57
+ size += chunk.length;
58
+ oversized ||= size > limit;
59
+ if (!oversized) chunks.push(chunk);
60
+ });
61
+ req.on("end", () => {
62
+ if (oversized) return reject(Object.assign(new Error("Request body too large"), { statusCode: 413 }));
63
+ try {
64
+ resolve(JSON.parse(Buffer.concat(chunks).toString("utf8")));
65
+ } catch {
66
+ reject(Object.assign(new Error("Invalid JSON body"), { statusCode: 400 }));
67
+ }
68
+ });
69
+ req.on("error", reject);
70
+ });
71
+ function validateHttpOptions(o) {
72
+ if (!Number.isInteger(o.port) || o.port < 1 || o.port > 65535) throw new Error(`Invalid HTTP port: ${o.port}`);
73
+ if (o.maxBodyBytes !== void 0 && (!Number.isInteger(o.maxBodyBytes) || o.maxBodyBytes < 1)) throw new Error(`Invalid HTTP body limit: ${o.maxBodyBytes}`);
74
+ if (!loopback.has(o.host) && !o.bearerToken) throw new Error("A bearer token is required when binding beyond loopback");
75
+ if (!loopback.has(o.host) && !o.allowedHosts?.length) throw new Error("HTTP_ALLOWED_HOSTS is required when binding beyond loopback");
76
+ }
77
+ function createHttpServer(factory, o) {
78
+ validateHttpOptions(o);
79
+ const hosts = new Set(o.allowedHosts?.map((v) => v.toLowerCase()));
80
+ const origins = new Set(o.allowedOrigins?.map((v) => v.toLowerCase()));
81
+ return import_node_http.default.createServer(async (req, res) => {
82
+ const path = new URL(req.url ?? "/", "http://localhost").pathname;
83
+ if (path === "/health") return send(res, 200, { status: "ok", server: o.serverName });
84
+ if (path !== "/mcp") return void res.writeHead(404).end();
85
+ if (hosts.size && !hosts.has((req.headers.host ?? "").toLowerCase())) return error(res, 403, -32e3, "Host not allowed");
86
+ if (req.headers.origin && !origins.has(req.headers.origin.toLowerCase())) return error(res, 403, -32e3, "Origin not allowed");
87
+ if (o.bearerToken && !matches(req.headers.authorization, o.bearerToken)) {
88
+ res.setHeader("WWW-Authenticate", "Bearer");
89
+ return error(res, 401, -32001, "Unauthorized");
90
+ }
91
+ if (req.method !== "POST") {
92
+ res.setHeader("Allow", "POST");
93
+ return error(res, 405, -32e3, "Method not allowed");
94
+ }
95
+ const server = factory();
96
+ const transport = new import_streamableHttp.StreamableHTTPServerTransport({ sessionIdGenerator: void 0 });
97
+ try {
98
+ const body = await readBody(req, o.maxBodyBytes ?? 1048576);
99
+ await server.connect(transport);
100
+ await transport.handleRequest(req, res, body);
101
+ res.once("close", () => {
102
+ void transport.close();
103
+ void server.close();
104
+ });
105
+ } catch (cause) {
106
+ void transport.close();
107
+ void server.close();
108
+ if (!res.headersSent) {
109
+ const status = cause.statusCode ?? 500;
110
+ error(res, status, status === 400 ? -32700 : -32603, status < 500 ? cause.message : "Internal server error");
111
+ }
112
+ }
113
+ });
114
+ }
115
+ // Annotate the CommonJS export names for ESM import in node:
116
+ 0 && (module.exports = {
117
+ createHttpServer,
118
+ validateHttpOptions
119
+ });