Skip to main content

MCP Tools and Resources

Tools perform actions in the CODESYS project or on the device and return results. Reading tools have no impact on the project or device. Writing tools permanently change the contents or structure of the project and are marked accordingly in the table.

Development tools

Development tools edit the CODESYS project without establishing a connection to the controller.

The development tools are used for the following tasks:

  • Programming in Structured Text

  • Managing the project structure and libraries

  • Checking the project

Tool

Description

Effect

add_or_remove_library

Adds a library reference to the project or removes it.

Change of library references in the Library Manager

add_or_remove_program_call_in_task

Assigns a program to a task so that it is executed in the runtime cycle. The tool is used after a new program has been created.

The tool can also remove program calls from tasks.

Change of the program calls of tasks

browse_project_tree

Displays the structure of the project tree or a specific subtree. Methods, properties, and actions are optionally shown below their parent POUs.

Read only

check_for_errors

Checks the project for errors and returns diagnostic messages with source paths and line numbers. In standard mode, the tool refers to precompile rules. Optionally, a full compilation can be triggered.

Read only. Optionally, the tool can trigger the compilation of the project.

create_folder

Creates a new folder in the project tree. This tool is used to organize POUs into logical groups.

A new folder will be created in the project.

create_or_replace_structured_text_object

Creates new Structured Text objects or completely rewrites existing ones. A complete POU with nested sub-POUs can be created in a single call. Sub-POUs which are not explicitly included will be retained.

Existing objects at the same path will be overwritten.

get_active_app_as_path

Returns the path of the currently loaded project.

Read only

get_active_path_and_selection

Returns the path of the active selection in CODESYS. When code is selected, line numbers and the selected text are also returned.

Read only

get_available_libraries_list

Returns a list of all libraries available in CODESYS.

Read only

get_detailed_library_documentation

Returns detailed documentation for specific functions of a library. Includes parameters, return type, and other relevant details.

Read only

get_library_documentation

Provides a concise overview of the contents of a library. Contains all functions, types, and their top-level signatures.

Read only

get_libraries_referenced_in_application

Returns a list of all libraries referenced in the application.

Read only

get_structured_text_content

Returns the Structured Text source code of an object at the specified path. Nested sub-objects (e.g. methods, actions, properties, and transitions) are included in the output by default.

Also supports the restriction of output by using a start and end line

Read only

remove_object

Removes an object from the project. The tool is also used to remove individual subordinate POUs from a function block.

The object will be irrevocably deleted.

rename_object

Renames an object and updates all references to that object. If a reference cannot be adjusted, then the renaming will not be done.

Complete renaming with a change to all references

replace_text_in_structured_text

Performs targeted text replacements in a Structured Text object.

The specified text will be replaced in the target object.

search_in_files_by_regex

Searches the entire project code for a text pattern. Matches are returned and grouped by object path with line numbers.

Read only

search_libraries_for_type

Searches for a type or function by name over all available libraries. Returns the library name and element type.

Read only

search_path_by_glob

Uses glob patterns to find objects in the project tree. In the case of many results with a common ancestor, the output is displayed in a group.

Read only

Device tools

Device tools edit the device tree of the CODESYS project and manage the device repository.

The device tools are used for the following tasks:

  • Scanning for, adding, replacing, and configuring devices

  • Mapping variables to I/O channels

  • Managing device descriptions in the device repository

The device tools do not establish a connection to the controller. Changed configurations reach the controller only with the next download or online change.

Tool

Description

Effect

acknowledge_device_diagnosis

Acknowledges the diagnostic messages of a device on the controller. Optionally, the tool also acknowledges the diagnostic messages of all subordinate devices. The tool corresponds to the Acknowledge Diagnosis, Acknowledge Diagnosis for Subtree commands in CODESYS. The application must be in online mode.

Writing. Writes a value to the acknowledgment parameter of the device on the controller. The device driver determines how the device responds.

add_device

Adds a device from the device repository to the device tree. The tool adds the device as a top-level device or below a device or connector. A top-level device is a controller, for example. For slots, plug_device is used.

Writing. Adds a device to the project. If an application of the controller is in online mode, the tool is not available.

copy_scanned_devices

Scans for the devices on the fieldbus below a master, scanner, or controller and adds the devices to the project. The tool corresponds to the Scan for Devices command in CODESYS and then copies the devices to the project. If no devices are selected, the tool adds all responding devices for which a device description is installed. For fieldbuses that assign devices by their identity, the tool also adds individual devices from the result of scan_for_devices.

