OPC UA MCP Server 标志

OPC UA MCP Server

组织
IndustriAgents

MCP server that connects AI agents ( Claude, ChatGPT, Gemini, Cursor etc.) to OPC UA systems — read, browse, history, subscriptions, events and alarms.

发布者IndustriAgents
代码仓库OPCUA-MCP
语言Python
复刻数
10
星标数
25
可用工具
0
传输类型stdio
分类
许可协议MIT
链接
  • 将工具接入 AI 工作流

    OPC UA MCP Server 提供 MCP 功能,可供兼容的 AI 客户端和智能体使用。

  • 0 个可用工具

    浏览下方可调用的操作;如果服务器提供了名称和描述,也会一并显示。

  • 可直接复制的配置

    使用安装配置片段,在您首选的 MCP 客户端中配置此服务器。

  • 开源社区热度

    关联的代码仓库有 25 个星标和 10 个复刻。

🏭 OPC UA MCP Server

Read industrial sensors and control equipment on any OPC UA server — through natural language with Claude and any MCP client.

npm version PyPI version npm downloads CI License: MIT GitHub stars

Python 3.10+ Node.js 22.13+ MCP PRs Welcome

Quick Start · Install · Tools · Examples · Compatibility · Architecture · Testing · Roadmap · Contributing

OPC UA MCP Server Screenshot

Overview

Thirteen MCP tools over plain OPC UA: read and write nodes, browse the address space, call methods, read history and server-side aggregates, and subscribe to data changes, events and alarms. It connects to any server that speaks OPC UA — PLC, SCADA gateway or historian.

What is actually offered on a given connection depends on three things: what the server advertises it can do, what the OPC UA account is permitted to do, and which tool profile you configured. The default profile is read-only.

There are two interchangeable implementations, Python and TypeScript/Node, held to one shared contract by the test suite — same tools, same arguments, same responses. Install whichever your machine already has; nothing below depends on the choice.

Which servers and operations the test suite exercises, and which are only reported by users, is set out in docs/compatibility.md.

One process talks to one endpoint. OPCUA_SERVER_URL is read once at startup, every tool targets it, and the only transport is stdio — so the server runs beside the MCP client that started it, and each client gets its own OPC UA session. That is the right shape for an engineer at a workstation, which is what this is built for. A site with five PLCs runs five entries in the client config, and if OPC UA sessions are a licensed resource on your equipment, count on one per client per endpoint. What it would take to be a shared plant-wide gateway instead is set out in the roadmap.

Quick Start

Claude Desktop, nothing installed? Download the .mcpb bundle from the latest release and drag it into Settings → Extensions. It carries the server and every dependency, Claude Desktop supplies the runtime, and the OPC UA endpoint is a field in the settings form — no Node, no Python, no JSON to edit.

Already have a runtime? Install the package and let it write the config:

bash
npm install -g opcua-mcp-server        # or: uv tool install opcua-mcp-server
opcua-mcp-server --install claude-desktop --url opc.tcp://192.168.0.10:4840

--install writes absolute paths rather than a bare npx, which matters more than it sounds: Claude Desktop is launched from the GUI and does not inherit a login shell's PATH. --dry-run shows the result without writing it. Without a permanent install, npx and uvx fetch the package on demand.

Prefer to configure it yourself? Add this to your MCP client config and point OPCUA_SERVER_URL at your OPC UA endpoint:

json
{
  "mcpServers": {
    "opcua": {
      "command": "npx",
      "args": ["-y", "opcua-mcp-server"],
      "env": { "OPCUA_SERVER_URL": "opc.tcp://localhost:4840" }
    }
  }
}

The two runtimes are interchangeable — same tools, same arguments, same responses — so this is a question of what is already on the machine, not of capability. For the Python package, swap the command:

json
{ "command": "uvx", "args": ["opcua-mcp-server"] }

Claude Code needs no file at all:

bash
claude mcp add opcua -e OPCUA_SERVER_URL=opc.tcp://localhost:4840 -- npx -y opcua-mcp-server

Single-file executables for machines with no runtime and no network, and what to do when Claude Desktop cannot start the server: docs/install.md.

No OPC UA server to hand? This repo ships a mock industrial plant — see Try it against the mock.

Tools

Both servers expose the same fifteen tools, defined once in contract/tools.json so they cannot drift apart.

