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).
flua-mcp --http, one
POST /mcp endpoint in stateless mode (ADR 0011): no SSE, no
Mcp-Session-Id (sessions are explicit tool arguments), same dispatch
core as stdio.params._meta
and server/discover (required) lists supportedVersions. The legacy
initialize handshake (2025-06-18) is still served for older clients.
Unsupported versions answer error -32022 with {supported, requested}.tools, resources (the packaged docs as
flua://docs/* and the skill guidance as flua://skills/*), and
prompts (qa_debug, qa_skeleton).| 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.
qa_checkStatic 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_runRuns 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_toolRuns 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_uiThe 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"]}}
devicesRuns 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_testRuns 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_readThe 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.
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.
qa_start — {files, mode?, instant?, speed?, start?, ttl?} →
{sessionId, qaIds}. Idle sessions are reaped after ttl seconds
(default 600).qa_probe — {sessionId} → {devices, qas, debugMessages,
systemEvents, refreshStates}. The three feeds are deltas since the
previous probe (cursor-based) — repeated probes only show what is
new. refreshStates carries the HC3 polling shape
{status, last, changes, events}.qa_action — {sessionId, qaId, action, args?} → {status};
dispatches POST /devices/{id}/action/{action} into the running engine
(reaches the QA's callAction).qa_sessions — {} → {sessions: [{sessionId, qaIds, ageSeconds}]}.qa_stop — {sessionId} → {stopped}. Unknown session ids are
isError tool results.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).
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.
Two reusable guidance prompts:
qa_debug — {error (required), code?} → one message with the
debugging workflow in order: static checks (qa_check), offline
reproduction (qa_run), how to read each error shape (syntax vs
traceback vs timeout/drain), the JSON log format, shrinking the problem,
and the doc resources to consult (flua://docs/invariants.md,
flua://docs/walkthroughs.md, the tutorial's debugging chapter,
flua://docs/USAGE.md). The reported error and code are bound into the
message.qa_skeleton — {name?} → a runnable, self-testing QA template:
--%%file:$flua-test.lua (assertions that no-op on a real HC3), the
deferred-onInit pattern, and t:expect/t:assert_eq/t:finish() with
the exit code as the verdict. The emitted skeleton is pinned by a test
that extracts it and runs it through qa_run — it never rots.Missing required arguments and unknown prompt names are JSON-RPC errors
(-32602/-32601), like the tools.
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"}}}
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:
claude_desktop_config.json):json
{"mcpServers": {"flua": {"command": "flua-mcp"}}}
mcp.json hosts (uses the interpreter flua runs on):json
{"mcpServers": {"flua": {"command": "python", "args": ["-m", "flua.mcp.server"]}}}
initialize and tools/list are the discovery surface — schemas are
complete and typed; never parse tools/list prose. resources/list is
the same for docs: read resources/read, don't guess file locations.
prompts/list is the same for guidance: prompts/get renders it.text content block (single block).qa_run never talks to a controller unless mode: "remote" is explicit;
the default is the offline sim.mode: "remote" uses the server process's environment
(HC3_URL/HC3_USER/HC3_PASSWORD, the same chain flua uses) — never
tool arguments.timeout) and capped: at most 4 concurrent one-shot
runs (qa_run/devices/qa_test) — further ones fail fast with
isError.
Every tool failure is either an isError result or a JSON-RPC error —
the server process never dies on a bad request. Engine errors are
actionable: a wrong --%%type names close matches and points at
flua --tool catalog.qa_check, qa_run, qa_ui,
devices, qa_test, flua_tool), the session tier (qa_start/qa_probe/qa_action/
qa_sessions/qa_stop), the resource tier (flua://docs/*) plus its
tool fallback (docs_list/docs_read — hosts without resource
support), the prompt tier (qa_debug/qa_skeleton), the Streamable
HTTP transport (stateless), packaging, tests (tests/test_mcp.py,
tests/test_mcp_http.py).