twincat-mcp
v0.3.2
Published
MCP stdio server for TwinCAT ADS operations.
Downloads
454
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.
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
},
"io": {
"targetAdsPort": 300
}
}
}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.
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 test:mcp
npm run build
npm run pack:mcpFor package-level checks:
npm run check -w twincat-mcp
npm run test -w twincat-mcp