Логотип Codesys MCP

Codesys MCP

Сообщество
luke-harriman

An MCP server for Codesys that enables AI systems to stand up a live UI where they can edit/push code and view variables live on device.

Издательluke-harriman
РепозиторийCodesys-MCP
ЯзыкPython
Форки
19
Звёзды
87
Доступные инструменты
0
Тип транспортаstdio
Категории
ЛицензияMIT
Ссылки
  • Подключайте инструменты к рабочим процессам с ИИ

    Codesys MCP предоставляет возможности MCP, доступные совместимым ИИ-клиентам и агентам.

  • Доступные инструменты: 0

    Ниже представлены доступные для вызова действия с названиями и описаниями, если сервер их предоставляет.

  • Готовая конфигурация для копирования

    Используйте примеры конфигурации, чтобы настроить этот сервер в предпочитаемом MCP-клиенте.

  • Показатели интереса к открытому проекту

    Звёзды: 87, форки: 19 — в связанном репозитории.

codesys-mcp-persistent

MCP server that exposes the CODESYS V3.5 IDE scripting API as 41 tools and 3 resources, with the CODESYS UI kept open across calls via a file-based IPC watcher.

Unlike headless-only wrappers that spawn a new --noUI CODESYS process per command, this server launches CODESYS with its UI visible and routes every tool call through a watcher script running inside that same instance. Changes appear in the IDE in real time and the user can interact with CODESYS alongside AI-driven automation.

Requirements

  • Windows
  • Node.js 18+
  • CODESYS V3.5 SP19 or SP20 for persistent mode. SP21+ runs only in headless mode — see Known limitations.

Install

bash
git clone <repository-url>
cd Codesys-MCP
npm install
npm run build
npm link

Configure

.mcp.json (Claude Code):

json
{
  "mcpServers": {
    "codesys": {
      "command": "codesys-mcp-persistent",
      "args": [
        "--codesys-path", "C:\\Program Files\\CODESYS 3.5.20.0\\CODESYS\\Common\\CODESYS.exe",
        "--codesys-profile", "CODESYS V3.5 SP20",
        "--mode", "persistent"
      ]
    }
  }
}

For SP21+, set --mode headless (each tool call spawns a --noUI CODESYS process).

CLI

FlagDescriptionDefault
-p, --codesys-path <path>Path to CODESYS.exe$CODESYS_PATH or C:\Program Files\CODESYS 3.5.21.0\CODESYS\Common\CODESYS.exe
-f, --codesys-profile <name>CODESYS profile name$CODESYS_PROFILE or CODESYS V3.5 SP21
-w, --workspace <dir>Workspace for relative pathscwd
-m, --mode <mode>persistent or headlesspersistent
--no-auto-launchDon't launch CODESYS on startupauto-launch on
--fallback-headlessFall back to headless if persistent launch failstrue
--keep-aliveKeep CODESYS running after server stopsfalse
--kill-existing-codesysKill any running CODESYS.exe before launchingfalse
--timeout <ms>Default command timeout60000
--detectList installed CODESYS versions and exit-
--verbose / --debugLogging-

Environment variables:

  • CODESYS_PATH, CODESYS_PROFILE — defaults for the corresponding flags
  • CODESYS_MCP_READY_TIMEOUT_MS — watcher-ready deadline (default 180000)

Tools

Management

ToolDescription
launch_codesysManually launch CODESYS (use with --no-auto-launch). Adopts a live session if one exists
shutdown_codesysShut down the persistent CODESYS instance
get_codesys_statusReport state, PID, execution mode
eval_python[DEV] Execute arbitrary IronPython 2.7 against the live scriptengine. Code must print("SCRIPT_SUCCESS") before exit

Project

