OPC-UA MCP Server

io.github.mwieczorkiewicz由 GitHub 帳號 mwieczorkiewicz 發布v1.0.0更新於 Oct 27, 2026

Read, write, browse, search, and subscribe to live data on an OPC-UA industrial automation server.

已驗證STDIO僅桌面資料庫雲端與基礎設施

概覽

AI 產生的概覽

讓助理讀取、寫入、瀏覽、搜尋並訂閱 OPC-UA 工業自動化伺服器即時資料的 MCP 伺服器。

可以做什麼
  • 依節點 ID 或瀏覽名稱讀取節點值,寫入時會做型別驗證
  • 逐層或遞迴瀏覽位址空間,並檢視節點中繼資料
  • 透過背景探索索引搜尋與模糊比對節點名稱
  • 訂閱推送式即時更新,列出並取消訂閱
  • 管理連線,檢視伺服器資訊、探索統計與診斷資訊
適用情境
適合需要檢視或修改 OPC-UA 伺服器(例如 PLC、SCADA 系統)即時數值的情境,例如依名稱查找變數、持續監控數值,或在工程與除錯時寫入設定值。
執行需求
以本機程序執行(建置需 Go 1.26+,也可使用已發布的容器映像);內附測試伺服器可選用 Docker。需以 OPCUA_ENDPOINT 指定目標伺服器。使用者名稱密碼驗證需 OPCUA_USERNAME 與 OPCUA_PASSWORD;憑證驗證需憑證與金鑰檔案。需能連線至 OPC-UA 端點。
安裝前請注意
寫入會作用於真實工業設備,錯誤數值可能影響運作中的流程,文中僅提到型別驗證這層保護。使用者名稱密碼驗證需要 OPCUA_PASSWORD 密鑰。匿名使用遙測預設開啟,可用 DO_NOT_TRACK=1 或 OPCUA_MCP_TELEMETRY=false 關閉。快速上手的通道會把伺服器公開曝光。

安裝

在 SourceWeft 中

  1. 開啟 儀表板中的 OPC-UA MCP Server,將其新增到工作區。
  2. 為需要使用其工具的對話啟用該服務。

Desktop only,透過 STDIO。 STDIO 服務會啟動本機處理程序,因此需要 SourceWeft 桌面主機。

其他 MCP 客戶端

參照 儲存庫 中的啟動說明。

README

OPC-UA MCP Server

An MCP server that lets an LLM read, write, browse, search, and subscribe to live data on an OPC-UA industrial automation server - over stdio or HTTP, with a persistent cache and a searchable index of the address space built in.

https://github.com/user-attachments/assets/0b676e6e-17ce-42f5-918f-9a615e939008

Quick start

The fastest way to see it working end-to-end, using the bundled Microsoft OPC-UA test server and a public tunnel Claude can reach:

bash
git clone https://github.com/mwieczorkiewicz/opcua-mcp.gitcd opcua-mcpmake compose-up        # starts a test OPC-UA server, opcua-mcp, and a public HTTPS tunnelmake connector-url      # prints a URL like https://xyz.trycloudflare.com/mcp

Paste that URL into Claude at Settings → Connectors → Add custom connector, then ask it to browse the server or read a value. Stop with make compose-down when you're done - see docs/deployment.md for what that tunnel exposes and how to run against your own OPC-UA server instead.

Building and running locally

bash
go build -o opcua-mcp ./cmd/opcua-mcp.go
# stdio (default) - no OPC-UA connection until the client calls opcua_connect./opcua-mcp
# HTTP - connects eagerly at startupSERVER_TRANSPORT=http OPCUA_ENDPOINT=opc.tcp://localhost:4840 ./opcua-mcp

Requires Go 1.26+ and, optionally, Docker for the test server / containerized deployment.