ToolWhat it does
read_opcua_nodesRead one or more nodes — value, data type, status, timestamps, engineering unit and range
browse_opcua_nodesList children, walk a subtree, resolve a browse path, search by name
write_opcua_nodesWrite to one or more nodes
call_opcua_methodInvoke a method on an object node
get_server_statusConnection state, server health, the namespace array and the server's own diagnostics
subscribe_opcua_nodesWatch nodes for data changes instead of polling them, with an optional deadband
list_subscriptionsThe active subscriptions, each with its buffered changes
unsubscribe_opcua_nodesCancel subscriptions
subscribe_eventsStart collecting events from a notifier node
read_eventsRead the events collected since the last read
list_active_alarmsThe alarms the server is currently retaining
acknowledge_alarmAcknowledge one of them, with a comment
act_on_alarmConfirm, annotate or shelve an alarm — the rest of the operator workflow
read_opcua_history †Historical values, raw or summarised by a server-side aggregate
read_event_history †Events the server stored, for a range that has already passed

† Capability-gated. read_opcua_history appears only when the connected server advertises historical access (AccessHistoryDataCapability) or aggregates (a non-empty AggregateFunctions folder). Its aggregate_function argument appears only with the latter, and its description then lists the functions that server actually offers. read_event_history is gated separately, on AccessHistoryEventsCapability — keeping values and keeping events are different features and a server commonly does one without the other. What a server cannot do is not on the menu, rather than failing at call time.

One tool per operation, not one per arity. Reading one node and reading fifty is the same request with a longer list, so it is one tool and one code path. Batching is the caller's choice, not a different API.

Both servers also expose one resource, opcua://subscriptions: the same records list_subscriptions returns, re-readable without spending a tool call.

Full per-tool reference with inputs, outputs and a node-ID map: docs/examples.md.

Example usage in conversation

Once configured, you can ask in plain language:

  • "What's the current temperature reading from the reactor vessel?"
  • "Set the valve position to 80%"
  • "Show me all available variables in the system"
  • "What was the temperature over the last hour?"
  • "Start production on line 1 at 100 units/hour"
  • "Give me the hourly average temperature for today"
  • "Watch the tank level and tell me what it does over the next minute"
  • "What alarms are active right now?"
  • "Acknowledge the high-temperature alarm — I'm looking into it"
  • "That level switch has cycled 40 times in an hour. Shelve it for half an hour."

Every answer comes back as a record, not prose. A reading carries its data type, its OPC UA status and both timestamps — because quality and age are what decide whether a value can be acted on, and a bare number carries neither:

read_opcua_nodes  node_ids=["ns=2;i=3", "ns=2;i=12"]
→ { "node_id": "ns=2;i=3", "value": 23.10, "data_type": "Double", "status": "Good",
    "source_timestamp": "2026-09-10T13:15:12.214Z",
    "server_timestamp": "2026-09-10T13:15:12.214Z",
    "engineering": { "unit": "°C", "unit_description": "degree Celsius",
                     "eu_range": { "low": 0, "high": 150 },
                     "instrument_range": { "low": -50, "high": 250 } } }
  { "node_id": "ns=2;i=12", "value": true, "data_type": "Boolean", "engineering": null, … }

engineering is what the plant says the number means, read from the node's own OPC UA properties: 23.10 cannot be told from °C, PSI or %, and cannot be told from a trip. It is null for a node that publishes none, which is most of them — only an AnalogItemType carries it. The range is not only reported: a write outside the node's own EURange is refused before anything is sent, which is a safety bound the equipment declared rather than one a human retyped.

A walk of the address space says whether it finished, so a partial answer can never pass for a complete one:

browse_opcua_nodes  depth=4  node_class="Variable"  include_values=true
→ { "nodes": [ { "node_id": "ns=2;i=3", "browse_name": "2:Temperature",
                 "node_class": "Variable", "data_type": "Double", "value": 26.34, … } ],
    "truncated": false, "inspected": 22 }

Every tool declares a result shape, and both runtimes are held to it. The shapes live in contract/tools.json; the suite checks each runtime's actual output against them and then diffs the two runtimes against each other — so a client that has learned one server's answers can read the other's.