ToolDescription
open_projectOpen an existing .project file
create_projectCreate a new project. Defaults to copying CODESYS's installed Standard.project; pass templatePath to copy a specific .project, or templateName to instantiate a template registered with CODESYS's Template Manager
list_project_templatesEnumerate templates from CODESYS's Template Manager and %ProgramData%/CODESYS
save_projectSave the currently open project
compile_projectBuild with structured error output (120s timeout)
get_compile_messagesRetrieve last compiler messages without rebuilding

POU / code authoring

ToolDescription
create_pouCreate a Program, Function Block, or Function
set_pou_codeSet declaration and/or implementation. Accepts Method/Property paths (Application/MyFB/Method1). Auto-saves to disk
create_property / create_methodAdd a Property / Method to a Function Block
create_dutCreate a Data Unit Type (Structure, Enumeration, Union, Alias)
create_gvlCreate a Global Variable List, optionally with initial declaration
create_folderCreate an organisational folder
delete_objectDelete a user-created object. Refuses system nodes (Application, Device, Library Manager, etc.) and top-level paths
rename_objectRename any project object
get_all_pou_codeBulk read every declaration + implementation in the project (120s timeout)
search_codeRegex or literal substring search across every textual POU/Method/Property/DUT/GVL body
find_referencesWord-boundary search for a symbol; wraps search_code
rename_symbolTextual rename across all POU bodies. Two-phase plan + apply; dryRun=true by default

Online / runtime

ToolDescription
connect_to_deviceLogin to the PLC runtime. Optionally pass ipAddress (and gatewayName, default Gateway-1); the device address is set then re-resolved from IP form to the gateway-scan node form before login
disconnect_from_deviceLogout. No-op if not connected
set_credentialsSet default username/password for subsequent logins. Username must be non-empty
set_simulation_modeToggle device-level simulation mode
get_application_stateReport run / stop / exception plus login status
read_variableRead a live variable. Path: GVL.var / PRG.var / GVL.s.aRoi[0].field (no Application. prefix)
write_variableWrite via set_prepared_value + force_prepared_values. The variable is FORCED until unforced or runtime restart
download_to_deviceDownload compiled application. mode: auto (default), online_change, or full. Boot application created after login. 120s timeout
start_stop_applicationStart or stop the PLC application
monitor_variablesSample one or more variables at a fixed interval. Duration capped at 60s, intervalMs floor 10ms

Online tools route every scriptengine.online call through an ExecuteSource frame via the with_executor helper in ensure_online_connection.py. Without it, create_online_application raises InvalidOperationException: Stack empty from IPC-driven scripts on real PLCs.

Library management

ToolDescription
list_project_librariesList referenced libraries with version info
add_libraryAdd a library reference. Pass the fully-qualified placeholder string from the Library Manager UI (e.g. Standard, * (System)) — bare names like Util won't resolve

Device tree

ToolDescription
list_device_repositoryEnumerate device descriptors in the local CODESYS Device Repository. Optional vendor, nameContains, maxResults filters
inspect_device_nodeRead-only introspection of a device node: descriptor metadata, parameters with values, child sub-devices
add_deviceWrap parent.add_device(name, type, id, version). Pair with list_device_repository to source canonical ids
set_device_parameterEXPERIMENTAL. Many fieldbus parameters are GUI-only and return a clear error
map_io_channelBind (or clear) a fieldbus I/O channel to a global variable. Channel resolved by name path (Inputs/Byte 0/Bit 3) or numeric indices (0/3)

Archiving

ToolDescription
create_project_archiveSave the open project as a .projectarchive. Saves unsaved edits first

Resources

URIDescription
codesys://project/statusScripting status and open-project info
codesys://project/{path}/structureProject tree
codesys://project/{path}/pou/{pou}/codePOU / Method / Property declaration + implementation

{path} and {pou} use RFC 6570 reserved expansion — pass values with raw : and /, not percent-encoded. On Windows, use forward slashes:

codesys://project/C:/Users/me/Documents/MyPLC.project/structure
codesys://project/C:/Users/me/Documents/MyPLC.project/pou/Application/MyFB/Method1/code