Writing. Changes the project. For fieldbuses that assign devices by their position, the tool replaces an existing configuration below the master only with the replace_devices parameter. In this case, the tool removes devices that the scan does not find. If no device responds, the tool does not change anything.

enable_or_disable_device

Enables or disables a device, a module, or a plugged slot. The tool corresponds to the and commands in CODESYS.

Writing. Changes the device in the project. When a device is disabled, its subordinate devices are also disabled. The tool cannot be executed while an application of the controller is logged in.

get_device_online_status

Reads the online status of a device and all subordinate devices. The online status corresponds to the status icons in the device tree, for example:

  • Running

  • Warning

  • Error

  • No license

  • Diagnosis

  • Disabled

With the include_diagnosis parameter, the tool also reads the diagnosis from the status page of the device, for example a diagnostic message or statistics. The tool reads the status only when the application is in online mode.

Read only.

install_device_descriptions

Installs device description files to the device repository, for example devdesc.xml, ESI, EDS, GSDML, and IODD. The tool installs a maximum of 20 files per call.

Writing. Changes the device repository of the installation. Overwrites existing descriptions with the same version.

list_device_identifications

Lists all devices, connectors, and slots with the type, ID, version, and module ID of their device description. The tool is used to reproduce a configuration or to check the revision used.

Read only.

list_io_channels

Lists the I/O channels of a device with the data type and mapped variables. The output corresponds to the page in the device editor.

Read only.

map_variables_to_io_channels

Maps variables to I/O channels or removes the mapping. A single call can also process multiple devices. The tool checks all entries in advance.

Writing. Replaces the previous mapping. If the tool rejects an entry, the project remains unchanged.

plug_device

Plugs a device into an empty slot or port. For example, the tool plugs a module into a bus coupler or a device into an IO-Link port.

Writing. A device is plugged in the project. If an application of the controller is in online mode, the tool is not available.

read_device_parameters

Reads the parameters of a device with the value, default value, data type, and access. The output corresponds to the parameter pages of the device editor in offline mode.

Read only. The tool does not read any online values.

scan_for_devices

Scans for the devices that are connected to the fieldbus below a master, controller, or scanner. The controller must be reachable. For most fieldbuses, the application with the fieldbus configuration must also be running.

Read only. Existing devices are retained. The tool includes every responding device, including a device of another machine on the same network. Therefore, check the result. CODESYS is blocked during the scan. The scan usually takes a few seconds. If the controller does not respond, the scan takes about 20 seconds.

copy_scanned_devices

The tool adds the devices that were found with scan_for_devices and are not yet in the project to the project. The controller must be reachable. For most fieldbuses, the application with the fieldbus configuration must also be running.

Writing. Adds the found devices to the project. Existing devices are retained. The tool adds every responding device.

search_device_catalogue

Uses a regular expression to search the installed device descriptions by name, vendor, and order number. Optionally, the tool restricts the search to devices that fit below a specific device or into a slot.

Read only.

uninstall_device_descriptions

Irrevocably uninstalls device descriptions from the device repository. The tool also uninstalls descriptions that depend on them.

Writing. The uninstallation is irrevocable and affects all projects, including currently open projects. The tool does not check open projects. Afterwards, the devices in these projects are missing their description.

unplug_device

Removes the device from a slot or port. The slot remains empty in the device tree.

Writing. Removes the device and all subordinate elements.

update_device

Replaces the device description of a device. The tool corresponds to the command in CODESYS. If no description is specified, the tool uses the latest installed version.

Writing. The device keeps its name and position. Where possible, the device also keeps its subnodes and settings.

write_device_parameters

Changes values of device parameters in the project. The tool checks the values in the same way as the device editor.

Writing. Changes only the project. The tool cannot be executed while an application of the controller is logged in.

Online tools

With real hardware, the online tools act on the application of the physical plant. Reading online tools have no impact on the application and device. Writing online tools change the state of the application or device.

Caution

Use these security functions to protect the controller from unintended actions of an AI assistant:

  • Confirmed Online Mode: If Confirmed Online Mode is enabled for the device, the following tools do not perform any action and report an error:

    • logout_application

    • reset_application

    • set_online_values

    • start_application

    • stop_application

    • execute_single_cycle_or_step

  • PLC-UserManagement: With PLC-UserManagement, you define in fine detail who is allowed to perform which actions. On the controller, create a user who has only the rights intended for the AI assistant. Log in to the device as this user.

  • Operating Modes: The Operating Modes generally protect the controller against unintended access, including tools executed by mistake.

