Metadata-Version: 2.4
Name: logix-tag-mcp
Version: 0.1.0
Summary: MCP server for reading (and optionally writing) live Logix controller tags
Keywords: mcp,logix,plc,rockwell,controllogix,compactlogix,ethernet/ip
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: pycomm3>=1.2.16
Requires-Python: >=3.12
Project-URL: Repository, https://github.com/zwood16/logix-tag-mcp
Project-URL: Issues, https://github.com/zwood16/logix-tag-mcp/issues
Description-Content-Type: text/markdown

# Logix Tag MCP

> [!IMPORTANT]
> This project is still very early. Consider it an Alpha for the time being

`logix-tag-mcp` is a Python MCP server that lets a coding agent such as Claude Code or VS Code Chat read live tag values from a running Rockwell Logix PLC's (CompactLogix, ControlLogix, etc.). It talks to the controller over EtherNet/IP with [pycomm3](https://github.com/ottowayi/pycomm3).

It pairs with [l5x-mcp](https://github.com/zwood16/l5x-mcp). The agent reads the logic offline with `l5x-mcp` and checks the live values here while you debug online. Tag names can be passed exactly as `l5x-mcp` shows them, as a bare program tag name plus its program.

The server is read-only by default. The `write_tag` tool is only registered when the server is started with writes enabled. See [Writing tags](#writing-tags).

> [!NOTE]
> This project is not affiliated with Rockwell Automation in any way.


## Quick start

`logix-tag-mcp` needs network access to the controller on EtherNet/IP port TCP 44818.

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

```bash
uvx logix-tag-mcp --help
```

The server is normally started by your MCP client. See [Register the MCP server](#register-the-mcp-server).

There is no default controller. Every tool that talks to a controller takes a required `host` argument, for example `192.168.1.10`, or `192.168.1.10/1` for a processor in slot 1. The agent asks you for the address when it does not know it.

### Install as a tool with uv (optional)

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

```bash
uv tool install logix-tag-mcp
```

### Updating

`uvx` caches the package, so refresh it to pick up a new release with `uvx --refresh logix-tag-mcp --help`. MCP clients configured with `uvx logix-tag-mcp` use the new version after you restart them. With `uv tool install`, run `uv tool upgrade logix-tag-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 logix-tags -- uvx logix-tag-mcp
```

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

```bash
claude mcp add -s user logix-tags -e LOGIX_TAG_MCP_ALLOWED_HOSTS=192.168.1.10 -- uvx logix-tag-mcp
```

### Other MCP clients

Other clients need the same command and arguments. This example is a VS Code `.vscode/mcp.json`:

```json
{
    "servers": {
        "logix-tags": {
            "type": "stdio",
            "command": "uvx",
            "args": ["logix-tag-mcp"]
        }
    }
}
```

With `uv tool install`, use `"command": "logix-tag-mcp"` and no `args`. Claude Code also reads a project `.mcp.json`. See [`.mcp.json.example`](.mcp.json.example).

## Configuration

| Env var                         | CLI flag            | Meaning                                                                                                                         |
| ------------------------------- | ------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
| `LOGIX_TAG_MCP_TIMEOUT`         | `--timeout`         | Socket timeout in seconds. Default: `5`.                                                                                        |
| `LOGIX_TAG_MCP_ALLOWED_HOSTS`   | `--allowed-hosts`   | Comma-separated hosts the server may connect to. Other hosts are refused. Default: any host.                                    |
| `LOGIX_TAG_MCP_LOG_DIR`         | `--log-dir`         | Folder for logger files and the write audit log. Relative paths start at the folder the server runs in. Default: `logix-tag-mcp-logs`. |
| `LOGIX_TAG_MCP_ENABLE_WRITES`   | `--enable-writes`   | Register the `write_tag` tool. Default: off.                                                                                    |
| `LOGIX_TAG_MCP_WRITE_ALLOWLIST` | `--write-allowlist` | Comma-separated glob patterns. When set, only matching tags can be written. Default: none.                                      |

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

## Tools

### Discovery tools

| Tool               | Description                                                                                                       |
| ------------------ | ----------------------------------------------------------------------------------------------------------------- |
| `controller_info`  | Controller name, product, firmware, serial number, key switch, programs, tasks, modules, tag count and clock.      |
| `list_tags`        | Paged tag list, filtered by name or glob, program and data type. Returns full names that `read_tags` accepts.     |
| `get_data_type`    | Members of a UDT, AOI, module or built-in type.                                                                   |
| `refresh_tag_list` | Upload the tag list and data types again after a download or online edit.                                         |

### Read tools

| Tool          | Description                                                                                                                                                  |
| ------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `read_tags`   | Read any number of tags, members, bits, array elements or whole arrays in one batch. Each tag succeeds or fails on its own.                                  |
| `read_struct` | Read a struct whole, or member by member up to 3 levels deep when the controller refuses the whole read. `members` filters large types such as axes.         |
| `sample_tags` | Watch tags for up to 30 seconds and return only the changes, with timestamps.                                                                                |

### Logger tools

| Tool                 | Description                                                                                                                                       |
| -------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------- |
| `start_logger`       | Log tags to a JSONL file on a background thread with its own connection. Logs on change or every sample, with an optional deadband.               |
| `list_loggers`       | Status of all loggers.                                                                                                                            |
| `get_logger_data`    | Logged rows, filtered by time and tag, paged.                                                                                                     |
| `get_logger_summary` | Per tag statistics and communication outages. Numbers get minimum, maximum and time-weighted mean. BOOLs get edges and time true and false. Other types get change counts. |
| `export_logger_csv`  | Write a wide, forward-filled CSV next to the JSONL file for opening in Excel.                                                                     |
| `stop_logger`        | Stop a logger.                                                                                                                                    |

Up to 5 loggers can run at once, with 100 tags each. The minimum interval is 50 ms. A logger runs for 1 hour by default and 24 hours at most. Loggers keep running through a lost connection and record `comm_error` and `comm_restored` events.

### Writing tags

`write_tag` is only registered when writes are enabled. It changes values in a running machine, which can start motion or change machine state. Enable it only when you mean to, and set an allowlist:

```bash
claude mcp add logix-tags \
  -e LOGIX_TAG_MCP_ENABLE_WRITES=1 \
  -e "LOGIX_TAG_MCP_WRITE_ALLOWLIST=Program:MainProgram.Setpoint*" -- \
  uvx logix-tag-mcp
```

How `write_tag` works:

- It refuses tags outside the allowlist, Read Only tags, and whole structs or arrays. Write members or elements instead.
- It checks the value against the tag type. BOOL takes only true, false, 0 or 1. Integers are range-checked. REALs must be finite. Strings are length-checked.
- It reads the current value first. With `expected_current`, it refuses the write if the value has changed. This check is not atomic, so logic can change the value between the check and the write.
- It sends the write once and never retries it. If the connection drops during the write, the result says the write may or may not have been applied.
- It reads the value back and warns if it differs. A difference usually means logic overwrites the tag every scan.
- It appends every attempt, including refusals, to `writes.jsonl` in the log folder.

## Tag names and l5x-mcp

Online, program tags are named `Program:<program>.<tag>`. `l5x-mcp` shows them by bare name with a program scope. Pass the bare name with `program` and the server resolves it the way Logix does. It looks for a program tag first, then a controller tag.

```text
read_tags(host="192.168.1.10", tags=["Timer1.DN", "Motor1_Run"], program="MainProgram")
# Timer1.DN resolves to Program:MainProgram.Timer1.DN
# Motor1_Run resolves to the controller tag, because MainProgram has no tag with that name
```

Fully qualified names such as `Program:MainProgram.Timer1` and `Local:1:I.Pt00.Data` are used unchanged.

## Controller behavior

- Tags with External Access set to None are not visible over the network. They read as if they do not exist. `l5x-mcp` shows each tag's `external_access`.
- The controller refuses whole reads of AOI instances, axes and module I/O structs such as `Local:1:I`. `read_tags` and `read_struct` fall back to reading their members. AOI local tags cannot be read, only parameters.
- BOOL arrays are stored as DWORDs. The server shows and reads them as BOOL arrays, so `Tag[5]` is bit 5.
- The controller clock is reported as the controller holds it, without timezone conversion.
- A dropped connection is reconnected on the next call. While the controller is unreachable, each call fails after about one timeout.

## Development

### Install from source

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

### 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 unit tests use a fake driver and need no hardware. Tests that need a real controller are marked `integration` and are skipped unless `LOGIX_TAG_MCP_TEST_HOST` is set to the controller address. Run only the offline tests, as the publish workflows do, with:

```bash
uv run pytest -m "not integration"
```

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