opcua-readonly-mcp
This server does not currently have a deployable release on Glama. Follow the repository's setup instructions to install and configure it for your MCP client, including any required credentials and local dependencies.
opcua-readonly-mcp
Problem
An AI model that can browse and read plant data over OPC UA is useful. A model that can write a setpoint or call a method on a running machine is a safety risk. This project is a Model Context Protocol (MCP) server that lets a model browse and read OPC UA nodes through a node allowlist, a rate limit, and an audit log. The code has no write, method call, or subscription path. Static tests and runtime tests prove this. The tool limits what this server can send. It does not make a plant safe.
Related MCP server: opcua-mcp
Quick start
python -m venv .venv
.venv/Scripts/python -m pip install -r requirements.txt # Linux/macOS: .venv/bin/python
.venv/Scripts/python demo.pyThe demo starts an in-process OPC UA simulator on a free port, builds the MCP server, and calls the tools through mcp.Client. It exits 0 when all simulator counters are 0.
Run as a stdio MCP server against your own test server:
python -m opcua_readonly_mcp --config config/demo.json --check # connect, resolve, print allowlist; exit 0, or 2 on error
python -m opcua_readonly_mcp --config config/demo.json # stdio MCP serverTo run the simulator alone on port 4840 (matches config/demo.json): python -m simulator.sim_server.
Tools
Tool | Arguments | Returns |
| none |
|
|
|
|
|
| One row per node: |
|
|
|
Resource opcua://allowlist returns the resolved allow and deny patterns, the roots, and the namespace array.
Errors are MCP tool errors with a fixed prefix: Access denied:, Rate limit:, Bad request: (REQ001 too many nodes, REQ002 max_results out of range, REQ003 node ID does not parse, REQ004 attribute name not in the set), OPC UA error:, Timeout:.
Read-only layers
Layer | Where | What it stops | Test |
RO1 Tool surface |
| Exactly four tools and one resource. No tool has a value, data, or method argument. Extra JSON keys are dropped. |
|
RO2 One gateway |
| Only this module imports asyncua. The client is private; the gateway has only |
|
RO3 Forbidden names |
| Write, call, subscribe, node management, and history names; |
|
RO4 Runtime proof |
| Counts writes, method calls, subscriptions, and node changes while every tool runs on every allowed node plus hostile input. All stay 0; all Plant values and the address space size stay the same. |
|
RO5 Negative control |
| A raw asyncua client writes the bait node and calls the bait method; each counter goes to 1. This proves RO4 can see a write. |
|
RO6 Server side | your OPC UA server | Connect with an OPC UA user whose server rights are read-only. The server is the real guard. | none (the simulator does not enforce users) |
How the simulator counts (asyncua has callbacks for some cases only):
writes:
CallbackType.PreWriteserver callback, client sessions only (the server updates its own status nodes through an internal session).method calls: the handler of the bait method
Plant.Line1.ResetCounter.subscriptions:
CallbackType.ItemSubscriptionCreated(monitored items) plus a counting wrapper on the subscription service, because there is no callback for CreateSubscription.node changes: a counting wrapper on AddNodes, DeleteNodes, AddReferences, DeleteReferences, because asyncua has no callback for them. RO4 also compares all Plant values and the node count before and after.
Run the static scan alone: python -m opcua_readonly_mcp.selfscan [DIR] (exit 1 on a hit).
Allowlist and namespace URIs
A caller may send
ns=2;s=...,nsu=<uri>;s=..., or barei=,s=,g=,b=(namespace 0).The server turns each node ID into the canonical form
nsu=<uri>;<type>=<id>with the server namespace array, then matches it withfnmatch.fnmatchcase.Patterns must use the
nsu=form with a literal URI, so a namespace index change on the server cannot move a pattern to other nodes.Deny wins over allow. A
*in a caller node ID is a literal character, never a pattern.Namespace 0 nodes are denied unless an allow pattern names
nsu=http://opcfoundation.org/UA/;...explicitly.A denied node and a missing node give the same message, so a caller cannot probe for hidden nodes.
Configuration
Unknown keys are an error. Config errors exit 2 at start.
Key | Default | Meaning |
| required |
|
|
|
|
| required | Start nodes. Each must be allowed (CFG005). |
| required / |
|
| 60 | Sliding 60-second window per process. |
| 50 | REQ001 above this. |
| 200 | Upper bound for |
| 4096 | Strings, ByteString base64, and structure text are cut to this. |
| 1000 | Arrays are cut to this. |
| 5 |
|
|
| JSONL file, one line per tool call: |
All limits must be positive integers (CFG004). Values: DateTime as ISO 8601 UTC, ByteString as base64, LocalizedText as text, structures as {"type", "repr"}.
Sample output
Real output of python demo.py:
simulator: opc.tcp://127.0.0.1:62616/demo/ namespace urn:demo:plant
> server_info ok state=Running namespaces=3
> browse Plant.Line1 ok 4 children, 1 hidden
> read_values Press1.* ok Temperature=20.0 Running=True CycleCount=1200 State=AUTO
> read_values Recipe ok truncated at 4096 chars
> read Maintenance.Password Access denied
> 61 calls in one minute call 61: Rate limit
> audit.log 66 lines, outcomes ok 64 denied 1 rate_limited 1
simulator counters: writes 0, method calls 0, subscriptions 0, node changes 0Tests
python -m unittest discover -s tests -t .45 tests: config (8), allowlist (8), tools (12), limits and audit (7), read-only (10).
Design notes
No subscriptions: a subscription keeps server resources alive and pushes data without a tool call, so it bypasses the rate limit and the audit log. Polling with
read_valuesis enough for a model.One gateway module: the read-only claim is easy to check when one small file holds the only asyncua import and the only client object. The ast scan enforces this in CI.
Same message for denied and missing: different messages would let a caller find hidden node names by trial.
No
getattror string dispatch: a tool cannot turn caller text into a method name.Built on the official
mcpSDK (MCPServer,@mcp.tool(),@mcp.resource(...),ToolError), the same pattern as the siblingreadonly-sql-mcpproject.
Limits
Only security policy None is tested. Other security strings pass to asyncua unchanged.
One OPC UA endpoint per process. No reconnect after the connection drops; restart the process.
The rate limit is per process, not per user.
The server rights of the OPC UA user are the real guard (RO6). This project limits what this MCP server can send; it does not make a plant safe.
The simulator does not enforce users or access rights.
asyncua version:
requirements.txtpinsasyncua==1.1.8for Python below 3.14. On Python 3.14, 1.1.8 installs but its client fails at run time (TypeError in the binary serializer), so Python 3.14 usesasyncua==2.1.0, the newest release. Local tests ran on Python 3.14 with 2.1.0 only; the 1.1.8 path runs in CI on Python 3.12.Tool argument type errors are rejected by the MCP SDK before the tool runs, so they have no audit line.
All data is synthetic.
Tool Schema Changelog
Recent tool additions, removals, and schema changes observed during successful MCP inspections.
Loading tool schema changelog…
This server cannot be deployed
Maintenance
Related MCP Connectors
Read-only finance and operations controls for AI agents with evidence and safe next actions.
Read-only MCP tools for AI agent discovery, structured resources, and NIULAI information.
Read-only Attify tools: AI agent verdicts, standards, attestations and definitions.
Read-only access to a company's ERP for Claude, ChatGPT and Gemini, with OAuth and an audit trail.
Related MCP Servers
- AlicenseNot gradedqualityDmaintenanceConnects AI agents to OPC UA-enabled industrial systems for real-time monitoring and control of operational data. It enables users to read, write, and browse industrial device nodes through natural language interactions.MIT
- AlicenseNot gradedqualityBmaintenanceEnables LLMs to read, write, browse, search, and subscribe to live data on OPC-UA industrial automation servers, with caching, discovery index, and support for stdio or HTTP transports.7MIT
- AlicenseNot gradedqualityDmaintenanceEnables a language model to safely query internal services through a closed set of read-only, schema-validated tools, with full auditing and refusal logging.MIT
- AlicenseNot gradedqualityCmaintenanceEnables AI agents to discover, browse, read, search, and safely write OPC UA industrial device data within controlled edge networks, with guarded two-phase writes and evidence-based root-cause diagnostics.1Apache 2.0