What it does

  • Read / write node values, with type validation on writes so a mismatched value is rejected before it reaches the device.
  • Browse the address space one level at a time or recursively, and look nodes up by name instead of by node ID.
  • Subscribe to push-based live updates - subscriptions persist across restarts and are automatically re-established on reconnect.
  • Cache reads, browse results, and type info on disk (bbolt), so repeat lookups don't round-trip to the device; writes invalidate the relevant entry automatically.
  • Discover and search the address space in the background, indexed with Bleve for fuzzy/partial browse-name lookups.
  • Anonymous, username/password, or certificate auth, with configurable OPC-UA security policy and mode.

See docs/architecture.md for how the caching layer, subscription manager, and discovery index fit together.

MCP tools

ToolDescription
opcua_readRead one or more node values. Subscribed nodes are served from the live cache; others go live unless max_age_ms allows a cached value.
opcua_writeWrite a value to a node. Validates the value's type against the node before writing.
opcua_get_valueRead a single node's value - a convenience wrapper over opcua_read.
opcua_get_value_by_nameRead a value by browse name instead of node ID, via the discovery index.
opcua_browseList a node's immediate children.
opcua_browse_nodesRecursively browse from a node up to a depth limit, nesting children under their parent.
opcua_node_infoGet a node's metadata (data type, access level, etc.).
opcua_find_similar_nodesFuzzy-match browse names against the discovery index.
opcua_subscribeStart push-based updates for one or more nodes at a given interval.
opcua_unsubscribeCancel a subscription, by ID or by naming one of its nodes.
opcua_list_subscriptionsList active subscriptions.
opcua_connect / opcua_disconnectManage the connection explicitly (mainly relevant in stdio mode).
opcua_server_infoGet OPC-UA server metadata.
opcua_discovery_statsStats on the background discovery cache (node count, depth distribution, enabled flags).
opcua_force_discoveryTrigger an immediate discovery refresh instead of waiting for the next cycle.
opcua_debug_search / opcua_ensure_server_nodesDiagnostics for troubleshooting why a node isn't showing up in search.

Read-only mode

Set MCP_READ_ONLY=true to expose only tools that don't change anything on the OPC-UA server or the connection: opcua_write, opcua_disconnect, opcua_subscribe and opcua_unsubscribe are hidden from tools/list, and a client that calls one of them by name gets an error instead of running it. opcua_connect and the discovery tools stay available.

To approve specific tools on top of the read-only set, list them in MCP_ALLOWED_TOOLS, for example MCP_ALLOWED_TOOLS=opcua_subscribe,opcua_unsubscribe. An unknown tool name stops the server at startup, so a typo can't silently leave a tool disabled. Any tool added in a future release is excluded from read-only mode until it is classified as read-only.

MCP resources

ResourceDescription
opcua://node/{node_id}Node data, e.g. opcua://node/ns=2;i=1. Accepts a comma-separated list for multiple nodes.
opcua://serverOPC-UA server information.

Configuration

Configuration is loaded (via viper) from three sources, in ascending order of precedence:

  1. Built-in defaults (shown in the tables below).
  2. An optional config file - TOML, YAML, JSON, or any other format viper supports. By default ./config.{yaml,yml,toml,json,...} is read if present; point at an explicit path with CONFIG_FILE=/path/to/config.toml. A config file is entirely optional - env vars alone are still enough.
  3. Environment variables (SERVER_*, OPCUA_*, MCP_*, SEARCH_*, STORE_*) - always win over the config file, so existing env-var-only deployments keep working unchanged.

A config file mirrors the env var names, lowercased and nested under each prefix, e.g. SERVER_HTTP_PORT becomes:

yaml
server:  http_port: "8080"

Server

VariableDefaultDescription
SERVER_TRANSPORTstdiostdio or http
SERVER_HTTP_PORT8080Port for HTTP transport
SERVER_LOG_LEVELinfodebug, info, warn, error
SERVER_LOG_FORMATjsonjson or text
SERVER_LOG_OUTPUTstdoutstdout, stderr, or file (forced to stderr in stdio mode, since stdout carries the MCP stream)
SERVER_LOG_FILE-Log file path, required if SERVER_LOG_OUTPUT=file
SERVER_LOG_ADD_SOURCEfalseAdd source file/line to log entries