A per-node rejection is a status inside a successful result, never a failed call: one unreadable node in a batch of fifty must not discard the other forty-nine. Only a failure of the whole operation is an error.

Events are collected, not pushed: MCP is request/response, so subscribe_events starts a real OPC UA subscription in the background and read_events hands over what has arrived since you last asked. list_active_alarms does not need one — it asks the server for its retained conditions directly (ConditionRefresh).

Configuration

Both runtimes read the same environment variables:

VariableDefaultMeaning
OPCUA_SERVER_URLopc.tcp://localhost:4840OPC UA endpoint to connect to
OPCUA_SECURITY_POLICYNoneNone, Basic128Rsa15, Basic256, Basic256Sha256 — plus Aes128_Sha256_RsaOaep and Aes256_Sha256_RsaPss on the Node runtime
OPCUA_SECURITY_MODESignAndEncrypt once a policy is set, otherwise NoneNone, Sign or SignAndEncrypt
OPCUA_CLIENT_CERT—Client certificate (PEM/DER). Required for any policy other than None
OPCUA_CLIENT_KEY—Private key for OPCUA_CLIENT_CERT
OPCUA_APPLICATION_URIthe subjectAltName URI of OPCUA_CLIENT_CERTApplication URI announced to the server. Set it only for a certificate that carries no URI of its own
OPCUA_SERVER_CERT—The OPC UA server's certificate, pinned. Without it, encryption protects against eavesdropping but not against an impostor endpoint. Requires a policy other than None
OPCUA_USERNAME—Username identity; the session is anonymous when unset
OPCUA_PASSWORD—Password for OPCUA_USERNAME
OPCUA_USER_CERT—Certificate identifying the user, for X.509 authentication. A different key pair from OPCUA_CLIENT_CERT, which secures the channel. Cannot be combined with OPCUA_USERNAME
OPCUA_USER_KEY—Private key for OPCUA_USER_CERT. Signs the server's challenge; never sent
OPCUA_PROFILEobserveobserve, operator, or full tool profile (read-only is an alias for observe)
OPCUA_POLICY_FILE—Optional version-1 JSON policy file; environment variables override it
OPCUA_ALLOWED_TOOLS—Comma-separated allowlist that can only narrow the selected profile
OPCUA_ALLOWED_WRITE_NODES—Comma-separated node IDs writable by the operator profile. ns=2;i=5 or, preferably, nsu=<namespace-uri>;i=5 — see Writing an allowlist that stays correct
OPCUA_ALLOWED_METHODS—Comma-separated object_node_id|method_node_id pairs callable by operator
OPCUA_ALLOW_ACKNOWLEDGE_ALARMSfalseAllow operator to act on alarms — acknowledge_alarm and every act_on_alarm action
OPCUA_ALLOW_INSECURE_CONTROLfalseLab-only override permitting control tools without OPC UA channel security
OPCUA_ALLOW_OUT_OF_RANGE_WRITESfalseAllow a write outside the EURange the OPC UA server itself published for that node — see Bounding the value, not only the node
OPCUA_AUDIT_FILE—Append-only file for the control audit trail, one JSON object per line, written beside stderr. A file that cannot be opened stops the server rather than falling back
OPCUA_OPERATOR_ID—Label stamped on every audit record, so a shipped log says which deployment a control call came from
OPCUA_RECONNECT_INITIAL_DELAY_MS1000Delay before the first reconnection attempt; doubles each attempt
OPCUA_RECONNECT_MAX_DELAY_MS8000Ceiling for that doubling
OPCUA_RECONNECT_MAX_RETRY3Retries after the first attempt. 0 disables retrying, -1 retries forever
OPCUA_SESSION_TIMEOUT_MS60000Session timeout asked of the OPC UA server; also sets the keep-alive period

Staying connected

Neither server needs restarting when the OPC UA server does. A dropped connection is retried with exponential backoff on the four OPCUA_RECONNECT_* / OPCUA_SESSION_TIMEOUT_MS settings above, the read and write paths transparently re-establish a dead session, and the data-change subscriptions an agent is holding are re-created on the new session — the IDs keep working and the values already buffered are still there to be read.

Reconnection is driven by tool calls rather than by a timer: if the endpoint is unreachable when the MCP client starts, the server still starts, and the first call that needs a session connects. get_server_status is the one tool that answers either way — it reports connected: false and the reason instead of failing, and every other tool's error points at it.

