# An AI agent can already read Siemens TIA Portal. Writing back is where it breaks.

> Source: <https://dev.to/tiaforge/an-ai-agent-can-already-read-siemens-tia-portal-writing-back-is-where-it-breaks-3pbn>
> Published: 2026-11-19 08:09:32+00:00

**Recommendation:** Split read and write tools by trust level, require revision-id matching on every block write, and attach a passing simulator scenario to each proposed diff before human approval.
More in the playbook "Designing agent systems": <https://wpnews.pro/playbooks/agent-architecture>

An AI agent can already open a Siemens TIA Portal project and read it: block interfaces, hardware tree, tag tables, the SCL inside each FB. That part is solved — Siemens Openness has been scriptable for years, and wrapping it in MCP takes a weekend.

Writing back is where it falls apart. Not because the model writes bad SCL, but because five specific things go wrong the first time an agent touches a live engineering project, and none of them are visible in a chat window.

If you're building this — an MCP server for PLC tooling, or a gateway like the one we maintain — these are the failures to design against from the start, in the order we hit them.

The reflex is to read through the PLC: OPC UA, browse the tag tree, done. That works for values. It does not give you the program: block interfaces, DB layouts, network titles, comment text, the declaration table.

For anything that involves *editing* a program you need the engineering tool's API (Openness on Siemens, the scripting API on CODESYS, L5X on Rockwell). Two different data sources with two different security models — plan for both, because "read the current value of this tag" and "show me what this block does" are different questions.

The model reads a block, spends 40 seconds reasoning, produces a modified version. Meanwhile someone else — a colleague, a batch job, the agent's own previous call — changed the same block. Your write now silently reverts their change.

Nothing about the output looks wrong. That's what makes it dangerous: it is valid SCL, it compiles, and it deletes a fix.

The fix is cheap and non-negotiable: read the block's revision id (or timestamp + hash), send it back with the write, and reject the write if it no longer matches. Optimistic concurrency, applied to control code. Same idea as `If-Match` on an HTTP PUT — nothing novel, just usually missing in AI tooling.

Split the tool surface by trust level:

`update_block(text)` that can do both, and never a generic "execute SCL".
An agent that can rewrite a logic block and also write a setpoint will, sooner or later, decide the setpoint is the problem. Design the API so it can't.

Every Openness round-trip on a real project is slow — compile, download and read-back are minutes, not milliseconds. If your tool list has 60 granular calls, the agent burns its context and the operator's patience walking them one by one, and half the calls fail on state that changed between them.

The shape that actually works is coarse: *apply this block → compile → tell me the first error, with its network number*. One tool call, one verifiable outcome, and the error text is what the model needs for the next attempt. Granularity should match the editor's own save points, not its keystrokes.

"Compiles" is not "works". The agent needs an oracle it can't argue with: run the logic against a scenario and get PASS/FAIL back.

That's why the most useful MCP server in this stack is the simulator, not the code writer. A cloud LAD/SCL runner that takes a block plus a scenario (`start button pressed, E-stop not pressed, 3 s later conveyor motor = on`) and returns a pass/fail with the first divergence is what lets an agent iterate on its own — reject its own drafts, without a PLC and without a human in the loop.

Once you have that, the loop becomes: draft → simulate → fix → simulate → propose. The human moves from writing code to approving a diff that already has a passing scenario attached.

Six things, in this order, before any write reaches a real project:

Plus one policy decision: anything that changes a setpoint, a safety-relevant parameter or a hardware configuration requires a human approval step, no matter how good the scenario result was.

If you're evaluating this kind of tooling (ours or anyone's), don't measure "did it generate valid SCL" — every decent model does. Measure how it behaves when the input is wrong: does a sensor that never comes on produce one specific labelled fault, or an endless wait? Does a stale block version get rejected, or silently overwrite? Does the agent stop at the guard, or route around it?

That's the difference between a demo and something you'd let near a machine.

*Disclosure: I work on [TiaLink](https://tia.hubwiz.com/tia-link?utm_source=devto&utm_medium=article&utm_campaign=tia-portal-mcp-guards), a commercial TIA Portal MCP gateway that implements the guards above — on-premises, driving Siemens Openness on the same machine as TIA Portal.*

*If you want to try the pieces without installing anything or buying a licence, three hosted MCP services take plain SimaticML over Streamable HTTP and give 100 free calls on signup:*

*No affiliation with Siemens implied; Openness is their interface, the guards and mistakes above are ours.*
