Metadata-Version: 2.4
Name: l5x-mcp
Version: 0.4.2
Summary: An MCP server for interacting with L5X files
Keywords: mcp,l5x,studio 5000,logix,plc,rockwell
License-Expression: MIT
License-File: LICENSE
Classifier: Programming Language :: Python :: 3
Classifier: Operating System :: OS Independent
Classifier: Topic :: Software Development
Requires-Dist: mcp[cli]>=2.3.0
Requires-Dist: py-l5x>=0.6.0
Requires-Python: >=3.12
Project-URL: Repository, https://github.com/zwood16/l5x-mcp
Project-URL: Issues, https://github.com/zwood16/l5x-mcp/issues
Description-Content-Type: text/markdown

# L5X MCP

`l5x-mcp` is a Python MCP server that gives a coding agent (Claude Code, VS Code Chat, etc.) structured access to Rockwell Studio 5000 Logix Designer projects exported as `.L5X` files. The agent can explore tasks, programs, routines, tags, UDTs, AOIs and I/O modules, read logic, and find cross-references without reading the large raw XML files.

It can also edit projects and create Import Component files (UDTs, AOIs, programs, routines, rungs, tags). Edits never modify the source project: every change is written to a new `.L5X` file that you open or import in Studio 5000.

Routines in all four languages are supported: ladder (RLL), structured text (ST), function block diagram (FBD) and sequential function chart (SFC).

> [!NOTE]
> Generated files are verified by importing and building them in Studio 5000 Logix Designer v37 and v38. Logic itself is not checked by the tools; open the result in Studio 5000 to verify it.
>
> This project is not affiliated with Rockwell Automation in any way.

## Quick Start

