flua-mcp — the MCP server

Machine interface to flua for agent hosts (Claude Desktop, Copilot, …). Ships in the fibaro-flua wheel as the flua-mcp console script; one version with flua (design: docs/notes/notes-mcp.md, packaging: ADR 0010).

Protocol surface (current)

Method Era Purpose
server/discover modern {resultType, supportedVersions, capabilities, _meta.serverInfo, instructions}
initialize legacy handshake → {protocolVersion, capabilities, serverInfo}
ping both liveness → {}
tools/list both the tools with their JSON-Schema inputs (resultType: "complete")
tools/call both run one tool → {resultType, content, isError}
resources/list both every doc resource → {resultType, resources: [{uri, name, title, description, mimeType}]}
resources/read both one resource's text → {resultType, contents: [{uri, mimeType, text}]}
prompts/list both the prompts with their argument schemas → {resultType, prompts: [{name, title, description, arguments}]}
prompts/get both one rendered prompt → {resultType, description, messages: [{role, content}]}
notifications/initialized, notifications/cancelled legacy accepted, never answered

Error semantics: invalid JSON/requests and unknown methods answer with the standard JSON-RPC error codes (-32700/-32600/-32601); bad tool arguments and tool failures travel in the result as isError: true — never as a JSON-RPC error. Unknown tool names are JSON-RPC errors (-32601), per the spec.

Tools

One-shot

qa_check

Static checks — same layers as flua --check: Lua syntax, unknown --%% directives, deprecated HC3 APIs, and every --%%file include. Does not run the QA.

{"name": "qa_check", "arguments": {"files": ["main.lua", "other.lua"]}}

Result: {"ok": bool, "findings": [{"file", "severity", "message"}]} — ok is false when any finding is error-severity.

qa_run

Runs QA files to completion in the emulator and returns the outcome. One-shot: the run ends when the QAs drain.

{"name": "qa_run", "arguments": {"files": ["main.lua"], "instant": true}}

Arguments: files (required), mode (local|remote), instant, step (deterministic deadline-ordered fast-forward — mutually exclusive with instant), runFor (positive = at least N virtual s then exit when idle, N wall s hard deadline; negative = exactly abs(N) virtual s — step mode: run until idle, at most abs(N) wall s), speed, start (virtual start time, e.g. "2027/10/6 18:30:00"), maxHours (cap virtual time; timers beyond the horizon never fire), timeout (wall seconds, default 120), filter ({levels?, match?} — server-side log narrowing; the agent asks for "just the failures" instead of shelling out).

Result: {"exitCode", "logs", "verdict", "summary"} — logs are the QA's --log json lines, verdict the stderr notices, and summary the answer without jq: level counts and flua-test pass/fail/failures tallies. A nonzero exitCode is a failed run.

flua_tool