The two templated resources don't appear in ListMcpResourcesTool (only project-status is static).

⚠️ If the requested project path differs from the currently-open project, the resource handler refuses to switch — it raises rather than silently swapping context.

Execution modes

Persistent (default). On launch, the server scans %TEMP%/codesys-mcp-persistent/ for a live session left by a previous MCP server (matching profile, PID alive, ready.signal present) and adopts it. Otherwise it spawns CODESYS.exe --runscript=watcher.py (no --noUI). The watcher writes ready.signal, then runs a background thread that polls a commands/ directory and marshals each script onto the CODESYS UI thread via system.execute_on_primary_thread(). Results land in results/; Node polls with exponential backoff (100ms → 1s). The UI stays interactive between commands and pauses briefly during synchronous API calls (compile, open).

Headless. Each tool call spawns a new --noUI CODESYS process, runs the script, and exits. No UI. Used when --mode headless is set, when --no-auto-launch is used and launch_codesys hasn't been called, or when persistent launch fails and --fallback-headless is on.

Detect installations

bash
codesys-mcp-persistent --detect

Scans Program Files and Program Files (x86) for CODESYS installations.

Known limitations

  • Persistent mode is broken on CODESYS V3.5 SP21+. CODESYS removed se.system.execute_on_primary_thread() from the scripting API somewhere in the SP21 line. Persistent launch completes (ready.signal fires) and then every tool call returns Marshal error: The functionality 'system.execute_on_primary_thread(...)' is no longer supported. --fallback-headless is launch-time only and does not catch this. Workarounds: (a) run with --mode headless; (b) use the forward-port at phobicdotno/Codesys-MCP-SP21-plus. SP19/SP20 are unaffected.
  • set_pou_code auto-saves to disk every successful call. UI Ctrl+Z does NOT recover prior content.
  • set_pou_code empty string is a no-op. Passing declarationCode: "" or implementationCode: "" leaves the section unchanged. To clear a section, pass a single-line placeholder (e.g. // cleared).
  • delete_object refuses system nodes and any top-level object (no /). System-reserved exact paths: Application, Device, Project Settings, Device/Plc Logic, Application/Library Manager, Application/Task Configuration, Application/Task Configuration/MainTask, Device/Communication, Device/Communication/Ethernet, Device/SoftMotion General Axis Pool (and the Device/Plc Logic/... variants).
  • set_credentials rejects empty usernames. For no-auth runtimes, do not call this tool at all.
  • add_library requires a fully-qualified placeholder matching the Library Manager UI string (e.g. Standard, * (System)). Bare names fail with placeholder library X could not be resolved.
  • DUT names containing . are rejected by CODESYS (The name 'X.Y' is not valid for this object).
  • Identifier length isn't enforced at create time. CODESYS only complains at compile/save. Stick to ≤32-char IEC identifiers.
  • find_object_by_path refuses ambiguous matches and returns None. Pass a more specific path.
  • is_simulation_mode getter returns None on some device descriptors. The setter works; verify via compile + login.

Troubleshooting

CODESYS not found — verify with --detect. Executable is typically at C:\Program Files\CODESYS 3.5.XX.X\CODESYS\Common\CODESYS.exe.

Every tool call returns Marshal error: ... is no longer supported — you're on SP21+. Restart with --mode headless.

Watcher timeout — default is 180s. Cold first launches of older SPs can exceed the older 60s budget. Bump further on slow hardware: CODESYS_MCP_READY_TIMEOUT_MS=300000. If CODESYS is still coming up, just call launch_codesys again — the launcher will re-attach to the live PID rather than spawning a second instance.

Command timeout — default 60s; compile_project, get_all_pou_code, and download_to_device use 120s. Increase with --timeout <ms>.

Project file locked across MCP restarts — the launcher adopts a live session from the prior server on startup. If you still hit StandardError: The selected project is currently in use, kill the orphan CODESYS.exe via Task Manager, or pass --kill-existing-codesys on next launch (off by default to protect external IDE sessions).

Online tools fail — they require a device/gateway configured (or connect_to_device(ipAddress=...), or set_simulation_mode(enable=true)), a successful compile, and a reachable PLC.

Network error: No route to host from connect_to_device even though ping works — V3 login routes by the gateway-scan node address (e.g. 0301.B0F7), not by the IP-encoded form (0192.0168.0083.0247) that set_gateway_and_address stores from a raw IP. connect_to_device re-scans and re-sets the address before login; if it still fails, the gateway-to-runtime port (TCP 11740 by default) is probably blocked.

Development

bash
npm install
npm run build      # tsc + copy src/scripts/ -> dist/scripts/
npm test
npm run typecheck
pwsh dev/check-scripts.ps1   # ASCII + template-reference static checks

Project layout:

src/
  bin.ts              CLI entry point
  server.ts           MCP tool / resource registration
  launcher.ts         CODESYS process management + session adoption
  ipc.ts              File-based IPC transport
  headless.ts         Headless fallback executor
  script-manager.ts   Python template loading + interpolation
  executor-proxy.ts   Race-free executor swap during background auto-launch
  result-parser.ts    RESULT_JSON marker extraction
  scripts/            IronPython 2.7 watcher + helpers + tool scripts
tests/
  unit/               IPC, script manager, launcher
  integration/        Script pipeline + manual CODESYS tests

License

MIT

Установка

TypingMind
{
  "mcpServers": {
    "codesys-mcp": {
      "command": "codesys-mcp-persistent",
      "args": [
        "--codesys-path",
        "{{config.CODESYS_PATH}}",
        "--codesys-profile",
        "{{config.CODESYS_PROFILE}}",
        "--mode",
        "persistent"
      ],
      "env": {
        "CODESYS_PATH": "<CODESYS_PATH>",
        "CODESYS_PROFILE": "<CODESYS_PROFILE>"
      }
    }
  }
}

Используйте MCP Codesys MCP с разными ИИ-моделями

TypingMind подключает инструменты MCP на уровне рабочего пространства, поэтому после подключения Codesys MCP вы можете использовать их с разными моделями ИИ в TypingMind, не настраивая подключение отдельно для каждой модели. Эта интеграция MCP работает локально на вашем устройстве через коннектор MCP TypingMind.

Руководство по настройке локального коннектора

Выберите этот способ, если серверу MCP нужен доступ к локальным файлам, приложениям или закрытым ресурсам на вашем компьютере.

1

Откройте настройки MCP

В TypingMind откройте «Настройки», затем «Расширенные настройки», перейдите в раздел «Протокол контекста модели» и выберите «Настроить коннектор».

  1. Откройте TypingMind в браузере.
  2. Нажмите значок настроек.
  3. Перейдите в «Расширенные настройки».
  4. Откройте раздел «Протокол контекста модели».
  5. Нажмите «Настроить коннектор» и выберите «Это устройство».
Экран настройки коннектора MCP в TypingMind с выбранным вариантом «Это устройство»
2

Выполните команду коннектора

Выберите «Это устройство», скопируйте команду из TypingMind и выполните её в терминале. Не останавливайте процесс, пока используете MCP.

  1. Скопируйте команду настройки, показанную в TypingMind.
  2. Откройте «Терминал» в macOS или Windows Terminal в Windows.
  3. Вставьте и выполните команду.
  4. Подтвердите установку пакета, если терминал запросит разрешение продолжить.
  5. Не закрывайте окно терминала и не останавливайте процесс, пока используете инструменты MCP.
3

Добавьте Codesys MCP как сервер

Когда статус коннектора сменится на «Готов», нажмите «Изменить серверы» и вставьте конфигурацию сервера MCP.

  1. Дождитесь, пока статус коннектора сменится на «Готов».
  2. Нажмите «Изменить серверы».
  3. Вставьте конфигурацию сервера MCP для Codesys MCP.
  4. Сохраните список серверов.
  5. Обновите статус, если хотите убедиться, что коннектор по-прежнему готов к работе.
Настройки MCP в TypingMind с активным сервером и кнопкой «Изменить серверы»
{
  "mcpServers": {
    "codesys-mcp": {
      "command": "npx",
      "args": [
        "-y",
        "codesys-mcp-persistent"
      ]
    }
  }
}
4

Используйте подключение с разными моделями

Сохраните список серверов, откройте раздел «Плагины», включите инструменты MCP для Codesys MCP, затем выберите любую поддерживаемую модель ИИ в TypingMind и используйте инструменты в чате или назначьте их ИИ-агенту.

  1. Откройте страницу «Плагины» в TypingMind.
  2. Включите инструменты MCP для Codesys MCP.
  3. Начните чат и выберите модель ИИ, которую хотите использовать.
  4. Используйте инструменты MCP в чате или назначьте их ИИ-агенту.
  5. При необходимости переключайтесь на другую модель ИИ без повторного подключения MCP.
Чат TypingMind с включёнными инструментами MCP и выбранной ИИ-моделью
Можете помочь мне с этой задачей с помощью Codesys MCP?
Codesys MCP
Конечно. Я всё прочитал.
Вот что я нашёл с помощью Codesys MCP.

Часто задаваемые вопросы

Для чего используется сервер MCP Codesys MCP?

Codesys MCP — это сервер MCP, который позволяет совместимым ИИ-клиентам подключаться к внешним инструментам и получать контекст. В TypingMind достаточно один раз добавить этот сервер MCP, чтобы его инструменты стали доступны в вашем рабочем пространстве с ИИ.

Можно ли использовать сервер MCP Codesys MCP с несколькими ИИ-моделями в TypingMind?

Да. TypingMind подключает инструменты MCP на уровне рабочего пространства, поэтому вы можете использовать Codesys MCP с разными ИИ-моделями, например Claude, ChatGPT, Gemini или другими моделями, настроенными в TypingMind, без отдельной настройки сервера MCP для каждой модели.

Зачем использовать MCP Codesys MCP с TypingMind?

TypingMind — один из лучших интерфейсов для чата с LLM: он объединяет разные ИИ-модели, промпты, плагины, ИИ-агентов, ключи API и инструменты MCP в одном рабочем пространстве. Подключив Codesys MCP, вы сможете использовать его инструменты MCP с предпочитаемыми моделями, сохраняя удобную организацию работы с чатами в TypingMind.

Как подключить сервер MCP Codesys MCP к TypingMind?

Codesys MCP работает через локальный коннектор MCP TypingMind. Этот вариант лучше всего подходит, когда серверу MCP нужен доступ к локальным файлам, настольным приложениям, инструментам командной строки или закрытым ресурсам на вашем компьютере.

Какие инструменты предоставляет сервер MCP Codesys MCP в TypingMind?

Codesys MCP предоставляет возможности MCP, которые можно включить на странице «Плагины» в TypingMind и использовать в чате или назначить ИИ-агентам.

Нужно ли передавать TypingMind свои ключи API для использования сервера MCP Codesys MCP?

Нет. TypingMind ориентирован прежде всего на локальную работу и позволяет вам контролировать выбор провайдеров моделей, ключи API, промпты и конфигурацию MCP. Если Codesys MCP требует аутентификации, при создании подключения добавьте необходимые заголовки, настройки OAuth или локальную конфигурацию для этого сервера MCP.

Похожие серверы MCP

Все

Создайте свою рабочую ИИ-среду сейчас

Подпишитесь на нашу рассылку, чтобы узнавать о новых функциях и предстоящих розыгрышах 👇