lx-mcp
# lx-mcp
An MCP server that reads concert lighting plots (DWG or DXF) and turns them into a checked fixture table. It finds the fixture symbols, matches them to the legend and to the fixture numbers written next to them, compares the counts against the legend, and keeps a fixture library in an Excel workbook. It runs as a stdio MCP server, so it works with any MCP client that can call tools; a client that can show images also gets the preview renders. I use it while preparing power and signal paperwork for shows.
[繁體中文說明](README.zh-TW.md)

The image above is the real `plot_preview` output for [`examples/sample_plot.dxf`](examples/sample_plot.dxf), a synthetic plot with two trusses, a floor row and a legend. The plot has four planted mistakes, and the import finds all of them: red rings mark number problems (106 is missing, 205 is used twice), and dashed rings mark a fixture type that's missing from the library.
## What the import returns
`examples/make_demo.py` builds the sample plot and a two-entry library, imports it and prints what the tools return. Condensed from the actual `plot_import` result:
| Legend label | Library type | Legend qty | Found |
|---|---|---|---|
| BLINDER 2L | (none) | 5 | 4 |
| SPOT 470 | SPOT 470 | 8 | 8 |
| WASH 19 | WASH 19 | 6 | 5 |
| Issue | Message |
|---|---|
| number_missing | 1 fixtures have no number nearby |
| number_duplicate | Number 205 is used by 2 fixtures in this view |
| type_unknown | 4 fixtures with legend label 'BLINDER 2L' have no fixture library entry |
| legend_count_mismatch | Legend says 5 x BLINDER 2L, found 4 |
| legend_count_mismatch | Legend says 6 x WASH 19, found 5 |
| number_sequence | SPOT 470: numbers 101-108 skip 106 |
"Found" counts distinct fixture numbers, so the same fixture drawn on several sheets is counted once. That's also why the six washes count as five: two of them share the number 205.
## Install
Requirements: Windows, Python 3.12, [uv](https://docs.astral.sh/uv/). DXF files work as they are. DWG files are converted to DXF with AutoCAD's `accoreconsole.exe` (default path `C:\Program Files\Autodesk\AutoCAD 2026\accoreconsole.exe`, override with the `LX_ACCORECONSOLE` environment variable).
```
git clone https://github.com/Camel031/lx-mcp.git
cd lx-mcp
uv sync
uv run pytest
uv run python examples/make_demo.py
```
Register the server with your MCP client. Most clients take a JSON entry like this one, which starts the server over stdio:
```json
{
"mcpServers": {
"lx": {
"command": "uv",
"args": ["--directory", "<path-to-lx-mcp>", "run", "lx-mcp"]
}
}
}
```
For example, Claude Desktop reads this from its `claude_desktop_config.json`.
## Folder layout
The server works on a show folder and looks for the fixture library in a folder named `燈庫` in the show folder or any folder above it:
```
Lighting/
燈庫/燈具資料庫.xlsx fixture library (sheet 燈具)
2026-11-sample-show/
plot.dwg
lx-system/ created by project_open
fixtures.json the current fixture table
work/<timestamp>/ DWG copy, converted DXF, previous table
out/previews/ PNG previews
```
The folder name, sheet name and column headers are in Traditional Chinese because they follow the spreadsheets I already use; they are constants in `src/lx/project.py` and `src/lx/library.py`.
To seed the library from an equipment weight list (columns: category, model, weight, rated W, actual W, TOP cable side, FL cable side, note):
```
uv run python -m lx.library import-weight-table weights.xlsx "Lighting\燈庫\燈具資料庫.xlsx"
```
## Tools
| Tool | What it does |
|---|---|
| `project_open` | Opens a show folder (absolute path) and creates `lx-system/` in it. |
| `plot_import` | Imports a DWG or DXF plot. The original is never modified. Returns per-label counts and every open issue. A re-import replaces the fixture table and keeps the old one as `fixtures.previous.json`. |
| `fixtures_list` | Lists fixtures page by page, filtered by view, legend label, or `only_issues=True` for number problems. |
| `plot_preview` | Renders one view as PNG with a ring and number on each fixture. |
| `fixtures_update` | Corrects numbers, labels, types or rig positions, deletes false detections, and confirms the table (`confirm=True`). Any later edit clears the confirmation. |
| `library_lookup`, `library_propose`, `library_commit` | Look up library entries; add a pending entry; confirm it after review. |
| `project_status` | Reports the open folder, whether a plot was imported, and its issues. |
All paths must be absolute, because the server's working directory is the repository, not the show folder.
## How recognition works
1. DWG files are copied to a work folder and saved as DXF 2018 by `accoreconsole`.
2. Model space is flattened (nested blocks included) into inserts, texts, dimensions and the model-space windows of each paper-space layout. Each layout becomes a view; without layouts the whole drawing is one view named `ALL`.
3. Legend rows are found as a block followed by text such as `SPOT 470*8 31CH`, `WASH 19 x6`, `PROFILE (19CH)` or `LED BAR @ 8CH`. Rows that are lengths or angles (truss and cable pieces) are skipped, and inserts on layers starting with `@SITE` (the venue base drawing) are never taken as legend symbols.
4. Every insert whose geometry matches a legend symbol becomes a fixture. Matching uses a geometry signature, so a copy of the block under another name still matches.
5. Numbers are assigned by distance, within 1.5 symbol sizes, and flagged as ambiguous when two candidates are nearly equally close.
6. The drawing scale is inferred from linear dimensions (displayed value divided by measured length, assumed to be in cm).
7. Issues are computed per view and per label: missing, ambiguous, duplicate or skipped numbers, labels without a library entry, and legend counts that don't match.
For acceptance testing on real plots, `uv run lx-eval <plot files...> --library <library.xlsx>` writes a Markdown report with counts, issues, preview paths and timings to `eval_runs/<timestamp>/report.md`.
## Limitations
- DWG and DXF only. DWG needs a local AutoCAD install for `accoreconsole`.
- Fixtures must be blocks. If a plot was exploded into loose lines, the import reports `legend_count_mismatch` (found 0) or `No fixtures were recognised`, and you fix the drawing or the table by hand.
- Large plots are slow: a DWG of tens of MB takes 3 to 5 minutes to convert and read, and the first preview takes about 3 minutes more. Each import keeps a DXF copy (up to about 500 MB) in `work/`; old work folders aren't deleted automatically.
- Writing the library with openpyxl drops charts and images from the workbook and clears cached formula results until Excel recalculates and saves it. Text written by the tools is always stored as text, never as a formula.
- `preview.py` uses an internal ezdxf API, so ezdxf is pinned to 1.4.x.
- Power and signal planning (the reason the fixture table exists) isn't part of this release.
## License
MIT, see [LICENSE](LICENSE).
TDQS
Scored across 9 tools
Each tool targets a clearly distinct action within its resource group: project open vs status, plot import vs preview, fixtures list vs update, and library lookup/propose/commit form a clean lifecycle. No two tools appear to do the same thing, and the descriptions reinforce the boundaries.
All nine tools follow a consistent domain_verb snake_case pattern (project_open, plot_import, fixtures_list, library_lookup, etc.). The naming is predictable and readable throughout.
Nine tools is well within the ideal 3-15 range and each earns its place across project setup, import, inspection, correction, and library management. Nothing feels redundant or gratuitously added.
The core workflow—open, import, preview, list, correct, and manage the fixture library—is fully covered with confirmation gating. Minor gaps exist, such as no export/save-back of corrections to the plot or an explicit project close, but agents can work around these.