[uv](https://docs.astral.sh/uv/getting-started/installation/) is the recommended way to install and run `l5x-mcp`. `uvx` downloads and caches the package, so nothing needs to be installed in a specific folder or environment.

```bash
uvx l5x-mcp --help
```

The server is normally started by your MCP client (see [Register the MCP Server](#register-the-mcp-server)). It looks for `.L5X` files in the folder it is started in, so with Claude Code, start `claude` in the folder that holds your exports.

### Install as a Tool with UV (optional)

`uv` can also install `l5x-mcp` as a tool. This puts `l5x-mcp` on your PATH.

```bash
uv tool install l5x-mcp
```

### Updating

`uvx` caches the package, so refresh it to pick up a new release: `uvx --refresh l5x-mcp --help` (or `uvx l5x-mcp@latest --help`). MCP clients configured with `uvx l5x-mcp` use the new version after you restart them (or the server) following that refresh. With `uv tool install`, run `uv tool upgrade l5x-mcp`.

## Register the MCP Server

### Claude Code

`-s user` registers the server for all your projects. Leave it out to add it to the current project only.

```bash
claude mcp add -s user l5x -- uvx l5x-mcp
```

If you installed it with `uv tool install`, replace `uvx l5x-mcp` with `l5x-mcp`. Server options go after the command and environment variables in `-e` options before `--`, for example:

```bash
claude mcp add -s user l5x -e L5X_MCP_READ_ONLY=1 -- uvx l5x-mcp
```

### Other MCP clients

Other clients (e.g. VS Code `.vscode/mcp.json`) need the same command and arguments. Set `L5X_MCP_ROOT` (or `--root`) when the client does not start the server in your project folder.

```json
{
    "servers": {
        "l5x": {
            "type": "stdio",
            "command": "uvx",
            "args": ["l5x-mcp"],
            "env": { "L5X_MCP_ROOT": "/path/to/exports" }
        }
    }
}
```

With `uv tool install`, use `"command": "l5x-mcp"` and no `args`.

## Configuration

| Env var                     | CLI flag              | Meaning                                                                                                                       |
| --------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
| `L5X_MCP_ROOT`              | `--root`              | Folder searched (recursively) for `.L5X` files. Default: the current working directory.                                       |
| `L5X_MCP_OUTPUT_DIR`        | `--output-dir`        | Where write tools put output given as a bare file name, relative to the root. Default: `l5x-mcp-output`.                    |
| `L5X_MCP_READ_ONLY`         | `--read-only`         | Register only the read tools. Write tools are enabled by default.                                                             |
| `L5X_MCP_STRUCTURED_OUTPUT` | `--structured-output` | Also return MCP `structuredContent` and output schemas. Results are always returned as compact JSON text.                    |

Flags take precedence over environment variables. Boolean variables accept `1`, `true`, `yes` or `on`. Restart the server after changing its configuration.

If the configured root does not exist (for example a temporary folder a client has since deleted), the server still starts and logs a warning. On the first tool call it asks the client for its roots (`roots/list`) and uses the first existing `file://` folder, then falls back to the server's current working directory. If neither works, the tool call fails with an error naming the missing folder and what was tried; the next call retries.

### Finding .L5X files

- `.L5X` files are found anywhere under the root. Hidden folders, `node_modules`, `__pycache__` and `venv` are skipped.
- When exactly one project is found it is used automatically. Otherwise every tool takes a `path` (absolute or relative to the root).
- Files are re-read when they change on disk, so saving (and re-exporting) the project in Studio 5000 is picked up without a restart.
- Files in the output folder are skipped when picking the default project, so edits don't hide the source.

## Tools

### Read tools

| Tool                                  | Description                                                                                                                     |
| ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `list_l5x_files`                      | List the `.L5X` files under the root.                                                                                           |
| `project_overview`                    | Summarize the controller, tasks, programs, AOIs, UDTs and modules.                                                              |
| `list_tasks` / `get_task`             | Tasks with type, rate, priority, watchdog and scheduled programs.                                                               |
| `list_programs` / `get_program`       | Programs with main routine, flags, routines and tags.                                                                           |
| `list_routines`                       | Routines of a program or AOI, with their language and size.                                                                     |
| `get_routine_logic`                   | Rungs, ST lines, or a text rendering of FBD/SFC diagrams, with a description of every operand. Paged to fit a size budget.     |
| `list_tags` / `get_tag`               | Controller, program and module I/O tags. `get_tag` resolves operand paths such as `Tag.Member[3].1` or `Local:1:I.Pt00.Data`. |
| `list_data_types` / `get_data_type`   | UDTs, their members and where they are used.                                                                                    |
| `list_aois` / `get_aoi`               | Add-On Instructions with parameters, local tags, instances and (optionally) logic.                                              |
| `list_modules` / `get_module`         | The I/O tree and module details.                                                                                                |
| `find_references`                     | Where a tag, instruction or text is used in program and AOI logic.                                                              |
| `instruction_usage`                   | How often each instruction is used.                                                                                             |

### Write tools

| Tool                                                                         | Description                                                                                |
| ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
| `get_spec`                                                                   | An existing UDT, AOI, program, tag or routine as an editable spec.                         |
| `add_tags` / `remove_tags` / `rename_tag` / `set_tag_values` / `update_tag`  | Tags, values, descriptions and operand comments.                                           |
| `add_routine` / `remove_routine` / `rename_routine`                          | Program routines in any language.                                                          |
| `add_rungs` / `replace_rung` / `remove_rungs`                                | Ladder rungs.                                                                              |
| `set_st_lines` / `set_routine_content`                                       | Replace the code of an ST routine, or the diagram of an FBD/SFC routine.                   |
| `add_*` / `replace_*` / `rename_*` / `remove_*` for data types, AOIs, programs | UDTs, AOIs and programs. Replacing migrates existing instances.                          |
| `schedule_program` / `set_description`                                       | Task scheduling and descriptions.                                                          |
| `export_component`                                                           | Write existing objects to an Import Component file, with their dependencies.               |
| `create_*_file`                                                              | Build a new UDT, AOI, program, routine, rungs or tags as an Import Component file.        |

How editing works:

- Every write tool needs an `output_path`. The source project is never modified, and existing files are not replaced (except, with `overwrite=true`, files the server wrote earlier in the same session).
- To make several changes, pass each result's `file` as the next call's `path`.
- To change a UDT, AOI, program or routine: `get_spec`, edit the spec, then call the matching `replace_*` (or `set_routine_content`) tool.
- Renaming or removing tags, routines and programs does not rewrite the logic that uses them; the result lists the remaining `references` so they can be fixed.
- Use instructions that exist in your project's version (v36+ uses `MOVE`, `EQ`, … instead of `MOV`, `EQU`, …).
- Source-protected AOIs and routines can be listed and exported but their logic cannot be read or edited.

## Development

### Install from source

```bash
git clone https://github.com/zwood16/l5x-mcp
cd l5x-mcp
uv sync
```

To use a checkout with Claude Code, register `uv run --project /path/to/l5x-mcp --no-sync l5x-mcp`. Use `--project`, not `--directory`, so the server still starts in your project folder.

### Running Tests

This project uses `pytest` for tests and `ruff` for linting. Both are dev dependencies:

```bash
uv run pytest
uv run ruff check
uv run ruff format
```

The tests never need Windows or Rockwell software. Generated files are compared byte-for-byte with golden files that were imported and built in Studio 5000 through the Logix Designer SDK; see [tools/sdk/README.md](tools/sdk/README.md) to re-run that verification after changing generated output.

