@mgsoftwarebv/mg-dashboard-mcp 6.6.1 → 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,7 @@ 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';
21
+ import { lookup } from 'dns/promises';
22
22
  import { connect } from 'tls';
23
23
  import { HeadObjectCommand, S3Client, ListObjectsV2Command, DeleteObjectsCommand, DeleteObjectCommand, CreateMultipartUploadCommand, UploadPartCommand, CompleteMultipartUploadCommand, AbortMultipartUploadCommand, PutObjectCommand, GetObjectCommand, CopyObjectCommand } from '@aws-sdk/client-s3';
24
24
 
@@ -1570,7 +1570,13 @@ async function fetchViaSshProxy(options) {
1570
1570
  const timeoutMs = options.timeoutMs ?? 6e4;
1571
1571
  let timer;
1572
1572
  try {
1573
- const stream = await forwardOut(ssh, targetHost, targetPort);
1573
+ let connectHost = targetHost;
1574
+ try {
1575
+ const resolved = await lookup(targetHost, { family: 4 });
1576
+ connectHost = resolved.address;
1577
+ } catch {
1578
+ }
1579
+ const stream = await forwardOut(ssh, connectHost, targetPort);
1574
1580
  const tlsSocket = connect({
1575
1581
  socket: stream,
1576
1582
  servername: targetHost,
@@ -1586,33 +1592,49 @@ async function fetchViaSshProxy(options) {
1586
1592
  })
1587
1593
  ]);
1588
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);
1589
1602
  return await new Promise((resolve, reject) => {
1590
- const req = https.request(
1591
- {
1592
- createConnection: () => tlsSocket,
1593
- hostname: targetHost,
1594
- port: targetPort,
1595
- path: `${parsedUrl.pathname}${parsedUrl.search}`,
1596
- method,
1597
- headers,
1598
- agent: false
1599
- },
1600
- (res) => {
1601
- const chunks = [];
1602
- res.on("data", (chunk) => chunks.push(chunk));
1603
- res.on("end", () => {
1604
- resolve({
1605
- status: res.statusCode ?? 0,
1606
- statusText: res.statusMessage ?? "",
1607
- body: Buffer.concat(chunks).toString("utf8")
1608
- });
1609
- });
1610
- 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);
1611
1634
  }
1612
- );
1613
- req.on("error", reject);
1614
- if (body) req.write(body);
1615
- req.end();
1635
+ resolve({ status, statusText, body: bodyBuf.toString("utf8") });
1636
+ });
1637
+ tlsSocket.on("error", onError);
1616
1638
  });
1617
1639
  } finally {
1618
1640
  if (timer) clearTimeout(timer);
@@ -4027,7 +4049,7 @@ async function mijnhostFetch(path, options = {}) {
4027
4049
  "API-Key": key,
4028
4050
  "Accept": "application/json",
4029
4051
  "Content-Type": "application/json",
4030
- "User-Agent": "mg-dashboard-mcp/6.6.0",
4052
+ "User-Agent": "mg-dashboard-mcp/6.6.3",
4031
4053
  ...options.headers || {}
4032
4054
  };
4033
4055
  const method = options.method ?? "GET";