@barivia/barsom-mcp 0.17.1 → 0.18.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.
@@ -23,6 +23,11 @@ export function startVizServer(apiCall, apiRawCall, loadViewHtml) {
23
23
  if (portOverride && (Number.isNaN(port) || port < 0 || port > 65535)) {
24
24
  return Promise.reject(new Error(`Invalid BARIVIA_VIZ_PORT: ${portOverride}`));
25
25
  }
26
+ // Resolved at listen time; exposed via /api/health so users/agents can confirm
27
+ // the viz server is up and on which port (it is ephemeral unless BARIVIA_VIZ_PORT
28
+ // is set, so standalone URLs from a prior session can become stale).
29
+ let assignedPort = port;
30
+ const portIsPinned = Boolean(portOverride);
26
31
  const server = http.createServer(async (req, res) => {
27
32
  const url = new URL(req.url ?? "/", `http://127.0.0.1`);
28
33
  const pathname = url.pathname;
@@ -55,6 +60,35 @@ export function startVizServer(apiCall, apiRawCall, loadViewHtml) {
55
60
  send(200, html, "text/html; charset=utf-8");
56
61
  return;
57
62
  }
63
+ // GET /api/health (diagnostic: viz server up, port, API reachability, optional job-state echo)
64
+ if (req.method === "GET" && pathname === "/api/health") {
65
+ const out = {
66
+ ok: true,
67
+ viz_port: assignedPort,
68
+ port_pinned: portIsPinned,
69
+ };
70
+ const jobId = url.searchParams.get("job_id");
71
+ if (jobId) {
72
+ if (!ID_REGEX.test(jobId)) {
73
+ out.api_reachable = false;
74
+ out.error = "Invalid job_id";
75
+ }
76
+ else {
77
+ try {
78
+ const data = (await apiCall("GET", `/v1/jobs/${jobId}`));
79
+ out.api_reachable = true;
80
+ out.job_status = data.status ?? null;
81
+ out.job_progress = data.progress ?? null;
82
+ }
83
+ catch (err) {
84
+ out.api_reachable = false;
85
+ out.error = err instanceof Error ? err.message : "Request failed";
86
+ }
87
+ }
88
+ }
89
+ sendJson(200, out);
90
+ return;
91
+ }
58
92
  // GET /api/results/:jobId
59
93
  const resultsMatch = pathname.match(/^\/api\/results\/([^/]+)$/);
60
94
  if (req.method === "GET" && resultsMatch) {
@@ -222,7 +256,8 @@ export function startVizServer(apiCall, apiRawCall, loadViewHtml) {
222
256
  return new Promise((resolve, reject) => {
223
257
  server.listen(port, "127.0.0.1", () => {
224
258
  const assigned = server.address()?.port;
225
- resolve(assigned ?? port);
259
+ assignedPort = assigned ?? port;
260
+ resolve(assignedPort);
226
261
  });
227
262
  server.on("error", reject);
228
263
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barivia/barsom-mcp",
3
- "version": "0.17.1",
3
+ "version": "0.18.1",
4
4
  "description": "barSOM MCP proxy — connect any MCP client to the barSOM cloud API for Self-Organizing Map analytics",
5
5
  "keywords": [
6
6
  "mcp",