@renanlido/tia-openness-mcp 1.6.1 → 1.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.
Files changed (2) hide show
  1. package/dist/index.js +25 -6
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -33129,7 +33129,7 @@ var PlanStore = class {
33129
33129
  prefix;
33130
33130
  issued = /* @__PURE__ */ new Map();
33131
33131
  consumed = /* @__PURE__ */ new Set();
33132
- issue(plan, fingerprint) {
33132
+ issue(plan, fingerprint, serveToken) {
33133
33133
  if (!fingerprint) throw new Error("planStore.issue: fingerprint is required");
33134
33134
  canonicalPlan(plan);
33135
33135
  const t = this.now();
@@ -33138,7 +33138,8 @@ var PlanStore = class {
33138
33138
  plan: { ...plan },
33139
33139
  fingerprint,
33140
33140
  issuedAt: t,
33141
- expiresAt: t + this.ttlMs
33141
+ expiresAt: t + this.ttlMs,
33142
+ ...serveToken ? { serveToken } : {}
33142
33143
  };
33143
33144
  this.issued.set(entry.token, entry);
33144
33145
  return entry;
@@ -33320,6 +33321,8 @@ function bodyFromApprovedPlan(issued) {
33320
33321
  software: plan.software
33321
33322
  }),
33322
33323
  expectedFingerprint: issued.fingerprint,
33324
+ // G3 on the serve: the token the serve issued with the plan (single use, bound to this exact request).
33325
+ ...issued.serveToken ? { approvalToken: issued.serveToken } : {},
33323
33326
  allowUpgradeTargetDevice: plan.allowUpgradeTargetDevice === true
33324
33327
  };
33325
33328
  }
@@ -33328,7 +33331,17 @@ async function planDownload(args, plan, store) {
33328
33331
  try {
33329
33332
  raw = await tiaFetch(
33330
33333
  `/plcs/${seg(args.plc)}/download/plan`,
33331
- { method: "POST", headers: JSON_HEADERS, body: JSON.stringify(connectionBody(args)) },
33334
+ // The serve binds its approval token to the WHOLE request, so the plan carries the same flags as the approved plan.
33335
+ {
33336
+ method: "POST",
33337
+ headers: JSON_HEADERS,
33338
+ body: JSON.stringify({
33339
+ ...connectionBody(args),
33340
+ hardware: plan.hardware,
33341
+ software: plan.software,
33342
+ allowUpgradeTargetDevice: plan.allowUpgradeTargetDevice
33343
+ })
33344
+ },
33332
33345
  { timeoutMs: SLOW_TIMEOUT_MS }
33333
33346
  );
33334
33347
  } catch (e) {
@@ -33367,7 +33380,8 @@ async function planDownload(args, plan, store) {
33367
33380
  false
33368
33381
  );
33369
33382
  }
33370
- const issued = store.issue(plan, fingerprint);
33383
+ const serveToken = typeof data.approvalToken === "string" && data.approvalToken.trim() ? data.approvalToken.trim() : void 0;
33384
+ const issued = store.issue(plan, fingerprint, serveToken);
33371
33385
  return textResult(
33372
33386
  {
33373
33387
  dryRun: true,
@@ -33424,6 +33438,11 @@ async function downloadFlow(args, store = planStore) {
33424
33438
  err,
33425
33439
  "Serve is installing a TIAOpenness app update: nothing was downloaded (the call was refused BEFORE running, so no CPU check is needed). The single-use approval token is already spent \u2014 after the update finishes, run a fresh dryRun plan and get a new human approval. There is no background job for this call."
33426
33440
  );
33441
+ if (err.status === 403 && (err.kind === "approval_required" || err.kind === "approval_invalid"))
33442
+ return errorResult(
33443
+ err,
33444
+ "Serve refused the download BEFORE running (its approval token was missing, expired, already used or for another request): nothing was downloaded and the CPU was not touched. Run a fresh dryRun plan and get a new human approval."
33445
+ );
33427
33446
  const knownRefusal = err.status === 409 && (err.kind === "plan_stale" || err.kind === "upgrade_target_device_required");
33428
33447
  if (knownRefusal) return errorResult(err);
33429
33448
  const isTransport = err.kind === "timeout" || err.kind === "connection_refused";
@@ -33481,7 +33500,7 @@ function registerDownloadTools(server2) {
33481
33500
  "tia_download",
33482
33501
  {
33483
33502
  title: "TIA \u2014 download to the PLC (GATE G3)",
33484
- description: "Downloads hardware/software to the PHYSICAL CPU (STOPS and RESTARTS the CPU). GATE G3: does NOT download without human approval. dryRun:true asks serve for a VERIFIED plan (clean compile, PG/PC interface found, software fingerprint) and returns a single-use planHash that expires (TIA_PLAN_TTL_MS, default 15 min). After a human approves that plan, call with approved:true and the SAME planHash; serve re-checks the fingerprint inside the download and refuses (plan_stale) if the project changed. Pick connectionMode/pcInterfaceName/targetInterfaceName with tia_pg_interfaces (no scan). Requires app \u2265 v1.6.0. Maps to POST /plcs/{plc}/download/plan and POST /plcs/{plc}/download. " + LONG_OPERATION_NOTE,
33503
+ description: "Downloads hardware/software to the PHYSICAL CPU (STOPS and RESTARTS the CPU). GATE G3: does NOT download without human approval. dryRun:true asks serve for a VERIFIED plan (clean compile, PG/PC interface found, software fingerprint) and returns a single-use planHash that expires (TIA_PLAN_TTL_MS, default 15 min). After a human approves that plan, call with approved:true and the SAME planHash; serve re-checks the fingerprint inside the download and refuses (plan_stale) if the project changed. Pick connectionMode/pcInterfaceName/targetInterfaceName with tia_pg_interfaces (no scan). The serve also issues its own single-use approval token with the plan; this MCP keeps it and sends it with the download (a newer serve refuses any download without it \u2014 keep this MCP up to date). Requires app \u2265 v1.6.0. Maps to POST /plcs/{plc}/download/plan and POST /plcs/{plc}/download. " + LONG_OPERATION_NOTE,
33485
33504
  inputSchema: {
33486
33505
  plc: external_exports.string().describe("PLC name"),
33487
33506
  connectionMode: external_exports.string().optional().describe(`connection mode (e.g., "PN/IE") \u2014 TIA's LOCALIZED name`),
@@ -34187,7 +34206,7 @@ function registerGuideTool(server2) {
34187
34206
 
34188
34207
  // src/index.ts
34189
34208
  var server = new McpServer(
34190
- { name: "tia-openness", version: "1.6.1" },
34209
+ { name: "tia-openness", version: "1.7.0" },
34191
34210
  // Camada 1 (ambiente): o brief operacional viaja no handshake MCP — qualquer cliente
34192
34211
  // que honre `instructions` recebe gates/serial-only/pipeline sem instalar nada.
34193
34212
  { instructions: BRIEF }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renanlido/tia-openness-mcp",
3
- "version": "1.6.1",
3
+ "version": "1.7.0",
4
4
  "description": "MCP server (stdio) — thin HTTP client over the TIA Openness `serve` API. Zero Openness/net48 references.",
5
5
  "license": "MIT",
6
6
  "type": "module",