@renanlido/tia-openness-mcp 1.10.7 → 1.11.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 +26 -15
- package/dist/index.js +83 -41
- package/package.json +19 -3
package/README.md
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
[](https://www.npmjs.com/package/@renanlido/tia-openness-mcp)
|
|
4
4
|
|
|
5
|
+
MCP server for Siemens TIA Portal V21, running on macOS, Linux and Windows and connecting to the PLCWare Desktop API on Windows. Using that API requires an active license.
|
|
6
|
+
|
|
7
|
+
30-day free trial: [https://plcware.io/en/trial?utm_source=npm&utm_medium=readme&utm_campaign=mcp](https://plcware.io/en/trial?utm_source=npm&utm_medium=readme&utm_campaign=mcp)
|
|
8
|
+
|
|
5
9
|
An **MCP (stdio) server** that is a **pure HTTP client** of the TIA Openness `serve` API
|
|
6
10
|
(see `docs/API-HTTP.md` in the repository). It does not reference Openness / net48 / x64 — all of that
|
|
7
11
|
complexity (`AssemblyResolve`, serial MTA worker) lives in the `serve` process. Here we only speak **MCP on
|
|
@@ -94,16 +98,23 @@ first. `discardUnsavedChanges:true` is the data-loss choice — the client's con
|
|
|
94
98
|
is sent — and is never a way past the refusal. If nothing is modified, both flags are no-ops.
|
|
95
99
|
|
|
96
100
|
**Trust GATE (G1):** setup pre-registers eligible installed executables (Program Files, admin-only ACLs) in the
|
|
97
|
-
Openness allow-list. If
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
`
|
|
105
|
-
|
|
106
|
-
|
|
101
|
+
Openness allow-list. If no current entry covers the executable, a human may need to confirm a security dialog
|
|
102
|
+
ON THE HOST. The proactive flow is **`tia_start` → `tia_show_ui` → (human confirms) → `tia_connect`**.
|
|
103
|
+
An explicit G1 handoff is emitted only with serve evidence: `EngineeringSecurityException` from `tia_connect`, or a failed
|
|
104
|
+
start with `kind:"tia_start_failed"` and `details.cause:"trust"`. A human may confirm G1 whenever a trust dialog is visible
|
|
105
|
+
on the serve host; `status:"running"` alone is not G1 evidence, so keep calling `tia_job_status` and do not call `tia_status`
|
|
106
|
+
or repeat the original call while it runs.
|
|
107
|
+
The fixed 20-minute client timeout applies to `tia_start`, `tia_show_ui`, `tia_connect` and `tia_project_create`. An
|
|
108
|
+
ambiguous timeout returns `STARTING_UNCONFIRMED`, not success or G1, and does not cancel the serve-side operation; its serial
|
|
109
|
+
worker may remain occupied. Do not queue serve-bound calls. Ask a human to inspect the serve host and wait until the operation
|
|
110
|
+
is known to be complete before querying `tia_status`. `TIA_CONNECT_TIMEOUT_MS` applies only to `tia_local_session_open` and
|
|
111
|
+
its G6 logon-dialog handling.
|
|
112
|
+
For an explicit `tia_connect` G1 handoff, after the human confirms the visible dialog, call `tia_connect` again with its
|
|
113
|
+
`resumeToken`.
|
|
114
|
+
For a failed start with `details.cause:"trust"`, follow the handoff cleanup steps: close any `stillRunningPids` TIA with no
|
|
115
|
+
project before retrying; verify `unknownPids` in Task Manager and close them only if confirmed as TIA started by this serve
|
|
116
|
+
with no project. Have a human ready at the serve host to click "Yes to all" if the dialog appears, then re-call the same tool
|
|
117
|
+
(for `tia_connect`, with the same `projectPath` and `resumeToken`). See `tia_guide {"topic":"gui-gates"}`.
|
|
107
118
|
|
|
108
119
|
### M3 — creation/authoring (class M-off) + guards
|
|
109
120
|
A **compliant-by-construction** creation surface (45 tools) with schema validation (Gd13); every tool except
|
|
@@ -294,8 +305,8 @@ soft-deadline job runner instead of blocking the call: `tia_connect`, `tia_start
|
|
|
294
305
|
be used to obtain the job ID. The same long tool called again with the same arguments (the key is the tool plus
|
|
295
306
|
all its arguments) returns the same `jobId` instead of starting a second run; a `tia_connect` that differs in any
|
|
296
307
|
argument (UI, UMAC, `resumeToken`) answers `busy` while the first one runs.
|
|
297
|
-
-
|
|
298
|
-
|
|
308
|
+
- A lifecycle job that remains running may still be starting or waiting for the trust dialog; `running` alone is not G1 evidence.
|
|
309
|
+
Follow its conditional `nextSteps`, and ask a human to confirm G1 only if the dialog is visible on the serve host.
|
|
299
310
|
|
|
300
311
|
### Tool annotations, structured output and confirmation dialogs (ADR 0026)
|
|
301
312
|
|
|
@@ -458,8 +469,8 @@ two inputs and answers the whole list, without `total` or `nextCursor`. The deci
|
|
|
458
469
|
|---|---|---|
|
|
459
470
|
| `TIA_API_BASE` | `http://localhost:5000` | Base URL of the `serve` API. |
|
|
460
471
|
| `TIA_API_TIMEOUT_MS` | `15000` | Per-request timeout (fail fast if the host/VM does not respond). |
|
|
461
|
-
| `TIA_SLOW_TIMEOUT_MS` | `120000` | Timeout for slow/cold ops (catalog, download plan and other slow M1–M3 calls). `tia_project_create`
|
|
462
|
-
| `TIA_CONNECT_TIMEOUT_MS` | `180000` | Timeout for
|
|
472
|
+
| `TIA_SLOW_TIMEOUT_MS` | `120000` | Timeout for slow/cold ops (catalog, download plan and other slow M1–M3 calls). Lifecycle tools (`tia_connect`, `tia_project_create`, `tia_start`, `tia_show_ui`) use a fixed 1,200,000 ms ceiling; `tia_compile` does NOT use this variable — it has a separate fixed 120 s timeout. `tia_crossrefs` waits up to 3 900 000 ms (the serve Long timeout of 3600 s plus five minutes, so the serve's own timeout answer arrives first): a larger value here raises that wait, a smaller one never lowers it. |
|
|
473
|
+
| `TIA_CONNECT_TIMEOUT_MS` | `180000` | Timeout for `tia_local_session_open` and its G6 logon-dialog handling. It does not control lifecycle operations or infer G1. |
|
|
463
474
|
| `TIA_SOFT_DEADLINE_MS` | `20000` | Soft deadline for the 38 long tools before they answer `status:"running"` (capped at `25000`). |
|
|
464
475
|
| `TIA_PLAN_TTL_MS` | `900000` | Validity of a G3 download `planHash` (15 min); the token lives only in this MCP process. |
|
|
465
476
|
| `TIA_MCP_MODE` | `full` | `full` registers every tool; `read-only` registers only the class R tools (see [Read-only mode](#read-only-mode-tia_mcp_mode)). Unset, empty or blank means `full`; any other value stops the MCP at start. |
|
|
@@ -644,7 +655,7 @@ guide — with the guided setup, each client's exact format and the Windows laun
|
|
|
644
655
|
only if the client says the server failed to start) — is in `docs/INSTALL.md` in the repository.
|
|
645
656
|
|
|
646
657
|
**Optional envs** (defaults are built into the MCP — only set them to override): `TIA_API_TIMEOUT_MS` (15000),
|
|
647
|
-
`TIA_SLOW_TIMEOUT_MS` (120000), `TIA_CONNECT_TIMEOUT_MS` (180000). E.g. `--env TIA_SLOW_TIMEOUT_MS=180000`
|
|
658
|
+
`TIA_SLOW_TIMEOUT_MS` (120000), `TIA_CONNECT_TIMEOUT_MS` (180000; `tia_local_session_open` G6 logon dialog only). E.g. `--env TIA_SLOW_TIMEOUT_MS=180000`
|
|
648
659
|
on `claude mcp add`, or the corresponding key in the `.mcp.json` `env`.
|
|
649
660
|
|
|
650
661
|
The `--scope user` command makes the server available across your projects. Only the `.mcp.json` alternative
|
package/dist/index.js
CHANGED
|
@@ -23465,7 +23465,7 @@ var JobRunner = class {
|
|
|
23465
23465
|
* MESMOS args (deep-equal, ordem de chaves irrelevante) dedupe para o job em andamento; quaisquer outros
|
|
23466
23466
|
* args, ou outro tool, respondem busy enquanto esse job não termina.
|
|
23467
23467
|
*/
|
|
23468
|
-
async run(tool, args, work) {
|
|
23468
|
+
async run(tool, args, work, options = {}) {
|
|
23469
23469
|
let key;
|
|
23470
23470
|
try {
|
|
23471
23471
|
key = dedupeKey(tool, args);
|
|
@@ -23484,6 +23484,7 @@ var JobRunner = class {
|
|
|
23484
23484
|
startedAt: this.now(),
|
|
23485
23485
|
finishedAt: null,
|
|
23486
23486
|
result: null,
|
|
23487
|
+
runningHint: options.runningHint ?? null,
|
|
23487
23488
|
retain: false,
|
|
23488
23489
|
done: Promise.resolve(toolResult({}, false))
|
|
23489
23490
|
// placeholder; substituído já a seguir, síncrono
|
|
@@ -23559,7 +23560,8 @@ var JobRunner = class {
|
|
|
23559
23560
|
deduplicated,
|
|
23560
23561
|
nextSteps: [
|
|
23561
23562
|
`Call tia_job_status {"jobId":"${job.id}"} \u2014 it waits up to ${MAX_STATUS_WAIT_MS / 1e3}s per call and returns the final result.`,
|
|
23562
|
-
"Do NOT repeat the original call: the operation is still running on serve."
|
|
23563
|
+
"Do NOT repeat the original call: the operation is still running on serve.",
|
|
23564
|
+
...job.runningHint === null ? [] : [job.runningHint]
|
|
23563
23565
|
]
|
|
23564
23566
|
},
|
|
23565
23567
|
false
|
|
@@ -23653,6 +23655,7 @@ function unboundedDispatcher() {
|
|
|
23653
23655
|
var TiaApiError = class extends Error {
|
|
23654
23656
|
status;
|
|
23655
23657
|
kind;
|
|
23658
|
+
licenseState;
|
|
23656
23659
|
/** Nome do tipo da exceção do lado do serve (ex.: "EngineeringSecurityException") — usado p/ detectar gates. */
|
|
23657
23660
|
type;
|
|
23658
23661
|
/** Mensagem da InnerException do serve, quando presente. */
|
|
@@ -23667,6 +23670,7 @@ var TiaApiError = class extends Error {
|
|
|
23667
23670
|
this.type = opts.type ?? null;
|
|
23668
23671
|
this.inner = opts.inner ?? null;
|
|
23669
23672
|
this.details = opts.details ?? null;
|
|
23673
|
+
this.licenseState = opts.licenseState ?? null;
|
|
23670
23674
|
this.auditWarning = opts.auditWarning ?? null;
|
|
23671
23675
|
if (opts.cause !== void 0) this.cause = opts.cause;
|
|
23672
23676
|
}
|
|
@@ -23733,6 +23737,7 @@ async function tiaFetch(path, init = {}, opts = {}) {
|
|
|
23733
23737
|
}
|
|
23734
23738
|
if (!res.ok) {
|
|
23735
23739
|
const env = body && typeof body === "object" ? body : {};
|
|
23740
|
+
const license = env.license;
|
|
23736
23741
|
const message = typeof env.error === "string" ? env.error : `HTTP ${res.status} ${res.statusText}`;
|
|
23737
23742
|
throw new TiaApiError(message, {
|
|
23738
23743
|
status: res.status,
|
|
@@ -23740,6 +23745,7 @@ async function tiaFetch(path, init = {}, opts = {}) {
|
|
|
23740
23745
|
type: typeof env.type === "string" ? env.type : null,
|
|
23741
23746
|
inner: typeof env.inner === "string" ? env.inner : null,
|
|
23742
23747
|
details: env.details ?? null,
|
|
23748
|
+
licenseState: typeof license?.state === "string" ? license.state : null,
|
|
23743
23749
|
auditWarning: typeof env.auditWarning === "string" && env.auditWarning.length > 0 ? env.auditWarning : null
|
|
23744
23750
|
});
|
|
23745
23751
|
}
|
|
@@ -23806,8 +23812,10 @@ function hintFor(err) {
|
|
|
23806
23812
|
return "Start the API on the serve host: `TIAOpenness.exe serve 5000 --host 0.0.0.0` and check TIA_API_BASE.";
|
|
23807
23813
|
case "invalid_api_base":
|
|
23808
23814
|
return "Set the PLCWare API URL (TIA_API_BASE, asked when the plugin, extension or bundle was installed) to http://<host>:<port>, then restart the agent so the MCP reads it again.";
|
|
23809
|
-
case "license_required":
|
|
23810
|
-
|
|
23815
|
+
case "license_required": {
|
|
23816
|
+
const expired = err.licenseState === "Expired";
|
|
23817
|
+
return "Server not activated: configure the API key in the TIAOpenness GUI ('License' tab). 30-day free trial: https://plcware.io/en/trial?utm_source=mcp&utm_medium=tool-error&utm_campaign=license" + (expired ? " Plans: https://plcware.io/en?utm_source=mcp&utm_medium=tool-error&utm_campaign=license#preco" : "");
|
|
23818
|
+
}
|
|
23811
23819
|
case "scope_required":
|
|
23812
23820
|
return "The active license does not include the scope this route requires (see `requiredScope` in the error). Deploy-class tools (download/online/upload) need the 'deploy' scope (Pro tier); offline authoring needs 'author'. Upgrade the plan or activate a license that includes it \u2014 this is a licensing limit, not a fault.";
|
|
23813
23821
|
case "not_connected":
|
|
@@ -23941,15 +23949,15 @@ function asTiaError(e) {
|
|
|
23941
23949
|
}
|
|
23942
23950
|
|
|
23943
23951
|
// src/content.gen.ts
|
|
23944
|
-
var BRIEF = '# TIA Openness MCP \u2014 operating brief\n\nYou are driving Siemens TIA Portal V21 through the `tia_*` tools (an MCP over the TIA\nOpenness HTTP `serve`). This brief is ALWAYS in effect. For depth, call the `tia_guide`\ntool (topics: `gates-guards`, `gui-gates`, `gotchas`, `pipeline`, `recipes`,\n`spec-format`) \u2014 read the relevant topic BEFORE authoring blocks, changing hardware,\nor preparing a deploy. You are an assistant up to the gate, never an autonomous\ncommissioner.\n\n## Vocabulary (used across all tool descriptions)\n\n- **Class R** \u2014 read-only; safe anytime.\n- **Class M-off** \u2014 offline mutation (edits the project; never touches the physical PLC).\n- **Class GATE** \u2014 touches the physical world or a human-only decision; needs a human.\n- **G1..G7** \u2014 the GATES: G1 trust dialog, G2 S7-connection precondition (tool-enforced:\n both CPUs must compile clean), G3 download / CPU-STOP, G4 go-online (incl. station upload),\n G5 safety / F-logic (NEVER autonomous), G6 credentials \u2014 master secret, UMAC, upload /\n block / certificate passwords, password policy (from a human \u2014 never invented), G7 network\n scan. All except G2 are human-only \u2014 never crossed autonomously.\n- **Gd\\*** \u2014 tool-enforced GUARDS (preconditions the tools check), e.g. Gd5\n `OrderNumber:<MLFB>/V<fw>` format (slash before V, never `:V`), Gd8 only ERRORs block\n a compile (warnings don\'t), Gd9 clean compile before deploy, Gd11 dryRun-then-approve.\n\n## Non-negotiable rules\n\n1. **Serial only.** The serve owns ONE TIA Portal on ONE serial worker. Never fire\n concurrent `tia_*` calls; one hung Openness call can stall the whole serve.\n2. **Never cross a GATE autonomously.** A `requires_human_action` response is a HANDOFF,\n not an error: relay its `youMustDo`/`nextSteps` to the human verbatim, wait for their\n explicit yes, then resume exactly as instructed. Never self-approve a download; never\n invent a secret (G6); never author, modify or deploy safety/F logic (G5).\n3. **Long operations are jobs.** A tool whose description says "Long operation" (connect,\n compile, download, upload, project create/save/archive, exports, CAx\u2026) may answer `status:"running"` with a\n `jobId` \u2014 the operation is STILL running on serve. Call `tia_job_status {jobId}`\n until it returns the final result; never repeat the original call. While a job runs,\n any OTHER ordinary serve-bound tool answers `kind:"busy"` (with `details.jobId`) \u2014 that is\n expected, not a failure: go back to `tia_job_status`. `tia_ping` probes `/health`: never busy,\n `activated:null` while a job runs, and no job ID in it \u2014 use it for reachability only. Offline\n tools (`tia_guide`, `tia_spec_validate`, `tia_spec_plan`, `tia_job_status` itself) never answer busy.\n4. **Compile before deploy.** `tia_compile` aggregates hardware + software and is the\n offline verifier: `errors:0` is the Gd9 precondition for download (G3) and for S7\n connections.\n5. **Follow the build pipeline order** (details: `tia_guide {"topic":"pipeline"}`):\n validate the spec (`tia_spec_validate`) \u2192 plan (`tia_spec_plan`) \u2192 scaffold\n (`tia_spec_apply` or the M-off tools) \u2192 verify (`tia_compile`) \u2192 human-gated deploy\n (`tia_download` with dryRun \u2192 human approval \u2192 `approved:true` + the same `planHash`).\n6. **Some CPU settings are GUI-only** (PUT/GET permission, OPC UA runtime license,\n OPC UA server interface). Hitting one is EXPECTED, not a bug: relay the exact GUI\n steps from `tia_guide {"topic":"gui-gates"}` and resume after the human confirms.\n7. **Prerequisites:** the serve
|
|
23952
|
+
var BRIEF = '# TIA Openness MCP \u2014 operating brief\n\nYou are driving Siemens TIA Portal V21 through the `tia_*` tools (an MCP over the TIA\nOpenness HTTP `serve`). This brief is ALWAYS in effect. For depth, call the `tia_guide`\ntool (topics: `gates-guards`, `gui-gates`, `gotchas`, `pipeline`, `recipes`,\n`spec-format`) \u2014 read the relevant topic BEFORE authoring blocks, changing hardware,\nor preparing a deploy. You are an assistant up to the gate, never an autonomous\ncommissioner.\n\n## Vocabulary (used across all tool descriptions)\n\n- **Class R** \u2014 read-only; safe anytime.\n- **Class M-off** \u2014 offline mutation (edits the project; never touches the physical PLC).\n- **Class GATE** \u2014 touches the physical world or a human-only decision; needs a human.\n- **G1..G7** \u2014 the GATES: G1 trust dialog, G2 S7-connection precondition (tool-enforced:\n both CPUs must compile clean), G3 download / CPU-STOP, G4 go-online (incl. station upload),\n G5 safety / F-logic (NEVER autonomous), G6 credentials \u2014 master secret, UMAC, upload /\n block / certificate passwords, password policy (from a human \u2014 never invented), G7 network\n scan. All except G2 are human-only \u2014 never crossed autonomously.\n- **Gd\\*** \u2014 tool-enforced GUARDS (preconditions the tools check), e.g. Gd5\n `OrderNumber:<MLFB>/V<fw>` format (slash before V, never `:V`), Gd8 only ERRORs block\n a compile (warnings don\'t), Gd9 clean compile before deploy, Gd11 dryRun-then-approve.\n\n## Non-negotiable rules\n\n1. **Serial only.** The serve owns ONE TIA Portal on ONE serial worker. Never fire\n concurrent `tia_*` calls; one hung Openness call can stall the whole serve.\n2. **Never cross a GATE autonomously.** A `requires_human_action` response is a HANDOFF,\n not an error: relay its `youMustDo`/`nextSteps` to the human verbatim, wait for their\n explicit yes, then resume exactly as instructed. Never self-approve a download; never\n invent a secret (G6); never author, modify or deploy safety/F logic (G5).\n3. **Long operations are jobs.** A tool whose description says "Long operation" (connect,\n compile, download, upload, project create/save/archive, exports, CAx\u2026) may answer `status:"running"` with a\n `jobId` \u2014 the operation is STILL running on serve. Call `tia_job_status {jobId}`\n until it returns the final result; never repeat the original call. While a job runs,\n any OTHER ordinary serve-bound tool answers `kind:"busy"` (with `details.jobId`) \u2014 that is\n expected, not a failure: go back to `tia_job_status`. `tia_ping` probes `/health`: never busy,\n `activated:null` while a job runs, and no job ID in it \u2014 use it for reachability only. Offline\n tools (`tia_guide`, `tia_spec_validate`, `tia_spec_plan`, `tia_job_status` itself) never answer busy.\n4. **Compile before deploy.** `tia_compile` aggregates hardware + software and is the\n offline verifier: `errors:0` is the Gd9 precondition for download (G3) and for S7\n connections.\n5. **Follow the build pipeline order** (details: `tia_guide {"topic":"pipeline"}`):\n validate the spec (`tia_spec_validate`) \u2192 plan (`tia_spec_plan`) \u2192 scaffold\n (`tia_spec_apply` or the M-off tools) \u2192 verify (`tia_compile`) \u2192 human-gated deploy\n (`tia_download` with dryRun \u2192 human approval \u2192 `approved:true` + the same `planHash`).\n6. **Some CPU settings are GUI-only** (PUT/GET permission, OPC UA runtime license,\n OPC UA server interface). Hitting one is EXPECTED, not a bug: relay the exact GUI\n steps from `tia_guide {"topic":"gui-gates"}` and resume after the human confirms.\n7. **Prerequisites:** run the serve (`http://localhost:5000`; `tia_ping`). First\n connect per process may need G1; running/timeout alone are not G1 evidence.\n8. **Confirmation dialogs.** Where the client supports it, a gated call first asks the human in the client\'s dialog\n (elicitation); only the human answers it, and it never replaces dryRun \u2192 approval \u2192 `planHash`. `declined_by_human` /\n `cancelled_by_human` = refused, nothing sent: stop, no retry unless asked.\n9. **Size budget and paging.** A result holding `{"omitted":true,\u2026}` had that value cut out WHOLE by the MCP\'s size budget:\n repeating the same call returns the same marker, so follow its `hint` instead. Read large lists (`tia_plc_blocks`,\n `tia_plc_tags`, `tia_device_tree`) in pages: pass `limit`, then each `nextCursor` as `cursor` until it is `null`. A page\n with a marker has NO `nextCursor` (it would skip the omitted data): retry the same request with a smaller `limit`.\n `cursor_stale` means the project changed: restart from the first page (no `cursor`). Gate handoffs, plans and job\n envelopes are never cut. For XML too big for one result use `tia_export_xml` (it writes files on the serve host).\n\nSession start: `tia_ping` \u2192 `tia_status` \u2192 (if needed) `tia_start` / `tia_connect`.\nBefore the first build on a project: read `tia_guide {"topic":"pipeline"}` and\n`tia_guide {"topic":"gotchas"}`.\n\n**Tool names** are written bare (`tia_status`) here and in the skills. Claude Code shows them qualified:\n`mcp__plugin_tia-harness_tia__tia_status` (plugin; what a subagent `tools:` list needs) or\n`mcp__tia__tia_status` (standalone). Other clients may display them differently; the `tia_*` suffix\nis the tool.\n';
|
|
23945
23953
|
var GATES_GUARDS = '# Gates vs guards\n\n## GATES vs GUARDS\n\n- **GATES (human-only \u2014 never auto-bypass):** trust dialog (**G1**), download / CPU-STOP\n (**G3**), go-online (**G4**, which includes a **station upload** (`tia_upload`): it goes\n online to read the CPU), network scan / accessible-devices (**G7**), master-secret/UMAC\n (**G6**, which includes a CPU **read-access password** for an upload, a block **know-how\n password** (`tia_block_protect`), a certificate file\'s password (`tia_certificate_import`)\n and the **password-policy** values (`tia_password_policy_set`)), **safety / F-logic\n (G5) \u2014 never autonomous**.\n- **GUARDS (tool-enforced preconditions):** compile-clean before deploy, consistency,\n dry-run\u2192approve, idempotency by name (advisory: re-runs do not converge), `OrderNumber:<MLFB>/V<fw>`\n format, serial-only.\n- Back up a physical CPU with the **`tia-backup`** skill (dedicated empty project; the upload\n token is bound to the project shown in the handoff).\n- **Picking the G3 download path (no gate, no scan):** `tia_pg_interfaces` lists the connection\n modes/PG-PC interfaces TIA already sees for the CPU (plus the OS status of each adapter) \u2014\n use it to fill `connectionMode`/`pcInterfaceName`/`targetInterfaceName` for `tia_download`\n instead of reaching for `tia_accessible_devices` (a real network scan, GATE G7).\n- **GUI-ONLY settings (NOT exposed via Openness \u2014 surface as a human gate, do not script):**\n "Permit access with PUT/GET communication", OPC UA **runtime license** / server-interface\n creation. (OPC UA server **activation** is the exception \u2014 settable via Openness with\n `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}` on the "OPC UA" device-item.)\n\n**Deploy-time approval gates** (download / online / network-scan / secret / safety = **G3/G4/G7/G6/G5**)\nare a *different* class \u2014 see the **`tia-handoff`** skill. Those are "a human **approves an action**",\nnot "a human **clicks a GUI setting**". Both are human interaction points; surface them as\n`requires_human_action` with concrete guidance, never as a tool failure.\n';
|
|
23946
|
-
var GUI_GATES = '# GUI gates \u2014 expected human interaction points\n\n## Human interaction points (GUI gates) \u2014 EXPECTED, not an error\n\nSome TIA settings are **not reachable via Openness** on the S7-1200/1500. The harness will hit a\nsignal that *looks* like an error but is actually a point where a **human must act in the TIA GUI**.\nWhen you see one of these, **do not treat it as a failure and do not retry blindly** \u2014 recognize it,\ntell the human the **exact GUI steps**, and resume after they confirm. A GUI gate is a *handoff*, not a *bug*.\n\n| # | Signal you\'ll see | Why it\'s expected | Tell the human (exact GUI steps) |\n|---|---|---|---|\n| **G1 trust** | `tia_connect`
|
|
23947
|
-
var GOTCHAS = '# Hard-won gotchas (runtime-validated)\n\n## Hard-won gotchas\n\n1. **Always compile before deploy.** `tia_compile` aggregates **hardware + software**; a\n **clean** compile (`errors:0`) is the precondition for download and for S7 connections.\n2. **The serve is a SINGLE serial worker** \u2014 one Openness op at a time. Do **not** fire\n concurrent `tia_*` calls; a hung Openness op can stall the serve (may need a restart).\n3. **Changing an FB\'s interface (e.g. regenerating it via `tia_source_put`) leaves its\n instance DB inconsistent.** Recompile FIRST: a software-scope `tia_compile` regenerates\n the instance DB in most cases \u2014 read the compile result\'s **`blockChanges`** (`tia_compile`\n and `tia_source_put {compile:true}` both return it): a `"change":"modified"` entry on the\n instance DB is your confirmation it was regenerated \u2014 **export and commit it**\n (`tia_export_block`/`tia_block_compare`) so what\'s versioned matches the project. Only if\n the DB still reports inconsistent after a compile, delete it (`tia_block_delete`),\n recreate it (`tia_instancedb_create`) and recompile.\n4. **Firmware rule: project FW \u2264 device FW.** Bump the project FW **in-place** with\n `tia_device_change_version` (`DeviceItem.ChangeType`), which preserves the **program** \u2014 never\n set the project higher than the physical CPU. **\u26A0\uFE0F It RESETS GUI-gated comm settings** (the\n **OPC UA server activation** + **runtime-license**; the server interface and PUT/GET survive):\n **archive first** (`tia_project_archive`) on a CPU with hand-configured OPC UA, recompile after\n (it marks blocks inconsistent), and re-verify. Same-version `ChangeType` is rejected.\n5. **Use a NON-optimized DB** for Modbus (`MB_HOLD_REG`) and S7 (absolute addressing); OPC UA\n works with optimized or not.\n6. **Order numbers use `/V<fw>`, not `:V<fw>`** (guard Gd5).\n7. **A station upload (`tia_upload`) ADDS a new station to the open project \u2014 back up into a\n dedicated EMPTY project.** Observed on hardware (S7-1200 1214C, 2026-09-26): the upload read\n the CPU into an empty project (0 \u2192 1 device, twice) in ~75 s (76.7 s and 74.2 s); the CPU\n stayed in RUN the whole time (owner watching its LEDs during the second upload). Protect the\n working project FIRST: `tia_project_create` closes the current project, and serve refuses it\n (`409 unsaved_changes`) while that project has unsaved changes \u2014 so `tia_project_save` +\n `tia_project_archive` before creating the backup project (never pass `discardUnsavedChanges` to\n get past the refusal) \u2014 and pass the archive `name` WITH the `.zap21` extension (`name` absent\n or extension-less fails; with `.zap21` it archived 1.6 MB).\n8. **One wrong know-how password can lock a block for the session.** Observed on the bench\n (2026-10-12): after one rejected unprotect (`tia_block_protect {protect:false}`), TIA refused\n the CORRECT password of that block for the rest of the session (cause not confirmed \u2014 possibly\n brute-force protection). Never retry with a guess \u2014 ask the human for the password (G6); if a\n password the human confirms is refused, stop and hand off instead of retrying.\n9. **`unsaved_changes` and `binding_conflict` are refusals, not faults: nothing was changed.**\n `tia_connect`, `tia_project_close`, `tia_disconnect` and `tia_project_create` answer\n `409 unsaved_changes` when the call would close a project with unsaved changes (the error lists\n each one). ASK the human; the recommended answer is to repeat the same call with\n `saveUnsavedChanges:true`. Pass `discardUnsavedChanges:true` (data loss) ONLY when the human\n explicitly decides to throw the work away, never to make the error go away (the client then asks\n the human to confirm in its own dialog; `declined_by_human` = nothing was sent, stop).\n `409 binding_conflict` means the project this session is bound to is no longer the one open in\n the bound TIA (closed, replaced or Save As done by hand; `tia_status` shows `boundProjectPath`\n and `bindingDrift`): ask the human which project is intended, then `tia_connect` with the bound\n path (back to it) or the open one (adopt it) \u2014 do not repeat the refused call first.\n10. **`503 audit_unavailable`: the serve could not write its audit log, so it refused the call BEFORE\n running (nothing reached the PLC).** Have the human fix the disk or permissions, then re-plan.\n An `auditWarning` in a response = the call ran but was not fully recorded: report it.\n\n## Prerequisites (environment)\n\n- The **`tia` serve must be running** (default `http://localhost:5000`, e.g.\n `TIAOpenness.exe serve 5000`). The MCP is a pure HTTP client; point it at the serve host via\n `TIA_API_BASE` if it runs elsewhere.\n- The Windows user must belong to the **"Siemens TIA Openness"** local group.\n-
|
|
23954
|
+
var GUI_GATES = '# GUI gates \u2014 expected human interaction points\n\n## Human interaction points (GUI gates) \u2014 EXPECTED, not an error\n\nSome TIA settings are **not reachable via Openness** on the S7-1200/1500. The harness will hit a\nsignal that *looks* like an error but is actually a point where a **human must act in the TIA GUI**.\nWhen you see one of these, **do not treat it as a failure and do not retry blindly** \u2014 recognize it,\ntell the human the **exact GUI steps**, and resume after they confirm. A GUI gate is a *handoff*, not a *bug*.\n\n| # | Signal you\'ll see | Why it\'s expected | Tell the human (exact GUI steps) |\n|---|---|---|---|\n| **G1 trust** | `tia_connect` returns `requires_human_action` (`trust_dialog`) only for `EngineeringSecurityException`; a failed start with `details.cause:"trust"` is also explicit G1 evidence. `running` is not G1: the operation may still be starting or waiting for a dialog. A 20-minute timeout without evidence returns the error state `STARTING_UNCONFIRMED`, not success or G1. | TIA shows a one-time security prompt the first time an Openness app attaches, **per process** | On the **serve host**, click **"Yes to all"** only if the trust dialog is visible. For a `running` lifecycle job, follow its conditional hint and keep polling `tia_job_status`. A timeout does not cancel the operation; the serial worker may remain occupied. Do not queue serve calls. Ask a human to inspect the host; confirm G1 only if a dialog is visible. Wait for completion before status checks or retry. After a G1 handoff, confirm the dialog and re-call `tia_connect` with the `resumeToken`. For `TRUST_DIALOG_DENIED_OR_EXPIRED`, the serve lists what it closed (`closedPids`), what is still running (`stillRunningPids`) and what it could not confirm (`unknownPids`) \u2014 close any still-running TIA (no project inside) before re-calling, and for an unconfirmed pid first verify in Task Manager that it is a TIA Portal started by this serve with no open project, with a human ready to click **"Yes to all"**. |\n| **OPC UA license** | `tia_compile` **ERROR**: *"The selected OPC UA license is not sufficient\u2026"* | License selection is GUI-only (no Openness service); a fresh project **or a firmware change** leaves it unset | CPU \u2192 **Properties \u2192 General \u2192 Runtime licenses \u2192 OPC UA** \u2192 *Type of required license* \u2192 select **"SIMATIC OPC UA S7-1200 Basic"** (the 1214C option), and *Type of purchased license* \u2192 the license the CPU holds (the human declares it; left at "No license" the compile still reports *"Type of purchased license: The selected OPC UA license is not sufficient"*). Recompile. |\n| **OPC UA interface** | OPC UA client connects but the DB nodes aren\'t there (`ns=4` empty / no `ServerInterfaces`) | The **S7-1200 does NOT auto-expose DBs** (unlike the S7-1500) \u2014 a server interface must be created by hand | CPU \u2192 **OPC UA \u2192 Server interfaces \u2192 Add new server interface** \u2192 add/drag the DB (e.g. `ModbusData`) into it. Recompile; data appears under `ns=4`. |\n| **PUT/GET** | S7 client (`nodes7`/`snap7`) connects on port 102 but reads return access-denied (`ROSCTR=2` / "BAD") | *"Permit access with PUT/GET"* is a GUI-only protection setting | CPU \u2192 **Properties \u2192 Protection & Security \u2192 Connection mechanisms** \u2192 check **"Permit access with PUT/GET communication from remote partner"**. Compile + download (`hardware:true`). |\n| **FW-change reset** | After `tia_device_change_version`: OPC UA server off, the license error on compile, blocks `isConsistent:false` | `DeviceItem.ChangeType` **resets GUI-gated comm settings** (server activation + license); the interface & PUT/GET survive | `tia_project_archive` **before** the FW change. After: re-set `OpcUaServer:true` via `tia_obj_set_attributes` (scriptable), re-select the license (row above), recompile. |\n\n**Not a gate (now scriptable):** *activating* the OPC UA server \u2014 `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}`\non the "OPC UA" device-item (it auto-generates the server certificate). Only the **license** and the\n**server interface** stay GUI-only.\n';
|
|
23955
|
+
var GOTCHAS = '# Hard-won gotchas (runtime-validated)\n\n## Hard-won gotchas\n\n1. **Always compile before deploy.** `tia_compile` aggregates **hardware + software**; a\n **clean** compile (`errors:0`) is the precondition for download and for S7 connections.\n2. **The serve is a SINGLE serial worker** \u2014 one Openness op at a time. Do **not** fire\n concurrent `tia_*` calls; a hung Openness op can stall the serve (may need a restart).\n3. **Changing an FB\'s interface (e.g. regenerating it via `tia_source_put`) leaves its\n instance DB inconsistent.** Recompile FIRST: a software-scope `tia_compile` regenerates\n the instance DB in most cases \u2014 read the compile result\'s **`blockChanges`** (`tia_compile`\n and `tia_source_put {compile:true}` both return it): a `"change":"modified"` entry on the\n instance DB is your confirmation it was regenerated \u2014 **export and commit it**\n (`tia_export_block`/`tia_block_compare`) so what\'s versioned matches the project. Only if\n the DB still reports inconsistent after a compile, delete it (`tia_block_delete`),\n recreate it (`tia_instancedb_create`) and recompile.\n4. **Firmware rule: project FW \u2264 device FW.** Bump the project FW **in-place** with\n `tia_device_change_version` (`DeviceItem.ChangeType`), which preserves the **program** \u2014 never\n set the project higher than the physical CPU. **\u26A0\uFE0F It RESETS GUI-gated comm settings** (the\n **OPC UA server activation** + **runtime-license**; the server interface and PUT/GET survive):\n **archive first** (`tia_project_archive`) on a CPU with hand-configured OPC UA, recompile after\n (it marks blocks inconsistent), and re-verify. Same-version `ChangeType` is rejected.\n5. **Use a NON-optimized DB** for Modbus (`MB_HOLD_REG`) and S7 (absolute addressing); OPC UA\n works with optimized or not.\n6. **Order numbers use `/V<fw>`, not `:V<fw>`** (guard Gd5).\n7. **A station upload (`tia_upload`) ADDS a new station to the open project \u2014 back up into a\n dedicated EMPTY project.** Observed on hardware (S7-1200 1214C, 2026-09-26): the upload read\n the CPU into an empty project (0 \u2192 1 device, twice) in ~75 s (76.7 s and 74.2 s); the CPU\n stayed in RUN the whole time (owner watching its LEDs during the second upload). Protect the\n working project FIRST: `tia_project_create` closes the current project, and serve refuses it\n (`409 unsaved_changes`) while that project has unsaved changes \u2014 so `tia_project_save` +\n `tia_project_archive` before creating the backup project (never pass `discardUnsavedChanges` to\n get past the refusal) \u2014 and pass the archive `name` WITH the `.zap21` extension (`name` absent\n or extension-less fails; with `.zap21` it archived 1.6 MB).\n8. **One wrong know-how password can lock a block for the session.** Observed on the bench\n (2026-10-12): after one rejected unprotect (`tia_block_protect {protect:false}`), TIA refused\n the CORRECT password of that block for the rest of the session (cause not confirmed \u2014 possibly\n brute-force protection). Never retry with a guess \u2014 ask the human for the password (G6); if a\n password the human confirms is refused, stop and hand off instead of retrying.\n9. **`unsaved_changes` and `binding_conflict` are refusals, not faults: nothing was changed.**\n `tia_connect`, `tia_project_close`, `tia_disconnect` and `tia_project_create` answer\n `409 unsaved_changes` when the call would close a project with unsaved changes (the error lists\n each one). ASK the human; the recommended answer is to repeat the same call with\n `saveUnsavedChanges:true`. Pass `discardUnsavedChanges:true` (data loss) ONLY when the human\n explicitly decides to throw the work away, never to make the error go away (the client then asks\n the human to confirm in its own dialog; `declined_by_human` = nothing was sent, stop).\n `409 binding_conflict` means the project this session is bound to is no longer the one open in\n the bound TIA (closed, replaced or Save As done by hand; `tia_status` shows `boundProjectPath`\n and `bindingDrift`): ask the human which project is intended, then `tia_connect` with the bound\n path (back to it) or the open one (adopt it) \u2014 do not repeat the refused call first.\n10. **`503 audit_unavailable`: the serve could not write its audit log, so it refused the call BEFORE\n running (nothing reached the PLC).** Have the human fix the disk or permissions, then re-plan.\n An `auditWarning` in a response = the call ran but was not fully recorded: report it.\n\n## Prerequisites (environment)\n\n- The **`tia` serve must be running** (default `http://localhost:5000`, e.g.\n `TIAOpenness.exe serve 5000`). The MCP is a pure HTTP client; point it at the serve host via\n `TIA_API_BASE` if it runs elsewhere.\n- The Windows user must belong to the **"Siemens TIA Openness"** local group.\n- A first connection per serve process may show a trust dialog; a human confirms it on the serve host. A slow start or timeout alone is not G1 evidence.\n';
|
|
23948
23956
|
var PIPELINE = '# The build pipeline (spec \u2192 verified project)\n\nStages in order \u2014 the class tells you what each stage may do:\n\n| # | Stage | Tool(s) | Class | What it does |\n|---|---|---|---|---|\n| 0 | Validate the spec | `tia_spec_validate` | R (pure) | Partial shape checks + the cross-field rules the tool implements: unique names, IP inside the subnet CIDR, Gd5 order-number format, no STL/GRAPH on S7-1200, the G5 safety rule, at most 8 SMs on an S7-1200. It does NOT run the JSON Schema or per-model module limits; the `spec-validate` skill covers both. Needs no serve. |\n| 1 | Plan | `tia_spec_plan` | R (pure) | Turns a VALID spec into the ordered list of M-off operations. Nothing mutates. |\n| 2 | Scaffold | `tia_spec_apply` (or the M-off tools manually) | M-off | Creates part of the project content in dependency order (scope below). Stops at every gate. |\n| 3 | Verify | `tia_compile` | M-off | THE offline verifier: aggregates hardware + software. Gd8: only ERRORs block. `errors:0` is the Gd9 precondition for any deploy. |\n| 4 | Handoff / deploy | `tia_download` | GATE G3 | `dryRun:true` asks serve for a VERIFIED plan (clean compile, resolved connection, software fingerprint) \u2192 plan + `planHash` \u2192 a HUMAN approves \u2192 re-call with `approved:true` + the SAME `planHash` (serve re-checks the fingerprint and refuses `plan_stale` if the software changed). The approval covers the connection/options and the covered software content \u2014 NOT the hardware configuration (a hardware change after approval passes the token check). Re-plan (new dryRun) + fresh human approval only when the hardware configuration changed AFTER the dryRun that produced the token \u2014 the fingerprint cannot detect that change, so the human must confirm nothing hardware-side moved; never reuse the old token for changed hardware. The fingerprint covers only user program blocks, UDTs and tag tables (what it leaves out, the `source:"dates"` fallback: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 download plan fingerprint limits\'). Never self-approve. Pick the connection with `tia_pg_interfaces` (no scan). |\n\nScaffold order (UDTs BEFORE the blocks that use them): by hand, `tia_guide {"topic":"recipes"}`, \'Pipeline order\'. `tia_spec_apply` automates only subnets, devices, modules, network, tag tables, tags, FB shells, control-module instance DBs and the compile; protection, constants, UDTs and all logic stay manual. The FB shells it creates are empty: add their logic with `tia_source_put` (SCL) or `tia_import_xml` (LAD/FBD).\n\nPLC-scoped steps use the PlcSoftware (e.g. `PLC_1`) read after the device step, not the device name.\n\n## The approval envelope (what a gate handoff looks like)\n\nGated tools return `status:"requires_human_action"` with:\n\n- `gate` \u2014 which gate (e.g. `download_approval`, `station_upload`, `go_online`, `trust_dialog`);\n- `youMustDo` \u2014 what the human must confirm, in plain words;\n- `plan` + `planHash` \u2014 exactly what would be executed (the hash binds the approval to\n this exact plan; a changed plan needs a new approval); the download\'s plan also carries\n `fingerprint` (the software content the plan was verified against \u2014 show it too);\n- `nextSteps` \u2014 how to resume after the human\'s yes.\n\nRelay the envelope to the human, wait for an explicit yes, resume exactly as\ninstructed. The AI never approves, never invents a secret, never deploys F-logic.\n\n**Confirmation dialog.** When the client supports elicitation, the crossing calls (`tia_download` with\n`approved:true`; `tia_upload`, `tia_online`, `tia_accessible_devices` with `confirm:true`) first ask the\nhuman in a dialog; clients without it behave as before. The dialog only checks the human\'s answer: the\n`planHash` and serve\'s approval token stay the authority.\nPasswords (G6) are never asked there. `declined_by_human` / `cancelled_by_human` = the human refused:\nnothing was sent, no retry unless asked. `elicitation_failed` (`isError`) = the dialog could not be\nshown or answered, nothing was sent (fails closed).\n\n## After scaffolding\n\n- Re-run `tia_compile` after ANY authoring change.\n- `tia_project_save` regularly; `tia_project_archive` BEFORE risky operations\n (firmware change \u2014 see `tia_guide {"topic":"gotchas"}`).\n- Auditing an existing project is class R (`tia_plc_*` reads); baseline: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 network, audit and CAx how-to\'.\n- `tia_crossrefs` (class R, a long read: it may answer `status:"running"` + `jobId`, then poll\n `tia_job_status`) reads the cross-references: in an audit, `filter:"UnusedObjects"` lists\n unused-object CANDIDATES, never proof (OBs, objects used only from outside the PLC such as an\n HMI, OPC UA or another CPU, and library TYPEs show as unreferenced); before changing an\n existing object, `target` + `kind` + `filter:"ObjectsWithReferences"` returns the objects related\n to it with each `referenceType` and `access` as TIA reports them (the direction of `Uses` /\n `UsedBy` is not interpreted: the human confirms it). Page a whole-PLC or container read with `limit`\n (for example 200) and `cursor` (the `nextCursor` of the previous page, until it is null; on\n `cursor_stale` restart from the first page, and on an omission marker repeat the same request\n with a smaller `limit`, never following a cursor from an omitted page); each page re-reads the\n whole PLC, so a later page can report less than an earlier one. Read `coverage` on every page,\n not only the first, and compare its counts across pages: differing counts restart the walk once\n from the first page (like `cursor_stale`). Only a finished walk whose pages all report\n `coverage.complete: true` supports "audited completely" or "nothing uses this"; an omission\n marker, an unfinished walk, differing counts or `coverage.complete: false` on any page (see\n `coverage.unavailableOwners`) means the result is NOT complete.\n- **FAT/SAT I/O list** (`tia-verify` step 6): `tia_io_map`; recipe: `tia_guide {"topic":"recipes"}`, \'Recipe \u2014 generate the FAT/SAT I/O list\'.\n- **Prove the project matches what\'s versioned** (a raw hash is NOT proof): `tia_guide {"topic":"recipes"}`, \'Recipe \u2014 prove the project matches the versioned XML\'.\n\n## Network lifecycle (subnets, PROFINET names, IO systems)\n\nRead first (`tia_subnet_get`, `tia_device_network`, `tia_io_systems`), then run each write\'s `dryRun` (answered by\nthe serve, needs an open project). Order, PROFINET names, `disconnectNodes`: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 network, audit and CAx how-to\'.\n\n- **Refused, nothing changed:** `tia_subnet_delete` of a non-empty subnet (`409 subnet_not_empty`);\n `tia_io_system_connect` across subnets (`409 cross_subnet_assignment`: `tia_network_connect` the device to that subnet first).\n- **`409 postcheck_failed`:** the write did not take effect as asked: re-read, never repeat blindly.\n\n## Libraries, HMI, CAx and PLC security\n\nReads are class R; every change is class M-off (offline, with `dryRun`) and reaches the CPU\nonly through a later `tia_compile` + human-gated `tia_download` (G3). Every file path is a\npath ON THE SERVE HOST.\n\n- **Guarded PLC writes** (`tia_tag_update`, `tia_constant_update`, `tia_constant_delete`,\n `tia_tagtable_delete`, `tia_block_group_delete`, `tia_ob_create`, `tia_block_compile`): the serve\n answers their `dryRun` (it needs an open project) with the guard verdict (name collision, default\n tag table, non-empty group, singleton OB).\n- **Project library:** `tia_library_mastercopies` / `tia_library_types` read it;\n `tia_library_mastercopy_create` turns a DEVICE into a master copy (a block cannot be a source);\n `tia_block_from_mastercopy` needs one that holds PLC blocks.\n- **Global libraries** (in the TIA Portal session, not the project): `tia_global_libraries`,\n `tia_global_library_create` / `_open` / `_save` / `_close`; save/close take the name from\n `tia_global_libraries` (exact name first, then ignoring case). REFUSED, nothing saved or closed\n (`404 not_found` / `409 conflict`): a name that picks no single open USER library (unknown, read-only\n system/corporate, several matches ignoring case) and a save of a `readWrite:false` library. Up to app\n 1.6.3 an unknown name can report success without saving or closing anything: check `tia_global_libraries`.\n- **HMI:** `tia_hmis` and `tia_hmi_screens` read any HMI; screen files\n (`tia_hmi_screen_export`, `tia_hmi_screens_import`) work for WinCC **Classic** only, and the\n import OVERWRITES same-named screens.\n- **CAx (AutomationML):** `tia_cax_export` / `tia_cax_import` (scope, `option` values: recipes). Archive the\n project before an overwrite. A failed transfer is an error after app 1.6.3; on an older serve check the\n devices with `tia_devices`.\n- **Error contracts by app version:** `tia_guide {"topic":"recipes"}`, \'Reference \u2014 global library and CAx error contracts (by app version)\'.\n- **PLC security:** `tia_certificates` / `tia_certificate_template` / `tia_password_policy`\n read; `tia_certificate_import` / `_export` / `_delete`, `tia_password_policy_set` and\n `tia_block_protect` change the project. **G6:** a block or certificate password and the\n password-policy values come from a HUMAN \u2014 never invent, guess or reuse one; dryRun plans\n show a password as `[redacted]`. A CPU without the certificate manager or a policy service\n answers 409.\n- **Multiuser:** `tia_project_servers`, `tia_server_projects` read Project Servers; `tia_local_session_open` needs NO open project (`tia_project_close`, `tia_start`). Nothing is ever checked in.\n';
|
|
23949
23957
|
var RECIPES = '# Recipes (runtime-verified) & scaffold order\n\n## Pipeline order (dependency-correct)\n\n`tia_spec_apply` automates only steps 1-4, the tag tables and tags of 6, the FB shells and control-module instance DBs of 8, and the compile of 9. Protection (5), constants (6), UDTs (7), OB/FC/DB blocks and all block logic stay manual: declaring `dataTypes` in the spec imports nothing. The FB shells of 8 are empty: their logic is step 8 by hand.\n\n1. **Subnets** (`tia_subnet_create`) \u2014 before connecting devices to them.\n2. **Devices** (`tia_device_create`, `OrderNumber:<MLFB>/V<fw>`) \u2014 CPUs first.\n3. **Modules** (`tia_device_plug`) \u2014 into existing devices, by slot.\n4. **Network** (`tia_network_connect`, IP, `createIoSystem`) \u2014 CPU + its IO-devices on the\n **same** subnet; exactly one `createIoSystem` per IO-system.\n5. **Protection recipe** (below) \u2014 so the CPU can compile clean.\n6. **Tag tables** (`tia_tagtable_create`) \u2192 **tags** (`tia_tag_create`) \u2192 **constants**.\n7. **UDTs first** (`tia_types_import`), **then** blocks that use them.\n8. **Blocks** \u2014 the FB comes with its logic: `tia_source_put` (SCL) or `tia_import_xml` (LAD/FBD/GRAPH), Gd6 format\n routing (`tia_fb_create` only makes an empty FB shell); then its instance DB (`tia_instancedb_create`).\n9. **Compile** (`tia_compile`) \u2014 the verifier; only `Error` blocks. It compiles the **software**\n scope (not just the CPU device item), so it makes freshly-generated blocks consistent and, in\n most cases, **regenerates** any instance DB left inconsistent by an FB interface change.\n **Recompile first**; only if the DB still reports inconsistent after a compile, delete it\n (`tia_block_delete`), recreate it (`tia_instancedb_create`) and recompile.\n\n**The PlcSoftware name.** TIA names the PlcSoftware of a CPU created through `tia_device_create` or `tia_spec_apply` after the CPU device item (default `PLC_1`), not the device, so `plc` in steps 6-9 is the name from `tia_plcs`. The spec plan carries `{plc}`; `tia_spec_apply` resolves it after the device step (`plc.resolve` in `applied`) and stops with kind `plc_unresolved` rather than guess. `devices[].plcName` names the CPU item.\n\n## Recipe \u2014 edit an existing block or type without overwriting a newer change (stale-write guard)\n\nRead it with `tia_export_block` (block) or `tia_export_type` / `tia_type_source` (type) and keep its `contentHash`: `contentHash`, `normalizedSha256` and `sha256` are different hash contracts over different normalizations, so never substitute one for another and pass only the `contentHash` of a fresh read as `expectedContentHash`. Edit, then write it back with `tia_import_xml`, `tia_source_put` or `tia_types_import` passing `expectedContentHash:<that contentHash>` (one object per write); on `state_changed` NOTHING was written \u2014 re-read, merge your edit onto the current content and retry with the new `contentHash`; a guarded write never compiles, so a block that is not consistent is refused with `409 inconsistent` (NOTHING written) \u2014 `tia_compile`, re-read with `tia_export_block` for the current `contentHash`, retry; an object whose current export is not well-formed XML has no hash (its read answers `contentHashError` instead of `contentHash`) and a guarded write over it is refused with `409 unverifiable` (NOTHING written) \u2014 repair or re-export it in TIA Portal, or retry WITHOUT `expectedContentHash` (an unguarded write); a verified write returns `contentGuard`.\n\n## Recipe \u2014 unlock a freshly-created CPU so it compiles clean (VERIFIED V21, firmware-dependent)\n\nA bare CPU added via Openness may fail `compile` with **protection** errors: the\n*confidential-PLC-configuration-data* password is unset, the *communication certificate*\ncan\'t be generated without it, and (on newer firmware) the *access control* defaults to a\nprotected level needing a password. **The recipe differs by CPU family/firmware \u2014 there is\nno single universal form.** Fix, in order:\n\n**Tell the human first.** The recipe lowers the CPU\'s protection in the project: it sets the\nconfidential-configuration password (typed by the human) and then either sets the access level\nto **Full access** (S7-1500) or turns access control **off** (S7-1200, FW V4.5+). The CPU runs\nwith that protection after the next download. Name these changes when you ask for the password\nand list them in the report; the human may pick a stricter level in the TIA GUI before deploying.\n\n**(1) Confidential-data password \u2192 also auto-generates the certificate** (common to both\nfamilies):\n\n```\n# find the CPU device-item handle:\ntia_obj_roots -> the device handle (role:"device")\ntia_obj_items { handle:<device>, composition:"DeviceItems" } -> the CPU item handle\n# acquire the service ON THE CPU MODULE (not the rack) and invoke Protect:\ntia_obj_service { handle:<cpu>, type:"Siemens.Engineering.HW.Features.PlcMasterSecretConfigurator" } -> <svc>\ntia_obj_invoke { handle:<svc>, name:"Protect", args:["<password>"] }\n```\n\n**(2) Clear the access-control error \u2014 pick the variant for the CPU\'s family/firmware:**\n\n- **S7-1500 V2.9** (verified 2026 on real hardware \u2014 a 1516-3 V2.9, 3 errors \u2192 0): set\n `PlcProtectionAccessLevel = "FullAccess"` **on the CPU device item**:\n\n ```\n tia_obj_set_attributes { handle:<cpu>, attributes:{ "PlcProtectionAccessLevel":"FullAccess" } }\n ```\n\n- **S7-1200 V4.7** (new security model, FW \u2273 V4.5; per `docs/HARNESS-KNOWLEDGE.md` \xA72,\n runtime-observed): set `PlcAccessControlConfiguration = "Disabled"` on the\n **`PlcAccessControlConfigurationProvider`** SERVICE \u2014 not a direct attribute on the CPU\n item:\n\n ```\n tia_obj_service { handle:<cpu>, type:"Siemens.Engineering.HW.Features.PlcAccessControlConfigurationProvider" } -> <svc2>\n tia_obj_set_attributes { handle:<svc2>, attributes:{ "PlcAccessControlConfiguration":"Disabled" } }\n ```\n\n \u26A0\uFE0F **The two variants are mutually exclusive \u2014 the wrong one returns HTTP 500 on the\n other family:** `PlcAccessControlConfiguration` isn\'t on a 1500\'s CPU item, and\n `PlcProtectionAccessLevel` isn\'t the right model on a 1200 V4.7 item. Detect the\n family/FW \u2014 or the compile-error signature \u2014 before picking a variant.\n\n- **S7-1200 V4.0** (old security model): nothing to do here \u2014 the same bare-CPU condition\n is only a **WARNING**, not an error; a plain `tia_compile` already returns `errors: 0`.\n\nThen `tia_compile` \u2192 `state: Warning, errors: 0` (any remaining warnings \u2014 e.g. CPU-display\npassword \u2014 are benign and do **not** block; Gd8).\n\n> **Requires the `tia_obj_service` tool** (acquire `GetService<T>` \u2192 handle) for step 1 and\n> for the S7-1200 V4.7 variant of step 2. Without it the MCP cannot run either.\n\n### Policy \u2014 who supplies the confidential password\n\n`Protect()` sets an **offline project** password (it is not the online master secret / G6), but\nit protects confidential configuration data, so **the human supplies it, every time** (the\nrecommended policy, pending the product owner\'s confirmation): the project-spec has no field\nfor it, and a skill never invents, defaults, stores or logs it. The online master secret (`tia_mastersecret_set`, G6) is **always**\nhuman-supplied too.\n\n## S7 connection precondition (G2)\n\n`tia_connection_create` needs **\u2265 2 CONSISTENT CPUs** (both compile clean). Two *bare* CPUs\nnever form a valid S7 connection \u2014 apply the protection recipe + `tia_compile` to make each\nconsistent first, then create the connection. Use `tia_connections_diagnose` on failure.\n\n## Recipe \u2014 bump the project firmware **in-place** (keeps the program) (VERIFIED, V21 / S7-1200 1214C)\n\nBumped a project **V4.0 \u2192 V4.4** on a real S7-1200 1214C **without losing blocks or tags**\n(verified 2026-06-07). Use this for **auto-FW-match**: align the project to the firmware\nactually read from the CPU. `DeviceItem.ChangeType(typeIdentifier)` changes the item type\nin place and **preserves the software** \u2014 it does **not** require delete/recreate.\n\n```\n# archive first (see the warning below), then change the CPU\'s type to the SAME MLFB with the target /V<fw>:\ntia_device_change_version { plc:"<plc>", typeIdentifier:"OrderNumber:6ES7 214-1HG40-0XB0/V4.4" }\n# then recompile \u2014 a regenerated FB may need a fresh compile before download:\ntia_compile { ... }\n```\n\n(`tia_device_change_version` runs `ChangeType` on the CPU item for you; the raw form, `tia_obj_invoke`\nwith `name:"ChangeType"` on the CPU item handle from `tia_obj_roots` / `tia_obj_items`, does the same.)\n\n- **Rule: `project FW \u2264 device FW`** \u2014 never set the project firmware **higher** than the physical\n device\'s (download would be rejected). Bumping the project *up to* the device FW is the safe move.\n- Keep the **same MLFB**, swap only the `/V<fw>` suffix. The program (blocks/tags) survives.\n- After `ChangeType` the CPU/blocks can be inconsistent; **always recompile** before any handoff.\n- **\u26A0\uFE0F `ChangeType` RESETS GUI-gated comm settings** (runtime-validated on the 1214C): it **disabled\n the OPC UA server** (`OpcUaServer`\u2192`false`) and **cleared the OPC UA runtime-license** selection\n (the custom server interface and PUT/GET *survived*). So **`tia_project_archive` first** on a CPU\n with hand-configured OPC UA/PUT-GET, and **re-verify after**. Recovery: `tia_obj_set_attributes\n {handle, attributes:{OpcUaServer:true}}` on the "OPC UA" device-item (it **is** writable; re-select the license in the\n GUI). `ChangeType` to the **same** version is rejected ("Cannot change the type of the device item").\n\n## Recipe \u2014 enable a **Modbus TCP server** (`MB_SERVER`) on the S7-1200 (VERIFIED, FW V4.0)\n\nLets an external client (e.g. a Node backend) read/write the CPU over **Modbus TCP, port 502**\n(verified 2026-06-07; full backend/app detail in `docs/COMM-SCENARIOS.md`).\n\n1. **Non-optimized DB with an `Array of Word`** for the holding-register block (`MB_HOLD_REG`).\n Modbus needs a byte-addressable (non-optimized) DB \u2014 optimized access won\'t map.\n2. **On FW V4.0 use `MB_SERVER` V1.x**, which takes **`CONNECT_ID` + `IP_PORT`** parameters\n (**not** `CONNECT`/`TCON`, which the newer instruction versions use). Pin the instruction\n version when generating the FB.\n3. Instantiate `MB_SERVER` as a **multi-instance inside an FB** (its instance lives in the FB\'s\n instance DB), call it cyclically.\n4. **Map a holding register \u2192 a command tag** (e.g. `MB_HOLD_REG[0]` \u2192 `LedCmd`), so writing the\n register drives the output.\n\n> **Instance-DB gotcha (the big one):** when you regenerate the FB via `tia_source_put`, the\n> existing **instance DB** can go inconsistent (its interface no longer matches the FB).\n> **Recompile first** \u2014 a software-scope `tia_compile` regenerates the instance DB in most cases.\n> Only if it still reports inconsistent after a compile (typical when the interface was edited via\n> source), delete + recreate it, then recompile:\n>\n> ```\n> tia_compile { ... } # try first\n> tia_block_delete { ... the stale instance DB ... } # only if still inconsistent\n> tia_instancedb_create { ... fresh instance DB for the FB ... }\n> tia_compile { ... }\n> ```\n>\n> (Matches the \xA7Pipeline note: recompile first, delete+recreate only as the fallback.)\n\n## Recipe \u2014 enable **S7 / PUT-GET** on the S7-1200 (port 102)\n\nLets an external S7 client (e.g. `nodes7`) read/write the CPU over **S7comm, port 102**.\n\n1. **GATE (human, GUI only):** enable PUT/GET \u2014 *Properties \u2192 Protection & Security \u2192\n Connection mechanisms \u2192 "Permit access with PUT/GET communication"*. **Not exposed by\n Openness** on this CPU/FW (we tried `PlcAccessLevelProvider` \u2014 no toggle). Mark it as a\n **human gate** and surface it in `tia-handoff`; do **not** attempt to script it.\n2. **Non-optimized DB** for the data the client touches (PUT/GET addresses absolute offsets, so\n the DB must be byte-addressable / non-optimized).\n3. Compile + download as usual; the client then reads/writes the DB by area+offset.\n\n## Recipe \u2014 enable **OPC UA** on the S7-1200 (port 4840)\n\nLets an external OPC UA client read/write the CPU over **OPC UA, port 4840**. This path is the\nmost gated \u2014 most of it is **human GUI steps**, not Openness.\n\n**Prerequisite \u2014 firmware \u2265 V4.4.** OPC UA server isn\'t available on V4.0. If the project is on\nan older FW, bump it in-place first (see *bump the project firmware in-place* above \u2014\n`ChangeType` to `.../V4.4`).\n\nThen the setup sequence. **Step 1 is scriptable; steps 2\u20133 are human/GUI** on this CPU/FW (for those two\nwe tried `CommunicationManagement` and `OpcUaUserManagement\u2192404`):\n\n1. **Activate the OPC UA server** \u2014 *Properties \u2192 OPC UA \u2192 Server* (enable). *(This step **is**\n scriptable via Openness: `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}` on the "OPC UA"\n device-item \u2014 it auto-generates the server certificate. Steps 2\u20133 stay GUI-only.)*\n2. **Select the runtime license** \u2014 *"SIMATIC OPC UA S7-1200 Basic"* (Runtime licenses).\n3. **Create a server interface** that **exposes the DB** \u2014 the **S7-1200 does NOT auto-expose**\n tags/DBs to OPC UA (unlike the S7-1500), so you must add a server interface and place the DB\n nodes in it manually.\n\n**Finding the node IDs (client side):** browse `ns=3;s=ServerInterfaces` with any OPC UA client;\nthe actual data nodes show up under **`ns=4`**. Use those node IDs from the backend.\n\n> What Openness *can* still do here: create the DB/blocks, compile, download \u2014 **and activate the OPC UA\n> server** (step 1: `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}`; do NOT gate it on a human). Only **three**\n> items are truly human/GUI: the **runtime license**, the **server interface** \u2014 and **PUT/GET** in the S7\n> recipe. See `docs/TIA-Openness-Casos-de-Uso.md` \xA78c for the full "GUI-only gates" table.\n\n## Recipe \u2014 WinCC Unified HMI: read, then guarded writes\n\nOnly for a WinCC **Unified** HMI (`tia_hmis` \u2192 `kind:"unified"`). A Classic HMI answers `409 hmi_not_unified`; use the screen export/import there. Everything below is offline (M-off): it edits the project, never the panel or the PLC.\n\n1. **Read first.** `tia_hmis` for the HMI name, then `tia_hmi_tag_tables`, `tia_hmi_tags` (`table`), `tia_hmi_alarm_classes`, `tia_hmi_alarms` (`kind`: `discrete`|`analog`) and `tia_hmi_connections`. Every read pages (`limit` 1..1000, `cursor`): follow `nextCursor` UNCHANGED, and on `cursor_stale` restart from the first page. Read `inventoryGaps` too: a non-empty list means a value reads `null` because Openness refused it, so do not write on the strength of that value.\n2. **Baseline.** `tia_hmi_validate` (scope `all`, or `tags`/`alarms`/`connections`/`screens`) aggregates the per-object `Validate()` results into `errors`, `warnings` and `findings`. Unified has NO compile: a clean validate is not a clean compile, and it can be slow (Long).\n3. **`dryRun:true` on EVERY write first** (`tia_hmi_tag_table_create|delete`, `tia_hmi_tag_create|update|delete`, `tia_hmi_alarm_create|update|delete`). The plan runs the same guards as the real call and changes nothing; repeat without `dryRun` only when it answers `plan_ok`. The real answer carries `postcheck` (`verified:true`, `requested` equal to `actual`). `409 postcheck_failed` is NOT a success: read the object again before going on (`rollback` says what was undone; a delete is never rolled back).\n4. **What the guards enforce \u2014 fix the cause, do not retry the same call.** Names: letters, digits and `_`, starting with a letter or `_` (tag tables may also hold spaces and `-` inside), at most 128 characters (`invalid_name`), unique ignoring case (`name_collision`). `dataType` is an allow-list: Bool, Byte, Char, DInt, DWord, Int, LInt, LReal, LWord, Real, SInt, String, UDInt, UInt, ULInt, USInt, Word, WChar, WString, DateTime, Time (`invalid_data_type`). A tag without `connection` is internal and needs `dataType`; with `connection` it is external and takes exactly one of `plcTag` or `address`. A PLC-bound tag needs a `plcTag` that EXISTS in the connected PLC (`plcName` when the connection\'s partner does not resolve to one PLC): `plc_unresolved` / `reference_not_found` mean fix the link, never invent a tag. A PLC tag whose own name contains a dot or a bracket is sent as ONE quoted token (`"A.B"`, `"Valve[1]"`): unquoted, `A.B` is member `B` of data block `A` and `Valve[1]` is an indexed name, so the call is refused. A discrete alarm needs an existing `alarmClass` and `triggerTag` and a `triggerBit` inside the width of the tag\'s type (Bool: 0, Word: 0..15; `trigger_bit_out_of_range`); an analog alarm has ONE `condition` and ONE `conditionValue` on a numeric tag (no limit ordering exists), and the value must fit the type (`condition_value_out_of_range`).\n5. **Alarm values, event text and what a read shows.** TIA stores the condition value of an alarm as a double: on an `LInt`, `ULInt` or `LWord` trigger tag a whole `conditionValue` above 2^53 in absolute value is refused `409 condition_value_out_of_range` (a `dryRun` too, nothing written); 2^53 itself is accepted, sent as a string, and `Real` and `LReal` values are always JSON numbers. `eventText` is PLAIN single-paragraph text per active project language: the serve wraps it as the rich text TIA stores (`<body><p>\u2026</p></body>`) and escapes `&`, `<` and `>`, so send no markup; a line break, an XML-invalid character (a tab is allowed), an unpaired surrogate, a blank text or more than 1024 characters is `400 bad_request`, and a text cannot be cleared by a write. A read answers the plain text (an event-text item without text is `""`, a language without an item `null`; any other markup comes back as raw rich text, which cannot be written back). TIA\'s placeholders read as `null`: an internal tag has `connection`, `plcName`, `plcTag`, `address`, `accessMode`, `acquisitionMode` and `acquisitionCycle` all `null` (TIA reads its connection back as a placeholder such as `<Internal tag>`), and an alarm class without a common class has `commonAlarmClass` `null` (`<No alarm class>`). The attribute list of an alarm itself is never read: `hmi_attribute_list_unavailable` and `hmi_attribute_not_writable` apply to tags and to the event text item of each culture (its list unreadable, `Text` not writable, or no item for that language), never to another alarm attribute.\n6. **Deleting.** A tag, or a tag table that holds one, is refused with `tag_in_use` while an alarm references it; a non-empty table needs `recursive:true` (`tag_table_not_empty`); the default table is refused. References from screens, scripts and logging are NOT scanned, so run `tia_hmi_validate` again after a delete.\n7. **Finish** with `tia_hmi_validate` and compare `errors` and `findings` with the baseline.\n\nLimits to remember: a **create\'s `dryRun` cannot check writability** (a `plan_ok` can still end in `hmi_attribute_not_writable`, after which the new object is removed again); an **update checks only what it changes** (a tag change against the stored bit or value, a connection change against its link), never a reference it leaves alone, and never switches a tag between `plcTag` and `address` \u2014 `tia_hmi_validate` finds a dangling carried reference; send a whole `conditionValue` as a **JSON integer or a string** (`5.0` and `1e3` are refused, and so is a whole value above 2^53 on an `LInt`, `ULInt` or `LWord` tag: step 5); a system tag may be an alarm trigger tag; `tia_hmi_validate` is Long, so it may answer `status:"running"` with a `jobId`: follow `tia_job_status` and never repeat the call.\n\nNo tool creates an HMI connection: when `tia_hmi_connections` is empty, PLC-bound tags cannot be created \u2014 ask the human to create the connection in TIA Portal.\n\n## Recipe \u2014 diff a project against a VCI workspace, or round-trip a block through a new one\n\nA VCI workspace is a folder on the serve host that mirrors project objects as files, so a diff tool or git can version\nthem. VCI takes **leaf objects only** (PLC blocks, PLC data types, tag tables): a device, a PLC, a group or the library is\nrefused with `409 vci_not_leaf` before VCI is called. Every write takes `dryRun:true` first (Gd11), a call holds at most 50\nobjects, and a batch is NOT a transaction: it stops at the first failure.\n\n**(1) A workspace that already has mapped objects is a baseline: its diff is READ-ONLY.**\n\n```\ntia_vci_workspaces -> `mappedObjects` above 0: a baseline exists\ntia_vci_status { workspace:"WS_1", limit:100 } -> follow nextCursor until it is null\n```\n\nClassify every row. `equal` is the only verified match. `projectChanged` (the project object changed), `workspaceChanged`\n(the file changed), `conflict` (both), `workspaceFileMissing` (the file is gone) and `unequal` (a difference of unknown\nside) are differences: report each by name, they are the result, not something to repair. `unknown`, `unsupported` and\n`statusFailed` prove nothing, neither equality nor a diff: report them by name, and the diff is NOT complete. **Never\nexport or import just to make a comparison equal.** `tia_vci_export` over a mapped object REPLACES its workspace file\nwith the project content (the plan says `action:"synchronize"`) and `tia_vci_import` replaces the project object with\nthe file, so either one destroys the difference you were asked to see. Refreshing the baseline is an explicit decision\nof the human: name the objects, ask, and only then export with `dryRun:true` first and read which files the plan\nreplaces.\n\n**(2) A NEW workspace, or new objects: export, then prove it.**\n\n```\n(a) tia_vci_workspaces -> reuse a workspace that is listed\n # none yet: ask the HUMAN for the root folder on the serve host. Never choose or invent a rootPath.\n tia_vci_workspace_create { name:"WS_1", rootPath:"<the folder the human gave>", dryRun:true }\n tia_vci_workspace_create { name:"WS_1", rootPath:"<the same folder>" } -> created | reused\n(b) tia_vci_export { workspace:"WS_1", objects:[{ kind:"block", name:"FB_Motor" }], dryRun:true }\n tia_vci_export { workspace:"WS_1", objects:[{ kind:"block", name:"FB_Motor" }] } -> the file(s) written\n(c) tia_vci_status { workspace:"WS_1", limit:100 } -> follow nextCursor until it is null\n(d) tia_export_block { plc:"PLC_1", block:"FB_Motor" } -> contentHash\n tia_block_set_attribute { plc:"PLC_1", block:"FB_Motor", name:"HeaderAuthor", value:"<a new text>" } -> an edit IN PLACE: the mapping survives\n tia_block_compile { plc:"PLC_1", block:"FB_Motor" }\n tia_export_block { plc:"PLC_1", block:"FB_Motor" } -> a DIFFERENT contentHash\n tia_vci_status { workspace:"WS_1", limit:100 } -> that row is now projectChanged\n(e) tia_vci_import { workspace:"WS_1", objects:[{ kind:"block", name:"FB_Motor" }], dryRun:true }\n tia_export_block { plc:"PLC_1", block:"FB_Motor" } -> a fresh contentHash\n tia_vci_import { workspace:"WS_1", objects:[{ kind:"block", name:"FB_Motor", expectedContentHash:"<fresh>" }] }\n tia_export_block { plc:"PLC_1", block:"FB_Motor" } -> the import REPLACED the project object: read it again by name\n tia_vci_status { workspace:"WS_1", limit:100 } -> that row is equal again\n```\n\n- **(b) Read the plan.** `action:"export"` creates a new file; `willCreateDirectory:true` on an object means the serve will\n create its target folder (the first export into a fresh workspace has none yet), and the dry run creates nothing. An\n object the plan lists as `synchronize` is already\n mapped and its file would be REPLACED: stop and go back to (1). `format` chooses the file format of an UNMAPPED object\n only (leave it out unless the serve answers `400 bad_request` with `details.supportedFormats`); a mapped object keeps its\n mapping\'s format and the selector is neither applied nor validated for it.\n- **(c) Verify an export.** Every row of every page must be `equal`. Read `coverage` on EVERY page: `summary` and\n `coverage` describe only the rows of that response (the serve compares only the rows of the page), so fold them over all\n pages before saying the workspace is in sync. `409 cursor_stale` (a mapping appeared or went) restarts the walk once.\n- **(d) Edit the project IN PLACE, never by regenerating.** A block attribute (`tia_block_set_attribute`, a header attribute such as `HeaderAuthor`) keeps the project object, so its mapping stays and the row becomes `projectChanged` (measured on V21). If `tia_export_block` shows the same `contentHash` afterwards, that attribute is not part of the exported XML: try another header attribute (`HeaderFamily`, `HeaderName`). `tia_source_put` (regenerating the block from SCL) REPLACES the project object, and V21 DROPS its VCI mapping (measured): the row vanishes from `tia_vci_status` and `tia_vci_import` answers `409 not_mapped`, which is the correct answer, not a fault; `tia_import_xml` over an existing block replaces it the same way (not measured separately). Export the new object again to map it: `tia_vci_export` is refused `409 vci_path_collision` (`reason:"file_exists"`) while the old workspace file is still in the folder, so ask the human to remove or move that file first; on a baseline you were asked to diff, report the dropped mapping instead of exporting over it.\n- **(d) What a row says.** Only `equal` is a match. After a human edits a workspace file its row should show\n `workspaceChanged`; a row that still says `equal` after a known edit means the status is not live (V21 has no refresh\n call): say so and treat the check as NOT verified.\n- **(e) Read the plan before importing, and read the hash per kind.** The dry run shows per object `statusBefore` and\n `overwritesProjectChanges` (`true` for `projectChanged` and `conflict`: the import discards an edit that exists only in\n the project, there is no undo, so ask the human). An object that is already `equal` is skipped. The hash reader depends\n on the kind: a block uses `tia_export_block`, a type uses `tia_export_type { plc:"PLC_1", type:"UDT_Motor" }`, and a tag\n table has NO hash (the serve and the MCP refuse `expectedContentHash` for it), so rely on the dry run and the postcheck.\n A wrong `expectedContentHash` is `409 state_changed` and nothing was written.\n- **An import REPLACES the project object.** After a real import the old object is disposed: a handle of it (`tia_obj_*`) and every value read before are stale, so re-read the block by name (`tia_export_block`, `tia_plc_blocks`) and then `tia_vci_status`. The serve does the same for its postcheck: an object it cannot find again by name, or whose mapping the replacement dropped, is `409 import_unverified` (the object WAS written). In a batch, an object that can no longer be found or mapped when its turn comes stops the batch there: `409 vci_batch_incomplete` naming it, or `409 conflict` when nothing was imported yet; nothing more is written.\n- **Verified only with a postcheck.** An import is done only when every imported object has `postcheck.verified:true`. Every\n other answer means it is NOT verified: `409 import_unverified` (the object WAS written, review it with `tia_export_block`\n or `tia_export_type`), `409 vci_batch_incomplete` (the objects in `done` WERE written), a status row `unsupported`,\n `statusFailed` or `unknown`, `coverage.complete:false`, an omission marker that survives smaller `limit` retries, or a\n page walk that did not finish.\n- **Unknown outcomes.** `504 worker_restarted`, a `timeout` or a lost session during an export or an import leaves the\n outcome UNKNOWN or partial: walk `tia_vci_status` and re-read the object before repeating anything.\n- **Refusals before any write** (nothing changed): `vci_path_collision` (two objects, another mapping or an existing file\n share a target; `reason:"alias_unverifiable"` means the short 8.3 name of an existing file in the target folder could not\n be read, so a collision with its alias cannot be excluded), `vci_path_too_long`, `vci_mapping_outside_workspace` for an\n EXISTING mapping rejected in the plan, `not_mapped` (export it first), `workspace_file_missing`, `workspace_exists`,\n `workspace_root_in_use`, `workspace_ambiguous` (ask the human which workspace is meant) and `vci_inventory_incomplete`\n (the workspace inventory could not be read completely: report it and stop, never guess a workspace).\n- **`vci_mapping_outside_workspace` has TWO outcomes.** An existing mapping rejected in the plan changed nothing. After a\n NEW export the same kind means the file WAS written outside the workspace root: read its message and `details`\n (`object`, `directory`, `root`, `done`), report it, hand the cleanup to the human and never retry blindly.\n\n## Reference \u2014 global library and CAx error contracts (by app version)\n\n**Project library** (`tia_block_from_mastercopy`). A device copy is refused (`409 mastercopy_not_blocks` after app 1.6.3; up to 1.6.3 a 500).\n\n**Global libraries** (`tia_global_library_save` / `_close`). After app 1.6.3 a name that picks no single open USER library is refused, nothing saved or closed: `404 not_found` (`details.userLibraries` lists the names that work), or `409 conflict` for a read-only system/corporate library or a name several user libraries match only ignoring case; up to 1.6.3 the serve reports success even for an unknown name. A library opened read-only (`readWrite:false`) cannot be saved: `409 conflict` (`details.readOnly`) after app 1.6.3, a 500 up to 1.6.3 \u2014 close it and open it again with `readWrite:true` to change and save it.\n\n**CAx (AutomationML)** (`tia_cax_export` / `tia_cax_import`). A failed transfer is an error (`500 cax_transfer_failed`) after app 1.6.3; up to 1.6.3 the serve returns an opaque `result` even on failure \u2014 check the devices with `tia_devices`.\n\n## Reference \u2014 download plan fingerprint limits\n\n**Fingerprint limits** (`tia_download`): user program blocks, UDTs and tag tables only \u2014 no hardware configuration, system block groups, S7-1500 software units or technology objects; per-object fallback to modification dates (`source:"dates"`, warned in the plan \u2014 dates can false-positive `plan_stale`).\n\n## Recipe \u2014 generate the FAT/SAT I/O list (tia_io_map)\n\n**Generate the FAT/SAT I/O list** (`tia-verify` step 6). `tia_io_map` (`jobId` \u2192 `tia_job_status`), one\nlist per PLC, `limit:100`, `cursor` = previous `nextCursor` unchanged until null. Read `coverage` on every\npage; `cursor_stale` or differing coverage restarts once; omission marker: same call and cursor, half the\n`limit`, max 3 times, never follow its cursor. Rows: one per tag on a `channel`, or on a `range` with\nstatus `matched`; per unmatched `tag` entry; and (empty tag) per unmatched `channel` or channelless\n`range`; none for a `range` with status `channels`; a tag spanning channels: ONE row (`table`+`name`)\nlisting them; statuses `matched`|`unmatched`|`conflict` only. Unresolved channels/ranges and unparsed\ntags: "Could not be mapped". Print `coverage` numbers, `coverage.limits`, DERIVED addresses (spot-check in\nTIA). Complete ONLY after a finished walk with no marker left on ANY page and `coverage.complete: true`,\nsame counts, on every page; else start "NOT complete", say why. An unmatched tag is never\n"unused"/"orphan"; never invent, round or fix an address. Read-only; the human signs.\n\nLengths: a `range`\'s `start` is a byte number and its `length` is in BYTES (Openness reports an address length in bits and the map converts it, rounding up to whole bytes); `from` and `to` are its first and last bit (2 bytes from `%I0.0` end at `%I1.7`). `tia_device_tree` shows the raw Openness value, in BITS: convert before comparing the two.\n\n## Recipe \u2014 prove the project matches the versioned XML (tia_block_compare)\n\n**The project matches what\'s versioned \u2014 prove it, don\'t assume it.** A raw hash of an\nexport is NOT proof (two exports of the same block differ in `<Created>`/UIds). Use\n`tia_export_block` to pull a block inline and `tia_block_compare` to diff it against the\ncommitted XML (normalized \u2014 ignores formatting/BOM/`<Created>`/UIds); `verdict:"equal"` is\nthe actual round-trip proof. After `tia_compile`/`tia_source_put`, read `blockChanges` and\nexport/commit any regenerated instance DBs before calling the project verified.\n\n## Reference \u2014 network, audit and CAx how-to\n\n**Network lifecycle.** `tia_subnet_delete` on a non-empty subnet is refused (`409 subnet_not_empty`); `disconnectNodes:true` disconnects its nodes and removes its IO systems. A subnet rename (`tia_subnet_update` `name`) takes at most 24 characters: a longer name is `400 invalid_subnet_name` (a `dryRun` too, nothing changed) although `tia_subnet_create` accepts longer names; a name equal to the current one is not a rename, and the serve counts UTF-16 code units, spaces included. PROFINET name (`tia_pn_name_set`): lower-case DNS labels (`a-z0-9-`) split by `.`, not an IP look-alike. A node in its default state (automatic name generation on, `PnDeviceName` read-only) takes a `name`: the serve switches auto-generation off first and writes the name second, and its `dryRun` cannot prove that the name becomes writable, so a `plan_ok` can still be followed by `409 pn_name_unsupported` from the real call; the serve then writes the previous auto-generation back and verifies it, the error ends with "Nothing was changed." only when that read-back confirmed it, and otherwise `409 conflict` names `autoGeneration` as NOT restored: re-read with `tia_device_network`. IO system first: `tia_io_system_create` on the controller, then `tia_io_system_connect` per device; `409 cross_subnet_assignment`: connect the device to that subnet (`tia_network_connect`) first.\n\n**Audit** (class R). Read blocks/types/tags via `tia_plc_*` and check the engineering baseline: optimized access, 100% symbolic, UDT-typed interfaces, FB + instance-DB, uniform naming. Scope `tia_crossrefs` with `target`/`kind` on a big project: a whole-PLC read can take minutes.\n\n**CAx (AutomationML).** `tia_cax_export` exports one device or the whole project; `tia_cax_import` takes `option`: `RetainTiaDevice` (default) / `OverwriteTiaDevice` / `MoveToParkingLot`.\n\n## Where to stop\n\nEverything above is **offline (M-off)**. `tia_download` / `tia_online` (G3/G4) are **not**\npart of scaffold \u2014 they belong to `tia-handoff` and require explicit human approval.\n';
|
|
23950
23958
|
var SPEC_FORMAT = '# The project-spec (input model)\n\nA project-spec is ONE JSON document describing the whole project. Always run it\nthrough the pipeline front door: `tia_spec_validate` (rung 0, pure) \u2192 `tia_spec_plan`\n(dry) \u2192 `tia_spec_apply` (M-off, stops at gates).\n\n`tia_spec_validate` checks the shape only in part (it does not run the JSON Schema; the `spec-validate`\nskill adds it) and enforces: unique device/subnet/UDT/block/per-table tag names; every network node IP\ninside the subnet CIDR; `OrderNumber:<MLFB>/V<fw>` with `/V` \u2014 never `:V` (Gd5); no STL/GRAPH on an\nS7-1200; at most 8 SMs on an S7-1200 (its only module limit); and G5 \u2014 a spec with safety content\nmarked autonomous is REJECTED (F-logic is never autonomous).\n\nMinimal example:\n\n```json\n{\n "project": { "name": "Line2", "directory": "C:\\\\TIA\\\\Line2" },\n "conventions": {\n "namingScheme": "plcopen",\n "optimizedAccess": true,\n "symbolicOnly": true,\n "defaultLanguages": { "interlocks": "LAD", "algorithms": "SCL", "sequencers": "GRAPH" }\n },\n "devices": [\n {\n "name": "Line2_CPU",\n "typeIdentifier": "OrderNumber:6ES7 511-1AK02-0AB0/V2.9",\n "role": "cpu",\n "family": "S7-1500"\n }\n ],\n "network": {\n "subnet": { "type": "System:Subnet.Ethernet", "name": "PN_Line2", "cidr": "192.168.0.0/24" },\n "nodes": [{ "device": "Line2_CPU", "ip": "192.168.0.1", "createIoSystem": true }]\n },\n "dataTypes": [\n {\n "name": "UDT_Motor",\n "members": [\n { "name": "xStart", "dataType": "Bool", "comment": "Start command" },\n { "name": "rSpeed", "dataType": "Real", "comment": "Speed [%]" }\n ]\n }\n ],\n "tagTables": [{ "name": "IO", "purpose": "IO" }],\n "tags": [{ "table": "IO", "name": "Conv01_Run", "dataType": "Bool", "address": "%Q0.0" }]\n}\n```\n\nThe plan and `tia_spec_apply` neither import `dataTypes` nor author block logic: UDTs go in with\n`tia_types_import`, logic with `tia_source_put` / `tia_import_xml`.\n\nResolve every concrete MLFB + firmware via `tia_catalog` before building \u2014 never guess\nan order number. Project firmware must be \u2264 the physical device\'s firmware.\n';
|
|
23951
23959
|
var FULL_GUIDE = [BRIEF, GATES_GUARDS, GUI_GATES, GOTCHAS, PIPELINE, RECIPES, SPEC_FORMAT].join("\n---\n\n");
|
|
23952
|
-
var CODEX_GUIDE = '# TIA Openness MCP \u2014 operating brief\n\nYou are driving Siemens TIA Portal V21 through the `tia_*` tools (an MCP over the TIA\nOpenness HTTP `serve`). This brief is ALWAYS in effect. For depth, call the `tia_guide`\ntool (topics: `gates-guards`, `gui-gates`, `gotchas`, `pipeline`, `recipes`,\n`spec-format`) \u2014 read the relevant topic BEFORE authoring blocks, changing hardware,\nor preparing a deploy. You are an assistant up to the gate, never an autonomous\ncommissioner.\n\n## Vocabulary (used across all tool descriptions)\n\n- **Class R** \u2014 read-only; safe anytime.\n- **Class M-off** \u2014 offline mutation (edits the project; never touches the physical PLC).\n- **Class GATE** \u2014 touches the physical world or a human-only decision; needs a human.\n- **G1..G7** \u2014 the GATES: G1 trust dialog, G2 S7-connection precondition (tool-enforced:\n both CPUs must compile clean), G3 download / CPU-STOP, G4 go-online (incl. station upload),\n G5 safety / F-logic (NEVER autonomous), G6 credentials \u2014 master secret, UMAC, upload /\n block / certificate passwords, password policy (from a human \u2014 never invented), G7 network\n scan. All except G2 are human-only \u2014 never crossed autonomously.\n- **Gd\\*** \u2014 tool-enforced GUARDS (preconditions the tools check), e.g. Gd5\n `OrderNumber:<MLFB>/V<fw>` format (slash before V, never `:V`), Gd8 only ERRORs block\n a compile (warnings don\'t), Gd9 clean compile before deploy, Gd11 dryRun-then-approve.\n\n## Non-negotiable rules\n\n1. **Serial only.** The serve owns ONE TIA Portal on ONE serial worker. Never fire\n concurrent `tia_*` calls; one hung Openness call can stall the whole serve.\n2. **Never cross a GATE autonomously.** A `requires_human_action` response is a HANDOFF,\n not an error: relay its `youMustDo`/`nextSteps` to the human verbatim, wait for their\n explicit yes, then resume exactly as instructed. Never self-approve a download; never\n invent a secret (G6); never author, modify or deploy safety/F logic (G5).\n3. **Long operations are jobs.** A tool whose description says "Long operation" (connect,\n compile, download, upload, project create/save/archive, exports, CAx\u2026) may answer `status:"running"` with a\n `jobId` \u2014 the operation is STILL running on serve. Call `tia_job_status {jobId}`\n until it returns the final result; never repeat the original call. While a job runs,\n any OTHER ordinary serve-bound tool answers `kind:"busy"` (with `details.jobId`) \u2014 that is\n expected, not a failure: go back to `tia_job_status`. `tia_ping` probes `/health`: never busy,\n `activated:null` while a job runs, and no job ID in it \u2014 use it for reachability only. Offline\n tools (`tia_guide`, `tia_spec_validate`, `tia_spec_plan`, `tia_job_status` itself) never answer busy.\n4. **Compile before deploy.** `tia_compile` aggregates hardware + software and is the\n offline verifier: `errors:0` is the Gd9 precondition for download (G3) and for S7\n connections.\n5. **Follow the build pipeline order** (details: `tia_guide {"topic":"pipeline"}`):\n validate the spec (`tia_spec_validate`) \u2192 plan (`tia_spec_plan`) \u2192 scaffold\n (`tia_spec_apply` or the M-off tools) \u2192 verify (`tia_compile`) \u2192 human-gated deploy\n (`tia_download` with dryRun \u2192 human approval \u2192 `approved:true` + the same `planHash`).\n6. **Some CPU settings are GUI-only** (PUT/GET permission, OPC UA runtime license,\n OPC UA server interface). Hitting one is EXPECTED, not a bug: relay the exact GUI\n steps from `tia_guide {"topic":"gui-gates"}` and resume after the human confirms.\n7. **Prerequisites:** the serve must be running (default `http://localhost:5000` \u2014\n check with `tia_ping`); the FIRST connect per serve process hits the G1 trust dialog\n on the serve host.\n8. **Confirmation dialogs.** Where the client supports it, a gated call first asks the human in the client\'s dialog\n (elicitation); only the human answers it, and it never replaces dryRun \u2192 approval \u2192 `planHash`. `declined_by_human` /\n `cancelled_by_human` = refused, nothing sent: stop, no retry unless asked.\n9. **Size budget and paging.** A result holding `{"omitted":true,\u2026}` had that value cut out WHOLE by the MCP\'s size budget:\n repeating the same call returns the same marker, so follow its `hint` instead. Read large lists (`tia_plc_blocks`,\n `tia_plc_tags`, `tia_device_tree`) in pages: pass `limit`, then each `nextCursor` as `cursor` until it is `null`. A page\n with a marker has NO `nextCursor` (it would skip the omitted data): retry the same request with a smaller `limit`.\n `cursor_stale` means the project changed: restart from the first page (no `cursor`). Gate handoffs, plans and job\n envelopes are never cut. For XML too big for one result use `tia_export_xml` (it writes files on the serve host).\n\nSession start: `tia_ping` \u2192 `tia_status` \u2192 (if needed) `tia_start` / `tia_connect`.\nBefore the first build on a project: read `tia_guide {"topic":"pipeline"}` and\n`tia_guide {"topic":"gotchas"}`.\n\n**Tool names** are written bare (`tia_status`) here and in the skills. Claude Code shows them qualified:\n`mcp__plugin_tia-harness_tia__tia_status` (plugin; what a subagent `tools:` list needs) or\n`mcp__tia__tia_status` (standalone). Other clients may display them differently; the `tia_*` suffix\nis the tool.\n\n---\n\n# Gates vs guards\n\n## GATES vs GUARDS\n\n- **GATES (human-only \u2014 never auto-bypass):** trust dialog (**G1**), download / CPU-STOP\n (**G3**), go-online (**G4**, which includes a **station upload** (`tia_upload`): it goes\n online to read the CPU), network scan / accessible-devices (**G7**), master-secret/UMAC\n (**G6**, which includes a CPU **read-access password** for an upload, a block **know-how\n password** (`tia_block_protect`), a certificate file\'s password (`tia_certificate_import`)\n and the **password-policy** values (`tia_password_policy_set`)), **safety / F-logic\n (G5) \u2014 never autonomous**.\n- **GUARDS (tool-enforced preconditions):** compile-clean before deploy, consistency,\n dry-run\u2192approve, idempotency by name (advisory: re-runs do not converge), `OrderNumber:<MLFB>/V<fw>`\n format, serial-only.\n- Back up a physical CPU with the **`tia-backup`** skill (dedicated empty project; the upload\n token is bound to the project shown in the handoff).\n- **Picking the G3 download path (no gate, no scan):** `tia_pg_interfaces` lists the connection\n modes/PG-PC interfaces TIA already sees for the CPU (plus the OS status of each adapter) \u2014\n use it to fill `connectionMode`/`pcInterfaceName`/`targetInterfaceName` for `tia_download`\n instead of reaching for `tia_accessible_devices` (a real network scan, GATE G7).\n- **GUI-ONLY settings (NOT exposed via Openness \u2014 surface as a human gate, do not script):**\n "Permit access with PUT/GET communication", OPC UA **runtime license** / server-interface\n creation. (OPC UA server **activation** is the exception \u2014 settable via Openness with\n `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}` on the "OPC UA" device-item.)\n\n**Deploy-time approval gates** (download / online / network-scan / secret / safety = **G3/G4/G7/G6/G5**)\nare a *different* class \u2014 see the **`tia-handoff`** skill. Those are "a human **approves an action**",\nnot "a human **clicks a GUI setting**". Both are human interaction points; surface them as\n`requires_human_action` with concrete guidance, never as a tool failure.\n\n---\n\n# GUI gates \u2014 expected human interaction points\n\n## Human interaction points (GUI gates) \u2014 EXPECTED, not an error\n\nSome TIA settings are **not reachable via Openness** on the S7-1200/1500. The harness will hit a\nsignal that *looks* like an error but is actually a point where a **human must act in the TIA GUI**.\nWhen you see one of these, **do not treat it as a failure and do not retry blindly** \u2014 recognize it,\ntell the human the **exact GUI steps**, and resume after they confirm. A GUI gate is a *handoff*, not a *bug*.\n\n| # | Signal you\'ll see | Why it\'s expected | Tell the human (exact GUI steps) |\n|---|---|---|---|\n| **G1 trust** | `tia_connect` \u2192 `requires_human_action` (`trust_dialog`), or the **1st** TIA-starting call per `serve` process goes **~180 s** (`TIA_CONNECT_TIMEOUT_MS`) without an answer \u2014 `tia_connect`, `tia_start`, `tia_show_ui` and `tia_project_create` all share that wait, and a client timeout with `/health` alive yields the same `trust_dialog` handoff. A `running` answer from any of them can still mean a trust dialog is waiting on the serve host | TIA shows a one-time security prompt the first time an Openness app attaches, **per process** | On the **serve host**, in TIA Portal, click **"Yes to all"** in the access dialog. *Caveat:* it can false-positive on a client timeout with **no** real dialog \u2014 check `tia_status` (**`hasProject:true`**, not `attached:true`) and\u2026 If the handoff state is `TRUST_DIALOG_DENIED_OR_EXPIRED`, the dialog was denied or left to expire: the serve lists what it closed (`closedPids`), what is still running (`stillRunningPids`) and what it could not confirm (`unknownPids`) \u2014 close any still-running TIA (no project inside) before re-calling, and for an unconfirmed pid first verify in Task Manager that it is a TIA Portal started by this serve with no open project, with a human ready to click **"Yes to all"**. |\n| **OPC UA license** | `tia_compile` **ERROR**: *"The selected OPC UA license is not sufficient\u2026"* | License selection is GUI-only (no Openness service); a fresh project **or a firmware change** leaves it unset | CPU \u2192 **Properties \u2192 General \u2192 Runtime licenses \u2192 OPC UA** \u2192 *Type of required license* \u2192 select **"SIMATIC OPC UA S7-1200 Basic"** (the 1214C option), and *Type of purchased license* \u2192 the license the CPU holds (the human declares it; left at "No license" the compile still reports *"Type of purchased license: The selected OPC UA license is not sufficient"*). Recompile. |\n| **OPC UA interface** | OPC UA client connects but the DB nodes aren\'t there (`ns=4` empty / no `ServerInterfaces`) | The **S7-1200 does NOT auto-expose DBs** (unlike the S7-1500) \u2014 a server interface must be created by hand | CPU \u2192 **OPC UA \u2192 Server interfaces \u2192 Add new server interface** \u2192 add/drag the DB (e.g. `ModbusData`) into it. Recompile; data appears under `ns=4`. |\n| **PUT/GET** | S7 client (`nodes7`/`snap7`) connects on port 102 but reads return access-denied (`ROSCTR=2` / "BAD") | *"Permit access with PUT/GET"* is a GUI-only protection setting | CPU \u2192 **Properties \u2192 Protection & Security \u2192 Connection mechanisms** \u2192 check **"Permit access with PUT/GET communication from remote partner"**. Compile + download (`hardware:true`). |\n| **FW-change reset** | After `tia_device_change_version`: OPC UA server off, the license error on compile, blocks `isConsistent:false` | `DeviceItem.ChangeType` **resets GUI-gated comm settings** (server activation + license); the interface & PUT/GET survive | `tia_project_archive` **before** the FW change. After: re-set `OpcUaServer:true` via `tia_obj_set_attributes` (scriptable), re-select the license (row above), recompile. |\n\n**Not a gate (now scriptable):** *activating* the OPC UA server \u2014 `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}`\non the "OPC UA" device-item (it auto-generates the server certificate). Only the **license** and the\n**server interface** stay GUI-only.\n\n---\n\n# Hard-won gotchas (runtime-validated)\n\n## Hard-won gotchas\n\n1. **Always compile before deploy.** `tia_compile` aggregates **hardware + software**; a\n **clean** compile (`errors:0`) is the precondition for download and for S7 connections.\n2. **The serve is a SINGLE serial worker** \u2014 one Openness op at a time. Do **not** fire\n concurrent `tia_*` calls; a hung Openness op can stall the serve (may need a restart).\n3. **Changing an FB\'s interface (e.g. regenerating it via `tia_source_put`) leaves its\n instance DB inconsistent.** Recompile FIRST: a software-scope `tia_compile` regenerates\n the instance DB in most cases \u2014 read the compile result\'s **`blockChanges`** (`tia_compile`\n and `tia_source_put {compile:true}` both return it): a `"change":"modified"` entry on the\n instance DB is your confirmation it was regenerated \u2014 **export and commit it**\n (`tia_export_block`/`tia_block_compare`) so what\'s versioned matches the project. Only if\n the DB still reports inconsistent after a compile, delete it (`tia_block_delete`),\n recreate it (`tia_instancedb_create`) and recompile.\n4. **Firmware rule: project FW \u2264 device FW.** Bump the project FW **in-place** with\n `tia_device_change_version` (`DeviceItem.ChangeType`), which preserves the **program** \u2014 never\n set the project higher than the physical CPU. **\u26A0\uFE0F It RESETS GUI-gated comm settings** (the\n **OPC UA server activation** + **runtime-license**; the server interface and PUT/GET survive):\n **archive first** (`tia_project_archive`) on a CPU with hand-configured OPC UA, recompile after\n (it marks blocks inconsistent), and re-verify. Same-version `ChangeType` is rejected.\n5. **Use a NON-optimized DB** for Modbus (`MB_HOLD_REG`) and S7 (absolute addressing); OPC UA\n works with optimized or not.\n6. **Order numbers use `/V<fw>`, not `:V<fw>`** (guard Gd5).\n7. **A station upload (`tia_upload`) ADDS a new station to the open project \u2014 back up into a\n dedicated EMPTY project.** Observed on hardware (S7-1200 1214C, 2026-09-26): the upload read\n the CPU into an empty project (0 \u2192 1 device, twice) in ~75 s (76.7 s and 74.2 s); the CPU\n stayed in RUN the whole time (owner watching its LEDs during the second upload). Protect the\n working project FIRST: `tia_project_create` closes the current project, and serve refuses it\n (`409 unsaved_changes`) while that project has unsaved changes \u2014 so `tia_project_save` +\n `tia_project_archive` before creating the backup project (never pass `discardUnsavedChanges` to\n get past the refusal) \u2014 and pass the archive `name` WITH the `.zap21` extension (`name` absent\n or extension-less fails; with `.zap21` it archived 1.6 MB).\n8. **One wrong know-how password can lock a block for the session.** Observed on the bench\n (2026-10-12): after one rejected unprotect (`tia_block_protect {protect:false}`), TIA refused\n the CORRECT password of that block for the rest of the session (cause not confirmed \u2014 possibly\n brute-force protection). Never retry with a guess \u2014 ask the human for the password (G6); if a\n password the human confirms is refused, stop and hand off instead of retrying.\n9. **`unsaved_changes` and `binding_conflict` are refusals, not faults: nothing was changed.**\n `tia_connect`, `tia_project_close`, `tia_disconnect` and `tia_project_create` answer\n `409 unsaved_changes` when the call would close a project with unsaved changes (the error lists\n each one). ASK the human; the recommended answer is to repeat the same call with\n `saveUnsavedChanges:true`. Pass `discardUnsavedChanges:true` (data loss) ONLY when the human\n explicitly decides to throw the work away, never to make the error go away (the client then asks\n the human to confirm in its own dialog; `declined_by_human` = nothing was sent, stop).\n `409 binding_conflict` means the project this session is bound to is no longer the one open in\n the bound TIA (closed, replaced or Save As done by hand; `tia_status` shows `boundProjectPath`\n and `bindingDrift`): ask the human which project is intended, then `tia_connect` with the bound\n path (back to it) or the open one (adopt it) \u2014 do not repeat the refused call first.\n10. **`503 audit_unavailable`: the serve could not write its audit log, so it refused the call BEFORE\n running (nothing reached the PLC).** Have the human fix the disk or permissions, then re-plan.\n An `auditWarning` in a response = the call ran but was not fully recorded: report it.\n\n## Prerequisites (environment)\n\n- The **`tia` serve must be running** (default `http://localhost:5000`, e.g.\n `TIAOpenness.exe serve 5000`). The MCP is a pure HTTP client; point it at the serve host via\n `TIA_API_BASE` if it runs elsewhere.\n- The Windows user must belong to the **"Siemens TIA Openness"** local group.\n- The **FIRST connection per serve process shows a trust dialog** that a **human must confirm**\n ("Yes to all") on the serve host \u2014 this **cannot be automated** (gate G1).\n\n---\n\n# The build pipeline (spec \u2192 verified project)\n\nStages in order \u2014 the class tells you what each stage may do:\n\n| # | Stage | Tool(s) | Class | What it does |\n|---|---|---|---|---|\n| 0 | Validate the spec | `tia_spec_validate` | R (pure) | Partial shape checks + the cross-field rules the tool implements: unique names, IP inside the subnet CIDR, Gd5 order-number format, no STL/GRAPH on S7-1200, the G5 safety rule, at most 8 SMs on an S7-1200. It does NOT run the JSON Schema or per-model module limits; the `spec-validate` skill covers both. Needs no serve. |\n| 1 | Plan | `tia_spec_plan` | R (pure) | Turns a VALID spec into the ordered list of M-off operations. Nothing mutates. |\n| 2 | Scaffold | `tia_spec_apply` (or the M-off tools manually) | M-off | Creates part of the project content in dependency order (scope below). Stops at every gate. |\n| 3 | Verify | `tia_compile` | M-off | THE offline verifier: aggregates hardware + software. Gd8: only ERRORs block. `errors:0` is the Gd9 precondition for any deploy. |\n| 4 | Handoff / deploy | `tia_download` | GATE G3 | `dryRun:true` asks serve for a VERIFIED plan (clean compile, resolved connection, software fingerprint) \u2192 plan + `planHash` \u2192 a HUMAN approves \u2192 re-call with `approved:true` + the SAME `planHash` (serve re-checks the fingerprint and refuses `plan_stale` if the software changed). The approval covers the connection/options and the covered software content \u2014 NOT the hardware configuration (a hardware change after approval passes the token check). Re-plan (new dryRun) + fresh human approval only when the hardware configuration changed AFTER the dryRun that produced the token \u2014 the fingerprint cannot detect that change, so the human must confirm nothing hardware-side moved; never reuse the old token for changed hardware. The fingerprint covers only user program blocks, UDTs and tag tables (what it leaves out, the `source:"dates"` fallback: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 download plan fingerprint limits\'). Never self-approve. Pick the connection with `tia_pg_interfaces` (no scan). |\n\nScaffold order (UDTs BEFORE the blocks that use them): by hand, `tia_guide {"topic":"recipes"}`, \'Pipeline order\'. `tia_spec_apply` automates only subnets, devices, modules, network, tag tables, tags, FB shells, control-module instance DBs and the compile; protection, constants, UDTs and all logic stay manual. The FB shells it creates are empty: add their logic with `tia_source_put` (SCL) or `tia_import_xml` (LAD/FBD).\n\nPLC-scoped steps use the PlcSoftware (e.g. `PLC_1`) read after the device step, not the device name.\n\n## The approval envelope (what a gate handoff looks like)\n\nGated tools return `status:"requires_human_action"` with:\n\n- `gate` \u2014 which gate (e.g. `download_approval`, `station_upload`, `go_online`, `trust_dialog`);\n- `youMustDo` \u2014 what the human must confirm, in plain words;\n- `plan` + `planHash` \u2014 exactly what would be executed (the hash binds the approval to\n this exact plan; a changed plan needs a new approval); the download\'s plan also carries\n `fingerprint` (the software content the plan was verified against \u2014 show it too);\n- `nextSteps` \u2014 how to resume after the human\'s yes.\n\nRelay the envelope to the human, wait for an explicit yes, resume exactly as\ninstructed. The AI never approves, never invents a secret, never deploys F-logic.\n\n**Confirmation dialog.** When the client supports elicitation, the crossing calls (`tia_download` with\n`approved:true`; `tia_upload`, `tia_online`, `tia_accessible_devices` with `confirm:true`) first ask the\nhuman in a dialog; clients without it behave as before. The dialog only checks the human\'s answer: the\n`planHash` and serve\'s approval token stay the authority.\nPasswords (G6) are never asked there. `declined_by_human` / `cancelled_by_human` = the human refused:\nnothing was sent, no retry unless asked. `elicitation_failed` (`isError`) = the dialog could not be\nshown or answered, nothing was sent (fails closed).\n\n## After scaffolding\n\n- Re-run `tia_compile` after ANY authoring change.\n- `tia_project_save` regularly; `tia_project_archive` BEFORE risky operations\n (firmware change \u2014 see `tia_guide {"topic":"gotchas"}`).\n- Auditing an existing project is class R (`tia_plc_*` reads); baseline: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 network, audit and CAx how-to\'.\n- `tia_crossrefs` (class R, a long read: it may answer `status:"running"` + `jobId`, then poll\n `tia_job_status`) reads the cross-references: in an audit, `filter:"UnusedObjects"` lists\n unused-object CANDIDATES, never proof (OBs, objects used only from outside the PLC such as an\n HMI, OPC UA or another CPU, and library TYPEs show as unreferenced); before changing an\n existing object, `target` + `kind` + `filter:"ObjectsWithReferences"` returns the objects related\n to it with each `referenceType` and `access` as TIA reports them (the direction of `Uses` /\n `UsedBy` is not interpreted: the human confirms it). Page a whole-PLC or container read with `limit`\n (for example 200) and `cursor` (the `nextCursor` of the previous page, until it is null; on\n `cursor_stale` restart from the first page, and on an omission marker repeat the same request\n with a smaller `limit`, never following a cursor from an omitted page); each page re-reads the\n whole PLC, so a later page can report less than an earlier one. Read `coverage` on every page,\n not only the first, and compare its counts across pages: differing counts restart the walk once\n from the first page (like `cursor_stale`). Only a finished walk whose pages all report\n `coverage.complete: true` supports "audited completely" or "nothing uses this"; an omission\n marker, an unfinished walk, differing counts or `coverage.complete: false` on any page (see\n `coverage.unavailableOwners`) means the result is NOT complete.\n- **FAT/SAT I/O list** (`tia-verify` step 6): `tia_io_map`; recipe: `tia_guide {"topic":"recipes"}`, \'Recipe \u2014 generate the FAT/SAT I/O list\'.\n- **Prove the project matches what\'s versioned** (a raw hash is NOT proof): `tia_guide {"topic":"recipes"}`, \'Recipe \u2014 prove the project matches the versioned XML\'.\n\n## Network lifecycle (subnets, PROFINET names, IO systems)\n\nRead first (`tia_subnet_get`, `tia_device_network`, `tia_io_systems`), then run each write\'s `dryRun` (answered by\nthe serve, needs an open project). Order, PROFINET names, `disconnectNodes`: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 network, audit and CAx how-to\'.\n\n- **Refused, nothing changed:** `tia_subnet_delete` of a non-empty subnet (`409 subnet_not_empty`);\n `tia_io_system_connect` across subnets (`409 cross_subnet_assignment`: `tia_network_connect` the device to that subnet first).\n- **`409 postcheck_failed`:** the write did not take effect as asked: re-read, never repeat blindly.\n\n## Libraries, HMI, CAx and PLC security\n\nReads are class R; every change is class M-off (offline, with `dryRun`) and reaches the CPU\nonly through a later `tia_compile` + human-gated `tia_download` (G3). Every file path is a\npath ON THE SERVE HOST.\n\n- **Guarded PLC writes** (`tia_tag_update`, `tia_constant_update`, `tia_constant_delete`,\n `tia_tagtable_delete`, `tia_block_group_delete`, `tia_ob_create`, `tia_block_compile`): the serve\n answers their `dryRun` (it needs an open project) with the guard verdict (name collision, default\n tag table, non-empty group, singleton OB).\n- **Project library:** `tia_library_mastercopies` / `tia_library_types` read it;\n `tia_library_mastercopy_create` turns a DEVICE into a master copy (a block cannot be a source);\n `tia_block_from_mastercopy` needs one that holds PLC blocks.\n- **Global libraries** (in the TIA Portal session, not the project): `tia_global_libraries`,\n `tia_global_library_create` / `_open` / `_save` / `_close`; save/close take the name from\n `tia_global_libraries` (exact name first, then ignoring case). REFUSED, nothing saved or closed\n (`404 not_found` / `409 conflict`): a name that picks no single open USER library (unknown, read-only\n system/corporate, several matches ignoring case) and a save of a `readWrite:false` library. Up to app\n 1.6.3 an unknown name can report success without saving or closing anything: check `tia_global_libraries`.\n- **HMI:** `tia_hmis` and `tia_hmi_screens` read any HMI; screen files\n (`tia_hmi_screen_export`, `tia_hmi_screens_import`) work for WinCC **Classic** only, and the\n import OVERWRITES same-named screens.\n- **CAx (AutomationML):** `tia_cax_export` / `tia_cax_import` (scope, `option` values: recipes). Archive the\n project before an overwrite. A failed transfer is an error after app 1.6.3; on an older serve check the\n devices with `tia_devices`.\n- **Error contracts by app version:** `tia_guide {"topic":"recipes"}`, \'Reference \u2014 global library and CAx error contracts (by app version)\'.\n- **PLC security:** `tia_certificates` / `tia_certificate_template` / `tia_password_policy`\n read; `tia_certificate_import` / `_export` / `_delete`, `tia_password_policy_set` and\n `tia_block_protect` change the project. **G6:** a block or certificate password and the\n password-policy values come from a HUMAN \u2014 never invent, guess or reuse one; dryRun plans\n show a password as `[redacted]`. A CPU without the certificate manager or a policy service\n answers 409.\n- **Multiuser:** `tia_project_servers`, `tia_server_projects` read Project Servers; `tia_local_session_open` needs NO open project (`tia_project_close`, `tia_start`). Nothing is ever checked in.\n\n---\n\n# Recipes (runtime-verified)\n\nNot copied here: Codex reads at most 32 KiB of AGENTS.md and cuts the rest without a word. Call\n`tia_guide {"topic":"recipes"}` for the verified recipes (unlocking a freshly-created CPU, the in-place firmware\nbump, Modbus TCP, S7 PUT/GET and OPC UA on the S7-1200, the scaffold order) before you need one.\n\n---\n\n# The project-spec (input model)\n\nA project-spec is ONE JSON document describing the whole project. Always run it\nthrough the pipeline front door: `tia_spec_validate` (rung 0, pure) \u2192 `tia_spec_plan`\n(dry) \u2192 `tia_spec_apply` (M-off, stops at gates).\n\n`tia_spec_validate` checks the shape only in part (it does not run the JSON Schema; the `spec-validate`\nskill adds it) and enforces: unique device/subnet/UDT/block/per-table tag names; every network node IP\ninside the subnet CIDR; `OrderNumber:<MLFB>/V<fw>` with `/V` \u2014 never `:V` (Gd5); no STL/GRAPH on an\nS7-1200; at most 8 SMs on an S7-1200 (its only module limit); and G5 \u2014 a spec with safety content\nmarked autonomous is REJECTED (F-logic is never autonomous).\n\nMinimal example:\n\n```json\n{\n "project": { "name": "Line2", "directory": "C:\\\\TIA\\\\Line2" },\n "conventions": {\n "namingScheme": "plcopen",\n "optimizedAccess": true,\n "symbolicOnly": true,\n "defaultLanguages": { "interlocks": "LAD", "algorithms": "SCL", "sequencers": "GRAPH" }\n },\n "devices": [\n {\n "name": "Line2_CPU",\n "typeIdentifier": "OrderNumber:6ES7 511-1AK02-0AB0/V2.9",\n "role": "cpu",\n "family": "S7-1500"\n }\n ],\n "network": {\n "subnet": { "type": "System:Subnet.Ethernet", "name": "PN_Line2", "cidr": "192.168.0.0/24" },\n "nodes": [{ "device": "Line2_CPU", "ip": "192.168.0.1", "createIoSystem": true }]\n },\n "dataTypes": [\n {\n "name": "UDT_Motor",\n "members": [\n { "name": "xStart", "dataType": "Bool", "comment": "Start command" },\n { "name": "rSpeed", "dataType": "Real", "comment": "Speed [%]" }\n ]\n }\n ],\n "tagTables": [{ "name": "IO", "purpose": "IO" }],\n "tags": [{ "table": "IO", "name": "Conv01_Run", "dataType": "Bool", "address": "%Q0.0" }]\n}\n```\n\nThe plan and `tia_spec_apply` neither import `dataTypes` nor author block logic: UDTs go in with\n`tia_types_import`, logic with `tia_source_put` / `tia_import_xml`.\n\nResolve every concrete MLFB + firmware via `tia_catalog` before building \u2014 never guess\nan order number. Project firmware must be \u2264 the physical device\'s firmware.\n';
|
|
23960
|
+
var CODEX_GUIDE = '# TIA Openness MCP \u2014 operating brief\n\nYou are driving Siemens TIA Portal V21 through the `tia_*` tools (an MCP over the TIA\nOpenness HTTP `serve`). This brief is ALWAYS in effect. For depth, call the `tia_guide`\ntool (topics: `gates-guards`, `gui-gates`, `gotchas`, `pipeline`, `recipes`,\n`spec-format`) \u2014 read the relevant topic BEFORE authoring blocks, changing hardware,\nor preparing a deploy. You are an assistant up to the gate, never an autonomous\ncommissioner.\n\n## Vocabulary (used across all tool descriptions)\n\n- **Class R** \u2014 read-only; safe anytime.\n- **Class M-off** \u2014 offline mutation (edits the project; never touches the physical PLC).\n- **Class GATE** \u2014 touches the physical world or a human-only decision; needs a human.\n- **G1..G7** \u2014 the GATES: G1 trust dialog, G2 S7-connection precondition (tool-enforced:\n both CPUs must compile clean), G3 download / CPU-STOP, G4 go-online (incl. station upload),\n G5 safety / F-logic (NEVER autonomous), G6 credentials \u2014 master secret, UMAC, upload /\n block / certificate passwords, password policy (from a human \u2014 never invented), G7 network\n scan. All except G2 are human-only \u2014 never crossed autonomously.\n- **Gd\\*** \u2014 tool-enforced GUARDS (preconditions the tools check), e.g. Gd5\n `OrderNumber:<MLFB>/V<fw>` format (slash before V, never `:V`), Gd8 only ERRORs block\n a compile (warnings don\'t), Gd9 clean compile before deploy, Gd11 dryRun-then-approve.\n\n## Non-negotiable rules\n\n1. **Serial only.** The serve owns ONE TIA Portal on ONE serial worker. Never fire\n concurrent `tia_*` calls; one hung Openness call can stall the whole serve.\n2. **Never cross a GATE autonomously.** A `requires_human_action` response is a HANDOFF,\n not an error: relay its `youMustDo`/`nextSteps` to the human verbatim, wait for their\n explicit yes, then resume exactly as instructed. Never self-approve a download; never\n invent a secret (G6); never author, modify or deploy safety/F logic (G5).\n3. **Long operations are jobs.** A tool whose description says "Long operation" (connect,\n compile, download, upload, project create/save/archive, exports, CAx\u2026) may answer `status:"running"` with a\n `jobId` \u2014 the operation is STILL running on serve. Call `tia_job_status {jobId}`\n until it returns the final result; never repeat the original call. While a job runs,\n any OTHER ordinary serve-bound tool answers `kind:"busy"` (with `details.jobId`) \u2014 that is\n expected, not a failure: go back to `tia_job_status`. `tia_ping` probes `/health`: never busy,\n `activated:null` while a job runs, and no job ID in it \u2014 use it for reachability only. Offline\n tools (`tia_guide`, `tia_spec_validate`, `tia_spec_plan`, `tia_job_status` itself) never answer busy.\n4. **Compile before deploy.** `tia_compile` aggregates hardware + software and is the\n offline verifier: `errors:0` is the Gd9 precondition for download (G3) and for S7\n connections.\n5. **Follow the build pipeline order** (details: `tia_guide {"topic":"pipeline"}`):\n validate the spec (`tia_spec_validate`) \u2192 plan (`tia_spec_plan`) \u2192 scaffold\n (`tia_spec_apply` or the M-off tools) \u2192 verify (`tia_compile`) \u2192 human-gated deploy\n (`tia_download` with dryRun \u2192 human approval \u2192 `approved:true` + the same `planHash`).\n6. **Some CPU settings are GUI-only** (PUT/GET permission, OPC UA runtime license,\n OPC UA server interface). Hitting one is EXPECTED, not a bug: relay the exact GUI\n steps from `tia_guide {"topic":"gui-gates"}` and resume after the human confirms.\n7. **Prerequisites:** run the serve (`http://localhost:5000`; `tia_ping`). First\n connect per process may need G1; running/timeout alone are not G1 evidence.\n8. **Confirmation dialogs.** Where the client supports it, a gated call first asks the human in the client\'s dialog\n (elicitation); only the human answers it, and it never replaces dryRun \u2192 approval \u2192 `planHash`. `declined_by_human` /\n `cancelled_by_human` = refused, nothing sent: stop, no retry unless asked.\n9. **Size budget and paging.** A result holding `{"omitted":true,\u2026}` had that value cut out WHOLE by the MCP\'s size budget:\n repeating the same call returns the same marker, so follow its `hint` instead. Read large lists (`tia_plc_blocks`,\n `tia_plc_tags`, `tia_device_tree`) in pages: pass `limit`, then each `nextCursor` as `cursor` until it is `null`. A page\n with a marker has NO `nextCursor` (it would skip the omitted data): retry the same request with a smaller `limit`.\n `cursor_stale` means the project changed: restart from the first page (no `cursor`). Gate handoffs, plans and job\n envelopes are never cut. For XML too big for one result use `tia_export_xml` (it writes files on the serve host).\n\nSession start: `tia_ping` \u2192 `tia_status` \u2192 (if needed) `tia_start` / `tia_connect`.\nBefore the first build on a project: read `tia_guide {"topic":"pipeline"}` and\n`tia_guide {"topic":"gotchas"}`.\n\n**Tool names** are written bare (`tia_status`) here and in the skills. Claude Code shows them qualified:\n`mcp__plugin_tia-harness_tia__tia_status` (plugin; what a subagent `tools:` list needs) or\n`mcp__tia__tia_status` (standalone). Other clients may display them differently; the `tia_*` suffix\nis the tool.\n\n---\n\n# Gates vs guards\n\n## GATES vs GUARDS\n\n- **GATES (human-only \u2014 never auto-bypass):** trust dialog (**G1**), download / CPU-STOP\n (**G3**), go-online (**G4**, which includes a **station upload** (`tia_upload`): it goes\n online to read the CPU), network scan / accessible-devices (**G7**), master-secret/UMAC\n (**G6**, which includes a CPU **read-access password** for an upload, a block **know-how\n password** (`tia_block_protect`), a certificate file\'s password (`tia_certificate_import`)\n and the **password-policy** values (`tia_password_policy_set`)), **safety / F-logic\n (G5) \u2014 never autonomous**.\n- **GUARDS (tool-enforced preconditions):** compile-clean before deploy, consistency,\n dry-run\u2192approve, idempotency by name (advisory: re-runs do not converge), `OrderNumber:<MLFB>/V<fw>`\n format, serial-only.\n- Back up a physical CPU with the **`tia-backup`** skill (dedicated empty project; the upload\n token is bound to the project shown in the handoff).\n- **Picking the G3 download path (no gate, no scan):** `tia_pg_interfaces` lists the connection\n modes/PG-PC interfaces TIA already sees for the CPU (plus the OS status of each adapter) \u2014\n use it to fill `connectionMode`/`pcInterfaceName`/`targetInterfaceName` for `tia_download`\n instead of reaching for `tia_accessible_devices` (a real network scan, GATE G7).\n- **GUI-ONLY settings (NOT exposed via Openness \u2014 surface as a human gate, do not script):**\n "Permit access with PUT/GET communication", OPC UA **runtime license** / server-interface\n creation. (OPC UA server **activation** is the exception \u2014 settable via Openness with\n `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}` on the "OPC UA" device-item.)\n\n**Deploy-time approval gates** (download / online / network-scan / secret / safety = **G3/G4/G7/G6/G5**)\nare a *different* class \u2014 see the **`tia-handoff`** skill. Those are "a human **approves an action**",\nnot "a human **clicks a GUI setting**". Both are human interaction points; surface them as\n`requires_human_action` with concrete guidance, never as a tool failure.\n\n---\n\n# GUI gates \u2014 expected human interaction points\n\n## Human interaction points (GUI gates) \u2014 EXPECTED, not an error\n\nSome TIA settings are **not reachable via Openness** on the S7-1200/1500. The harness will hit a\nsignal that *looks* like an error but is actually a point where a **human must act in the TIA GUI**.\nWhen you see one of these, **do not treat it as a failure and do not retry blindly** \u2014 recognize it,\ntell the human the **exact GUI steps**, and resume after they confirm. A GUI gate is a *handoff*, not a *bug*.\n\n| # | Signal you\'ll see | Why it\'s expected | Tell the human (exact GUI steps) |\n|---|---|---|---|\n| **G1 trust** | `tia_connect` returns `requires_human_action` (`trust_dialog`) only for `EngineeringSecurityException`; a failed start with `details.cause:"trust"` is also explicit G1 evidence. `running` is not G1: the operation may still be starting or waiting for a dialog. A 20-minute timeout without evidence returns the error state `STARTING_UNCONFIRMED`, not success or G1. | TIA shows a one-time security prompt the first time an Openness app attaches, **per process** | On the **serve host**, click **"Yes to all"** only if the trust dialog is visible. For a `running` lifecycle job, follow its conditional hint and keep polling `tia_job_status`. A timeout does not cancel the operation; the serial worker may remain occupied. Do not queue serve calls. Ask a human to inspect the host; confirm G1 only if a dialog is visible. Wait for completion before status checks or retry. After a G1 handoff, confirm the dialog and re-call `tia_connect` with the `resumeToken`. For `TRUST_DIALOG_DENIED_OR_EXPIRED`, the serve lists what it closed (`closedPids`), what is still running (`stillRunningPids`) and what it could not confirm (`unknownPids`) \u2014 close any still-running TIA (no project inside) before re-calling, and for an unconfirmed pid first verify in Task Manager that it is a TIA Portal started by this serve with no open project, with a human ready to click **"Yes to all"**. |\n| **OPC UA license** | `tia_compile` **ERROR**: *"The selected OPC UA license is not sufficient\u2026"* | License selection is GUI-only (no Openness service); a fresh project **or a firmware change** leaves it unset | CPU \u2192 **Properties \u2192 General \u2192 Runtime licenses \u2192 OPC UA** \u2192 *Type of required license* \u2192 select **"SIMATIC OPC UA S7-1200 Basic"** (the 1214C option), and *Type of purchased license* \u2192 the license the CPU holds (the human declares it; left at "No license" the compile still reports *"Type of purchased license: The selected OPC UA license is not sufficient"*). Recompile. |\n| **OPC UA interface** | OPC UA client connects but the DB nodes aren\'t there (`ns=4` empty / no `ServerInterfaces`) | The **S7-1200 does NOT auto-expose DBs** (unlike the S7-1500) \u2014 a server interface must be created by hand | CPU \u2192 **OPC UA \u2192 Server interfaces \u2192 Add new server interface** \u2192 add/drag the DB (e.g. `ModbusData`) into it. Recompile; data appears under `ns=4`. |\n| **PUT/GET** | S7 client (`nodes7`/`snap7`) connects on port 102 but reads return access-denied (`ROSCTR=2` / "BAD") | *"Permit access with PUT/GET"* is a GUI-only protection setting | CPU \u2192 **Properties \u2192 Protection & Security \u2192 Connection mechanisms** \u2192 check **"Permit access with PUT/GET communication from remote partner"**. Compile + download (`hardware:true`). |\n| **FW-change reset** | After `tia_device_change_version`: OPC UA server off, the license error on compile, blocks `isConsistent:false` | `DeviceItem.ChangeType` **resets GUI-gated comm settings** (server activation + license); the interface & PUT/GET survive | `tia_project_archive` **before** the FW change. After: re-set `OpcUaServer:true` via `tia_obj_set_attributes` (scriptable), re-select the license (row above), recompile. |\n\n**Not a gate (now scriptable):** *activating* the OPC UA server \u2014 `tia_obj_set_attributes {handle, attributes:{OpcUaServer:true}}`\non the "OPC UA" device-item (it auto-generates the server certificate). Only the **license** and the\n**server interface** stay GUI-only.\n\n---\n\n# Hard-won gotchas (runtime-validated)\n\n## Hard-won gotchas\n\n1. **Always compile before deploy.** `tia_compile` aggregates **hardware + software**; a\n **clean** compile (`errors:0`) is the precondition for download and for S7 connections.\n2. **The serve is a SINGLE serial worker** \u2014 one Openness op at a time. Do **not** fire\n concurrent `tia_*` calls; a hung Openness op can stall the serve (may need a restart).\n3. **Changing an FB\'s interface (e.g. regenerating it via `tia_source_put`) leaves its\n instance DB inconsistent.** Recompile FIRST: a software-scope `tia_compile` regenerates\n the instance DB in most cases \u2014 read the compile result\'s **`blockChanges`** (`tia_compile`\n and `tia_source_put {compile:true}` both return it): a `"change":"modified"` entry on the\n instance DB is your confirmation it was regenerated \u2014 **export and commit it**\n (`tia_export_block`/`tia_block_compare`) so what\'s versioned matches the project. Only if\n the DB still reports inconsistent after a compile, delete it (`tia_block_delete`),\n recreate it (`tia_instancedb_create`) and recompile.\n4. **Firmware rule: project FW \u2264 device FW.** Bump the project FW **in-place** with\n `tia_device_change_version` (`DeviceItem.ChangeType`), which preserves the **program** \u2014 never\n set the project higher than the physical CPU. **\u26A0\uFE0F It RESETS GUI-gated comm settings** (the\n **OPC UA server activation** + **runtime-license**; the server interface and PUT/GET survive):\n **archive first** (`tia_project_archive`) on a CPU with hand-configured OPC UA, recompile after\n (it marks blocks inconsistent), and re-verify. Same-version `ChangeType` is rejected.\n5. **Use a NON-optimized DB** for Modbus (`MB_HOLD_REG`) and S7 (absolute addressing); OPC UA\n works with optimized or not.\n6. **Order numbers use `/V<fw>`, not `:V<fw>`** (guard Gd5).\n7. **A station upload (`tia_upload`) ADDS a new station to the open project \u2014 back up into a\n dedicated EMPTY project.** Observed on hardware (S7-1200 1214C, 2026-09-26): the upload read\n the CPU into an empty project (0 \u2192 1 device, twice) in ~75 s (76.7 s and 74.2 s); the CPU\n stayed in RUN the whole time (owner watching its LEDs during the second upload). Protect the\n working project FIRST: `tia_project_create` closes the current project, and serve refuses it\n (`409 unsaved_changes`) while that project has unsaved changes \u2014 so `tia_project_save` +\n `tia_project_archive` before creating the backup project (never pass `discardUnsavedChanges` to\n get past the refusal) \u2014 and pass the archive `name` WITH the `.zap21` extension (`name` absent\n or extension-less fails; with `.zap21` it archived 1.6 MB).\n8. **One wrong know-how password can lock a block for the session.** Observed on the bench\n (2026-10-12): after one rejected unprotect (`tia_block_protect {protect:false}`), TIA refused\n the CORRECT password of that block for the rest of the session (cause not confirmed \u2014 possibly\n brute-force protection). Never retry with a guess \u2014 ask the human for the password (G6); if a\n password the human confirms is refused, stop and hand off instead of retrying.\n9. **`unsaved_changes` and `binding_conflict` are refusals, not faults: nothing was changed.**\n `tia_connect`, `tia_project_close`, `tia_disconnect` and `tia_project_create` answer\n `409 unsaved_changes` when the call would close a project with unsaved changes (the error lists\n each one). ASK the human; the recommended answer is to repeat the same call with\n `saveUnsavedChanges:true`. Pass `discardUnsavedChanges:true` (data loss) ONLY when the human\n explicitly decides to throw the work away, never to make the error go away (the client then asks\n the human to confirm in its own dialog; `declined_by_human` = nothing was sent, stop).\n `409 binding_conflict` means the project this session is bound to is no longer the one open in\n the bound TIA (closed, replaced or Save As done by hand; `tia_status` shows `boundProjectPath`\n and `bindingDrift`): ask the human which project is intended, then `tia_connect` with the bound\n path (back to it) or the open one (adopt it) \u2014 do not repeat the refused call first.\n10. **`503 audit_unavailable`: the serve could not write its audit log, so it refused the call BEFORE\n running (nothing reached the PLC).** Have the human fix the disk or permissions, then re-plan.\n An `auditWarning` in a response = the call ran but was not fully recorded: report it.\n\n## Prerequisites (environment)\n\n- The **`tia` serve must be running** (default `http://localhost:5000`, e.g.\n `TIAOpenness.exe serve 5000`). The MCP is a pure HTTP client; point it at the serve host via\n `TIA_API_BASE` if it runs elsewhere.\n- The Windows user must belong to the **"Siemens TIA Openness"** local group.\n- A first connection per serve process may show a trust dialog; a human confirms it on the serve host. A slow start or timeout alone is not G1 evidence.\n\n---\n\n# The build pipeline (spec \u2192 verified project)\n\nStages in order \u2014 the class tells you what each stage may do:\n\n| # | Stage | Tool(s) | Class | What it does |\n|---|---|---|---|---|\n| 0 | Validate the spec | `tia_spec_validate` | R (pure) | Partial shape checks + the cross-field rules the tool implements: unique names, IP inside the subnet CIDR, Gd5 order-number format, no STL/GRAPH on S7-1200, the G5 safety rule, at most 8 SMs on an S7-1200. It does NOT run the JSON Schema or per-model module limits; the `spec-validate` skill covers both. Needs no serve. |\n| 1 | Plan | `tia_spec_plan` | R (pure) | Turns a VALID spec into the ordered list of M-off operations. Nothing mutates. |\n| 2 | Scaffold | `tia_spec_apply` (or the M-off tools manually) | M-off | Creates part of the project content in dependency order (scope below). Stops at every gate. |\n| 3 | Verify | `tia_compile` | M-off | THE offline verifier: aggregates hardware + software. Gd8: only ERRORs block. `errors:0` is the Gd9 precondition for any deploy. |\n| 4 | Handoff / deploy | `tia_download` | GATE G3 | `dryRun:true` asks serve for a VERIFIED plan (clean compile, resolved connection, software fingerprint) \u2192 plan + `planHash` \u2192 a HUMAN approves \u2192 re-call with `approved:true` + the SAME `planHash` (serve re-checks the fingerprint and refuses `plan_stale` if the software changed). The approval covers the connection/options and the covered software content \u2014 NOT the hardware configuration (a hardware change after approval passes the token check). Re-plan (new dryRun) + fresh human approval only when the hardware configuration changed AFTER the dryRun that produced the token \u2014 the fingerprint cannot detect that change, so the human must confirm nothing hardware-side moved; never reuse the old token for changed hardware. The fingerprint covers only user program blocks, UDTs and tag tables (what it leaves out, the `source:"dates"` fallback: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 download plan fingerprint limits\'). Never self-approve. Pick the connection with `tia_pg_interfaces` (no scan). |\n\nScaffold order (UDTs BEFORE the blocks that use them): by hand, `tia_guide {"topic":"recipes"}`, \'Pipeline order\'. `tia_spec_apply` automates only subnets, devices, modules, network, tag tables, tags, FB shells, control-module instance DBs and the compile; protection, constants, UDTs and all logic stay manual. The FB shells it creates are empty: add their logic with `tia_source_put` (SCL) or `tia_import_xml` (LAD/FBD).\n\nPLC-scoped steps use the PlcSoftware (e.g. `PLC_1`) read after the device step, not the device name.\n\n## The approval envelope (what a gate handoff looks like)\n\nGated tools return `status:"requires_human_action"` with:\n\n- `gate` \u2014 which gate (e.g. `download_approval`, `station_upload`, `go_online`, `trust_dialog`);\n- `youMustDo` \u2014 what the human must confirm, in plain words;\n- `plan` + `planHash` \u2014 exactly what would be executed (the hash binds the approval to\n this exact plan; a changed plan needs a new approval); the download\'s plan also carries\n `fingerprint` (the software content the plan was verified against \u2014 show it too);\n- `nextSteps` \u2014 how to resume after the human\'s yes.\n\nRelay the envelope to the human, wait for an explicit yes, resume exactly as\ninstructed. The AI never approves, never invents a secret, never deploys F-logic.\n\n**Confirmation dialog.** When the client supports elicitation, the crossing calls (`tia_download` with\n`approved:true`; `tia_upload`, `tia_online`, `tia_accessible_devices` with `confirm:true`) first ask the\nhuman in a dialog; clients without it behave as before. The dialog only checks the human\'s answer: the\n`planHash` and serve\'s approval token stay the authority.\nPasswords (G6) are never asked there. `declined_by_human` / `cancelled_by_human` = the human refused:\nnothing was sent, no retry unless asked. `elicitation_failed` (`isError`) = the dialog could not be\nshown or answered, nothing was sent (fails closed).\n\n## After scaffolding\n\n- Re-run `tia_compile` after ANY authoring change.\n- `tia_project_save` regularly; `tia_project_archive` BEFORE risky operations\n (firmware change \u2014 see `tia_guide {"topic":"gotchas"}`).\n- Auditing an existing project is class R (`tia_plc_*` reads); baseline: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 network, audit and CAx how-to\'.\n- `tia_crossrefs` (class R, a long read: it may answer `status:"running"` + `jobId`, then poll\n `tia_job_status`) reads the cross-references: in an audit, `filter:"UnusedObjects"` lists\n unused-object CANDIDATES, never proof (OBs, objects used only from outside the PLC such as an\n HMI, OPC UA or another CPU, and library TYPEs show as unreferenced); before changing an\n existing object, `target` + `kind` + `filter:"ObjectsWithReferences"` returns the objects related\n to it with each `referenceType` and `access` as TIA reports them (the direction of `Uses` /\n `UsedBy` is not interpreted: the human confirms it). Page a whole-PLC or container read with `limit`\n (for example 200) and `cursor` (the `nextCursor` of the previous page, until it is null; on\n `cursor_stale` restart from the first page, and on an omission marker repeat the same request\n with a smaller `limit`, never following a cursor from an omitted page); each page re-reads the\n whole PLC, so a later page can report less than an earlier one. Read `coverage` on every page,\n not only the first, and compare its counts across pages: differing counts restart the walk once\n from the first page (like `cursor_stale`). Only a finished walk whose pages all report\n `coverage.complete: true` supports "audited completely" or "nothing uses this"; an omission\n marker, an unfinished walk, differing counts or `coverage.complete: false` on any page (see\n `coverage.unavailableOwners`) means the result is NOT complete.\n- **FAT/SAT I/O list** (`tia-verify` step 6): `tia_io_map`; recipe: `tia_guide {"topic":"recipes"}`, \'Recipe \u2014 generate the FAT/SAT I/O list\'.\n- **Prove the project matches what\'s versioned** (a raw hash is NOT proof): `tia_guide {"topic":"recipes"}`, \'Recipe \u2014 prove the project matches the versioned XML\'.\n\n## Network lifecycle (subnets, PROFINET names, IO systems)\n\nRead first (`tia_subnet_get`, `tia_device_network`, `tia_io_systems`), then run each write\'s `dryRun` (answered by\nthe serve, needs an open project). Order, PROFINET names, `disconnectNodes`: `tia_guide {"topic":"recipes"}`, \'Reference \u2014 network, audit and CAx how-to\'.\n\n- **Refused, nothing changed:** `tia_subnet_delete` of a non-empty subnet (`409 subnet_not_empty`);\n `tia_io_system_connect` across subnets (`409 cross_subnet_assignment`: `tia_network_connect` the device to that subnet first).\n- **`409 postcheck_failed`:** the write did not take effect as asked: re-read, never repeat blindly.\n\n## Libraries, HMI, CAx and PLC security\n\nReads are class R; every change is class M-off (offline, with `dryRun`) and reaches the CPU\nonly through a later `tia_compile` + human-gated `tia_download` (G3). Every file path is a\npath ON THE SERVE HOST.\n\n- **Guarded PLC writes** (`tia_tag_update`, `tia_constant_update`, `tia_constant_delete`,\n `tia_tagtable_delete`, `tia_block_group_delete`, `tia_ob_create`, `tia_block_compile`): the serve\n answers their `dryRun` (it needs an open project) with the guard verdict (name collision, default\n tag table, non-empty group, singleton OB).\n- **Project library:** `tia_library_mastercopies` / `tia_library_types` read it;\n `tia_library_mastercopy_create` turns a DEVICE into a master copy (a block cannot be a source);\n `tia_block_from_mastercopy` needs one that holds PLC blocks.\n- **Global libraries** (in the TIA Portal session, not the project): `tia_global_libraries`,\n `tia_global_library_create` / `_open` / `_save` / `_close`; save/close take the name from\n `tia_global_libraries` (exact name first, then ignoring case). REFUSED, nothing saved or closed\n (`404 not_found` / `409 conflict`): a name that picks no single open USER library (unknown, read-only\n system/corporate, several matches ignoring case) and a save of a `readWrite:false` library. Up to app\n 1.6.3 an unknown name can report success without saving or closing anything: check `tia_global_libraries`.\n- **HMI:** `tia_hmis` and `tia_hmi_screens` read any HMI; screen files\n (`tia_hmi_screen_export`, `tia_hmi_screens_import`) work for WinCC **Classic** only, and the\n import OVERWRITES same-named screens.\n- **CAx (AutomationML):** `tia_cax_export` / `tia_cax_import` (scope, `option` values: recipes). Archive the\n project before an overwrite. A failed transfer is an error after app 1.6.3; on an older serve check the\n devices with `tia_devices`.\n- **Error contracts by app version:** `tia_guide {"topic":"recipes"}`, \'Reference \u2014 global library and CAx error contracts (by app version)\'.\n- **PLC security:** `tia_certificates` / `tia_certificate_template` / `tia_password_policy`\n read; `tia_certificate_import` / `_export` / `_delete`, `tia_password_policy_set` and\n `tia_block_protect` change the project. **G6:** a block or certificate password and the\n password-policy values come from a HUMAN \u2014 never invent, guess or reuse one; dryRun plans\n show a password as `[redacted]`. A CPU without the certificate manager or a policy service\n answers 409.\n- **Multiuser:** `tia_project_servers`, `tia_server_projects` read Project Servers; `tia_local_session_open` needs NO open project (`tia_project_close`, `tia_start`). Nothing is ever checked in.\n\n---\n\n# Recipes (runtime-verified)\n\nNot copied here: Codex reads at most 32 KiB of AGENTS.md and cuts the rest without a word. Call\n`tia_guide {"topic":"recipes"}` for the verified recipes (unlocking a freshly-created CPU, the in-place firmware\nbump, Modbus TCP, S7 PUT/GET and OPC UA on the S7-1200, the scaffold order) before you need one.\n\n---\n\n# The project-spec (input model)\n\nA project-spec is ONE JSON document describing the whole project. Always run it\nthrough the pipeline front door: `tia_spec_validate` (rung 0, pure) \u2192 `tia_spec_plan`\n(dry) \u2192 `tia_spec_apply` (M-off, stops at gates).\n\n`tia_spec_validate` checks the shape only in part (it does not run the JSON Schema; the `spec-validate`\nskill adds it) and enforces: unique device/subnet/UDT/block/per-table tag names; every network node IP\ninside the subnet CIDR; `OrderNumber:<MLFB>/V<fw>` with `/V` \u2014 never `:V` (Gd5); no STL/GRAPH on an\nS7-1200; at most 8 SMs on an S7-1200 (its only module limit); and G5 \u2014 a spec with safety content\nmarked autonomous is REJECTED (F-logic is never autonomous).\n\nMinimal example:\n\n```json\n{\n "project": { "name": "Line2", "directory": "C:\\\\TIA\\\\Line2" },\n "conventions": {\n "namingScheme": "plcopen",\n "optimizedAccess": true,\n "symbolicOnly": true,\n "defaultLanguages": { "interlocks": "LAD", "algorithms": "SCL", "sequencers": "GRAPH" }\n },\n "devices": [\n {\n "name": "Line2_CPU",\n "typeIdentifier": "OrderNumber:6ES7 511-1AK02-0AB0/V2.9",\n "role": "cpu",\n "family": "S7-1500"\n }\n ],\n "network": {\n "subnet": { "type": "System:Subnet.Ethernet", "name": "PN_Line2", "cidr": "192.168.0.0/24" },\n "nodes": [{ "device": "Line2_CPU", "ip": "192.168.0.1", "createIoSystem": true }]\n },\n "dataTypes": [\n {\n "name": "UDT_Motor",\n "members": [\n { "name": "xStart", "dataType": "Bool", "comment": "Start command" },\n { "name": "rSpeed", "dataType": "Real", "comment": "Speed [%]" }\n ]\n }\n ],\n "tagTables": [{ "name": "IO", "purpose": "IO" }],\n "tags": [{ "table": "IO", "name": "Conv01_Run", "dataType": "Bool", "address": "%Q0.0" }]\n}\n```\n\nThe plan and `tia_spec_apply` neither import `dataTypes` nor author block logic: UDTs go in with\n`tia_types_import`, logic with `tia_source_put` / `tia_import_xml`.\n\nResolve every concrete MLFB + firmware via `tia_catalog` before building \u2014 never guess\nan order number. Project firmware must be \u2264 the physical device\'s firmware.\n';
|
|
23953
23961
|
|
|
23954
23962
|
// src/mode.ts
|
|
23955
23963
|
var MCP_MODES = ["full", "read-only"];
|
|
@@ -32774,7 +32782,7 @@ function registerJobTools(server) {
|
|
|
32774
32782
|
"tia_job_status",
|
|
32775
32783
|
{
|
|
32776
32784
|
title: "TIA \u2014 long-operation status",
|
|
32777
|
-
description: 'Waits (up to waitSeconds, default 20, max 25) for a background job started by a long tool that answered status:"running" (tia_connect, tia_start, tia_show_ui, tia_project_create/save/saveas/close/archive, tia_compile, tia_source_put, tia_download, tia_upload, tia_export_xml, tia_export_block, tia_block_compare, tia_crossrefs, tia_io_map, tia_spec_apply, tia_cax_export/import, tia_hmi_screen_export, tia_hmi_screens_import, tia_hmi_validate, tia_global_library_create/open/save, tia_library_mastercopy_create, tia_vci_status, tia_vci_export, tia_vci_import) and returns its FINAL result with job:{id,tool,state,durationMs} \u2014 including a gate handoff if the operation ended in one. While a job runs, every other serve-bound tool answers kind:"busy" (with details.jobId): call this instead of polling tia_status, and never repeat the original call.
|
|
32785
|
+
description: 'Waits (up to waitSeconds, default 20, max 25) for a background job started by a long tool that answered status:"running" (tia_connect, tia_start, tia_show_ui, tia_project_create/save/saveas/close/archive, tia_compile, tia_source_put, tia_download, tia_upload, tia_export_xml, tia_export_block, tia_block_compare, tia_crossrefs, tia_io_map, tia_spec_apply, tia_cax_export/import, tia_hmi_screen_export, tia_hmi_screens_import, tia_hmi_validate, tia_global_library_create/open/save, tia_library_mastercopy_create, tia_vci_status, tia_vci_export, tia_vci_import) and returns its FINAL result with job:{id,tool,state,durationMs} \u2014 including a gate handoff if the operation ended in one. While a job runs, every other serve-bound tool answers kind:"busy" (with details.jobId): call this instead of polling tia_status, and never repeat the original call. A lifecycle job that is still running may be starting or waiting for a trust dialog; running alone is not G1 evidence. Follow its conditional nextSteps, and ask a human to confirm G1 only if the dialog is visible on the serve host. Does not call serve. Class R.',
|
|
32778
32786
|
inputSchema: {
|
|
32779
32787
|
jobId: external_exports.string().describe("jobId returned by the long tool (or by a busy error's details.jobId)"),
|
|
32780
32788
|
waitSeconds: external_exports.number().int().min(0).max(25).optional().describe("how long this call may wait (default 20, max 25)")
|
|
@@ -33679,37 +33687,46 @@ function discardConfirmation(tool, target) {
|
|
|
33679
33687
|
}
|
|
33680
33688
|
|
|
33681
33689
|
// src/tools/lifecycle.ts
|
|
33682
|
-
|
|
33683
|
-
|
|
33684
|
-
return [
|
|
33685
|
-
"1. The original create may STILL BE RUNNING on the serve (the client timeout did not cancel it \u2014 the worker is blocked on the dialog). Ask a human to confirm the trust dialog on the serve host.",
|
|
33686
|
-
"2. After the human confirms, check tia_status / tia_project_info: if the project exists (hasProject, path matches), just continue \u2014 do NOT re-call.",
|
|
33687
|
-
"3. Re-call tia_project_create with the SAME arguments only if the create did not complete (a second create into the same folder would conflict)."
|
|
33688
|
-
];
|
|
33689
|
-
}
|
|
33690
|
-
return [
|
|
33691
|
-
"1. Ask a human to find the trust dialog on the serve host \u2014 it may be hidden behind other windows or on the taskbar. Do NOT call tia_show_ui while the original call is still blocked: it would queue behind it on the same serial worker.",
|
|
33692
|
-
"2. Only once tia_status answers again (the worker is free) may tia_show_ui be used to render the dialog.",
|
|
33693
|
-
`3. Re-call ${tool} with the SAME arguments after the human confirms.`
|
|
33694
|
-
];
|
|
33695
|
-
}
|
|
33690
|
+
var LIFECYCLE_TIMEOUT_MS = 20 * 60 * 1e3;
|
|
33691
|
+
var LIFECYCLE_RUNNING_HINT = "This lifecycle operation may still be starting or waiting for the Openness trust dialog on the serve host. A running result is not success or a G1 handoff. If a dialog is visible, ask a human to confirm it (G1); otherwise keep calling tia_job_status. Do not call tia_status or repeat the original call while the job is running.";
|
|
33696
33692
|
async function postResult2(path, body, opts) {
|
|
33697
33693
|
return postResult(path, body, {
|
|
33698
33694
|
timeoutMs: opts?.timeoutMs,
|
|
33699
33695
|
mapError: async (err) => {
|
|
33700
|
-
if (err.kind === "tia_start_failed") return tiaStartFailedResult(err, opts?.
|
|
33701
|
-
|
|
33702
|
-
|
|
33703
|
-
return waitingForTrustHandoff(tool, tool, startToolNextSteps(tool), err);
|
|
33696
|
+
if (err.kind === "tia_start_failed") return tiaStartFailedResult(err, opts?.lifecycleTool ?? path);
|
|
33697
|
+
if (opts?.lifecycleTool !== void 0 && err.kind === "timeout") {
|
|
33698
|
+
return startingUnconfirmedResult(err, opts.lifecycleTool);
|
|
33704
33699
|
}
|
|
33705
33700
|
return errorResult(err);
|
|
33706
33701
|
}
|
|
33707
33702
|
});
|
|
33708
33703
|
}
|
|
33704
|
+
function startingUnconfirmedResult(err, operation) {
|
|
33705
|
+
return textResult(
|
|
33706
|
+
{
|
|
33707
|
+
state: "STARTING_UNCONFIRMED",
|
|
33708
|
+
operation,
|
|
33709
|
+
error: "The 20-minute client timeout expired before completion was observed; the serve operation may still be running.",
|
|
33710
|
+
kind: err.kind,
|
|
33711
|
+
status: err.status,
|
|
33712
|
+
type: err.type,
|
|
33713
|
+
// Stryker disable next-line LogicalOperator: Client-created timeouts omit `inner` and TiaApiError defaults it to null; the serve emits no timeout kind.
|
|
33714
|
+
inner: err.inner ?? null,
|
|
33715
|
+
// Stryker disable next-line LogicalOperator: Client-created timeouts omit `details` and TiaApiError defaults it to null; the serve emits no timeout kind.
|
|
33716
|
+
details: err.details ?? null,
|
|
33717
|
+
hint: "The client timeout does not cancel the serve-side operation, so its serial worker may still be occupied. A timeout or reachable /health endpoint proves neither success nor G1.",
|
|
33718
|
+
nextSteps: [
|
|
33719
|
+
"1. The client timeout did not cancel the serve-side operation; its serial worker may still be occupied.",
|
|
33720
|
+
"2. Do not queue any further serve-bound calls (including tia_status, tia_show_ui, or the original mutation) while the worker may be held. Ask a human to inspect the serve host and wait until the operation is known to have completed.",
|
|
33721
|
+
"3. Only after the serve is responsive, call tia_status. If a trust dialog is visible on the serve host, ask a human to confirm it (G1)."
|
|
33722
|
+
],
|
|
33723
|
+
...auditWarningOf(err)
|
|
33724
|
+
},
|
|
33725
|
+
true
|
|
33726
|
+
);
|
|
33727
|
+
}
|
|
33709
33728
|
function looksLikeTrustGate(err) {
|
|
33710
|
-
|
|
33711
|
-
const blob = `${err.message} ${err.inner ?? ""}`.toLowerCase();
|
|
33712
|
-
return /\b(trust|security)\b/.test(blob) || blob.includes("operation has timed out") || blob.includes("engineeringsecurity");
|
|
33729
|
+
return err.type === "EngineeringSecurityException";
|
|
33713
33730
|
}
|
|
33714
33731
|
function trustHandoff(projectPath, err) {
|
|
33715
33732
|
return waitingForTrustHandoff(`connect ${projectPath}`, projectPath, [
|
|
@@ -33728,7 +33745,7 @@ function waitingForTrustHandoff(canDo, resumeSubject, nextSteps, err) {
|
|
|
33728
33745
|
state: "WAITING_FOR_TRUST",
|
|
33729
33746
|
canDo,
|
|
33730
33747
|
youMustDo: 'A human needs to confirm the TIA Openness TRUST/SECURITY dialog ON THE SERVE HOST (click "Sim, para tudo" / "Yes to all"). It is required on the 1st connection of each `serve` process and CANNOT be automated (for security reasons).',
|
|
33731
|
-
caveat: 'This handoff is
|
|
33748
|
+
caveat: 'This handoff is based on an explicit serve-reported trust signal: EngineeringSecurityException or tia_start_failed with details.cause:"trust". A client timeout or reachable /health endpoint alone is not evidence of a pending dialog. While a lifecycle job is running, keep calling tia_job_status; if a trust dialog is visible on the serve host, ask a human to confirm it. Details: tia_guide {"topic":"gui-gates"}.',
|
|
33732
33749
|
nextSteps,
|
|
33733
33750
|
blockingError: err.message,
|
|
33734
33751
|
...auditWarningOf(err),
|
|
@@ -33798,7 +33815,7 @@ async function connectFlow(args) {
|
|
|
33798
33815
|
const data = await tiaFetch(
|
|
33799
33816
|
"/connect",
|
|
33800
33817
|
{ method: "POST", headers: JSON_HEADERS, body: JSON.stringify(body) },
|
|
33801
|
-
{ timeoutMs:
|
|
33818
|
+
{ timeoutMs: LIFECYCLE_TIMEOUT_MS }
|
|
33802
33819
|
);
|
|
33803
33820
|
return textResult(resumeToken ? { resumed: true, project: data, ...auditWarningOf(data) } : data);
|
|
33804
33821
|
} catch (e) {
|
|
@@ -33807,7 +33824,7 @@ async function connectFlow(args) {
|
|
|
33807
33824
|
if (err.kind === "unsaved_changes") return errorResult(err);
|
|
33808
33825
|
if (err.kind === "tia_start_failed") return tiaStartFailedResult(err, `connect ${projectPath}`);
|
|
33809
33826
|
if (looksLikeTrustGate(err)) return trustHandoff(projectPath, err);
|
|
33810
|
-
if (err.kind === "timeout"
|
|
33827
|
+
if (err.kind === "timeout") return startingUnconfirmedResult(err, "tia_connect");
|
|
33811
33828
|
return errorResult(err);
|
|
33812
33829
|
}
|
|
33813
33830
|
}
|
|
@@ -33833,7 +33850,15 @@ function registerLifecycleTools(server) {
|
|
|
33833
33850
|
headless: external_exports.boolean().optional().describe("true = no window (fast offline authoring); false (default) = with window. Only when creating a new instance.")
|
|
33834
33851
|
}
|
|
33835
33852
|
},
|
|
33836
|
-
async ({ headless }) => jobs.run(
|
|
33853
|
+
async ({ headless }) => jobs.run(
|
|
33854
|
+
"tia_start",
|
|
33855
|
+
{ headless },
|
|
33856
|
+
() => postResult2("/tia/start", jsonBody({ headless }), {
|
|
33857
|
+
timeoutMs: LIFECYCLE_TIMEOUT_MS,
|
|
33858
|
+
lifecycleTool: "tia_start"
|
|
33859
|
+
}),
|
|
33860
|
+
{ runningHint: LIFECYCLE_RUNNING_HINT }
|
|
33861
|
+
)
|
|
33837
33862
|
);
|
|
33838
33863
|
server.registerTool(
|
|
33839
33864
|
"tia_show_ui",
|
|
@@ -33843,7 +33868,15 @@ function registerLifecycleTools(server) {
|
|
|
33843
33868
|
inputSchema: {}
|
|
33844
33869
|
},
|
|
33845
33870
|
// Sem args: chave de dedupe = {} literal (nunca o `extra` do SDK, que muda a cada chamada).
|
|
33846
|
-
async () => jobs.run(
|
|
33871
|
+
async () => jobs.run(
|
|
33872
|
+
"tia_show_ui",
|
|
33873
|
+
{},
|
|
33874
|
+
() => postResult2("/tia/show-ui", void 0, {
|
|
33875
|
+
timeoutMs: LIFECYCLE_TIMEOUT_MS,
|
|
33876
|
+
lifecycleTool: "tia_show_ui"
|
|
33877
|
+
}),
|
|
33878
|
+
{ runningHint: LIFECYCLE_RUNNING_HINT }
|
|
33879
|
+
)
|
|
33847
33880
|
);
|
|
33848
33881
|
server.registerTool(
|
|
33849
33882
|
"tia_connect",
|
|
@@ -33861,7 +33894,14 @@ function registerLifecycleTools(server) {
|
|
|
33861
33894
|
}
|
|
33862
33895
|
},
|
|
33863
33896
|
// args INTEIROS na chave (dedupe por valor; o runner guarda só o hash — UMAC nunca fica em texto plano).
|
|
33864
|
-
async (args, extra) => confirmedDiscard(
|
|
33897
|
+
async (args, extra) => confirmedDiscard(
|
|
33898
|
+
server,
|
|
33899
|
+
"tia_connect",
|
|
33900
|
+
`open ${args.projectPath}`,
|
|
33901
|
+
args.discardUnsavedChanges,
|
|
33902
|
+
() => jobs.run("tia_connect", args, () => connectFlow(args), { runningHint: LIFECYCLE_RUNNING_HINT }),
|
|
33903
|
+
extra
|
|
33904
|
+
)
|
|
33865
33905
|
);
|
|
33866
33906
|
server.registerTool(
|
|
33867
33907
|
"tia_disconnect",
|
|
@@ -33899,10 +33939,12 @@ function registerLifecycleTools(server) {
|
|
|
33899
33939
|
() => jobs.run(
|
|
33900
33940
|
"tia_project_create",
|
|
33901
33941
|
{ directory, name, withUserInterface, saveUnsavedChanges, discardUnsavedChanges },
|
|
33902
|
-
() => postResult2(
|
|
33903
|
-
|
|
33904
|
-
|
|
33905
|
-
|
|
33942
|
+
() => postResult2(
|
|
33943
|
+
"/project/create",
|
|
33944
|
+
jsonBody({ directory, name, withUserInterface, saveUnsavedChanges, discardUnsavedChanges }),
|
|
33945
|
+
{ timeoutMs: LIFECYCLE_TIMEOUT_MS, lifecycleTool: "tia_project_create" }
|
|
33946
|
+
),
|
|
33947
|
+
{ runningHint: LIFECYCLE_RUNNING_HINT }
|
|
33906
33948
|
),
|
|
33907
33949
|
extra
|
|
33908
33950
|
)
|
|
@@ -39793,7 +39835,7 @@ function buildServer(mode, version2, budget = resolveBudget()) {
|
|
|
39793
39835
|
}
|
|
39794
39836
|
|
|
39795
39837
|
// src/index.ts
|
|
39796
|
-
var VERSION = "1.
|
|
39838
|
+
var VERSION = "1.11.0";
|
|
39797
39839
|
async function main() {
|
|
39798
39840
|
if (process.argv.slice(2).some((a) => a === "--version" || a === "-v")) {
|
|
39799
39841
|
console.log(VERSION);
|
package/package.json
CHANGED
|
@@ -1,7 +1,24 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@renanlido/tia-openness-mcp",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.11.0",
|
|
4
4
|
"description": "MCP server (stdio) — thin HTTP client over the TIA Openness `serve` API. Zero Openness/net48 references.",
|
|
5
|
+
"mcpName": "io.github.renanlido/tia-openness",
|
|
6
|
+
"keywords": [
|
|
7
|
+
"mcp",
|
|
8
|
+
"model-context-protocol",
|
|
9
|
+
"tia-portal",
|
|
10
|
+
"siemens",
|
|
11
|
+
"openness",
|
|
12
|
+
"plc",
|
|
13
|
+
"scl",
|
|
14
|
+
"simaticml",
|
|
15
|
+
"industrial-automation",
|
|
16
|
+
"automation"
|
|
17
|
+
],
|
|
18
|
+
"homepage": "https://plcware.io/en?utm_source=npm&utm_medium=package&utm_campaign=mcp-listing",
|
|
19
|
+
"bugs": {
|
|
20
|
+
"url": "https://github.com/renanlido/tia-openness/issues"
|
|
21
|
+
},
|
|
5
22
|
"license": "MIT",
|
|
6
23
|
"type": "module",
|
|
7
24
|
"bin": {
|
|
@@ -16,8 +33,7 @@
|
|
|
16
33
|
},
|
|
17
34
|
"repository": {
|
|
18
35
|
"type": "git",
|
|
19
|
-
"url": "git+https://github.com/
|
|
20
|
-
"directory": "mcp"
|
|
36
|
+
"url": "git+https://github.com/renanlido/tia-openness.git"
|
|
21
37
|
},
|
|
22
38
|
"publishConfig": {
|
|
23
39
|
"access": "public"
|