niagara-mcp
README.md
# niagara-mcp
A local [Model Context Protocol](https://modelcontextprotocol.io) server that lets Claude Desktop read points, check station health, pull history, tag points to Haystack/Brick and place **confirmed** overrides on a Niagara 4 JACE over BACnet/IP.
> **Safety first.** This tool can command live building equipment. Writes are limited to an allowlist, priority 8 or lower, and a two-step confirm, but you are responsible for what it is pointed at. Try it on the simulator and a bench JACE before any occupied building. See [SECURITY.md](SECURITY.md).
**Requirements:** Python 3.11+ (tested on 3.13 and 3.14), Claude Desktop, and a Niagara 4 station with BACnet/IP export enabled. The helper scripts are written for Windows; `setup.sh` covers Linux and macOS.
```
Claude Desktop ──stdio──> server.py ──reads──> data\bas.db <──writes── poller.py ──BACnet/IP──> JACE
└──────── commands table ────────────────┘ (UDP 47808)
```
The poller is the only process that talks BACnet. It runs all the time and keeps the database live. The MCP server works through the database, and asks the poller for anything that needs the wire (live reads, priority arrays, overrides, releases).
## Get it running
Do these in order. Each step proves one layer before the next depends on it.
**1. Station prep in Workbench**
- BacnetNetwork enabled on UDP 47808, with a Local Device instance.
- Export table: your real points, the health AVs (`Sys_CPU_Pct`, `Sys_Heap_Used_MB`, `Sys_Heap_Max_MB`, `Sys_Mem_Free_MB`), and the two test points `MCP_Test_SP` and `MCP_Test_Cmd` exported as **commandable** AV and BV.
- BACnet has no megabyte unit, so the heap and memory AVs arrive with no units. That is expected.
**2. Install**
Clone or download this repo to a folder with no spaces in its path (the examples use `C:\niagara-mcp`):
```
git clone https://github.com/neilcarruthers/niagara-mcp.git C:\niagara-mcp
```
- **Windows:** double-click `setup.bat`. It creates `.venv`, installs the pinned packages, creates `config.yaml` and runs the offline checks. It uses `C:\Python314\python.exe` if present; pass `-Python <path>` to `setup.ps1` to choose another.
- **Linux / macOS:** `./setup.sh` does the same. Use `.venv/bin/python` wherever this README says `.venv\Scripts\python.exe`.
**3. Configure**
Open `config.yaml` and set the values marked `CHANGE ME`: `site` (id, name and the station's time zone), `jace_address` and `jace_device_instance`. Leave `local_ip: auto` unless the laptop has more than one route to the JACE. `config.yaml` is git-ignored, so your site details stay local.
**4. Prove the station side.** The command line uses local port 47810, so it can run while YABE or the poller holds 47808. Double-click `terminal.bat` for a command window that is already in this folder with the right Python.
```
.venv\Scripts\python.exe bacnet_client.py whois
.venv\Scripts\python.exe bacnet_client.py list
.venv\Scripts\python.exe bacnet_client.py read MCP_Test_SP
.venv\Scripts\python.exe bacnet_client.py write MCP_Test_SP 22
.venv\Scripts\python.exe bacnet_client.py pa MCP_Test_SP
.venv\Scripts\python.exe bacnet_client.py release MCP_Test_SP
```
After the write, `in8` on `MCP_Test_SP` should read 22 in Workbench. After the release it should be empty.
**5. Start the poller**
```
.venv\Scripts\python.exe poller.py --once (one discovery and one poll, then exits)
run_poller.bat (keeps running in a window)
```
**6. Optional: try every tool in MCP Inspector**
```
npx @modelcontextprotocol/inspector C:\niagara-mcp\.venv\Scripts\python.exe C:\niagara-mcp\server.py
```
**7. Register with Claude Desktop**
Settings → Developer → Edit Config, then add the block from `claude_desktop_config.example.json`, changing both paths to where you put the repo. The file is `%APPDATA%\Claude\claude_desktop_config.json` on Windows and `~/Library/Application Support/Claude/claude_desktop_config.json` on macOS. Quit Claude Desktop fully (system tray → Quit) and reopen it. Leave `confirm_override` and `release_override` on "ask every time".
On macOS or Linux the entry looks like this:
```json
{
"mcpServers": {
"niagara-bacnet": {
"command": "/path/to/niagara-mcp/.venv/bin/python",
"args": ["/path/to/niagara-mcp/server.py"]
}
}
}
```
**8. Acceptance prompts**
| Ask Claude | Expect |
| --- | --- |
| List the points on the JACE | the exported objects with their names |
| How hard is the JACE working? | CPU and heap values that match PlatformServices |
| Set the test setpoint to 22 | a preview; it writes only after you agree; `in8` reads 22 in Workbench |
| Release it | `in8` clears and the point falls back to its default |
| Set AHU1_SAT_SP to 15 / set the test setpoint to 40 | both refused |
| (unplug the JACE) Read MCP_Test_SP live | a clean timeout message |
| Show the audit log | a row for every write and release |
| What is the tag coverage? | counts of tagged, excluded, in review and failing |
**9. Make the poller always-on**
```
powershell -ExecutionPolicy Bypass -File install_poller_task.ps1
```
It starts at logon with no window and restarts after a failure. Close the `run_poller.bat` window first. Laptop sleep leaves gaps in history.
## Try it without a JACE
`run_sim.bat` starts a simulated JACE (one AHU, two VAVs, a boiler and pump, health AVs and the test points). `run_poller_sim.bat` polls it into a separate database, `data\sim.db`. To point Claude Desktop at the simulator, add this to the server entry in the Claude config:
```json
"env": { "NIAGARA_MCP_CONFIG": "C:\\niagara-mcp\\config.sim.yaml" }
```
`.venv\Scripts\python.exe tests\e2e_sim.py` runs the whole acceptance list against the simulator through a real MCP client (84 checks, about two and a half minutes).
## Tools
| Group | Tools |
| --- | --- |
| Read | `list_points`, `read_point`, `read_points`, `get_priority_array`, `get_station_health`, `poller_status`, `refresh_points` |
| History | `get_history`, `list_histories`, `link_history` |
| Overrides | `propose_override`, `confirm_override`, `release_override`, `list_active_overrides`, `get_audit_log` |
| Tagging | `find_points`, `get_equip`, `review_tags`, `approve_tags`, `tag_coverage`, `add_abbreviation`, `retag`, `export_model`, `import_niagara_tags` |
| Drawings | `drawing_extract_schema`, `load_drawing_extract`, `crosscheck_drawing_pdf`, `review_graph`, `approve_graph`, `trace`, `get_equip_graph` |
Values come from the last poll (60 s by default). `read_point` with `live=true` forces a fresh BACnet read.
## History: two sources
**The poller's own samples.** From the first poll that sees a point, the poller stores a row whenever the value moves past its deadband, and at least every 15 minutes. Nothing to set up. It only reaches back to the day the poller first saw the point.
**The station's own histories.** A Niagara history can be exported as a BACnet Trend Log object, and the poller copies its records into the same database. That reaches back as far as the station has kept.
To export histories, in Workbench:
1. Open `Config > Drivers > BacnetNetwork > Local Device > Export Table`.
2. Right-click the Export Table and choose **Views > Bacnet Niagara Log Export Manager**. The ordinary Bacnet Export Manager view does not list histories. (That is the view's name in Tridium's BACnet guide; a newer Workbench may word it slightly differently.)
3. Click **Discover**. The station's histories appear in the top pane. Select them and click **Add**. Object Name defaults to the history's path, which works. A short name that starts with the name of the point it logs (`RTU1_SpaceTemp_History`) is easier to read.
4. Save, then ask Claude to refresh the points, or wait up to 15 minutes.
To check from the command line before involving the poller:
```
.venv\Scripts\python.exe bacnet_client.py histories
.venv\Scripts\python.exe bacnet_client.py history RTU1_SpaceTemp_History 10
```
How the copy works:
- New histories start copying as soon as discovery finds them, 18 records per request, one request at a time. After that each history costs one request every 5 minutes.
- The first page is read by position and the rest by time, the two methods every Niagara history export answers. Sequence numbers are not used, because a standard history export does not provide them.
- A history is linked to its point by the reference the station gives, else by name. `list_histories` shows the links, and `link_history` sets one by hand.
- `get_history` uses the station's history when the window starts before the poller's samples do, and says which source it used. `source="station"` or `source="poller"` forces one.
- Trend log timestamps are the station's local time with no zone attached. They are converted with `site.tz` in `config.yaml`, which must be the station's time zone. `list_histories` warns when the station clock and the laptop disagree by more than two minutes. Time zone rules do change (Alberta, for example, stopped changing clocks in November 2026 and stays at UTC-6). A station or laptop with older zone rules reads an hour off until its zone data is updated.
- Settings are under `histories:` in `config.yaml`: `sync_interval_s`, `backfill_days` (0 = everything the station still holds), `records_per_request`, `retention_days`.
## How overrides are kept safe
- **Allowlist.** Only object names under `writes.allowlist` in `config.yaml` can be written. Analog points need `min` and `max`.
- **Two steps.** `propose_override` writes nothing. It returns a preview and a one-time token that expires in 2 minutes. `confirm_override` needs that token.
- **Priority 8 only.** Priorities 1 to 7 are refused in code (`MIN_WRITE_PRIORITY` in `config.py`); config cannot lower it.
- **Checked twice.** The MCP server checks the request, and the poller checks allowlist, limits and priority again before it touches BACnet. A row written straight into the database is refused.
- **Name re-check.** The allowlist is by object name, so the poller reads the object's name from the JACE immediately before writing and refuses if it has changed since discovery.
- **Commandable points only.** A point with no priority array is refused, because an override on it could not be released.
- **Read-back.** After the write the poller reads the priority-8 slot and the present value. If the slot does not hold the requested value the result is a failure. If a higher priority is in control, the result says the override is stored but not in control.
- **Unacknowledged writes are not called failures.** If the JACE does not answer a write, the result says the state is unknown and to check the priority array before retrying.
- **No late writes.** A request the poller has not picked up within 30 seconds is expired, so nothing lands after a restart.
- **No auto-expiry.** An override stays until `release_override`. `list_active_overrides` shows what this server has placed.
- **Audit.** Proposals, refusals, writes and releases go to the `audit` table and to `audit.log`.
## Tagging to 100%
The poller tags points as it discovers them. Haystack 4 tags are the master record; Brick classes are derived from them.
1. `tag_coverage` shows where things stand. `review_tags` lists what needs a decision, with the proposed tags and the reason.
2. Resolve each point with `approve_tags`: `accept` the proposal, `edit` it (tags and equip), or `exclude` it with a reason.
3. If a site uses an abbreviation the tagger does not know, `add_abbreviation` teaches it and re-runs the queue.
4. `export_model` writes Haystack JSON, a Brick `.ttl` (SHACL-validated) and a CSV tag sheet to `data\exports`. Files carry `_INCOMPLETE` until coverage is 100%.
A point counts as resolved only when it has `point` plus exactly one of `sensor`/`cmd`/`sp`, a tag for what it measures or controls, an `equipRef` and `siteRef`, a specific Brick class, units that fit the quantity, a function that fits the object type, and a plausible live value. Exclusion patterns are under `tagging.exclude` in `config.yaml`.
Equipment grouping depends on the name prefix (`AHU1_`, `VAV2_04_`, `BLR1_`, `PM1_`). Points with no recognisable prefix go to review, unless a rule under `tagging.equip_rules` in `config.yaml` says where the equipment sits in the name:
```yaml
tagging:
equip_rules:
# "Voltage L1 to N A", "Power Sum Element A" -> equipment PM-A; the matched ending is taken off the name
- {pattern: '(?i)\s*(?:element\s*|\s)([A-H])$', id: 'PM-\1', name: 'Power Meter Element \1', kind: elecMeter}
```
Electrical metering is tagged with Haystack's `elec` set: `volt`, `current`, `power` (`active`, `reactive`, `apparent`), `energy` (`import`, `export`, `net`), `freq`, `pf`, with `avg`, `total`, `demand` and a `phase` value (`L1`, `L1-N`, `L1-L2`; `L-N` and `L-L` for an average across the phases). A meter channel `CH1` to `CH3` is read as the phase with the same number.
### Tags already in the station
`import_niagara_tags` takes a CSV exported from Workbench, with one row per point: an ord or slot path column, and either one column per tag (`hs:point`, `hs:sensor`...) or a single `tags` column. Pass the BACnet export table as a second CSV (object id and point ord columns) and points join exactly on object type and instance; without it they join by name. Precedence is manual approvals, then Niagara tags, then rules. Disagreements go to review.
## Drawings to graph
1. In Claude Desktop, attach a few sheets and ask Claude to extract them for `load_drawing_extract`. Claude calls `drawing_extract_schema` for the format.
2. For vector PDFs saved on the laptop, `crosscheck_drawing_pdf` compares what Claude read against the PDF text layer.
3. Everything loads as proposed, with its sheet number. `review_graph`, then `approve_graph` (in bulk or line by line; link near-miss point names to the right BACnet point).
4. `trace` follows `feeds` up or downstream with live values. `get_equip_graph` shows one piece of equipment with parts, points and what it serves.
## Files
| File | What it is |
| --- | --- |
| `server.py` | MCP server (stdio). Never talks BACnet. |
| `poller.py` | Always-on poller: discovery, polling, history, station history copy, rollups, command execution. |
| `trendlog.py` | Station history logic: time conversion, linking a history to its point, hourly rollup. |
| `terminal.bat` | Opens a command window in this folder with the virtual environment active. |
| `bacnet_client.py` | BACnet/IP client, and a command line for testing the station side. |
| `db.py` | SQLite schema and shared queries (`data\bas.db`, WAL mode). |
| `overrides.py` | Write-safety rules used by both the server and the poller. |
| `tagger.py`, `quality.py`, `brick.py`, `model_export.py` | Tagging rules, checks and coverage, Brick derivation, exports. |
| `niagara_import.py` | Niagara tag import (CSV or nHaystack). |
| `graph.py` | Drawing extract schema, graph storage, trace. |
| `sim_jace.py`, `config.sim.yaml` | Simulated JACE and its config. |
| `tests\` | `unit_checks.py` (offline) and `e2e_sim.py` (simulator, real MCP client). |
| `setup.bat` / `setup.ps1`, `setup.sh` | One-step install for Windows, and for Linux/macOS. |
| `run_poller.bat`, `run_sim.bat`, `run_poller_sim.bat`, `install_poller_task.ps1` | Windows helpers: poller in a window, simulator, always-on scheduled task. |
## Troubleshooting
| Symptom | Likely cause |
| --- | --- |
| `whois` says no response | Wrong `jace_address`, BACnet network not enabled on the JACE, different subnet with no route, or Windows Firewall dropping the reply. If YABE on the same laptop can see the JACE, add an inbound UDP rule: `New-NetFirewallRule -DisplayName "niagara-mcp BACnet" -Direction Inbound -Protocol UDP -LocalPort 47808,47810 -Action Allow -Profile Private,Domain` (elevated PowerShell). |
| "UDP port 47808 ... already in use" | YABE, Workbench's BACnet utilities or a second poller is running on the laptop. |
| "reports instance X, but config.yaml expects Y" | Fix `jace_device_instance`. |
| Write refused by the JACE | The point is not exported as commandable, or the BACnet licence lacks export (server) write rights. |
| Claude says the poller is not running | Start `run_poller.bat` or the scheduled task. Check `logs\poller.log`. |
| Server missing in Claude Desktop | Quit and reopen Claude Desktop fully. Check `%APPDATA%\Claude\logs\mcp-server-niagara-bacnet.log`. Paths in the config must be absolute with doubled backslashes. |
| Values marked `stale` | The poller is stopped, the JACE is offline, or the laptop slept. |
| `histories` lists nothing | The histories were added in the wrong view. They must be added in the Bacnet Niagara Log Export Manager view of the Export Table. A descriptor in fault with "Server capability not licensed" means the BACnet licence has no export. |
| A history shows `error:` in `list_histories` | The message is the station's own. Check the descriptor's status in the Export Table, then `bacnet_client.py history NAME` to see the raw reply. |
| History times are an hour out | The station's time zone or clock differs from `site.tz`. Fix whichever is wrong; records already copied keep the times they were stored with. |
## What has been tested, and what has not
Tested: the full stack against the simulated JACE on Linux with Python 3.13 and 3.14, through a real MCP client over stdio. 84 end-to-end checks and the unit checks pass.
Tested on a bench JACE (Niagara 4.14): discovery, polling, the override and release path through Claude Desktop, the allowlist refusal and the audit log.
Not tested, because it needs your machine or station:
- Anything on Windows itself: `setup.ps1`, the scheduled task, the firewall behaviour.
- Station histories against a real JACE. The copy is tested against simulated Trend Log objects only. Niagara's replies may differ in small ways (which properties a history export serves, how many records it puts in a reply, whether it fills the logged-point reference).
- Segmented replies from a real JACE. Requests are sized to fit one 480-byte frame so that they are not needed.
- nHaystack over HTTP, and real Workbench CSV exports. The parsers go by column shape, but your column names may still need a tweak.
- Drawing extraction accuracy. The graph code is tested with a hand-written extract.
## Design notes
- **MCP SDK 2.x.** `FastMCP` was renamed `MCPServer` in mcp 2.0. The code targets mcp 2.3.0.
- **BAC0 starts the stack; bacpypes3 does the I/O.** BAC0's `write()` does not wait for or report the result, so reads and writes call the bacpypes3 application BAC0 wraps.
- **Poller architecture.** The MCP server never opens a BACnet socket; only the poller does, so Claude Desktop restarts never disturb the BACnet stack.
- **Brick classes come from a curated table first.** brickschema's `from_haystack` runs on Brick 1.5 but misclassified common points in testing (a duct static sensor as a differential pressure sensor, a boiler status as a run-time sensor). It is used for tag sets the table does not cover, and its disagreements are reported.
- **Locations are RealEstateCore classes.** Brick 1.5 deprecates its own Site/Floor/Zone classes in favour of REC, so exports use `rec:Site`, `rec:Level`, `rec:HVACZone`. Hydronic loops export as Brick collections (`rec:includes`) with `feeds` between the equipment on either side.
- **VBIS is equipment-only** and uses the Brick 1.3 master list, which is the last one brickschema ships.
- **Abbreviations** are seeded from brickschema's map plus a standard HVAC set. Teach site-specific ones with `add_abbreviation`.
## Contributing, security and licence
- [CONTRIBUTING.md](CONTRIBUTING.md): how to run the checks and the rules for write-path changes.
- [SECURITY.md](SECURITY.md): safe-use guidance and how to report a safety problem privately.
- [CHANGELOG.md](CHANGELOG.md)
- Licensed under the [MIT License](LICENSE).
Niagara, Workbench and JACE are trademarks of Tridium, Inc. This project is independent and not affiliated with or endorsed by Tridium or Honeywell.
This server cannot be deployed
Maintenance
ActivityMaintained
ResponsivenessNo recent community issues