mirror of
https://github.com/OPCFoundation/UA-.NETStandard.git
synced 2026-10-19 07:02:16 +08:00
5530a12d4a
Replaces the static-only ExportRoot / env-var-only configuration in NodeSetExportTools with an instance-aware ResolveExportRoot(IServiceProvider) that consults McpServerOptions from DI first. Same pattern applied to PacketDecodeTools.GetDecodeAllowedRoot for symmetric naming. Precedence (both options): services.GetService<McpServerOptions>().Property > OPCUA_MCP_EXPORT_ROOT env var (NodeSet) or PcapOptions.BaseFolder (Decode) > per-tool default. Backward-compat: ExportRoot static property + OPCUA_MCP_EXPORT_ROOT env var both still work. Program.cs now seeds McpServerOptions from OPCUA_MCP_NODESET_EXPORT_ROOT and OPCUA_MCP_PCAP_BASE_FOLDER environment variables so hosts can override without code changes. Tests: 7 NUnit tests in McpServerOptionsTests covering DI > env var > default precedence for both options. Reflection-based to reach internal/private helpers — same pattern as the existing PacketDecodePathValidationTests. Build: 0 warnings / 0 errors on Applications/McpServer for net10.0. Pcap.Tests build blocked locally by the unrelated SDK 10 workload manifest issue (see prior commit for details).
OPC UA MCP Server
An MCP (Model Context Protocol) server that exposes OPC UA Part 4 service calls as MCP tools, enabling LLMs (Claude, Copilot, VS Code, etc.) to interact with OPC UA servers.
Features
- 64 MCP tools covering all OPC UA Part 4 service sets (except session management), plus PKI, configuration, NodeSet export, and OPC UA-aware packet capture
- Both stdio and HTTP/SSE transports
- JSON representation of all OPC UA types for LLM-friendly interactions
- Session management via Connect/Disconnect tools
Tool Inventory
| Service Set | Tools | Description |
|---|---|---|
| Connection | GetEndpoints, Connect, Disconnect, GetConnectionStatus | Endpoint discovery and session lifecycle |
| Attribute | Read, Write, HistoryRead, HistoryUpdate | Read/write node attributes and historical data |
| View | Browse, BrowseNext, TranslateBrowsePaths, RegisterNodes, UnregisterNodes, QueryFirst, QueryNext | Navigate and query the address space |
| Node Management | AddNodes, AddReferences, DeleteNodes, DeleteReferences | Modify address space |
| Method | Call | Invoke methods |
| Subscription | CreateSubscription, ModifySubscription, SetPublishingMode, Publish, Republish, DeleteSubscriptions, TransferSubscriptions | Notification subscriptions |
| MonitoredItem | CreateMonitoredItems, ModifyMonitoredItems, SetMonitoringMode, SetTriggering, DeleteMonitoredItems | Data change monitoring |
| Discovery | FindServers, FindServersOnNetwork, RegisterServer, RegisterServer2 | Server discovery and registration |
| PKI Management | ListCertificates, TrustCertificate, RemoveCertificate, GetPkiStorePaths | Manage certificate trust lists |
| Configuration | GetConfiguration, SetConfiguration | View/modify client settings for current session |
| NodeSet Export | ExportNodeSet, ExportNodeSetPerNamespace | Export address space to NodeSet2 XML |
| Convenience | ReadValue, ReadValues, WriteValue, BrowseAll, CallMethod, ReadNode, Cancel | Simplified operations |
| Packet Capture | list_interfaces, start_capture, stop_capture, list_captures, get_capture, capture_now, list_active_channels, dump_keys, decode_pcap_with_keys, summarize_service_calls, replay_pcap, stop_replay, list_replays | OPC UA-aware packet capture, offline decode, service-call summaries, replay |
Documentation
See the full documentation and Nuget readme.
Claude Desktop Configuration
Add to your claude_desktop_config.json:
{
"mcpServers": {
"opcua": {
"command": "dotnet",
"args": ["run", "--project", "/path/to/Applications/McpServer/Opc.Ua.Mcp.csproj"]
}
}
}
VS Code Configuration
Add to .vscode/mcp.json:
{
"servers": {
"opcua": {
"command": "dotnet",
"args": ["run", "--project", "/path/to/Applications/McpServer/Opc.Ua.Mcp.csproj"]
}
}
}
Example Tool Calls
Connect to a server
Tool: Connect
Arguments:
endpointUrl: "opc.tcp://localhost:62541/Quickstarts/ReferenceServer"
useSecurity: true
autoAcceptCerts: true
Browse the Objects folder
Tool: Browse
Arguments:
nodeId: "i=85"
Read a variable value
Tool: ReadValue
Arguments:
nodeId: "i=2258"
Write a value
Tool: WriteValue
Arguments:
nodeId: "ns=2;s=MyVariable"
value: "42"
dataType: "Int32"
Call a method
Tool: CallMethod
Arguments:
objectId: "ns=2;s=MyObject"
methodId: "ns=2;s=MyMethod"
inputArguments: ["arg1", "arg2"]
OPC UA Client Configuration
The server uses McpServer.Config.xml for OPC UA client configuration, including:
- Application certificate settings
- Trust list management
- Transport quotas
- Operation limits
Certificates are stored under %LocalApplicationData%/OPC Foundation/pki/.