> ## Documentation Index
> Fetch the complete documentation index at: https://docs.coreflux.org/llms.txt
> Use this file to discover all available pages before exploring further.

# Using AI with Coreflux

> Go from installation to AI-generated LoT code in minutes — build Actions, Connectors, and documentation with natural language prompts.

## Accelerate Your IIoT Development with AI

You've installed Coreflux and deployed your first Action. Now what if you could describe your next feature in plain English and have an AI assistant write the LoT (Language of Things) code for you — correctly, using verified syntax, following best practices?

That's exactly what Coreflux's AI integration enables. By connecting your AI assistant to the Coreflux MCP (Model Context Protocol), you give it real-time access to the official documentation. The result: you describe your goal, and the AI produces production-ready LoT code — Actions, Connectors, Models, and more — without you memorizing a single keyword.

> [!NOTE]
>
> The MCP connection in this guide is the [documentation MCP](https://docs.coreflux.org/ai/mcp.md) (`https://docs.coreflux.org/mcp`). To let the same assistant **operate a live broker**, enable the [MCP Server](https://docs.coreflux.org/v2.22/mqtt-broker/mcp-server.md) (`Mcp.Enabled`) and add it as a second MCP server in the client.

> [!TIP]
>
> **Like hiring a LoT specialist who never sleeps.** You explain what your factory floor needs — "alert me when temperature spikes" — and the specialist drafts the code, wires the database, and writes the documentation.

### When to Use This

* You want to **build IIoT features faster** by describing them in natural language
* You're **new to LoT syntax** and want correct code without a learning curve
* You need to **connect PLCs, databases, and alerts** and want AI to handle the wiring
* You want AI to **document your system** as you build it
* You want the assistant to **operate a live broker** (deploy LoT, run commands) through the [MCP Server](https://docs.coreflux.org/v2.22/mqtt-broker/mcp-server.md)

***

## Step 1: Installation & Prerequisites

Before using AI with Coreflux, ensure the core environment is running.

| Requirement | Details |
| - | - |
| **Coreflux Broker** | Installed and running on your machine or server |
| **AI Assistant** | Cursor, Claude Desktop, Claude.ai, or VS Code with GitHub Copilot |
| **MQTT Client** | MQTT Explorer or any MQTT client for verifying results |

**1. Install the Coreflux Broker**

Follow the [Installation Guide](https://docs.coreflux.org/v2.22/quick-start/installation.md) for your platform (Docker, Docker Compose, Windows, or Linux). Verify the broker is running by connecting with MQTT Explorer.

**2. Verify Your Setup**

Connect to the broker and subscribe to `$SYS/#`. If you see system topics, the broker is ready.

| Setting | Default Value |
| - | - |
| Host | `localhost` |
| Port | `1883` |
| Username | `root` |
| Password | `coreflux` |

> [!NOTE]
>
> If you haven't completed the [Getting Started](https://docs.coreflux.org/v2.22/quick-start/getting-started.md) guide yet, do that first. It takes under 15 minutes and confirms your environment is working.

***

## Step 2: Setup AI (MCP & Agents)

Coreflux uses the **Model Context Protocol (MCP)** to give your AI assistant real-time access to the official documentation. This means the AI doesn't guess at LoT syntax — it looks it up. Combined with an **AGENTS.md** file that defines your project's conventions, your AI assistant becomes a LoT expert that follows your team's rules.

> [!NOTE]
>
> The steps below install the [documentation MCP](https://docs.coreflux.org/ai/mcp.md). That server searches official docs. It does **not** control a broker.
>
> To let the assistant deploy LoT and run broker commands on a live broker, also enable the [MCP Server](https://docs.coreflux.org/v2.22/mqtt-broker/mcp-server.md) — the broker's built-in MCP listener (`Mcp.Enabled`, Streamable HTTP `/mcp`) — and add it as a second server in the client.

### Configure the MCP Connection

Add the Coreflux documentation MCP server to your AI client. Use **Native** to install from the contextual menu on any docs page, or **Manual** to add the server URL to a config file.

> [tab] Native
>
> Open the **Copy page** menu (top right) on any Coreflux documentation page. From there you can copy the MCP URL, run the install command, or connect directly to VS Code or Cursor.
>
> ![Documentation page contextual menu showing Copy MCP Server, Copy MCP install command, Connect to Cursor, and Connect to VS Code](https://mintcdn.com/coreflux/2Qlxw_T8xvkddvBy/images/MCP/action-menu-install-mcp.png?fit=max\&auto=format\&n=2Qlxw_T8xvkddvBy\&q=85\&s=ab62d6ffe924c7ef063007d4fc93c08b)
>
> Contextual menu with MCP install options
>
> > [tab] VS Code
> >
> > **1. Connect from the menu**
> >
> > Select **Connect to VS Code** from the contextual menu.
> >
> > **2. Install the server**
> >
> > Click **Install** or **Install in Workspace** on the MCP server page.
> >
> > ![VS Code MCP Server tab for Coreflux Documentation with Install buttons and server URL configuration](https://mintcdn.com/coreflux/2Qlxw_T8xvkddvBy/images/MCP/vscode-install-mcp.png?fit=max\&auto=format\&n=2Qlxw_T8xvkddvBy\&q=85\&s=e83435c5b09e548d23b3b3ef1cb90b4a)
> >
> > VS Code MCP server install page
> >
> > **3. Enable in Copilot**
> >
> > Reload VS Code if needed, open Copilot Chat in **Agent** mode, and enable the Coreflux tools.
>
> > [tab] Cursor
> >
> > **1. Connect from the menu**
> >
> > Select **Connect to Cursor** from the contextual menu.
> >
> > **2. Install the server**
> >
> > In **Settings → Tools & MCPs**, confirm the **Install MCP Server?** details and click **Install**.
> >
> > ![Cursor Settings Tools page with Install MCP Server dialog for Coreflux Documentation](https://mintcdn.com/coreflux/2Qlxw_T8xvkddvBy/images/MCP/cursor-install-mcp.png?fit=max\&auto=format\&n=2Qlxw_T8xvkddvBy\&q=85\&s=4ba9395dd8281d8683178457bfcb5f20)
> >
> > Cursor MCP server install dialog
> >
> > **3. Confirm the connection**
> >
> > Verify **Coreflux Documentation** appears under **Installed MCP Servers** with tools enabled.
>
> > [tab] Other clients
> >
> > Use **Copy MCP Server** or **Copy MCP install command** from the menu, then follow the **Manual** tab below or the [MCP Configuration Guide](https://docs.coreflux.org/ai/mcp.md#setup) for Claude Desktop and other clients.

> [tab] Manual
>
> Add this URL to your editor's MCP configuration:
>
> ```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> https://docs.coreflux.org/mcp
> ```
>
> > [tab] VS Code
> >
> > Create or open `.vscode/mcp.json` in your workspace:
> >
> > ```json wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> > {
> >   "servers": {
> >     "coreflux": {
> >       "type": "sse",
> >       "url": "https://docs.coreflux.org/mcp"
> >     }
> >   }
> > }
> > ```
> >
> > Reload VS Code. The tools become available in Copilot's **Agent** mode.
>
> > [tab] Cursor
> >
> > Add the following to `.cursor/mcp.json` (project) or `~/.cursor/mcp.json` (global):
> >
> > ```json wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> > {
> >   "mcpServers": {
> >     "coreflux": {
> >       "url": "https://docs.coreflux.org/mcp"
> >     }
> >   }
> > }
> > ```
> >
> > Restart Cursor and verify the connection under **Settings → MCP**.
>
> > [tab] Claude Desktop
> >
> > Add the following to your Claude Desktop configuration file:
> >
> > > [tab] Windows
> > >
> > > `%APPDATA%\Claude\claude_desktop_config.json`
> >
> > > [tab] macOS
> > >
> > > `~/Library/Application Support/Claude/claude_desktop_config.json`
> >
> > > [tab] Linux
> > >
> > > `~/.config/Claude/claude_desktop_config.json`
> >
> > ```json wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> > {
> >   "mcpServers": {
> >     "coreflux": {
> >       "url": "https://docs.coreflux.org/mcp"
> >     }
> >   }
> > }
> > ```
> >
> > Restart Claude Desktop. The Coreflux tools appear in the tool picker (hammer icon).

For full setup details, editor-specific steps, and verification, see the [MCP Configuration Guide](https://docs.coreflux.org/ai/mcp.md#setup).

### Set Up AGENTS.md (Project Rules)

An **AGENTS.md** file in your project root tells your AI assistant how to write LoT code — naming conventions, patterns, and what to avoid. Without it, the AI may use inconsistent styles or invent syntax.

Create an `AGENTS.md` file in your project root with your project's conventions. The [Best Practices & AGENTS.md](https://docs.coreflux.org/ai/best-practices.md#setting-up-your-ai-assistant) page provides a complete starter template covering:

* **Naming rules** — PascalCase for entities, snake\_case for variables
* **Topic hierarchy** — `sensors/`, `processed/`, `alerts/` namespaces
* **Code standards** — Type casting, state management, modular Actions
* **Boundaries** — What the AI should always do, ask about, and never do

For a faster start, clone the [Coreflux AI Starter](https://github.com/CorefluxCommunity/coreflux-ai-starter) repo — it includes ready-to-use templates and pre-built MCP configs for every editor.

### Add Agent Skills

AGENTS.md holds your project's rules. The LoT and broker knowledge itself comes from the [Coreflux agent skills](https://docs.coreflux.org/ai/agent-skills.md), published in the public [coreflux-skills](https://github.com/CorefluxCommunity/coreflux-skills) repository. Install them with the skills CLI, the Claude Code plugin, or **Install Agent Skills...** in the LoT Notebooks extension:

```bash wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
npx skills add CorefluxCommunity/coreflux-skills
```

> [!TIP]
>
> Once the MCP, AGENTS.md, and agent skills are in place, your AI assistant has real-time documentation access, LoT knowledge, **and** your project's coding standards. You're ready to build.

***

## Step 3: Create LoT with AI

With your AI assistant connected via MCP, you can use natural language to perform complex IIoT tasks. The following examples demonstrate the full workflow — from prompt to deployable code.

### A. Generate a LoT Action from Scratch

The most common starting point: you describe a behavior, and the AI writes the Action.

**The Prompt:**

```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
Create a LoT Action called TempAlert that monitors the topic 
"factory/sensor/temp". If the temperature value (from a JSON payload 
with key "value") goes above 50, publish an alert to "alerts/hvac" 
with the current value. Use proper type casting.
```

**AI-Generated Output:**

The AI consults the Coreflux MCP documentation and produces verified LoT syntax:

```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE ACTION TempAlert
ON TOPIC "factory/sensor/temp" DO
    SET "current_temp" WITH (GET JSON "value" IN PAYLOAD AS DOUBLE)
    IF {current_temp} > 50 THEN
        PUBLISH TOPIC "alerts/hvac" WITH "High Temperature Detected: " + {current_temp}
```

**Why this works:**

| Line | What It Does |
| - | - |
| `DEFINE ACTION TempAlert` | Creates an Action named `TempAlert` (PascalCase, verb-like) |
| `ON TOPIC "factory/sensor/temp" DO` | Triggers every time a message arrives on this topic |
| `SET "current_temp" WITH (GET JSON "value" IN PAYLOAD AS DOUBLE)` | Extracts the `value` field from the JSON payload and casts it to a number |
| `IF {current_temp} > 50 THEN` | Conditional check against the threshold |
| `PUBLISH TOPIC "alerts/hvac" WITH ...` | Sends an alert with a descriptive message and the value |

**Deploy and Test:**

**1. Deploy the Action**

Paste the code into a LoT Notebook cell (`.lotnb` file) and run it, or publish to `$SYS/Coreflux/Command` with the `-addAction` prefix.

**2. Send a Test Message**

Publish to `factory/sensor/temp`:

```json wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
{"value": 62.5}
```

**3. Verify the Alert**

Subscribe to `alerts/hvac`. You should see:

```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
High Temperature Detected: 62.5
```

***

### B. PLC Integration & Automated Routing

A real-world scenario: you have a Siemens S7 PLC on the factory floor, and you want its data flowing into a PostgreSQL database. This requires **two Connectors** — one to read from the PLC, and one to store in the database. Topics are the bridge between them.

**The Prompt:**

```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
I have a Siemens S7-1500 PLC at IP 192.168.1.10. I need to:
1. Read the temperature (REAL at DB1.DBD100) and pressure (REAL at DB1.DBD104) 
   every 500 milliseconds and publish them to MQTT topics
2. Store all readings in a PostgreSQL database called "production_db" 
   at 192.168.1.50, user "flux_user", password "secure_pass"

Create the LoT Connectors for both.
```

**AI Logic:**

1. **Analyze** — The AI identifies the source (Siemens S7 PLC), the data bridge (MQTT topics), and the destination (PostgreSQL)
2. **Design** — It creates two Connectors: an industrial Connector for the PLC, and a data storage Connector for the database
3. **Generate** — Using the MCP to verify syntax, it produces:

**Connector 1 — Read from the PLC:**

```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE CONNECTOR S7Factory WITH TYPE SIEMENS_S7
    ADD S7_CONFIG
        WITH IP "192.168.1.10"
        WITH CPU_TYPE "S71500"
        WITH RACK '0'
        WITH SLOT '1'
    ADD MAPPING SensorData
        WITH EVERY 500 MILLISECONDS
        ADD TAG Temperature
            WITH ADDRESS "DB1.DBD100"
            WITH DATA_TYPE "REAL"
            WITH SOURCE_TOPIC "plc/s7/temperature"
            WITH UNIT "°C"
            WITH DECIMAL_PLACES "2"
        ADD TAG Pressure
            WITH ADDRESS "DB1.DBD104"
            WITH DATA_TYPE "REAL"
            WITH SOURCE_TOPIC "plc/s7/pressure"
            WITH UNIT "bar"
            WITH DECIMAL_PLACES "2"
```

This Connector reads PLC data and publishes it to MQTT topics every 500ms.

**Connector 2 — Store in PostgreSQL:**

```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE CONNECTOR ProductionDB WITH TYPE POSTGRESQL
    ADD SQL_CONFIG
        WITH SERVER "192.168.1.50"
        WITH PORT '5432'
        WITH DATABASE "production_db"
        WITH USERNAME "flux_user"
        WITH PASSWORD "secure_pass"
    ADD EVENT StoreTemperature
        WITH SOURCE_TOPIC "plc/s7/temperature"
        WITH QUERY "INSERT INTO sensor_readings (recorded_at, sensor, value) VALUES (NOW(), 'temperature', '{value}')"
    ADD EVENT StorePressure
        WITH SOURCE_TOPIC "plc/s7/pressure"
        WITH QUERY "INSERT INTO sensor_readings (recorded_at, sensor, value) VALUES (NOW(), 'pressure', '{value}')"
```

The AI generates a database Connector that subscribes to the MQTT topics published by the PLC Connector and inserts every reading into a `sensor_readings` table — complete with SQL templates, connection config, and event triggers, without you writing a single line of SQL manually.

**The Data Flow:**

| Step | Component | What Happens |
| - | - | - |
| 1 | S7 Connector | Reads `DB1.DBD100` and `DB1.DBD104` from the PLC |
| 2 | MQTT Topics | Values published to `plc/s7/temperature` and `plc/s7/pressure` |
| 3 | PostgreSQL Connector | Inserts each reading into the `sensor_readings` table |

> [!NOTE]
>
> The PLC Connector and PostgreSQL Connector are independent — they communicate through MQTT topics. This decoupled architecture means you can add more consumers (alerts, dashboards, other databases) without modifying the PLC Connector. For a step-by-step walkthrough of building a database Connector from scratch, see the [Developing with LoT Using AI](https://docs.coreflux.org/ai/developing-with-lot.md#step-4-connect-to-a-database-connector) guide.

***

### C. Modify Existing Code & Generate Documentation

AI excels at iterating on existing code and producing documentation alongside it.

**The Prompt:**

```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
Update the TempAlert action to also log every alert to "system/logs" 
with a timestamp. Then generate a markdown summary documenting this 
action on a project-specific LoT Notebook (LoTNB file).
```

**AI-Updated Code:**

The AI modifies the existing Action and adds the logging line:

```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE ACTION TempAlert
ON TOPIC "factory/sensor/temp" DO
    SET "current_temp" WITH (GET JSON "value" IN PAYLOAD AS DOUBLE)
    IF {current_temp} > 50 THEN
        PUBLISH TOPIC "alerts/hvac" WITH "High Temperature Detected: " + {current_temp}
        SET "log_time" WITH TIMESTAMP "UTC"
        PUBLISH TOPIC "system/logs" WITH "TempAlert triggered at " + {log_time} + " — value: " + {current_temp}
```

| What Changed | Why |
| - | - |
| Added `SET "log_time" WITH TIMESTAMP "UTC"` | Captures the current UTC timestamp into a variable |
| Added `PUBLISH TOPIC "system/logs"` | Creates an audit trail with timestamp and value |

**AI-Generated Documentation:**

The AI also produces a markdown summary you can add directly to your project's LoT Notebook (LoTNB):

```markdown wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
## Action: TempAlert

**Description:** Monitors temperature thresholds for the HVAC system. 
Triggers an alert when the factory temperature sensor exceeds 50°C and 
logs every alert event for auditing.

| Property | Value |
|----------|-------|
| **Trigger** | `factory/sensor/temp` |
| **Condition** | Temperature > 50°C |

**Outputs:**

| Topic | Purpose |
|-------|---------|
| `alerts/hvac` | Real-time alert with temperature value |
| `system/logs` | Timestamped audit trail of all triggered alerts |

**Payload Format:** Expects JSON with a `value` key (e.g., `{"value": 62.5}`)
```

This is the complete cycle: **build → modify → document** — all driven by natural language prompts.

***

## Step 4: Let an AI Agent Operate a Live Broker

Steps 2 and 3 connect your assistant to the documentation, and you deploy what it writes. The broker's built-in [MCP Server](https://docs.coreflux.org/v2.22/mqtt-broker/mcp-server.md) goes one step further: Claude Code or Claude Desktop connects to the broker itself, reads the live topics your Connectors bring in, checks its LoT with the broker, and deploys it. It does all of that as a broker user you create for it, with that user's permissions.

> [!WARNING]
>
> **`AllowedSystemConfiguration` makes the assistant an administrator.** To validate and deploy LoT, this walkthrough gives the assistant's broker user that flag. That flag passes almost every built-in gate: secrets and environment variables, audit log decryption and export, project pull, push, and load, log tracing, shell commands, every `$SYS/#` topic, users, rules, and broker configuration. `deploy_lot` does not follow the tool allow-list (`EnabledTools`). It deploys any `DEFINE` block, so the assistant can deploy a `DEFINE RULE` that widens its own access, or a Connector that sends your data off the broker. **With this flag, topic rules are not a hard boundary.**
>
> * Use it only on a development or test broker, or with a person reading every change before it is deployed.
> * For read-only work (explore, validate, diagnose), leave `deploy_lot` off the allow-list.
> * Mint tokens with short lifetimes, and revoke and re-mint them often.

> [!WARNING]
>
> The MCP Server listens on plain HTTP and accepts only a broker-issued bearer token. It has no built-in TLS and no OAuth sign-in. Keep the default loopback bind (`127.0.0.1:6278`) when Claude runs on the broker host. For any other setup, put a reverse proxy that terminates TLS in front of it and never publish the port on the internet. See [Docker and Kubernetes](https://docs.coreflux.org/v2.22/mqtt-broker/mcp-server.md#docker-and-kubernetes).

**1. Enable the MCP Server**

Set `Mcp.Enabled` to `true` (or `COREFLUX_MCP_ENABLED=true`) and **restart the broker**. In Coreflux HUB, use the **MCP** tab under **System → System Configuration**. Check it with:

```bash wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
curl http://127.0.0.1:6278/health
```

A healthy listener returns `status: "healthy"` and a `tools_count`. See [MCP Server Quick Start](https://docs.coreflux.org/v2.22/mqtt-broker/mcp-server.md#quick-start).

**2. Create a dedicated broker user**

Don't connect Claude as `root` or with the default `root` / `coreflux` login. Create a user and group for it. Publish each line to `$SYS/Coreflux/Command` as an administrator:

```bash wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
-addUser claude-line1 <strong-password>
-addUserToGroup claude-line1 ai-assistants
```

Management rights come from permission flags. With no flags, `explore_topics` is the only tool that works. `validate_lot`, `diagnose`, the list tools, and the `coreflux://topics` resources run broker commands, and the command gate admits only `AllowedUserManagement` or `AllowedSystemConfiguration`. Neither is a limited flag: `AllowedUserManagement` can change any user's flags, its own included. Deploying LoT needs `AllowedSystemConfiguration`. Read the warning at the top of Step 4 before you set it, and narrow its tools in the next steps:

```bash wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
-changeUserSettings claude-line1 AllowedSystemConfiguration true
```

**3. Narrow what it can see with rules**

Deploy each rule with its own `-addRule` command. The first rule keeps the assistant's group off every topic, and the second opens the line it works on:

```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE RULE AssistantNoReadElsewhere WITH PRIORITY 1000 FOR Subscribe TO TOPIC "#"
    IF USER IN GROUP "ai-assistants" THEN
        DENY
    ELSE
        ALLOW
```

```lot wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
DEFINE RULE Line1Readers WITH PRIORITY 500 FOR Subscribe TO TOPIC "plant/line1/#"
    ALLOW
```

On `plant/line1/…` the second rule is the strongest match, and the strongest matching rule decides for every user. Subscribe rules apply to `root` too, so the second rule allows everyone: with `ELSE DENY` it would also lock `root`, HUB sessions, and dashboards out of the line. If you already restrict `plant/line1/#`, add the `ai-assistants` group to those rules instead.

`explore_topics` now returns `plant/line1/…` only. The `coreflux://topics` resources follow the same rules, but they also need a flag that passes the command gate. Custom rules need a Growth or Enterprise license. See [AI clients follow your rules](https://docs.coreflux.org/v2.22/lot-language/rules/rbac.md#ai-clients-follow-your-rules).

Then limit the tools the MCP Server advertises to the ones this job needs. Names must match exactly:

```json wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
{
  "Mcp": {
    "Enabled": true,
    "EnableAllTools": false,
    "EnabledTools": ["explore_topics", "diagnose", "list_entities", "list_routes", "get_route_template", "validate_lot", "deploy_lot"]
  }
}
```

This keeps tools such as `add_user` off the assistant's surface even though its flag would allow them. The list does not limit `deploy_lot`: it deploys every kind of `DEFINE` block it is given, Rules and Connectors included, whether or not `add_rule` or `add_route` is on the list. For a read-only assistant, remove `deploy_lot` from the list. Otherwise read each change before it is deployed. Restart the broker after the change.

**4. Mint a token for that user**

```bash wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
-createMcpToken claude-line1 claude-desktop 30
```

The third argument is the lifetime in days. Without it the broker uses `Mcp.TokenLifetimeDays`, which defaults to `0` (the token never expires). The token is returned **once** in `data.token`. The reply goes to `$SYS/Coreflux/Command/Output`, and every user allowed to read that topic receives it (users with `AllowedUserManagement` or `AllowedSystemConfiguration`, `root`, and `admin`). That is true whether you mint from the HUB **MCP** tab, the Command Console, or your own MQTT client. Mint while few clients are subscribed to command output, and copy the token right away. Revoke it with `-revokeMcpToken claude-desktop` when the job is done or if it may have been seen. See [Bearer tokens](https://docs.coreflux.org/v2.22/mqtt-broker/mcp-server.md#bearer-tokens).

**5. Add the broker to Claude**

Claude Code connects to the broker over HTTP. Claude Desktop's config file runs only local (stdio) servers, so it reaches the broker through the `mcp-remote` bridge, which needs Node.js on that machine.

> [tab] Claude Code
>
> Project file: `.mcp.json` at the **repository root**.
>
> ```json wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> {
>   "mcpServers": {
>     "coreflux-broker": {
>       "type": "http",
>       "url": "http://127.0.0.1:6278/mcp",
>       "headers": {
>         "Authorization": "Bearer <token>"
>       }
>     }
>   }
> }
> ```
>
> `"type": "http"` is required. Without it Claude Code skips the entry with no error. Start a new Claude Code session after you change the file.

> [tab] Claude Desktop
>
> OS app config (`claude_desktop_config.json`), not a file in the repo.
>
> ```json wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
> {
>   "mcpServers": {
>     "coreflux-broker": {
>       "command": "npx",
>       "args": ["-y", "mcp-remote", "http://127.0.0.1:6278/mcp", "--header", "Authorization:${AUTH_HEADER}"],
>       "env": {
>         "AUTH_HEADER": "Bearer <token>"
>       }
>     }
>   }
> }
> ```
>
> The token goes in `env` because Claude Desktop can split arguments that contain spaces on Windows. `mcp-remote` accepts plain HTTP only on loopback. For a broker on another host, use the HTTPS address of your TLS proxy. Don't add the broker under Claude Desktop's **Connectors** settings: custom connectors connect from Anthropic's cloud and cannot reach `127.0.0.1`. Restart Claude Desktop after you change the file.

Keep the documentation MCP from Step 2 as a second server, so Claude can look up syntax and act on the broker in the same session. Don't commit a file that holds a token.

**6. Explore, validate, deploy, diagnose**

Ask for one change at a time and let Claude follow the same loop each time:

```text wrap theme={"theme":{"light":"css-variables","dark":"css-variables"},"languages":{"custom":["/languages/lot.json"]}}
Look at the live topics under plant/line1 and find the motor temperature.
Write a LoT Action that publishes an alarm to plant/line1/alarms/motor_overtemp when it goes above 85.
Validate it with validate_lot and show me the result before you deploy.
Deploy it with deploy_lot, then run diagnose.
```

| Step | Tool | What happens |
| - | - | - |
| Explore | `explore_topics` | Lists the topics the rules let it read. Detailed mode adds each payload and an inferred schema |
| Validate | `validate_lot` | The broker checks the LoT and deploys nothing. Every problem comes back with a code and a line, and Claude fixes and re-checks until it is valid |
| Deploy | `deploy_lot` | Deploys the `DEFINE` blocks in one call. On the first failure it rolls back what that call created or overwrote |
| Diagnose | `diagnose` | Reports connection status, Action errors, and pending work |

Read the LoT before you let Claude deploy it. It is plain text, and the broker runs exactly what you read. You can also compare a definition with what is running in the [HUB LoT Editor](https://docs.coreflux.org/hub/lot-editor.md#comparing-a-cell-with-the-broker).

***

## Best Practices

To get the most out of AI-assisted LoT development, keep these principles in mind:

* **Always verify the MCP connection** before starting a session. Without it, the AI may generate plausible-looking but incorrect LoT syntax
* **Be specific in your prompts** — include topic names, payload formats, thresholds, and hardware details. The more context you provide, the more accurate the output
* **Build incrementally** — deploy and test one Action, Connector, or Model at a time before moving to the next

For detailed prompt templates, see [Prompt Patterns That Work](https://docs.coreflux.org/ai/developing-with-lot.md#prompt-patterns-that-work). For naming conventions and a project rules template, see [Best Practices & AGENTS.md](https://docs.coreflux.org/ai/best-practices.md).

> [!WARNING]
>
> If your AI assistant generates LoT code **without** consulting the MCP, the syntax may be invented. Always verify that the MCP tools are active before trusting the output.

***

## Next Steps

> [card] [Creating Agents in Coreflux](https://docs.coreflux.org/v2.22/quick-start/creating-agents.md)
>
> Deploy AI agents on the broker — chat, automation, and multi-agent teams defined in LoT.

> [card] [Developing with LoT Using AI](https://docs.coreflux.org/ai/developing-with-lot.md)
>
> Deep-dive into the full AI-assisted workflow — planning, building, verifying, and scaling your IIoT system.

> [card] [Best Practices & AGENTS.md](https://docs.coreflux.org/ai/best-practices.md)
>
> Set up naming conventions, code patterns, and a project rules template to keep your AI assistant consistent.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.