Tool

Description

Effect

execute_single_cycle_or_step

Executes one cycle or one step of the logged-in application and then halts.

Writing. The controller reads inputs, executes the program, and writes outputs. In this process, a machine may move.

get_application_state

Returns whether the application is logged in. The tool also returns whether the application is running, is stopped, or is halted at a breakpoint.

Read only.

get_device_log

Reads the runtime log of the device. If an online operation has failed, the log contains the cause.

Read only.

get_online_values

Reads current values of variables of a logged-in application.

Read only.

list_forced_values

Lists all forced variables of a logged-in application.

Read only.

login_and_update_application_if_needed

Logs the user in to the application on the device. If required, the tool compiles the project and downloads it to the device.

Writing. Establishes a connection to the device and downloads code to the device if required.

login_application_if_unchanged

Logs the user in to the application on the device if the application has not changed. This login variant is more cautious and does not transfer any project changes to the device.

Warning

Subsequent tool calls may reset the logged-in application or write and force individual variables.

Writing. The tool compiles the application in order to compare it with the application on the device. The application on the device remains unchanged.

logout_application

Logs the user out of the application. Optionally, the tool unforces the variables first.

Writing. Terminates the online connection.

reset_application

Resets the application. The possible types are warm, cold, and origin.

Writing. Stops program execution and resets variable values. When resetting to origin, the tool deletes the application on the controller.

set_online_values

Writes variable values, forces them, or unforces them.

Writing. Forcing persists beyond the session.

start_application

Starts the specified application. The application must be logged in. First log in the application with login_application_if_unchanged or login_and_update_application_if_needed. If the application is not logged in, the tool reports an error. If the application is already running, the tool does not change anything.

Writing. Executes code on the target device. With real hardware, the code runs on the physical plant.

stop_application

Stops the specified application. The application must be logged in. First log in the application with login_application_if_unchanged or login_and_update_application_if_needed. If the application is not logged in, the tool reports an error. If the application is already stopped, the tool does not change anything.

Writing. Stops the code on the target device.

Project management tools

Project management tools open, save, and close the CODESYS project and return the project status. Only one project can be open at a time. Reading project management tools have no impact on the project. Writing project management tools change the open project or the project file.

Important

The following access restrictions apply to the project management tools:

  • Directory whitelist: The tools work only with project files in folders that the user has approved in Tools → Options → MCP Server → File Access. After installation, no folder is approved. Installation folders, repository folders, and Windows folders are always blocked.

  • User management: The rights of the CODESYS user management also apply to the tools. If the logged-in user does not have the right for a command, the tool does not execute the command and reports an error.

Tool

Description

Effect

close_project

Closes the open project. If the project contains unsaved changes, the tool reports an error. With the discard_changes parameter, the tool discards the changes and closes the project.

Writing. With discard_changes, unsaved changes are lost.

get_project_status

Returns the status of the open project. The status includes the file path, project type, unsaved changes, and write protection. Optionally, the tool also returns the project information.

Read only.

open_project

Opens a project, a library, or an FBS project. Optionally, the tool opens the project as read-only.

Writing. Loads the project. For large projects, opening may take several minutes.

save_project

Saves the open project to its storage location.

Writing. Overwrites the project file.

save_project_as

Saves the open project to a new path. The new project remains open.

Writing. Creates a new file. With the overwrite parameter, the tool overwrites an existing file. The original file remains unchanged.

Resources

Resources are read-only context data such as templates and syntax references. Unlike tools, resources do not perform actions, but provide static contents. Resources can be referenced directly in prompts, for example: "Create a test case according to the test case template".

Resource

Description

CODESYS Structured Text Dialect Description

Syntax reference for the dialect of CODESYS ST with explanations and examples of the IEC 61131-3 standard and CODESYS-specific extensions. The reference comprises syntax rules, data types and literals, variable sections, operators, control flow, calling conventions, interfaces, inheritance, and common sources of errors. This resource can be used during code generation and code checking to avoid syntax errors caused by dialect-specific peculiarities.

CODESYS IEC UnitTest Testcase Template

Test case template following the pattern TM.Testcase. The template contains the following methods:

  • Setup: Preparation of the test object

  • Execute: Stimulation and result testing

  • Teardown: Clean up after the test is complete

  • Abort: Cancellation handling of a running test

This resource is used when creating new unit tests so that test cases are generated according to the recommended pattern of the CODESYS Test Manager.