OPC-UA connection

VariableDefaultDescription
OPCUA_ENDPOINTopc.tcp://localhost:4840Server endpoint
OPCUA_AUTH_MODEanonymousanonymous, username, or certificate
OPCUA_USERNAME / OPCUA_PASSWORD-Required if AUTH_MODE=username
OPCUA_CERT_FILE / OPCUA_KEY_FILE-PEM client certificate/RSA key. Required if AUTH_MODE=certificate or security policy/mode is not None (secures the channel for any auth mode)
OPCUA_SERVER_CERT-Optional pinned server certificate (PEM or DER); the connection is refused if the endpoint's certificate differs. Without it the certificate is taken from GetEndpoints
OPCUA_SECURITY_POLICYNoneNone, Basic128Rsa15, Basic256, Basic256Sha256, Aes128_Sha256_RsaOaep
OPCUA_SECURITY_MODENoneNone, Sign, SignAndEncrypt
OPCUA_REQUEST_TIMEOUT30sPer-request timeout
OPCUA_SESSION_TIMEOUT60sSession timeout
OPCUA_MAX_RETRIES3Connection retry attempts
OPCUA_RETRY_DELAY1sDelay between retries

MCP

VariableDefaultDescription
MCP_NAMEOPC-UA MCP ServerServer name reported to clients
MCP_VERSION1.0.0Server version reported to clients
MCP_ENABLE_TOOLStrueEnable tools
MCP_ENABLE_RESOURCEStrueEnable resources
MCP_ENABLE_PROMPTSfalseEnable prompts
MCP_HTTP_PATH/mcpHTTP endpoint path
MCP_READ_ONLYfalseExpose only read-only tools (see Read-only mode)
MCP_ALLOWED_TOOLS(empty)Comma-separated tools to expose in addition to the read-only set; ignored unless MCP_READ_ONLY=true

Discovery and search

VariableDefaultDescription
SEARCH_ENABLE_DISCOVERYtrueEnable background node discovery
SEARCH_DISCOVERY_INTERVAL30sHow often to re-crawl the address space
SEARCH_DISCOVERY_ROOT_NODEi=85Root node to crawl from (Objects folder)
SEARCH_MAX_DISCOVERY_DEPTH10Maximum crawl depth
SEARCH_MAX_NODES_PER_BROWSE10000Cap on nodes returned per browse call
SEARCH_ENABLE_SEARCHtrueEnable the Bleve search index
SEARCH_INDEX_PATH./search_indexSearch index directory
SEARCH_MAX_RESULTS100Max results per search
SEARCH_MIN_SCORE0.1Minimum match score
SEARCH_ENABLE_CACHEtrueMaster switch for read-through caching. false makes every opcua_read/opcua_write/opcua_browse_nodes call go live, matching pre-cache behavior exactly

Persistent store

Backs read-through caching and subscription persistence with an on-disk bbolt database.

VariableDefaultDescription
STORE_DB_PATHmcp_opcua_store.dbDatabase file path
STORE_OPEN_TIMEOUT5sHow long to wait for the file lock on open
STORE_TYPEINFO_TTL24hFreshness window for cached type info
STORE_BROWSE_TTL5mFreshness window for cached browse results
STORE_BATCH_WINDOW25msHow often subscription notifications flush to the store
STORE_BATCH_MAX_ITEMS250Max notifications flushed per batch
STORE_NOTIFY_CHAN_BUFFER1024Buffer size for incoming subscription notifications

If the store fails to open (e.g. a stale lock from a prior ungraceful shutdown, or a read-only filesystem), the server logs a warning and keeps running with caching forced off and subscription tools returning an error - every other tool is unaffected.

