@mgsoftwarebv/mg-dashboard-mcp 6.6.2 → 6.6.3

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/dist/index.js CHANGED
@@ -18,7 +18,6 @@ import postgres from 'postgres';
18
18
  import { readFile, mkdtemp, writeFile, rm } from 'fs/promises';
19
19
  import { tmpdir } from 'os';
20
20
  import { once } from 'events';
21
- import https from 'https';
22
21
  import { lookup } from 'dns/promises';
23
22
  import { connect } from 'tls';
24
23
  import { HeadObjectCommand, S3Client, ListObjectsV2Command, DeleteObjectsCommand, DeleteObjectCommand, CreateMultipartUploadCommand, UploadPartCommand, CompleteMultipartUploadCommand, AbortMultipartUploadCommand, PutObjectCommand, GetObjectCommand, CopyObjectCommand } from '@aws-sdk/client-s3';
@@ -1593,33 +1592,49 @@ async function fetchViaSshProxy(options) {
1593
1592
  })
1594
1593
  ]);
1595
1594
  if (timer) clearTimeout(timer);
1595
+ const requestPath = `${parsedUrl.pathname || "/"}${parsedUrl.search}`;
1596
+ const headerLines = [`${method} ${requestPath} HTTP/1.1`];
1597
+ if (!("Connection" in headers)) headers.Connection = "close";
1598
+ for (const [k, v] of Object.entries(headers)) headerLines.push(`${k}: ${v}`);
1599
+ headerLines.push("", "");
1600
+ tlsSocket.write(headerLines.join("\r\n"));
1601
+ if (body) tlsSocket.write(body);
1596
1602
  return await new Promise((resolve, reject) => {
1597
- const req = https.request(
1598
- {
1599
- createConnection: () => tlsSocket,
1600
- hostname: targetHost,
1601
- port: targetPort,
1602
- path: `${parsedUrl.pathname}${parsedUrl.search}`,
1603
- method,
1604
- headers,
1605
- agent: false
1606
- },
1607
- (res) => {
1608
- const chunks = [];
1609
- res.on("data", (chunk) => chunks.push(chunk));
1610
- res.on("end", () => {
1611
- resolve({
1612
- status: res.statusCode ?? 0,
1613
- statusText: res.statusMessage ?? "",
1614
- body: Buffer.concat(chunks).toString("utf8")
1615
- });
1616
- });
1617
- res.on("error", reject);
1603
+ const chunks = [];
1604
+ const onError = (err) => {
1605
+ tlsSocket.removeAllListeners();
1606
+ reject(err);
1607
+ };
1608
+ tlsSocket.on("data", (chunk) => chunks.push(chunk));
1609
+ tlsSocket.on("end", () => {
1610
+ const raw = Buffer.concat(chunks);
1611
+ const headerEnd = raw.indexOf("\r\n\r\n");
1612
+ if (headerEnd === -1) return reject(new Error("mijn.host response missing headers"));
1613
+ const headerBlob = raw.slice(0, headerEnd).toString("utf8");
1614
+ const [statusLine, ...headerLinesIn] = headerBlob.split("\r\n");
1615
+ const statusMatch = statusLine?.match(/^HTTP\/\d\.\d (\d{3}) ?(.*)$/);
1616
+ if (!statusMatch) return reject(new Error(`Invalid status line: ${statusLine}`));
1617
+ const status = Number(statusMatch[1]);
1618
+ const statusText = statusMatch[2] ?? "";
1619
+ let bodyBuf = raw.slice(headerEnd + 4);
1620
+ const transferEnc = headerLinesIn.find((l) => /^transfer-encoding:/i.test(l))?.split(":")[1]?.trim().toLowerCase();
1621
+ if (transferEnc === "chunked") {
1622
+ const decoded = [];
1623
+ let i = 0;
1624
+ while (i < bodyBuf.length) {
1625
+ const lineEnd = bodyBuf.indexOf("\r\n", i);
1626
+ if (lineEnd === -1) break;
1627
+ const size = parseInt(bodyBuf.slice(i, lineEnd).toString("ascii"), 16);
1628
+ if (!Number.isFinite(size) || size <= 0) break;
1629
+ i = lineEnd + 2;
1630
+ decoded.push(bodyBuf.slice(i, i + size));
1631
+ i += size + 2;
1632
+ }
1633
+ bodyBuf = Buffer.concat(decoded);
1618
1634
  }
1619
- );
1620
- req.on("error", reject);
1621
- if (body) req.write(body);
1622
- req.end();
1635
+ resolve({ status, statusText, body: bodyBuf.toString("utf8") });
1636
+ });
1637
+ tlsSocket.on("error", onError);
1623
1638
  });
1624
1639
  } finally {
1625
1640
  if (timer) clearTimeout(timer);
@@ -4034,7 +4049,7 @@ async function mijnhostFetch(path, options = {}) {
4034
4049
  "API-Key": key,
4035
4050
  "Accept": "application/json",
4036
4051
  "Content-Type": "application/json",
4037
- "User-Agent": "mg-dashboard-mcp/6.6.2",
4052
+ "User-Agent": "mg-dashboard-mcp/6.6.3",
4038
4053
  ...options.headers || {}
4039
4054
  };
4040
4055
  const method = options.method ?? "GET";