twincat-mcp
v0.5.2
Published
MCP stdio server for TwinCAT ADS operations.
Readme
twincat-mcp
MCP stdio server for TwinCAT ADS PLC operations.
This package exposes twincat-mcp-core runtime operations as Model Context
Protocol tools. MCP-specific protocol handling lives here; ADS domain behavior,
configuration validation, watches, and write gates live in twincat-mcp-core.
Install
npm install -g twincat-mcpNode.js 20 or newer is required.
Bundled Skills
The package ships skills for agents that support npm-bundled skill discovery:
twincat-mcp-ads: MCP-specific runtime/ADS tool guidance for PLC, NC, IO, watches, write gates, connection tools, and TwinCAT runtime diagnostics.twincat-xae-project-guidelines: agent-neutral guidance for offline TwinCAT XAE/Visual Studio project-file work, including PLC project XML, POUs, GVLs, DUTs, tasks, I/O devices, boxes, and terminals.
The MCP server provides tools. Skills are agent-side guidance for choosing those tools, explaining results, and respecting the runtime/project-file safety boundary.
The XAE skill source lives centrally under
packages/skills/twincat-xae-project-guidelines. It is copied into this package
by the MCP prepack lifecycle and removed again by postpack, so npm artifacts
contain the skill without maintaining a second manual copy.
Run
twincat-mcp --config ./plc.config.jsonConfig can also be supplied with environment variables:
TWINCAT_ADS_CONFIG='{"connectionMode":"router",...}'TWINCAT_ADS_TARGET_AMS_NET_ID=192.168.1.120.1.1TWINCAT_ADS_TARGET_ADS_PORT=851TWINCAT_ADS_CONNECTION_MODE=routerTWINCAT_ADS_READ_ONLY=trueTWINCAT_ADS_WRITE_ALLOWLIST=MAIN.safeValue,MAIN.otherSafeValueTWINCAT_ADS_CONTEXT_SNAPSHOT_SYMBOLS=MAIN.someValueTWINCAT_ADS_NOTIFICATION_CYCLE_TIME_MS=250TWINCAT_ADS_MAX_NOTIFICATIONS=128TWINCAT_ADS_MAX_WAIT_UNTIL_MS=600000
Direct mode additionally uses:
TWINCAT_ADS_ROUTER_ADDRESSTWINCAT_ADS_ROUTER_TCP_PORTTWINCAT_ADS_LOCAL_AMS_NET_IDTWINCAT_ADS_LOCAL_ADS_PORT
Example Config
{
"connectionMode": "router",
"targetAmsNetId": "192.168.1.120.1.1",
"targetAdsPort": 851,
"readOnly": true,
"writeAllowlist": [],
"notificationCycleTimeMs": 250,
"maxNotifications": 128,
"maxWaitUntilMs": 600000,
"services": {
"plc": {
"targetAdsPort": 851,
"symbolGroups": {}
},
"nc": {
"targetAdsPort": 500,
"axes": [
{ "name": "X", "id": 1 }
]
},
"io": {
"targetAdsPort": 300,
"dataPoints": [
{
"name": "Input1",
"indexGroup": 61472,
"indexOffset": 128000,
"type": "BOOL"
}
],
"groups": {
"inputs": ["Input1"]
}
}
},
"diagnostics": {
"maxEvents": 50,
"maxLogBytes": 65536,
"eventSources": [
{
"id": "local-windows-application",
"kind": "windowsEventLog",
"logName": "Application",
"providerNames": ["TwinCAT", "Beckhoff", "TcSysSrv", "TcSysUi", "TcIoSrv", "TcNc", "TcEvent"],
"commandTimeoutMs": 8000
}
],
"logSources": [
{
"id": "local-windows-application-log",
"kind": "windowsEventLog",
"logName": "Application",
"providerNames": ["TwinCAT", "Beckhoff", "TcSysSrv", "TcSysUi", "TcIoSrv", "TcNc", "TcEvent"],
"commandTimeoutMs": 8000
}
]
}
}Tools
Connection:
ads_connectads_disconnect
PLC reads and state:
plc_list_symbolsplc_describe_symbolplc_readplc_read_manyplc_list_groupsplc_read_groupplc_state
plc_state includes ADS connection state, write gates, watch count, and a
readable PLC runtime status summary such as Run or Stop.
NC read-only:
nc_statenc_list_axesnc_read_axis_positionnc_read_axis_statusnc_read_axisnc_read_axis_manync_read_error
IO read-only:
io_list_groupsio_readio_read_manyio_read_group
TwinCAT runtime diagnostics:
tc_statetc_event_listtc_runtime_error_listtc_log_readtc_diagnose_errorstc_diagnose_runtime
Diagnostic tools use configured sources under diagnostics. The defaults target
the local Windows Application Event Log filtered for TwinCAT/Beckhoff entries;
when that API is unavailable, the result reports unavailable capability metadata
instead of failing server startup.
Prefer the individual tools for targeted investigation. Use
tc_diagnose_errors for a bounded first look at runtime errors, nearby events,
and log tail; use tc_diagnose_runtime for a compact TC/PLC/NC/IO runtime health
summary plus active runtime errors.
Writes and write gates:
plc_set_write_modeplc_get_write_modeplc_evaluate_write_accessplc_write
Watches:
plc_watchplc_wait_untilplc_unwatchplc_list_watches
Watches are modeled only as tools. They are not MCP resources or subscriptions yet.
Safety Model
MCP writes use the same three gates as the core and Pi package:
readOnly=falsein config.plc_set_write_modesets runtime write mode toenabled.- The exact symbol name is present in
writeAllowlist.
The default behavior is read-only.
Development
npm run sync:skills -w twincat-mcp
npm run test:mcp
npm run build
npm run pack:mcpnpm run pack:mcp runs the MCP package prepack/postpack hooks and verifies
that shared skills are present in the package tarball while keeping the
repository source of truth under packages/skills.
For package-level checks:
npm run check -w twincat-mcp
npm run test -w twincat-mcp