MCP Server¶
ModbusLab can expose the running desktop workspace through a local HTTP MCP server. This lets an MCP-capable LLM client inspect live server state, validate operations, and optionally control servers, memory, watches, simulation, rules, reactions, traffic diagnostics, and import/export.
MCP access works against the live WPF application state, not a copy of the project file. The app must be running.
Enable MCP¶
Open Application Settings and enable MCP server.
The endpoint is:
http://127.0.0.1:<port>/mcp
By default, the server is local-only and protected with a bearer token:
Authorization: Bearer <token>
Use the copy buttons in Application Settings to copy the endpoint and token. Regenerating the token invalidates the previous one.
Security Model¶
MCP is disabled by default. When enabled:
- the HTTP host binds only to
127.0.0.1; - token authentication is enabled by default;
- mutation permission is disabled by default, including for projects created from files that omit the setting;
- tools run against the same write paths used by the UI;
- mutating tools are blocked unless Allow mutations is enabled;
- mutating tools support
dryRunwhere validation without changes is useful.
Use dryRun=true before applying changes from an LLM client. Read tools, resources, validation tools, and dry runs remain available while mutations are disabled.
Only the local Application Settings window can grant Allow mutations. An MCP client cannot grant that permission to itself. A client that already has mutation permission may turn the permission off remotely; after that change, the local UI is required to enable it again.
Resources¶
Resources are read-only JSON snapshots:
modbuslab://project: project path, MCP settings summary, selected server, and recent MCP diagnostics.modbuslab://servers: configured servers and runtime state.modbuslab://selected-server: the currently selected server.modbuslab://diagnostics: runtime diagnostics for the selected server.
Read Tools¶
Read tools return compact JSON DTOs:
modbuslab_project_summarymodbuslab_list_serversmodbuslab_selected_servermodbuslab_server_settingsmodbuslab_read_memorymodbuslab_list_watchesmodbuslab_list_rulesmodbuslab_runtime_diagnosticsmodbuslab_mcp_status
Use these before mutating state so the client can resolve server names, Watch names, rule indexes, memory areas, and runtime keys.
Control Tools¶
Server and app control:
modbuslab_select_servermodbuslab_create_servermodbuslab_clone_servermodbuslab_delete_servermodbuslab_update_server_settingsmodbuslab_update_mcp_settingsmodbuslab_start_servermodbuslab_stop_servermodbuslab_start_all_serversmodbuslab_stop_all_serversmodbuslab_set_simulation
Memory and Watch control:
modbuslab_write_memorymodbuslab_clear_memorymodbuslab_capture_startup_snapshotmodbuslab_set_startup_memory_modemodbuslab_write_watchmodbuslab_upsert_watchmodbuslab_delete_watch
Rule control:
modbuslab_upsert_simulation_rulemodbuslab_delete_simulation_rulemodbuslab_upsert_fault_rulemodbuslab_delete_fault_rulemodbuslab_upsert_reactionmodbuslab_delete_reactionmodbuslab_reset_rule_hits
Runtime diagnostics and cleanup:
modbuslab_reset_statsmodbuslab_clear_logsmodbuslab_clear_log_entriesmodbuslab_clear_blocksmodbuslab_clear_block_entriesmodbuslab_clear_inactive_clientsmodbuslab_disconnect_client
Server transfer:
modbuslab_export_servermodbuslab_import_server
Validation Tools¶
Validation tools are read-only and do not change state:
modbuslab_validate_memory_writemodbuslab_validate_watch_writemodbuslab_validate_rule_payload
Most mutating tools also include a dryRun parameter. A dry run validates the request and returns the expected result shape without changing memory, settings, rules, logs, or files.
When a dedicated validation tool successfully performs validation, the outer call has ok=true even when the payload is invalid. Inspect result.valid, the normalized model, and the field-level errors:
{
"ok": true,
"result": {
"valid": false,
"normalized": {},
"errors": [
{ "Field": "TargetWatchName", "Message": "Watch 'Missing' was not found." }
]
}
}
Upsert and mutation tools use the same validator. An invalid mutation returns ok=false, including when dryRun=true, and does not change the workspace.
Common Workflows¶
Read the project and server list first:
- Read
modbuslab://projector callmodbuslab_project_summary. - Call
modbuslab_list_servers. - Select a server with
modbuslab_select_server. - Read memory, watches, rules, or diagnostics.
- Validate planned writes or rule payloads.
- Re-run the same tool with
dryRun=falseonly when the result is acceptable.
For typed values, prefer modbuslab_write_watch over raw memory writes. It uses the Watch data type, string format, byte order, and word order, then applies local write reactions through the existing app path.
For raw memory writes, pass a JSON array of booleans for bit areas or unsigned 16-bit values for register areas.
Diagnostics¶
MCP calls and failures are recorded in the app's MCP diagnostics. Project validation warnings and the latest save error are also exposed by project and runtime diagnostics. Use modbuslab_mcp_status, modbuslab_runtime_diagnostics, or Application Settings to inspect recent status and errors.
If a client receives 401 Unauthorized, check the bearer token. If it receives 404 Not Found, verify that it is connecting to /mcp and not /.