l5x-mcp 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
l5x_mcp-0.4.0/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Zac Wood
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
l5x_mcp-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,169 @@
1
+ Metadata-Version: 2.4
2
+ Name: l5x-mcp
3
+ Version: 0.4.0
4
+ Summary: An MCP server for interacting with L5X files
5
+ Keywords: mcp,l5x,studio 5000,logix,plc,rockwell
6
+ License-Expression: MIT
7
+ License-File: LICENSE
8
+ Classifier: Programming Language :: Python :: 3
9
+ Classifier: Operating System :: OS Independent
10
+ Classifier: Topic :: Software Development
11
+ Requires-Dist: mcp[cli]>=2.3.0
12
+ Requires-Dist: py-l5x>=0.5.3
13
+ Requires-Python: >=3.12
14
+ Project-URL: Repository, https://github.com/zwood16/l5x-mcp
15
+ Project-URL: Issues, https://github.com/zwood16/l5x-mcp/issues
16
+ Description-Content-Type: text/markdown
17
+
18
+ # L5X MCP
19
+
20
+ `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.
21
+
22
+ 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.
23
+
24
+ Routines in all four languages are supported: ladder (RLL), structured text (ST), function block diagram (FBD) and sequential function chart (SFC).
25
+
26
+ > [!NOTE]
27
+ > 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.
28
+ >
29
+ > This project is not affiliated with Rockwell Automation in any way.
30
+
31
+ ## Quick Start
32
+
33
+ [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.
34
+
35
+ ```bash
36
+ uvx l5x-mcp --help
37
+ ```
38
+
39
+ 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.
40
+
41
+ ### Install as a Tool with UV (optional)
42
+
43
+ `uv` can also install `l5x-mcp` as a tool. This puts `l5x-mcp` on your PATH.
44
+
45
+ ```bash
46
+ uv tool install l5x-mcp
47
+ ```
48
+
49
+ Upgrade later with `uv tool upgrade l5x-mcp`.
50
+
51
+ ## Register the MCP Server
52
+
53
+ ### Claude Code
54
+
55
+ `-s user` registers the server for all your projects. Leave it out to add it to the current project only.
56
+
57
+ ```bash
58
+ claude mcp add -s user l5x -- uvx l5x-mcp
59
+ ```
60
+
61
+ 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:
62
+
63
+ ```bash
64
+ claude mcp add -s user l5x -e L5X_MCP_READ_ONLY=1 -- uvx l5x-mcp
65
+ ```
66
+
67
+ ### Other MCP clients
68
+
69
+ 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.
70
+
71
+ ```json
72
+ {
73
+ "servers": {
74
+ "l5x": {
75
+ "type": "stdio",
76
+ "command": "uvx",
77
+ "args": ["l5x-mcp"],
78
+ "env": { "L5X_MCP_ROOT": "/path/to/exports" }
79
+ }
80
+ }
81
+ }
82
+ ```
83
+
84
+ With `uv tool install`, use `"command": "l5x-mcp"` and no `args`.
85
+
86
+ ## Configuration
87
+
88
+ | Env var | CLI flag | Meaning |
89
+ | --------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
90
+ | `L5X_MCP_ROOT` | `--root` | Folder searched (recursively) for `.L5X` files. Default: the current working directory. |
91
+ | `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`. |
92
+ | `L5X_MCP_READ_ONLY` | `--read-only` | Register only the read tools. Write tools are enabled by default. |
93
+ | `L5X_MCP_STRUCTURED_OUTPUT` | `--structured-output` | Also return MCP `structuredContent` and output schemas. Results are always returned as compact JSON text. |
94
+
95
+ Flags take precedence over environment variables. Boolean variables accept `1`, `true`, `yes` or `on`. Restart the server after changing its configuration.
96
+
97
+ ### Finding .L5X files
98
+
99
+ - `.L5X` files are found anywhere under the root. Hidden folders, `node_modules`, `__pycache__` and `venv` are skipped.
100
+ - When exactly one project is found it is used automatically. Otherwise every tool takes a `path` (absolute or relative to the root).
101
+ - 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.
102
+ - Files in the output folder are skipped when picking the default project, so edits don't hide the source.
103
+
104
+ ## Tools
105
+
106
+ ### Read tools
107
+
108
+ | Tool | Description |
109
+ | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
110
+ | `list_l5x_files` | List the `.L5X` files under the root. |
111
+ | `project_overview` | Summarize the controller, tasks, programs, AOIs, UDTs and modules. |
112
+ | `list_tasks` / `get_task` | Tasks with type, rate, priority, watchdog and scheduled programs. |
113
+ | `list_programs` / `get_program` | Programs with main routine, flags, routines and tags. |
114
+ | `list_routines` | Routines of a program or AOI, with their language and size. |
115
+ | `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. |
116
+ | `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`. |
117
+ | `list_data_types` / `get_data_type` | UDTs, their members and where they are used. |
118
+ | `list_aois` / `get_aoi` | Add-On Instructions with parameters, local tags, instances and (optionally) logic. |
119
+ | `list_modules` / `get_module` | The I/O tree and module details. |
120
+ | `find_references` | Where a tag, instruction or text is used in program and AOI logic. |
121
+ | `instruction_usage` | How often each instruction is used. |
122
+
123
+ ### Write tools
124
+
125
+ | Tool | Description |
126
+ | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
127
+ | `get_spec` | An existing UDT, AOI, program, tag or routine as an editable spec. |
128
+ | `add_tags` / `remove_tags` / `rename_tag` / `set_tag_values` / `update_tag` | Tags, values, descriptions and operand comments. |
129
+ | `add_routine` / `remove_routine` / `rename_routine` | Program routines in any language. |
130
+ | `add_rungs` / `replace_rung` / `remove_rungs` | Ladder rungs. |
131
+ | `set_st_lines` / `set_routine_content` | Replace the code of an ST routine, or the diagram of an FBD/SFC routine. |
132
+ | `add_*` / `replace_*` / `rename_*` / `remove_*` for data types, AOIs, programs | UDTs, AOIs and programs. Replacing migrates existing instances. |
133
+ | `schedule_program` / `set_description` | Task scheduling and descriptions. |
134
+ | `export_component` | Write existing objects to an Import Component file, with their dependencies. |
135
+ | `create_*_file` | Build a new UDT, AOI, program, routine, rungs or tags as an Import Component file. |
136
+
137
+ How editing works:
138
+
139
+ - 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).
140
+ - To make several changes, pass each result's `file` as the next call's `path`.
141
+ - To change a UDT, AOI, program or routine: `get_spec`, edit the spec, then call the matching `replace_*` (or `set_routine_content`) tool.
142
+ - 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.
143
+ - Use instructions that exist in your project's version (v36+ uses `MOVE`, `EQ`, … instead of `MOV`, `EQU`, …).
144
+ - Source-protected AOIs and routines can be listed and exported but their logic cannot be read or edited.
145
+
146
+ ## Development
147
+
148
+ ### Install from source
149
+
150
+ ```bash
151
+ git clone https://github.com/zwood16/l5x-mcp
152
+ cd l5x-mcp
153
+ uv sync
154
+ ```
155
+
156
+ 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.
157
+
158
+ ### Running Tests
159
+
160
+ This project uses `pytest` for tests and `ruff` for linting. Both are dev dependencies:
161
+
162
+ ```bash
163
+ uv run pytest
164
+ uv run ruff check
165
+ uv run ruff format
166
+ ```
167
+
168
+ 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.
169
+
@@ -0,0 +1,152 @@
1
+ # L5X MCP
2
+
3
+ `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.
4
+
5
+ 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.
6
+
7
+ Routines in all four languages are supported: ladder (RLL), structured text (ST), function block diagram (FBD) and sequential function chart (SFC).
8
+
9
+ > [!NOTE]
10
+ > 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.
11
+ >
12
+ > This project is not affiliated with Rockwell Automation in any way.
13
+
14
+ ## Quick Start
15
+
16
+ [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.
17
+
18
+ ```bash
19
+ uvx l5x-mcp --help
20
+ ```
21
+
22
+ 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.
23
+
24
+ ### Install as a Tool with UV (optional)
25
+
26
+ `uv` can also install `l5x-mcp` as a tool. This puts `l5x-mcp` on your PATH.
27
+
28
+ ```bash
29
+ uv tool install l5x-mcp
30
+ ```
31
+
32
+ Upgrade later with `uv tool upgrade l5x-mcp`.
33
+
34
+ ## Register the MCP Server
35
+
36
+ ### Claude Code
37
+
38
+ `-s user` registers the server for all your projects. Leave it out to add it to the current project only.
39
+
40
+ ```bash
41
+ claude mcp add -s user l5x -- uvx l5x-mcp
42
+ ```
43
+
44
+ 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:
45
+
46
+ ```bash
47
+ claude mcp add -s user l5x -e L5X_MCP_READ_ONLY=1 -- uvx l5x-mcp
48
+ ```
49
+
50
+ ### Other MCP clients
51
+
52
+ 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.
53
+
54
+ ```json
55
+ {
56
+ "servers": {
57
+ "l5x": {
58
+ "type": "stdio",
59
+ "command": "uvx",
60
+ "args": ["l5x-mcp"],
61
+ "env": { "L5X_MCP_ROOT": "/path/to/exports" }
62
+ }
63
+ }
64
+ }
65
+ ```
66
+
67
+ With `uv tool install`, use `"command": "l5x-mcp"` and no `args`.
68
+
69
+ ## Configuration
70
+
71
+ | Env var | CLI flag | Meaning |
72
+ | --------------------------- | --------------------- | ----------------------------------------------------------------------------------------------------------------------------- |
73
+ | `L5X_MCP_ROOT` | `--root` | Folder searched (recursively) for `.L5X` files. Default: the current working directory. |
74
+ | `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`. |
75
+ | `L5X_MCP_READ_ONLY` | `--read-only` | Register only the read tools. Write tools are enabled by default. |
76
+ | `L5X_MCP_STRUCTURED_OUTPUT` | `--structured-output` | Also return MCP `structuredContent` and output schemas. Results are always returned as compact JSON text. |
77
+
78
+ Flags take precedence over environment variables. Boolean variables accept `1`, `true`, `yes` or `on`. Restart the server after changing its configuration.
79
+
80
+ ### Finding .L5X files
81
+
82
+ - `.L5X` files are found anywhere under the root. Hidden folders, `node_modules`, `__pycache__` and `venv` are skipped.
83
+ - When exactly one project is found it is used automatically. Otherwise every tool takes a `path` (absolute or relative to the root).
84
+ - 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.
85
+ - Files in the output folder are skipped when picking the default project, so edits don't hide the source.
86
+
87
+ ## Tools
88
+
89
+ ### Read tools
90
+
91
+ | Tool | Description |
92
+ | ------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------- |
93
+ | `list_l5x_files` | List the `.L5X` files under the root. |
94
+ | `project_overview` | Summarize the controller, tasks, programs, AOIs, UDTs and modules. |
95
+ | `list_tasks` / `get_task` | Tasks with type, rate, priority, watchdog and scheduled programs. |
96
+ | `list_programs` / `get_program` | Programs with main routine, flags, routines and tags. |
97
+ | `list_routines` | Routines of a program or AOI, with their language and size. |
98
+ | `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. |
99
+ | `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`. |
100
+ | `list_data_types` / `get_data_type` | UDTs, their members and where they are used. |
101
+ | `list_aois` / `get_aoi` | Add-On Instructions with parameters, local tags, instances and (optionally) logic. |
102
+ | `list_modules` / `get_module` | The I/O tree and module details. |
103
+ | `find_references` | Where a tag, instruction or text is used in program and AOI logic. |
104
+ | `instruction_usage` | How often each instruction is used. |
105
+
106
+ ### Write tools
107
+
108
+ | Tool | Description |
109
+ | ---------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
110
+ | `get_spec` | An existing UDT, AOI, program, tag or routine as an editable spec. |
111
+ | `add_tags` / `remove_tags` / `rename_tag` / `set_tag_values` / `update_tag` | Tags, values, descriptions and operand comments. |
112
+ | `add_routine` / `remove_routine` / `rename_routine` | Program routines in any language. |
113
+ | `add_rungs` / `replace_rung` / `remove_rungs` | Ladder rungs. |
114
+ | `set_st_lines` / `set_routine_content` | Replace the code of an ST routine, or the diagram of an FBD/SFC routine. |
115
+ | `add_*` / `replace_*` / `rename_*` / `remove_*` for data types, AOIs, programs | UDTs, AOIs and programs. Replacing migrates existing instances. |
116
+ | `schedule_program` / `set_description` | Task scheduling and descriptions. |
117
+ | `export_component` | Write existing objects to an Import Component file, with their dependencies. |
118
+ | `create_*_file` | Build a new UDT, AOI, program, routine, rungs or tags as an Import Component file. |
119
+
120
+ How editing works:
121
+
122
+ - 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).
123
+ - To make several changes, pass each result's `file` as the next call's `path`.
124
+ - To change a UDT, AOI, program or routine: `get_spec`, edit the spec, then call the matching `replace_*` (or `set_routine_content`) tool.
125
+ - 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.
126
+ - Use instructions that exist in your project's version (v36+ uses `MOVE`, `EQ`, … instead of `MOV`, `EQU`, …).
127
+ - Source-protected AOIs and routines can be listed and exported but their logic cannot be read or edited.
128
+
129
+ ## Development
130
+
131
+ ### Install from source
132
+
133
+ ```bash
134
+ git clone https://github.com/zwood16/l5x-mcp
135
+ cd l5x-mcp
136
+ uv sync
137
+ ```
138
+
139
+ 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.
140
+
141
+ ### Running Tests
142
+
143
+ This project uses `pytest` for tests and `ruff` for linting. Both are dev dependencies:
144
+
145
+ ```bash
146
+ uv run pytest
147
+ uv run ruff check
148
+ uv run ruff format
149
+ ```
150
+
151
+ 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.
152
+
@@ -0,0 +1,70 @@
1
+ [project]
2
+ name = "l5x-mcp"
3
+ version = "0.4.0"
4
+ description = "An MCP server for interacting with L5X files"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ keywords = [
9
+ "mcp",
10
+ "l5x",
11
+ "studio 5000",
12
+ "logix",
13
+ "plc",
14
+ "rockwell",
15
+ ]
16
+ classifiers = [
17
+ "Programming Language :: Python :: 3",
18
+ "Operating System :: OS Independent",
19
+ "Topic :: Software Development",
20
+ ]
21
+ requires-python = ">=3.12"
22
+ dependencies = [
23
+ "mcp[cli]>=2.3.0",
24
+ "py-l5x>=0.5.3",
25
+ ]
26
+
27
+ [project.urls]
28
+ Repository = "https://github.com/zwood16/l5x-mcp"
29
+ Issues = "https://github.com/zwood16/l5x-mcp/issues"
30
+
31
+ [project.scripts]
32
+ l5x-mcp = "l5x_mcp:main"
33
+
34
+ [build-system]
35
+ requires = ["uv_build>=0.13.8,<0.14.0"]
36
+ build-backend = "uv_build"
37
+
38
+ [tool.ruff]
39
+ line-length = 88
40
+
41
+ [tool.ruff.lint]
42
+ select = [
43
+ "E",
44
+ "F",
45
+ "I",
46
+ "UP",
47
+ "B",
48
+ "SIM",
49
+ "D",
50
+ "ANN",
51
+ ]
52
+ ignore = ["ANN401"]
53
+
54
+ [tool.ruff.lint.pydocstyle]
55
+ convention = "google"
56
+
57
+ [tool.ruff.lint.per-file-ignores]
58
+ "tests/**" = [
59
+ "D",
60
+ "ANN",
61
+ ]
62
+
63
+ [tool.pytest.ini_options]
64
+ testpaths = ["tests"]
65
+
66
+ [dependency-groups]
67
+ dev = [
68
+ "pytest>=9.1.1",
69
+ "ruff>=0.6",
70
+ ]
@@ -0,0 +1,61 @@
1
+ [project]
2
+ name = "l5x-mcp"
3
+ version = "0.4.0"
4
+ description = "An MCP server for interacting with L5X files"
5
+ readme = "README.md"
6
+ license = "MIT"
7
+ license-files = ["LICENSE"]
8
+ keywords = ["mcp", "l5x", "studio 5000", "logix", "plc", "rockwell"]
9
+ classifiers = [
10
+ "Programming Language :: Python :: 3",
11
+ "Operating System :: OS Independent",
12
+ "Topic :: Software Development",
13
+ ]
14
+ requires-python = ">=3.12"
15
+ dependencies = [
16
+ "mcp[cli]>=2.3.0",
17
+ "py-l5x>=0.5.3",
18
+ ]
19
+
20
+ [project.urls]
21
+ Repository = "https://github.com/zwood16/l5x-mcp"
22
+ Issues = "https://github.com/zwood16/l5x-mcp/issues"
23
+
24
+ [project.scripts]
25
+ l5x-mcp = "l5x_mcp:main"
26
+
27
+ [build-system]
28
+ requires = ["uv_build>=0.13.8,<0.14.0"]
29
+ build-backend = "uv_build"
30
+
31
+ [tool.ruff]
32
+ line-length = 88
33
+
34
+ [tool.ruff.lint]
35
+ # The rule categories to enable.
36
+ select = [
37
+ "E", # pycodestyle (catches formatting-adjacent errors)
38
+ "F", # Pyflakes (catches logical errors, like unused variables)
39
+ "I", # isort (automatically sorts your imports)
40
+ "UP", # pyupgrade (suggests modern syntax upgrades)
41
+ "B", # flake8-bugbear (catches common bugs and gotchas)
42
+ "SIM", # flake8-simplify (suggests cleaner, more elegant code)
43
+ "D", # pydocstyle (docstrings, for generated API docs)
44
+ "ANN", # flake8-annotations (type hints)
45
+ ]
46
+ ignore = ["ANN401"] # Any is legitimate for py_l5x objects
47
+
48
+ [tool.ruff.lint.pydocstyle]
49
+ convention = "google"
50
+
51
+ [tool.ruff.lint.per-file-ignores]
52
+ "tests/**" = ["D", "ANN"]
53
+
54
+ [dependency-groups]
55
+ dev = [
56
+ "pytest>=9.1.1",
57
+ "ruff>=0.6",
58
+ ]
59
+
60
+ [tool.pytest.ini_options]
61
+ testpaths = ["tests"]
@@ -0,0 +1,122 @@
1
+ """MCP server that lets LLMs explore Studio 5000 .L5X project exports."""
2
+
3
+ from __future__ import annotations
4
+
5
+ import argparse
6
+ import os
7
+ import re
8
+ from collections.abc import Sequence
9
+
10
+ ROOT_ENV_VAR = "L5X_MCP_ROOT"
11
+ OUTPUT_DIR_ENV_VAR = "L5X_MCP_OUTPUT_DIR"
12
+ STRUCTURED_OUTPUT_ENV_VAR = "L5X_MCP_STRUCTURED_OUTPUT"
13
+ READ_ONLY_ENV_VAR = "L5X_MCP_READ_ONLY"
14
+ _TRUTHY = frozenset({"1", "true", "yes", "on"})
15
+
16
+
17
+ def _env_flag(name: str) -> bool:
18
+ return os.environ.get(name, "").strip().lower() in _TRUTHY
19
+
20
+
21
+ def _root_argument(value: str) -> str:
22
+ if re.search(r"\$\{[^}]+\}", value):
23
+ raise argparse.ArgumentTypeError(
24
+ f"Root contains an unresolved configuration variable: {value!r}. "
25
+ "Variables such as ${workspaceFolder} must be expanded by the MCP client, "
26
+ "not by this server. Omit --root and use "
27
+ "'uv run --project <server-repo> --no-sync l5x-mcp' to preserve the "
28
+ "client's launch directory, or provide a literal directory via --root "
29
+ f"or {ROOT_ENV_VAR}."
30
+ )
31
+ return value
32
+
33
+
34
+ def _output_dir_argument(value: str) -> str:
35
+ if re.search(r"\$\{[^}]+\}", value):
36
+ raise argparse.ArgumentTypeError(
37
+ f"Output directory contains an unresolved configuration variable: "
38
+ f"{value!r}. Variables such as ${{workspaceFolder}} must be expanded by "
39
+ "the MCP client, not by this server. Provide a literal folder via "
40
+ f"--output-dir or {OUTPUT_DIR_ENV_VAR}."
41
+ )
42
+ return value
43
+
44
+
45
+ def parse_args(argv: Sequence[str] | None = None) -> argparse.Namespace:
46
+ """Parse the command-line arguments (with environment-variable fallbacks).
47
+
48
+ Args:
49
+ argv: Argument list to parse; defaults to `sys.argv[1:]`.
50
+
51
+ Returns:
52
+ The parsed arguments namespace.
53
+ """
54
+ parser = argparse.ArgumentParser(
55
+ prog="l5x-mcp",
56
+ description="MCP server for exploring Studio 5000 .L5X project exports.",
57
+ )
58
+ parser.add_argument(
59
+ "--root",
60
+ type=_root_argument,
61
+ default=os.environ.get(ROOT_ENV_VAR) or None,
62
+ help=(
63
+ "Directory to search for .L5X files and resolve relative paths against. "
64
+ f"Defaults to {ROOT_ENV_VAR} or the current working directory. "
65
+ "Configuration variables must be expanded by the MCP client."
66
+ ),
67
+ )
68
+ parser.add_argument(
69
+ "--output-dir",
70
+ type=_output_dir_argument,
71
+ default=os.environ.get(OUTPUT_DIR_ENV_VAR) or None,
72
+ help=(
73
+ "Folder where write tools put bare output file names, relative to the "
74
+ "root (or absolute inside it). Defaults to "
75
+ f"{OUTPUT_DIR_ENV_VAR} or l5x-mcp-output."
76
+ ),
77
+ )
78
+ parser.add_argument(
79
+ "--transport",
80
+ choices=["stdio"],
81
+ default="stdio",
82
+ help="MCP transport (default: stdio).",
83
+ )
84
+ parser.add_argument(
85
+ "--structured-output",
86
+ action="store_true",
87
+ default=_env_flag(STRUCTURED_OUTPUT_ENV_VAR),
88
+ help=(
89
+ "Advertise output schemas and return results as structured_content in "
90
+ "addition to the compact JSON text block. "
91
+ f"Defaults to truthy {STRUCTURED_OUTPUT_ENV_VAR} (1/true/yes/on)."
92
+ ),
93
+ )
94
+ parser.add_argument(
95
+ "--read-only",
96
+ action="store_true",
97
+ default=_env_flag(READ_ONLY_ENV_VAR),
98
+ help=(
99
+ "Expose only the read tools; write tools (edits and component files) "
100
+ "are not registered. Write tools are enabled by default. "
101
+ f"Defaults to truthy {READ_ONLY_ENV_VAR} (1/true/yes/on)."
102
+ ),
103
+ )
104
+ return parser.parse_args(argv)
105
+
106
+
107
+ def main(argv: Sequence[str] | None = None) -> None:
108
+ """Run the l5x-mcp server (entry point).
109
+
110
+ Args:
111
+ argv: Argument list to parse; defaults to `sys.argv[1:]`.
112
+ """
113
+ args = parse_args(argv)
114
+
115
+ from l5x_mcp.registry import ProjectRegistry
116
+ from l5x_mcp.server import create_server
117
+
118
+ create_server(
119
+ ProjectRegistry(args.root, args.output_dir),
120
+ structured_output=args.structured_output,
121
+ read_only=args.read_only,
122
+ ).run(transport=args.transport)
@@ -0,0 +1,5 @@
1
+ """Run the server with `python -m l5x_mcp`."""
2
+
3
+ from l5x_mcp import main
4
+
5
+ main()