@renanlido/tia-openness-mcp 1.10.5 → 1.10.7

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 +92 -5
  2. package/package.json +1 -1
package/dist/index.js CHANGED
@@ -38549,7 +38549,7 @@ function uploadResumeSteps(reason) {
38549
38549
  function goOnlineResumeSteps() {
38550
38550
  return [
38551
38551
  "1. Confirm with a human that it is safe to connect to the target machine.",
38552
- "2. Re-call tia_online with confirm:true."
38552
+ "2. Re-call tia_online with confirm:true and the SAME connectionMode, pcInterfaceName, pcInterfaceNumber and targetInterfaceName as this plan."
38553
38553
  ];
38554
38554
  }
38555
38555
  function netScanResumeSteps() {
@@ -38895,6 +38895,78 @@ function uploadBodyFromApprovedPlan(issued, password) {
38895
38895
  ...password !== void 0 ? { password } : {}
38896
38896
  };
38897
38897
  }
38898
+ function modesToProbe(args, data, blockers) {
38899
+ if (args.connectionMode !== void 0 && args.connectionMode.trim().length > 0) return [];
38900
+ if (blockers.length === 0 || !blockers.every((b) => b === "connection_unresolved")) return [];
38901
+ if (!isObject2(data.connection)) return [];
38902
+ const mode = data.connection.mode;
38903
+ const pcInterface = data.connection.pcInterface;
38904
+ if (!isObject2(mode) || !isObject2(pcInterface)) return [];
38905
+ if (typeof mode.requested === "string" && mode.requested.trim().length > 0) return [];
38906
+ if (!Array.isArray(pcInterface.available) || pcInterface.available.length > 0) return [];
38907
+ if (!Array.isArray(mode.available)) return [];
38908
+ const modes = [];
38909
+ for (const m of mode.available) {
38910
+ if (modes.length === 8) break;
38911
+ if (typeof m === "string" && m.trim().length > 0 && !modes.includes(m)) modes.push(m);
38912
+ }
38913
+ return modes;
38914
+ }
38915
+ function parsePcInterfaces(connectionMode, available) {
38916
+ if (!Array.isArray(available)) return [];
38917
+ const out = [];
38918
+ for (const entry of available) {
38919
+ if (typeof entry !== "string") continue;
38920
+ const match = /([\s\S]+) \((\d+)\)$/.exec(entry);
38921
+ if (match === null || match[1].trim().length === 0) continue;
38922
+ const pcInterfaceNumber = Number(match[2]);
38923
+ if (!Number.isSafeInteger(pcInterfaceNumber)) continue;
38924
+ out.push({ connectionMode, pcInterfaceName: match[1], pcInterfaceNumber });
38925
+ }
38926
+ return out;
38927
+ }
38928
+ function stopsProbing(e) {
38929
+ const kind = asTiaError(e).kind;
38930
+ return ["timeout", "connection_refused", "busy", "installing", "audit_unavailable"].some((k) => k === kind);
38931
+ }
38932
+ function probeInterfaces(raw) {
38933
+ if (!isObject2(raw) || !isObject2(raw.connection) || !isObject2(raw.connection.pcInterface)) return null;
38934
+ return raw.connection.pcInterface.available;
38935
+ }
38936
+ async function probeConnectionCandidates(ip, modes) {
38937
+ const candidates = [];
38938
+ for (const connectionMode of modes) {
38939
+ let raw = null;
38940
+ try {
38941
+ raw = await tiaFetch(
38942
+ "/stations/upload/plan",
38943
+ { method: "POST", headers: JSON_HEADERS, body: JSON.stringify({ connectionMode, ip }) },
38944
+ { timeoutMs: SLOW_TIMEOUT_MS }
38945
+ );
38946
+ } catch (e) {
38947
+ if (stopsProbing(e)) break;
38948
+ }
38949
+ for (const c of parsePcInterfaces(connectionMode, probeInterfaces(raw))) {
38950
+ if (candidates.length === 32) return candidates;
38951
+ const known = candidates.some(
38952
+ (k) => k.connectionMode === c.connectionMode && k.pcInterfaceName === c.pcInterfaceName && k.pcInterfaceNumber === c.pcInterfaceNumber
38953
+ );
38954
+ if (!known) candidates.push(c);
38955
+ }
38956
+ }
38957
+ return candidates;
38958
+ }
38959
+ function candidateFields(candidates) {
38960
+ if (candidates.length === 0) return {};
38961
+ return {
38962
+ connectionCandidates: candidates,
38963
+ nextSteps: [
38964
+ "1. No connectionMode was given, so this plan resolved no PG/PC interface; serve lists these candidates for each available mode (connectionCandidates). This is not a sign that the host has no adapter.",
38965
+ "2. Pick ONE candidate (ask the human when several could reach the CPU) and call tia_upload again WITHOUT confirm, with that candidate's exact connectionMode, pcInterfaceName and pcInterfaceNumber.",
38966
+ "3. Relay the GATE G4 handoff that plan returns to the human and wait for an explicit yes before confirm:true. No candidate was chosen, approved or uploaded here."
38967
+ ]
38968
+ };
38969
+ }
38898
38970
  async function planUpload(args, plan, store) {
38899
38971
  let raw;
38900
38972
  try {
@@ -38936,6 +39008,7 @@ async function planUpload(args, plan, store) {
38936
39008
  const blockers = Array.isArray(data.blockers) ? [...data.blockers] : [];
38937
39009
  if (!isObject2(raw)) blockers.push("invalid_plan_response");
38938
39010
  if (data.ready === true) blockers.push("project_path_missing");
39011
+ const candidates = await probeConnectionCandidates(args.ip, modesToProbe(args, data, blockers));
38939
39012
  return markControl(
38940
39013
  textResult(
38941
39014
  {
@@ -38947,7 +39020,8 @@ async function planUpload(args, plan, store) {
38947
39020
  project: data.project ?? null,
38948
39021
  devices,
38949
39022
  note: typeof data.note === "string" ? data.note : null,
38950
- ...auditWarningOf(raw)
39023
+ ...auditWarningOf(raw),
39024
+ ...candidateFields(candidates)
38951
39025
  },
38952
39026
  false
38953
39027
  )
@@ -39110,7 +39184,7 @@ function registerUploadTools(server) {
39110
39184
  "tia_upload",
39111
39185
  {
39112
39186
  title: "TIA \u2014 station upload (GATE G4)",
39113
- description: "Station upload (GATE G4): goes ONLINE to the PHYSICAL CPU at `ip` and reads its hardware configuration and program into the OPEN project as a new station \u2014 it reads the CPU and does not write or stop it (observed on hardware: the CPU stayed in RUN). Back up into a dedicated EMPTY project, never the working project (skill tia-backup). Without confirm it asks serve for an upload plan (PG/PC interface resolved, the open project's path and devices \u2014 no network access) and returns a single-use planHash bound to that project; after a human confirms, call again with confirm:true and that planHash. A read-protected CPU needs its read-access password from a HUMAN (G6 \u2014 never invented). Needs the deploy license scope (Basic \u2192 403 scope_required) and app \u2265 v1.6.0. Maps to POST /stations/upload/plan and POST /stations/upload. " + LONG_OPERATION_NOTE,
39187
+ description: "Station upload (GATE G4): goes ONLINE to the PHYSICAL CPU at `ip` and reads its hardware configuration and program into the OPEN project as a new station \u2014 it reads the CPU and does not write or stop it (observed on hardware: the CPU stayed in RUN). Back up into a dedicated EMPTY project, never the working project (skill tia-backup). Without confirm it asks serve for an upload plan (PG/PC interface resolved, the open project's path and devices \u2014 no network access) and returns a single-use planHash bound to that project; after a human confirms, call again with confirm:true and that planHash. A plan blocked by connection_unresolved because no connectionMode was given asks serve for one more plan per available mode (one at a time, never confirmed; up to 8 modes) and lists the PG/PC interfaces it reports in connectionCandidates (up to 32): repeat without confirm with one candidate's exact connectionMode, pcInterfaceName and pcInterfaceNumber. A read-protected CPU needs its read-access password from a HUMAN (G6 \u2014 never invented). Needs the deploy license scope (Basic \u2192 403 scope_required) and app \u2265 v1.6.0. Maps to POST /stations/upload/plan and POST /stations/upload. " + LONG_OPERATION_NOTE,
39114
39188
  inputSchema: {
39115
39189
  ip: external_exports.string().describe("IPv4 of the PHYSICAL CPU"),
39116
39190
  connectionMode: external_exports.string().optional().describe(`connection mode (e.g., "PN/IE") \u2014 TIA's LOCALIZED name`),
@@ -39134,6 +39208,17 @@ function registerUploadTools(server) {
39134
39208
  }
39135
39209
 
39136
39210
  // src/tools/online.ts
39211
+ function onlineConnectionRefusal(plan) {
39212
+ const missing = ["connectionMode", "pcInterfaceName"].filter((k) => (plan[k] ?? "").trim().length === 0);
39213
+ if (missing.length === 0) return null;
39214
+ return errorResult(
39215
+ new TiaApiError(
39216
+ `tia_online with confirm:true needs connectionMode and pcInterfaceName; missing: ${missing.join(", ")}. Nothing was sent to serve and the PLC is not online.`,
39217
+ { status: 400, kind: "connection_fields_required", details: { missing, plan } }
39218
+ ),
39219
+ "Repeat tia_online with confirm:true and the SAME connectionMode, pcInterfaceName, pcInterfaceNumber and targetInterfaceName shown in the go_online plan the human approved. Never guess them: read the names with tia_pg_interfaces (no network scan) and, if they differ from that plan, ask the human again."
39220
+ );
39221
+ }
39137
39222
  function registerOnlineTools(server) {
39138
39223
  server.registerTool(
39139
39224
  "tia_connection_create",
@@ -39157,7 +39242,7 @@ function registerOnlineTools(server) {
39157
39242
  "tia_online",
39158
39243
  {
39159
39244
  title: "TIA \u2014 go online (GATE G4)",
39160
- description: "Connects ONLINE to the physical PLC. GATE G4: pass confirm:true (after a human confirms it's safe to connect to the target machine); without it, returns a handoff. Maps to POST /plcs/{plc}/online.",
39245
+ description: "Connects ONLINE to the physical PLC. GATE G4: pass confirm:true (after a human confirms it's safe to connect to the target machine); without it, returns a handoff. The confirm:true call must repeat the SAME connectionMode, pcInterfaceName, pcInterfaceNumber and targetInterfaceName as the approved plan: without connectionMode or pcInterfaceName it is refused (connection_fields_required) and nothing is sent. Maps to POST /plcs/{plc}/online.",
39161
39246
  inputSchema: {
39162
39247
  // Stryker disable next-line StringLiteral: handoff prose, facts are tested
39163
39248
  plc: external_exports.string().describe("PLC name"),
@@ -39175,6 +39260,8 @@ function registerOnlineTools(server) {
39175
39260
  async ({ plc, connectionMode, pcInterfaceName, pcInterfaceNumber, targetInterfaceName, confirm }, extra) => {
39176
39261
  const plan = { plc, connectionMode, pcInterfaceName, pcInterfaceNumber, targetInterfaceName };
39177
39262
  if (confirm !== true) return gateHandoff("go_online", { plc, plan });
39263
+ const refusal = onlineConnectionRefusal(plan);
39264
+ if (refusal !== null) return refusal;
39178
39265
  return runWithHumanConfirm(
39179
39266
  server,
39180
39267
  () => ({ message: onlineQuestion(plan), refusal: (verdict) => humanRefusal("go_online", verdict, { plc, plan }) }),
@@ -39706,7 +39793,7 @@ function buildServer(mode, version2, budget = resolveBudget()) {
39706
39793
  }
39707
39794
 
39708
39795
  // src/index.ts
39709
- var VERSION = "1.10.5";
39796
+ var VERSION = "1.10.7";
39710
39797
  async function main() {
39711
39798
  if (process.argv.slice(2).some((a) => a === "--version" || a === "-v")) {
39712
39799
  console.log(VERSION);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@renanlido/tia-openness-mcp",
3
- "version": "1.10.5",
3
+ "version": "1.10.7",
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",