The defaults (three retries, 1–8s apart) keep a single tool call from hanging for long. Raise OPCUA_RECONNECT_MAX_RETRY for a site where outages are measured in minutes; the last waiting a call will do is the sum of the delays.

Deciding what the agent may do

Three profiles, and the default is the restrictive one:

OPCUA_PROFILEWhat it offers
observe (default)Read, browse, history and monitoring. No writes, no methods
operatorThe above, plus only the write targets and methods you allowlist
fullEvery tool

operator is the one worth understanding. A write to a node outside OPCUA_ALLOWED_WRITE_NODES is refused before anything reaches OPC UA, and one forbidden target rejects an entire batch rather than letting part of it through. Both operator and full also require a secured OPC UA channel unless OPCUA_ALLOW_INSECURE_CONTROL=true says otherwise in as many words.

The policy is enforced again on every call, not only when tools are listed — an MCP client may hold a stale catalogue, and a hidden tool is a usability feature rather than a security boundary. Every control call is also recorded — with its targets, its outcome, the endpoint it went to and the session it rode on — to stderr and, if OPCUA_AUDIT_FILE is set, to an append-only file beside it.

Bounding the value, not only the node

An allowlist says where a write may go. It does not say what may be written, and for the one product category where a wrong number is a physical event that is the weaker half: a model that has correctly identified the right setpoint and hallucinated 9999 instead of 99.9 is fully allowlisted.

Two bounds now apply.

The one the plant published. An OPC UA AnalogItemType carries an EURange — what the value holds in normal operation. Both servers read it, report it on every reading, and refuse a write outside it before anything is sent. No configuration: the equipment set the bound. Set OPCUA_ALLOW_OUT_OF_RANGE_WRITES=true for the deployments that write outside normal operation on purpose.

The one you write. In a policy file, a writable_nodes entry may carry min, max, enum or max_change:

json
{
  "control": {
    "writable_nodes": [
      "nsu=urn:plant:line-a;s=Line1.SpeedSetpoint",
      { "node": "nsu=urn:plant:line-a;s=Line1.Temperature", "min": 0, "max": 120 },
      { "node": "nsu=urn:plant:line-a;s=Line1.Mode", "enum": ["AUTO", "MANUAL"] }
    ]
  }
}

A bare node id stays legal. Both bounds apply, so a policy can only ever narrow what the equipment already allows. OPCUA_ALLOWED_WRITE_NODES is a comma-separated list and cannot express a bound — a bounded node needs the file. The full shape is in SECURITY.md.

Writing an allowlist that stays correct

OPCUA_ALLOWED_WRITE_NODES and OPCUA_ALLOWED_METHODS accept two forms:

ns=2;i=5                       # namespace index — resolved per session
nsu=urn:plant:line-a;i=5       # namespace URI — stable across sessions

Prefer the second. A namespace index is not a property of a node; it is that node's position in the server's NamespaceArray for the current session. A firmware update, an added namespace or a reordered load can move it — and an allowlist written ns=2;i=5 then authorises writes to a different physical node, with nothing anywhere reporting that anything changed.

The namespace URI is the stable name. Both servers read the NamespaceArray on every connect and resolve URI-pinned entries against it, so the allowlist follows the node rather than the index. An entry naming a URI the server does not publish matches nothing and is reported on stderr at connect time.

Spelling does not matter: i=2253 and ns=0;i=2253 are the same node, entries are trimmed, and both runtimes canonicalise identically (pinned by tests/fixtures/node-id-forms.json).

Larger deployments can put all of it in a version-1 JSON file (OPCUA_POLICY_FILE) instead of the environment; the shape, and a worked example, are in SECURITY.md.

Connecting securely

The defaults are unencrypted and unauthenticated, which suits the mock plant and nothing else. A real deployment wants a policy, a client certificate, an identity and a pinned server certificate:

bash
OPCUA_SECURITY_POLICY=Basic256Sha256     # implies SignAndEncrypt
OPCUA_CLIENT_CERT=/etc/opcua/client.pem  # this server's identity
OPCUA_CLIENT_KEY=/etc/opcua/client_key.pem
OPCUA_SERVER_CERT=/etc/opcua/server.pem  # pin the server you meant to reach
OPCUA_USERNAME=mcp-operator              # or OPCUA_USER_CERT for X.509
OPCUA_PASSWORD=…

