@barivia/barmesh-mcp 0.6.3 → 0.7.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
@@ -79,12 +79,13 @@ API key; otherwise the analysis calls return HTTP 403. Contact Barivia to enable
79
79
  - **Uploads:** large CSVs use presigned PUT with explicit `Content-Length`; `.csv.gz` /
80
80
  `.tsv.gz` accepted. Pin `@barivia/barmesh-mcp@0.5.2` (clear `~/.npm/_npx` if stale).
81
81
  - **Live progress:** `barmesh_training_monitor(job_id)` or `barmesh_jobs(action=monitor)` block
82
- server-side with compact snapshots (phase, epoch, QE/TE, ETA, ordering_errors tail) until
82
+ server-side with compact snapshots (phase, epoch, QE, **panel/map TE**, ETA, ordering_errors tail) until
83
83
  terminal or `block_until_sec` (default 900). Waits for `cfd_finalize` by default. One-shot:
84
84
  `barmesh_jobs(action=status)`.
85
85
 
86
86
  ### Migration notes
87
87
 
88
+ - **Fixed-panel live TE (0.6.3 / barsom 0.20.4):** mid-training TE uses a fixed evaluation panel (`te_panel_size`; `te_inner_samples` alias). Curves stay on panel TE; monitors show **Panel TE** and **Map TE** separately — no snap-to-map on the curve tail.
88
89
  - **`barmesh_training_monitor` (0.5.3):** server-side blocking monitor with throttled snapshots — preferred after job submit instead of manual `barmesh_jobs(status)` loops. Equivalent to `barmesh_jobs(action=monitor)`.
89
90
  - **`send_feedback` → `barmesh_send_feedback` (0.3.0):** the feedback tool was renamed so it no longer collides with the `@barivia/barsom-mcp` tool of the same name when both servers are enabled in one client. Update any direct call sites; the behavior is unchanged.
90
91
 
package/dist/audit.js CHANGED
@@ -2,6 +2,7 @@
2
2
  * MCP tool audit wrapper — tool name, action, latency, outcome; no secrets.
3
3
  */
4
4
  import { logAudit } from "./logger.js";
5
+ import { runWithTrace } from "./shared.js";
5
6
  const AUDIT_PARAM_KEYS = new Set([
6
7
  "action",
7
8
  "preset",
@@ -87,6 +88,7 @@ export function registerAuditedTool(server, name, description, schema, handler)
87
88
  server.tool(name, description, schema, (async (args) => {
88
89
  const rec = args;
89
90
  const action = typeof rec.action === "string" && rec.action.length > 0 ? rec.action : "default";
90
- return runMcpToolAudit(name, action, rec, () => handler(args));
91
+ // One trace per tool invocation (every apiCall inside shares one trace_id).
92
+ return runWithTrace(() => runMcpToolAudit(name, action, rec, () => handler(args)));
91
93
  }));
92
94
  }
package/dist/shared.js CHANGED
@@ -7,6 +7,7 @@ import fs from "node:fs/promises";
7
7
  import { createReadStream, createWriteStream } from "node:fs";
8
8
  import { createGzip } from "node:zlib";
9
9
  import { createHash, randomUUID } from "node:crypto";
10
+ import { AsyncLocalStorage } from "node:async_hooks";
10
11
  import { Readable } from "node:stream";
11
12
  import { pipeline } from "node:stream/promises";
12
13
  import os from "node:os";
@@ -22,7 +23,7 @@ export const FETCH_TIMEOUT_MS = parseInt(process.env.BARIVIA_FETCH_TIMEOUT_MS ??
22
23
  export const MAX_RETRIES = 2;
23
24
  export const RETRYABLE_STATUS = new Set([502, 503, 504]);
24
25
  /** Single source of truth for the proxy version. Keep in sync with package.json on bump. */
25
- export const CLIENT_VERSION = "0.6.2";
26
+ export const CLIENT_VERSION = "0.7.0";
26
27
  export const PUBLIC_SITE_ORIGIN = "https://barivia.se";
27
28
  /** Large per-cell CSV uploads may exceed the default fetch timeout. */
28
29
  export const UPLOAD_DATASET_TIMEOUT_MS = 180_000;
@@ -260,6 +261,24 @@ function throwApiError(status, bodyText, requestId) {
260
261
  err.httpStatus = status;
261
262
  throw err;
262
263
  }
264
+ // ---- Distributed-trace context (W3C traceparent) ----
265
+ // One trace per logical tool action (scoped via AsyncLocalStorage in registerAuditedTool),
266
+ // so the API + job chain reconstruct end-to-end. Fresh span per API call; falls back to a
267
+ // per-call trace if no scope is set. Mirrors the barsom proxy.
268
+ const _traceStore = new AsyncLocalStorage();
269
+ function _newTraceId() {
270
+ return randomUUID().replace(/-/g, "");
271
+ }
272
+ function _newSpanId() {
273
+ return randomUUID().replace(/-/g, "").slice(0, 16);
274
+ }
275
+ /** Run `fn` within a fresh trace scope so all apiCall()s inside share one trace_id. */
276
+ export function runWithTrace(fn) {
277
+ return _traceStore.run(_newTraceId(), fn);
278
+ }
279
+ function _traceparentHeader() {
280
+ return `00-${_traceStore.getStore() ?? _newTraceId()}-${_newSpanId()}-01`;
281
+ }
263
282
  export async function apiCall(method, pathPart, body, extraHeaders, requestTimeoutMs) {
264
283
  const url = `${API_URL}${pathPart}`;
265
284
  const contentType = extraHeaders?.["Content-Type"] ?? "application/json";
@@ -268,6 +287,7 @@ export async function apiCall(method, pathPart, body, extraHeaders, requestTimeo
268
287
  Authorization: `Bearer ${API_KEY}`,
269
288
  "Content-Type": contentType,
270
289
  "X-Request-ID": requestId,
290
+ traceparent: _traceparentHeader(),
271
291
  "X-Barmesh-Client-Version": CLIENT_VERSION,
272
292
  ...extraHeaders,
273
293
  };
@@ -321,7 +341,7 @@ export async function apiRawCall(pathPart, requestTimeoutMs) {
321
341
  let lastError;
322
342
  for (let attempt = 0; attempt <= MAX_RETRIES; attempt++) {
323
343
  try {
324
- const resp = await fetchWithTimeout(url, { method: "GET", headers: { Authorization: `Bearer ${API_KEY}`, "X-Request-ID": requestId } }, effectiveTimeout);
344
+ const resp = await fetchWithTimeout(url, { method: "GET", headers: { Authorization: `Bearer ${API_KEY}`, "X-Request-ID": requestId, traceparent: _traceparentHeader() } }, effectiveTimeout);
325
345
  if (!resp.ok) {
326
346
  if (attempt < MAX_RETRIES && isTransientError(null, resp.status)) {
327
347
  await new Promise((r) => setTimeout(r, 1000 * 2 ** attempt));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@barivia/barmesh-mcp",
3
- "version": "0.6.3",
3
+ "version": "0.7.0",
4
4
  "description": "barmesh MCP proxy — SOM-based CFD mesh-convergence and Richardson/GCI analysis on the Barivia cloud API",
5
5
  "keywords": [
6
6
  "mcp",