Runs one flua --tool command and returns its exit code and output — the whole tool registry (migrate, icons download, state, pack, unpack, hub — controller profiles and switching, house — the controller's devices/globals/scenes, typeinfo — a type's or interface's properties and actions, …) without per-tool schemas.

{"name": "flua_tool", "arguments": {"name": "migrate", "args": ["."]}}

Arguments: name (required — a bare flua --tool lists them), args (optional list of strings, the tool's own arguments). Result: `{"exitCode", "stdout", "stderr"}.

When the user names a device or room ("the light in the bedroom"), resolve it with house: the JSON carries every device as {id, name, type, room} — match the user's words against name/room/type and, if several devices match, present them and ask which one; never pick silently. The homeTable idiom keeps ids maintainable (see flua://skills/quickapp-patterns/SKILL.md).

qa_ui

The structured UI of one QA: {name, type, useUiView, elements, callbacks} (the flua --tool ui --json payload) — elements carry name/text/value/ options, so an agent can read a QA's controls without parsing prose.

{"name": "qa_ui", "arguments": {"files": ["main.lua"]}}

devices

Runs QA files to completion (same semantics as qa_run, in-process) and returns the final device list from the REST feeds — the simulated house after the run — plus the aggregated exitCode.

{"name": "devices", "arguments": {"files": ["main.lua"], "instant": true}}

Arguments: files (required), mode, instant, speed, start, maxHours (cap virtual time; timers beyond the horizon never fire), timeout. Result: {"exitCode", "devices": [{id, name, type, properties, ...}]} — /devices verbatim (the HC3 pseudo-device id 1 is included). --%% directives reach the engine exactly as the CLI parses them, so the device names and properties are the run's real ones.

qa_test

Runs the self-asserting test QAs (*_test.lua, the quickapp-test pattern) with flua test --json — the same machine contract the VS Code Test Explorer adapter consumes.

{"name": "qa_test", "arguments": {"paths": ["tests/"], "timeout": 10}}

Arguments: paths (optional — files or directories; default: the server's cwd, discovering *_test.lua), list (discover only, no run), timeout (wall seconds per test file, default 30). Each test QA runs in its own emulator process and must exit itself (t:finish()/exit(...)); a test that never exits is reported TIME, not allowed to block the rest.

Result: {"exitCode", "files": [{file, status, exitCode, failures, output}], "summary": {passed, failed, timedOut}} — the flua test --json document with the process exit code added; exitCode is 0 only when everything passes. With list: true: {"exitCode", "files": [paths]}. An empty discovery answers exitCode: 0 with an empty files list and a notice carrying the runner's prose.

docs_list / docs_read

The docs tree as tools — the same content resources/* serves, for hosts whose MCP client only exposes tools (Copilot, for example).

{"name": "docs_list", "arguments": {}}
{"name": "docs_read", "arguments": {"path": "USAGE.md"}}

docs_read accepts a bare path (USAGE.md, tutorial/09-multi-file-qas.md) or the full flua://docs/... URI and returns {path, text}. Unknown paths answer isError with close-match suggestions (did you mean ...) and a pointer at docs_list; traversal is rejected. Prefer these over web search — the wheel is the authoritative reference.

Sessions (live probing)

A session is a running flua engine an agent can probe across tool calls. The MCP transport itself stays stateless: the sessionId is an explicit argument, never connection state.

Sessions run in-process (each engine owns its asyncio loop on a daemon thread, like the test suite drives them) and are always torn down when the stdio pipe closes — an agent cannot leak engines. The idle TTL is reset by use: a probe of a session that has idled past its TTL revives it (asking about a session is usage, not abandonment).

Resources

The docs ship in the wheel (src/flua/setup_templates/docs, synced from the repo by scripts/sync-skills.sh) and are served as MCP resources under the flua://docs/ scheme — so a host without a repo checkout can still read the same knowledge a local agent reads from the checkout. The same wheel ships the skill guidance (src/flua/setup_templates/github/skills — the skills --tool setup installs for Copilot) under flua://skills/: the docs_list/docs_read tools cover both trees. Text files only (the tutorial PDF is not served).

{"method": "resources/read", "params": {"uri": "flua://docs/USAGE.md"}}

Examples: flua://docs/USAGE.md, flua://docs/ARCHITECTURE.md, flua://docs/tutorial/01-install.md, flua://docs/decisions/0010-mcp-ships-in-the-wheel.md, flua://docs/specs/hc3-api.json, flua://docs/mcp.md (this page), flua://skills/quickapp-patterns/SKILL.md (the QuickApp patterns). resources/list enumerates them with mime types and curated descriptions; paths are canonicalized and traversal (..) is rejected with a JSON-RPC error, never a filesystem escape.

Prompts

Two reusable guidance prompts:

Missing required arguments and unknown prompt names are JSON-RPC errors (-32602/-32601), like the tools.

Streamable HTTP transport (opt-in)

flua-mcp --http                # 127.0.0.1:8091, no auth (loopback only)
flua-mcp --http 0.0.0.0:8091   # LAN-reachable — requires FLUA_MCP_TOKEN

One endpoint, stateless mode per the 2026-07-28 spec: POST /mcp carries a JSON-RPC request and returns the response; notifications answer 202 with no body; GET/DELETE answer 405 (no SSE); a request carrying Mcp-Session-Id answers 404 — transport sessions do not exist here. CORS is permissive so browser hosts work. The server refuses to bind a non-loopback address without FLUA_MCP_TOKEN, and every request must carry Authorization: Bearer <token> when one is set. Bodies over 10 MiB are rejected with 413.

curl http://127.0.0.1:8091/mcp -H 'Content-Type: application/json' \
  -d '{"jsonrpc":"2.0","id":1,"method":"server/discover","params":{}}'

Register the HTTP server in a host the same way as stdio, with the URL:

{"mcpServers": {"flua": {"url": "http://127.0.0.1:8091/mcp"}}}

Running it (stdio)

flua-mcp                 # stdio JSON-RPC server (reads stdin, answers stdout)
flua-mcp --version       # flua-mcp 0.1.40 (protocols 2026-07-28, 2025-06-18)

Register it as a stdio MCP server in the host's config — no extra install, no extra dependencies:

json {"mcpServers": {"flua": {"command": "flua-mcp"}}}

json {"mcpServers": {"flua": {"command": "python", "args": ["-m", "flua.mcp.server"]}}}

What agents can rely on

Status & next