Names are case-insensitive, and a policy on its own implies SignAndEncrypt. Anything the OPC UA spec cannot honour — a mode without a policy, a policy without a certificate, a username without a password, a path that does not exist — is refused at startup with a message naming the variable, rather than failing later against live equipment.

OPCUA_USERNAME / OPCUA_PASSWORD authenticate the session but encrypt nothing: without a security policy the password crosses the network in clear text unless the server's user-token policy protects it, and both servers say so on stderr. Pair credentials with a policy.

Why each of these matters, what is still not protected, and the full X.509 story: SECURITY.md. Generating a certificate a server will accept — including a file-naming trap on the Python runtime — is docs/certificates.md.

Try it against the mock

The repo ships a simulated industrial plant — sensors, actuators, methods, history and events — so you can try the tools without touching real equipment.

bash
git clone https://github.com/IndustriAgents/OPCUA-MCP.git && cd OPCUA-MCP
uv sync --all-packages
uv run --no-sync opcua-mock-server     # opc.tcp://localhost:4840/freeopcua/server/

Point your MCP client at that URL — .mcp.json.example is a ready-made config. Two smaller mocks cover what the main one deliberately does not model, server-side aggregates and acknowledgeable alarms; the compatibility matrix says which covers what, and docs/testing.md has an MCP Inspector walkthrough with example prompts.

Development & testing

bash
uv sync --all-packages                      # one-time workspace setup
cd tests
uv run --no-sync pytest unit/               # fast, no server needed (<1s)
uv run --no-sync pytest                     # unit + end-to-end, both runtimes
uv run --no-sync pytest -m smoke smoke/     # published-artifact smoke tests

Full guide, including the MCP Inspector and AI-agent walkthroughs: docs/testing.md. Project layout and how to add a tool: CONTRIBUTING.md. How it fits together: docs/architecture.md.

Security

[!WARNING] Both runtimes default to an observe-only tool profile, but the OPC UA connection itself still defaults to SecurityPolicy.None and MessageSecurityMode.None — unauthenticated and unencrypted. That combination is for the bundled mock and local development. For production, configure both channel security and an operator allowlist — see the two sections above. Control tools are blocked on an insecure channel unless the explicit lab override is set.

See SECURITY.md for the security posture, what the servers do and do not verify, and how to report a vulnerability; docs/certificates.md for client certificates and trust setup.

The MCP policy is defense in depth, not a replacement for OPC UA authorization. Scope the OPC UA account to the same nodes and methods; use a separate read-only account for observe deployments.

Contributing

Contributions are welcome — see CONTRIBUTING.md for project layout, local development, adding a new tool to both servers, and PR conventions. What is planned next is in ROADMAP.md; changes that have landed are tracked in CHANGELOG.md.

Results from a real OPC UA server are the most useful thing to send: open a compatibility report saying which server, which version and which tools worked. Test only on equipment you are authorised to use, and keep writes and method calls to a simulator or lab.

License

MIT — see LICENSE.

安装

TypingMind
{
  "mcpServers": {
    "opcua-mcp": {
      "command": "npx",
      "args": [
        "opcua-mcp-server"
      ],
      "env": {
        "OPCUA_SERVER_URL": "<OPCUA_SERVER_URL>"
      }
    }
  }
}

将 OPC UA MCP Server MCP 与多个 AI 模型配合使用

TypingMind 在工作区级别连接 MCP 工具,因此连接 OPC UA MCP Server 后,您就可以在 TypingMind 中搭配不同的 AI 模型使用,无需为每个模型单独设置。 此 MCP 通过您设备上的 TypingMind MCP 连接器在本地运行。

本地连接器设置指南

如果 MCP 服务器需要访问您电脑上的本地文件、应用或私有资源,请选择此方式。

1

打开 MCP 设置

在 TypingMind 中,依次前往“设置”、“高级设置”和“模型上下文协议”,然后选择“设置连接器”。

  1. 在您的浏览器中打开 TypingMind。
  2. 点击“设置”图标。
  3. 进入“高级设置”。
  4. 打开“模型上下文协议”部分。
  5. 点击“设置连接器”,然后选择“此设备”。