Telemetry

opcua-mcp collects anonymous, aggregate usage telemetry (which tools get used, cache hit rate, error categories - never node IDs, endpoint URLs, node values, or credentials) to help prioritize maintenance of this open-source project. It's on by default; see docs/telemetry.md for exactly what is and isn't collected.

Opt out with either:

VariableEffect
DO_NOT_TRACK=1The cross-project community convention (consoledonottrack.com)
OPCUA_MCP_TELEMETRY=falseThis project's own switch

Docker

bash
docker build -t opcua-mcp .docker run -p 8080:8080 -e SERVER_TRANSPORT=http -e OPCUA_ENDPOINT=opc.tcp://your-server:4840 opcua-mcp

Multi-stage build on Chainguard's minimal Go image, running from scratch - no shell, small attack surface. Mount ./search_index and ./mcp_opcua_store.db as volumes to persist discovery/cache/subscription state across restarts. Full auth-mode examples, the Compose dev stack, and the Claude-connector tunnel setup are in docs/deployment.md.

Development

bash
make start-opcua-server      # Microsoft OPC-UA test server in Dockermake run-with-test-server    # run the app against it (auto start/stop)
go test ./...                # unit testsgo test -race ./...make test-integration        # real Subscribe/reconnect/cache behavior via testcontainers-go (needs Docker)

VS Code launch configs are in .vscode/launch.example.json - copy to .vscode/launch.json to get stdio/HTTP/auth debug targets that start and stop the test server automatically. make help lists every available target.

Tests are table-driven and mock the OPC-UA client at the opcuaClient interface seam (internal/opcua/mock_client_test.go) rather than against a live/simulated server - see docs/architecture.md for how the pieces being tested fit together, and docs/COMMIT_CONVENTION.md for this repo's commit message format.

Changelog

Unreleased

  • New: read-only mode. MCP_READ_ONLY=true hides and rejects opcua_write, opcua_disconnect, opcua_subscribe and opcua_unsubscribe; MCP_ALLOWED_TOOLS re-enables named tools. Off by default, so existing setups see all 18 tools as before.
  • New: automatic recovery from a dead OPC-UA session. When the server rejects a request with BadSessionIDInvalid or BadServerNotConnected (for example after the server restarted or dropped the session), the client reconnects once with the same security settings and retries reads once. Writes are not replayed: they return an error saying the write was not applied, and the next call uses the new session. Subscriptions are restored after the reconnect.
  • Changed: opcua_connect verifies the connection. When already connected it now probes the server and rebuilds the session if it is no longer usable, instead of only reporting "Already connected".
  • Fixed: opcua_disconnect stays disconnected. Disconnecting no longer makes the subscription reconnect watcher bring the connection back.

Contributing

Fork it, make your changes, open a PR - see CONTRIBUTING.md.

License

MIT

來源:README.md,提交 62f6121

工具

0
SourceWeft 尚未在沙箱中啟動過該軟體包,因此其工具未知。

版本歷史

1
  1. v1.0.0最新Sep 16, 2026

評分

已滿足適用檢查項的 50%

該評分衡量此收錄條目的完整程度,依據註冊中心條目、端點與公開來源計算得出。它不是對伺服器本身的評價,也不表示伺服器安全或目前可用:可連通性是帶日期的檢查結果,評分也不包含安裝量或使用者評價。

  • 近 30 天內可連通25 分

    請保持端點能夠回應 MCP 握手;SourceWeft 每 30 天探測一次。

  • 已宣告認證方式10 分

    請在註冊中心條目中宣告憑證請求標頭,或保持端點能夠回應探測,以便判定其認證方式。

  • 已列出工具15 分

    請讓伺服器在無憑證時回應 tools/list,或發布可在沙箱中無憑證啟動的軟體包。

  • 描述必需15 分
  • 圖示10 分
  • 文件15 分
  • 授權條款10 分