TypingMind MCP 连接器设置界面,已选择“此设备”
2

运行连接器命令

选择“此设备”,从 TypingMind 复制命令并在终端中运行。使用 MCP 时,请保持该进程运行。

  1. 复制 TypingMind 显示的设置命令。
  2. 在 macOS 上打开“终端”,或在 Windows 上打开 Windows Terminal。
  3. 粘贴并运行命令。
  4. 如果终端询问您是否继续,请确认安装软件包。
  5. 使用 MCP 工具时,请勿关闭终端窗口或停止其中的连接器进程。
3

将 OPC UA MCP Server 添加为服务器

当连接器状态为“就绪”时,点击“编辑服务器”,然后粘贴 MCP 服务器配置。

  1. 等待连接器状态显示为“就绪”。
  2. 点击“编辑服务器”。
  3. 粘贴 OPC UA MCP Server MCP 服务器配置。
  4. 保存服务器列表。
  5. 如需确认连接器是否仍处于就绪状态,请刷新。
TypingMind MCP 设置界面,显示正在运行的服务器和“编辑服务器”按钮
{
  "mcpServers": {
    "opcua-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "opcua-mcp-server"
      ]
    }
  }
}
4

在不同模型中使用同一连接

保存服务器列表,打开“插件”,启用 OPC UA MCP Server MCP 工具,然后在 TypingMind 中选择任意受支持的 AI 模型,即可在聊天中使用这些工具,或将其分配给智能体。

  1. 在 TypingMind 中打开“插件”页面。
  2. 启用 OPC UA MCP Server MCP 工具。
  3. 开始聊天并选择您想使用的 AI 模型。
  4. 在聊天中使用 MCP 工具,或将其分配给 AI 智能体。
  5. 根据需要随时切换到其他 AI 模型,无需重新连接 MCP。
在 TypingMind 聊天中使用已启用的 MCP 工具和选定的 AI 模型
您能使用 OPC UA MCP Server 帮我完成这项任务吗?
OPC UA MCP Server
当然,我看过了。
以下是我使用 OPC UA MCP Server 得到的结果。

常见问题

OPC UA MCP Server MCP 服务器有什么用途?

OPC UA MCP Server 是一个 MCP 服务器,可让兼容的 AI 客户端连接外部工具并获取上下文。在 TypingMind 中,只需添加一次此 MCP 服务器,即可在您的 AI 工作区中使用其工具。

可以在 TypingMind 中让多个 AI 模型使用 OPC UA MCP Server MCP 吗?

可以。TypingMind 在工作区层面连接 MCP 工具,因此您无需为每个模型单独配置 MCP 服务器,就能在 Claude、ChatGPT、Gemini 或您在 TypingMind 中配置的其他 AI 模型中使用 OPC UA MCP Server。

为什么在 TypingMind 中使用 OPC UA MCP Server MCP?

TypingMind 将多个 AI 模型、提示词、插件、AI 智能体、API 密钥和 MCP 工具整合到同一个工作区中,是最出色的大语言模型聊天前端之一。连接 OPC UA MCP Server 后,您可以在偏好的不同模型中使用其 MCP 工具,同时在 TypingMind 中井然有序地管理聊天工作流程。

如何将 OPC UA MCP Server MCP 连接到 TypingMind?

OPC UA MCP Server 通过 TypingMind 本地 MCP 连接器运行。当 MCP 服务器需要访问您计算机上的本地文件、桌面应用、命令行工具或私有资源时,这种方式最合适。

OPC UA MCP Server MCP 在 TypingMind 中提供哪些工具?

OPC UA MCP Server 提供 MCP 功能,您可以在 TypingMind 的插件页面启用这些功能,然后在聊天中使用,或将其分配给 AI 智能体。

使用 OPC UA MCP Server MCP 需要向 TypingMind 提供我的 API 密钥吗?

不需要。TypingMind 采用本地优先的设计,让您自行选择模型提供商,并自行管理 API 密钥、提示词和 MCP 配置。如果 OPC UA MCP Server 需要身份验证,请在创建连接时,为该 MCP 服务器添加所需的请求头、OAuth 设置或本地配置。

相关 MCP 服务器

查看全部

立即创建您自己的 AI 工作区

订阅我们的电子简报,获取新功能和后续赠奖活动的通知 👇