loxone-mcp 0.0.0-stage → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. package/LICENSE +176 -0
  2. package/README.md +121 -2
  3. package/dist/LoxoneMcp.d.ts +60 -0
  4. package/dist/LoxoneMcp.d.ts.map +1 -0
  5. package/dist/LoxoneMcp.js +197 -0
  6. package/dist/LoxoneMcp.js.map +1 -0
  7. package/dist/McpHost.d.ts +89 -0
  8. package/dist/McpHost.d.ts.map +1 -0
  9. package/dist/McpHost.js +3 -0
  10. package/dist/McpHost.js.map +1 -0
  11. package/dist/auth/OAuthServer.d.ts +91 -0
  12. package/dist/auth/OAuthServer.d.ts.map +1 -0
  13. package/dist/auth/OAuthServer.js +377 -0
  14. package/dist/auth/OAuthServer.js.map +1 -0
  15. package/dist/auth/pages.d.ts +100 -0
  16. package/dist/auth/pages.d.ts.map +1 -0
  17. package/dist/auth/pages.js +140 -0
  18. package/dist/auth/pages.js.map +1 -0
  19. package/dist/auth/state.d.ts +18 -0
  20. package/dist/auth/state.d.ts.map +1 -0
  21. package/dist/auth/state.js +50 -0
  22. package/dist/auth/state.js.map +1 -0
  23. package/dist/catalog/actions.d.ts +52 -0
  24. package/dist/catalog/actions.d.ts.map +1 -0
  25. package/dist/catalog/actions.js +256 -0
  26. package/dist/catalog/actions.js.map +1 -0
  27. package/dist/catalog/control-specs.json +1 -0
  28. package/dist/cli.d.ts +3 -0
  29. package/dist/cli.d.ts.map +1 -0
  30. package/dist/cli.js +116 -0
  31. package/dist/cli.js.map +1 -0
  32. package/dist/home/LoxoneHome.d.ts +72 -0
  33. package/dist/home/LoxoneHome.d.ts.map +1 -0
  34. package/dist/home/LoxoneHome.js +175 -0
  35. package/dist/home/LoxoneHome.js.map +1 -0
  36. package/dist/http/McpHttpHandler.d.ts +60 -0
  37. package/dist/http/McpHttpHandler.d.ts.map +1 -0
  38. package/dist/http/McpHttpHandler.js +376 -0
  39. package/dist/http/McpHttpHandler.js.map +1 -0
  40. package/dist/http/confirmer.d.ts +40 -0
  41. package/dist/http/confirmer.d.ts.map +1 -0
  42. package/dist/http/confirmer.js +101 -0
  43. package/dist/http/confirmer.js.map +1 -0
  44. package/dist/index.d.ts +11 -0
  45. package/dist/index.d.ts.map +1 -0
  46. package/dist/index.js +26 -0
  47. package/dist/index.js.map +1 -0
  48. package/dist/model/place.d.ts +9 -0
  49. package/dist/model/place.d.ts.map +1 -0
  50. package/dist/model/place.js +20 -0
  51. package/dist/model/place.js.map +1 -0
  52. package/dist/model/present.d.ts +37 -0
  53. package/dist/model/present.d.ts.map +1 -0
  54. package/dist/model/present.js +287 -0
  55. package/dist/model/present.js.map +1 -0
  56. package/dist/model/resolve.d.ts +46 -0
  57. package/dist/model/resolve.d.ts.map +1 -0
  58. package/dist/model/resolve.js +170 -0
  59. package/dist/model/resolve.js.map +1 -0
  60. package/dist/model/text.d.ts +14 -0
  61. package/dist/model/text.d.ts.map +1 -0
  62. package/dist/model/text.js +79 -0
  63. package/dist/model/text.js.map +1 -0
  64. package/dist/model/vocabulary.d.ts +17 -0
  65. package/dist/model/vocabulary.d.ts.map +1 -0
  66. package/dist/model/vocabulary.js +86 -0
  67. package/dist/model/vocabulary.js.map +1 -0
  68. package/dist/safety/policy.d.ts +56 -0
  69. package/dist/safety/policy.d.ts.map +1 -0
  70. package/dist/safety/policy.js +118 -0
  71. package/dist/safety/policy.js.map +1 -0
  72. package/dist/store/FileStore.d.ts +9 -0
  73. package/dist/store/FileStore.d.ts.map +1 -0
  74. package/dist/store/FileStore.js +33 -0
  75. package/dist/store/FileStore.js.map +1 -0
  76. package/dist/tools/context.d.ts +41 -0
  77. package/dist/tools/context.d.ts.map +1 -0
  78. package/dist/tools/context.js +7 -0
  79. package/dist/tools/context.js.map +1 -0
  80. package/dist/tools/operate.d.ts +28 -0
  81. package/dist/tools/operate.d.ts.map +1 -0
  82. package/dist/tools/operate.js +91 -0
  83. package/dist/tools/operate.js.map +1 -0
  84. package/dist/tools/tools.d.ts +5 -0
  85. package/dist/tools/tools.d.ts.map +1 -0
  86. package/dist/tools/tools.js +310 -0
  87. package/dist/tools/tools.js.map +1 -0
  88. package/dist/version.d.ts +3 -0
  89. package/dist/version.d.ts.map +1 -0
  90. package/dist/version.js +7 -0
  91. package/dist/version.js.map +1 -0
  92. package/package.json +59 -4
package/LICENSE ADDED
@@ -0,0 +1,176 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
package/README.md CHANGED
@@ -1,3 +1,122 @@
1
- # Temporary Holding Version
1
+ # loxone-mcp
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ A [Model Context Protocol](https://modelcontextprotocol.io) server for Loxone Miniservers, **Gen1 and Gen2**.
4
+ An AI assistant (Claude Desktop, Claude Code, or any MCP client) can use it to find, read and safely
5
+ operate a Loxone home.
6
+
7
+ It connects with [`loxone-ts-client`](https://www.npmjs.com/package/loxone-ts-client), reads the
8
+ Structure File, and keeps every state live over the Miniserver's websocket. Loxone's own MCP plugin
9
+ needs Loxone Config 17.1 and a Gen2 Miniserver. This server talks to any Miniserver that has a
10
+ websocket API.
11
+
12
+ ## What the assistant gets
13
+
14
+ | Tool | What it does |
15
+ | --- | --- |
16
+ | `home_overview` | The home at a glance: alarms first, then per room the climate, lights, open windows and presence. Give a room to see everything in it. |
17
+ | `find` | Search controls by name, room or kind, in English, Dutch or German (`lamp keuken`, `rolluiken boven`, `Heizung Bad`). Typos are tolerated. |
18
+ | `describe` | One control: its state, how fresh that state is, what it can do and whether this connection may do it. |
19
+ | `get_states` | The current state of several controls at once. |
20
+ | `control` | Run an action (`on`, `setBrightness 40`, `FullDown`, `manualPosition 30`, …) on one or more controls. Supports `dry_run`. Answers with the state before and after. |
21
+ | `set_light_mood` | Switch a room's lighting controller to a mood by name (`Avond`, `off`). |
22
+
23
+ Names come back as `Name [Room]`, or `Controller / Name [Room]` for a sub-control, and the tools
24
+ accept them as given. Every state says when it last changed. A value that came with the first burst
25
+ after connecting is reported as "unchanged since …", not as fresh.
26
+
27
+ ## Safety
28
+
29
+ - **Read only by default.** Operating devices is off until the owner switches it on.
30
+ - The owner limits what may be operated: all controls, or only some rooms, categories or controls.
31
+ A block list and an extra confirm list are also available.
32
+ - **Doors, gates, locks, windows, alarms, intercoms and saunas are risky.** They stay off unless
33
+ allowed, and even then the person must confirm each action. Confirmation goes through MCP
34
+ elicitation, so it comes from the person, not the model. Risky means the control type, or an access
35
+ word (door, gate, lock, deur, poort, slot, Tür, Tor, …) in its name or icon. Emergency, smoke alarm
36
+ and NFC code controls are never operated.
37
+ - Actions on more than 5 controls at once need confirmation, and there is a hard maximum per call.
38
+ A call that is not allowed for every target does nothing at all.
39
+ - **Visualisation passwords are never seen by the model.** The person types the password on the
40
+ server's own page, opened through a URL elicitation.
41
+ - Every action, refusal and dry run goes to an audit log, with the state before and after.
42
+
43
+ ## Sign-in
44
+
45
+ In `serve` mode, each person signs in with **their own Loxone user** through OAuth 2.1, so the
46
+ Miniserver's user rights apply. The OAuth support covers:
47
+
48
+ - dynamic client registration
49
+ - PKCE S256
50
+ - rotating refresh tokens
51
+ - the protected-resource and authorization-server metadata the MCP spec asks for
52
+
53
+ The password is used once to get a Loxone token and is not stored. Refresh tokens and client secrets
54
+ are kept only as hashes. A person can sign in with read access only (`loxone:read`), or with control
55
+ access (`loxone:control`) as well.
56
+
57
+ ## Use
58
+
59
+ ### One person, local (stdio)
60
+
61
+ ```sh
62
+ LOXONE_HOST=192.168.1.77 LOXONE_USER=ai LOXONE_PASSWORD=… npx loxone-mcp stdio
63
+ ```
64
+
65
+ Claude Code:
66
+
67
+ ```sh
68
+ claude mcp add loxone -e LOXONE_HOST=192.168.1.77 -e LOXONE_USER=ai -e LOXONE_PASSWORD=… -- npx loxone-mcp stdio --control
69
+ ```
70
+
71
+ ### A server for the household (HTTP + OAuth)
72
+
73
+ ```sh
74
+ LOXONE_HOST=192.168.1.77 npx loxone-mcp serve --port 8765 --data /var/lib/loxone-mcp
75
+ claude mcp add --transport http loxone http://server:8765/mcp
76
+ ```
77
+
78
+ The client opens the sign-in page the first time. Behind a reverse proxy, pass `--public-url` and
79
+ `--trust-proxy`. MCP clients only accept a plain-HTTP OAuth server on `localhost`. Anywhere else,
80
+ serve over HTTPS.
81
+
82
+ The policy is read from `<data>/policy.json` at every call, so a change takes effect at once:
83
+
84
+ ```json
85
+ {
86
+ "control": true,
87
+ "controllable": { "rooms": ["Woonkamer", "Keuken"] },
88
+ "blocked": ["Sauna"],
89
+ "confirm": ["Garage light [Garage]"],
90
+ "risky": false,
91
+ "withoutConfirmation": "refuse",
92
+ "maxTargets": 20
93
+ }
94
+ ```
95
+
96
+ `withoutConfirmation` says what happens when the client cannot ask the person for confirmation
97
+ (no elicitation support). `refuse` turns the action down. `client-approval` relies on the client's
98
+ own tool-approval prompt.
99
+
100
+ ### Embedded in another program
101
+
102
+ Mimic hosts it on its own web server and manages the policy,
103
+ the signed-in users and the audit log from its admin pages:
104
+
105
+ ```ts
106
+ import { FileStore, LoxoneMcp } from 'loxone-mcp';
107
+
108
+ const mcp = new LoxoneMcp({
109
+ miniserver: () => ({ host: '192.168.1.77', port: 80 }),
110
+ policy: () => myPolicy,
111
+ store: new FileStore('/var/lib/my-host/mcp/state.json'),
112
+ audit: (entry) => myAuditLog.write(entry),
113
+ log,
114
+ });
115
+ mcp.start();
116
+ // in the host's request handler:
117
+ if (LoxoneMcp.owns(url.pathname)) return void mcp.handle(request, response);
118
+ ```
119
+
120
+ ## License
121
+
122
+ Apache-2.0
@@ -0,0 +1,60 @@
1
+ import type { IncomingMessage, ServerResponse } from 'node:http';
2
+ import { type GrantView } from './auth/OAuthServer';
3
+ import type { McpHost } from './McpHost';
4
+ /** What the model is told about this server, once per session. */
5
+ export declare const INSTRUCTIONS = "This server is a Loxone smart home (lights, blinds, heating, sensors, alarms, energy), live.\n- Start with home_overview; use find to locate controls (\"lamp keuken\", \"Rollladen Bad\", any language). Refer to controls as \"Name [Room]\" exactly as the tools write them.\n- describe shows a control's states and the actions it takes; control operates it, set_light_mood picks a room's lighting mood.\n- The person's own Loxone user decides what is visible and allowed; the server owner decides what may be operated. Doors, gates, alarms and bulk actions are only done after the person confirms in their client; never ask the person for passwords or codes yourself.\n- Values carry their freshness; say so when a value is old. Use dry_run when unsure what an action will do.";
6
+ export interface LoxoneMcpOptions {
7
+ /** Trust X-Forwarded-* headers (behind your own reverse proxy). */
8
+ trustProxy?: boolean;
9
+ }
10
+ /**
11
+ * A Loxone MCP server. Each person signs in (OAuth) with their own Loxone user; the server keeps one
12
+ * live connection per user (by their Loxone token, never their password), so every state is known
13
+ * and fresh. The host gives the Miniserver, the owner's policy and a store; it mounts `handle` on
14
+ * its web server, or the server runs alone (the `loxone-mcp` command).
15
+ */
16
+ export declare class LoxoneMcp {
17
+ private readonly host;
18
+ private readonly log;
19
+ private readonly state;
20
+ private readonly oauth;
21
+ private readonly http;
22
+ private readonly homes;
23
+ constructor(host: McpHost, options?: LoxoneMcpOptions);
24
+ /** Connects the homes of everyone with access, so their states are live (and tokens kept fresh). */
25
+ start(): void;
26
+ stop(): Promise<void>;
27
+ /** Answers the MCP and OAuth paths (`/mcp`, `/oauth/*`, `/.well-known/oauth-*`); false for others. */
28
+ handle(req: IncomingMessage, res: ServerResponse): Promise<boolean>;
29
+ /** Whether a path is one `handle` answers. */
30
+ static owns(path: string): boolean;
31
+ /** For the host's admin page: who has access through which client, and the live connections. */
32
+ status(): {
33
+ grants: GrantView[];
34
+ users: Array<{
35
+ user: string;
36
+ connected: boolean;
37
+ error: string | null;
38
+ }>;
39
+ sessions: number;
40
+ };
41
+ /** Takes a client's access away (its sessions end; it must sign in again). */
42
+ revokeGrant(id: string): Promise<void>;
43
+ /**
44
+ * Serves one person over stdio (for a local client such as Claude Desktop): signed in with a
45
+ * Loxone user and password from the environment, read-only unless `control` is set.
46
+ */
47
+ static serveStdio(host: Omit<McpHost, 'store'>, credentials: {
48
+ user: string;
49
+ password: string;
50
+ }, control: boolean): Promise<void>;
51
+ private policy;
52
+ private buildServer;
53
+ /** The live home of a signed-in user (connecting with their kept token). */
54
+ private homeOf;
55
+ private newHome;
56
+ /** Checks a Loxone sign-in by connecting as that user; on success this becomes their live home. */
57
+ private signIn;
58
+ private forgetUser;
59
+ }
60
+ //# sourceMappingURL=LoxoneMcp.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoxoneMcp.d.ts","sourceRoot":"","sources":["../src/LoxoneMcp.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,eAAe,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAIjE,OAAO,EAAe,KAAK,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAKjE,OAAO,KAAK,EAAE,OAAO,EAAU,MAAM,WAAW,CAAC;AAMjD,kEAAkE;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,EAC/C,OAAO,EAAE,OAAO,GACf,OAAO,CAAC,IAAI,CAAC;IAYhB,OAAO,CAAC,MAAM;IAId,OAAO,CAAC,WAAW;IAoBnB,4EAA4E;IAC5E,OAAO,CAAC,MAAM;IAWd,OAAO,CAAC,OAAO;IAef,mGAAmG;YACrF,MAAM;YAkBN,UAAU;CAMzB"}
@@ -0,0 +1,197 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.LoxoneMcp = exports.INSTRUCTIONS = void 0;
4
+ const mcp_js_1 = require("@modelcontextprotocol/sdk/server/mcp.js");
5
+ const stdio_js_1 = require("@modelcontextprotocol/sdk/server/stdio.js");
6
+ const loxone_ts_client_1 = require("loxone-ts-client");
7
+ const OAuthServer_1 = require("./auth/OAuthServer");
8
+ const state_1 = require("./auth/state");
9
+ const confirmer_1 = require("./http/confirmer");
10
+ const McpHttpHandler_1 = require("./http/McpHttpHandler");
11
+ const LoxoneHome_1 = require("./home/LoxoneHome");
12
+ const policy_1 = require("./safety/policy");
13
+ const context_1 = require("./tools/context");
14
+ const tools_1 = require("./tools/tools");
15
+ const version_1 = require("./version");
16
+ /** What the model is told about this server, once per session. */
17
+ exports.INSTRUCTIONS = `This server is a Loxone smart home (lights, blinds, heating, sensors, alarms, energy), live.
18
+ - Start with home_overview; use find to locate controls ("lamp keuken", "Rollladen Bad", any language). Refer to controls as "Name [Room]" exactly as the tools write them.
19
+ - describe shows a control's states and the actions it takes; control operates it, set_light_mood picks a room's lighting mood.
20
+ - The person's own Loxone user decides what is visible and allowed; the server owner decides what may be operated. Doors, gates, alarms and bulk actions are only done after the person confirms in their client; never ask the person for passwords or codes yourself.
21
+ - Values carry their freshness; say so when a value is old. Use dry_run when unsure what an action will do.`;
22
+ /**
23
+ * A Loxone MCP server. Each person signs in (OAuth) with their own Loxone user; the server keeps one
24
+ * live connection per user (by their Loxone token, never their password), so every state is known
25
+ * and fresh. The host gives the Miniserver, the owner's policy and a store; it mounts `handle` on
26
+ * its web server, or the server runs alone (the `loxone-mcp` command).
27
+ */
28
+ class LoxoneMcp {
29
+ host;
30
+ log;
31
+ state;
32
+ oauth;
33
+ http;
34
+ homes = new Map();
35
+ constructor(host, options = {}) {
36
+ this.host = host;
37
+ this.log = host.log;
38
+ this.state = new state_1.StateKeeper(host.store);
39
+ this.oauth = new OAuthServer_1.OAuthServer(this.state, this.log);
40
+ this.http = new McpHttpHandler_1.McpHttpHandler(this.oauth, {
41
+ serverName: host.serverName ?? 'Loxone',
42
+ signIn: (user, password) => this.signIn(user, password),
43
+ controlAllowed: () => this.policy().control,
44
+ buildServer: (principal, confirmer) => this.buildServer(principal, confirmer),
45
+ ...(this.log ? { log: this.log } : {}),
46
+ }, { ...(host.publicUrl ? { publicUrl: host.publicUrl } : {}), ...(options.trustProxy ? { trustProxy: true } : {}) });
47
+ }
48
+ /** Connects the homes of everyone with access, so their states are live (and tokens kept fresh). */
49
+ start() {
50
+ for (const user of this.oauth.users()) {
51
+ const home = this.homeOf(user);
52
+ if (!home)
53
+ continue;
54
+ home.ready().catch((error) => this.log?.warn(`MCP: Miniserver not reached for ${user}`, { message: error.message }));
55
+ }
56
+ }
57
+ async stop() {
58
+ await this.http.close();
59
+ for (const home of this.homes.values())
60
+ await home.close(true);
61
+ this.homes.clear();
62
+ }
63
+ /** Answers the MCP and OAuth paths (`/mcp`, `/oauth/*`, `/.well-known/oauth-*`); false for others. */
64
+ handle(req, res) {
65
+ return this.http.handle(req, res);
66
+ }
67
+ /** Whether a path is one `handle` answers. */
68
+ static owns(path) {
69
+ return McpHttpHandler_1.McpHttpHandler.owns(path);
70
+ }
71
+ /** For the host's admin page: who has access through which client, and the live connections. */
72
+ status() {
73
+ return {
74
+ grants: this.oauth.grants(),
75
+ users: [...this.homes.values()].map((h) => ({ user: h.user, connected: h.connected, error: h.failure?.message ?? null })),
76
+ sessions: this.http.sessionCount,
77
+ };
78
+ }
79
+ /** Takes a client's access away (its sessions end; it must sign in again). */
80
+ async revokeGrant(id) {
81
+ const grant = this.oauth.grants().find((g) => g.id === id);
82
+ this.oauth.revokeGrant(id);
83
+ await this.http.dropGrant(id);
84
+ if (grant && !this.oauth.users().includes(grant.user))
85
+ await this.forgetUser(grant.user);
86
+ }
87
+ /**
88
+ * Serves one person over stdio (for a local client such as Claude Desktop): signed in with a
89
+ * Loxone user and password from the environment, read-only unless `control` is set.
90
+ */
91
+ static async serveStdio(host, credentials, control) {
92
+ const address = host.miniserver();
93
+ if (!address)
94
+ throw new Error('no Miniserver address');
95
+ const home = new LoxoneHome_1.LoxoneHome(address, credentials, { clientUuid: (0, state_1.loxoneClientUuid)(), clientInfo: 'loxone-mcp', logger: quiet(host.log) });
96
+ const mcp = new LoxoneMcp({ ...host, store: { load: () => undefined, save: () => undefined } });
97
+ mcp.homes.set(credentials.user, home);
98
+ const principal = { user: credentials.user, client: 'stdio', scopes: new Set(control ? context_1.ALL_SCOPES : [context_1.ALL_SCOPES[0]]) };
99
+ const server = mcp.buildServer(principal, (s, requestId) => new confirmer_1.ElicitationConfirmer(s, null, () => undefined, requestId));
100
+ await home.ready();
101
+ await server.connect(new stdio_js_1.StdioServerTransport());
102
+ }
103
+ policy() {
104
+ return (0, policy_1.completePolicy)(this.host.policy());
105
+ }
106
+ buildServer(principal, confirmer) {
107
+ const server = new mcp_js_1.McpServer({ name: 'loxone-mcp', title: this.host.serverName ?? 'Loxone', version: version_1.VERSION }, { instructions: exports.INSTRUCTIONS });
108
+ const context = {
109
+ home: async () => {
110
+ const home = this.homeOf(principal.user);
111
+ if (!home)
112
+ throw new Error('this Loxone user is no longer signed in');
113
+ await home.ready();
114
+ return home;
115
+ },
116
+ principal,
117
+ policy: () => this.policy(),
118
+ confirmer: (call) => confirmer(server, call.requestId),
119
+ audit: (entry) => this.host.audit?.({ ...entry, at: new Date().toISOString(), user: principal.user, client: principal.client }),
120
+ now: Date.now,
121
+ };
122
+ (0, tools_1.registerTools)(server, context);
123
+ for (const extension of this.host.extensions ?? [])
124
+ extension.register(server, context);
125
+ return server;
126
+ }
127
+ /** The live home of a signed-in user (connecting with their kept token). */
128
+ homeOf(user) {
129
+ const existing = this.homes.get(user);
130
+ if (existing)
131
+ return existing;
132
+ const record = this.state.current.users[user];
133
+ const address = this.host.miniserver();
134
+ if (!record || !address)
135
+ return undefined;
136
+ const home = this.newHome(address, user, { user, token: record.token }, record.clientUuid);
137
+ this.homes.set(user, home);
138
+ return home;
139
+ }
140
+ newHome(address, user, credentials, clientUuid) {
141
+ const home = new LoxoneHome_1.LoxoneHome(address, credentials, {
142
+ clientUuid,
143
+ clientInfo: `${this.host.serverName ?? 'loxone-mcp'} MCP`,
144
+ logger: quiet(this.log),
145
+ onToken: (token) => this.state.change((s) => (s.users[user] = { user, token, clientUuid })),
146
+ onTokenRejected: () => {
147
+ this.log?.warn(`MCP: the Loxone token of ${user} was rejected; they must sign in again`);
148
+ this.oauth.revokeUser(user);
149
+ void this.forgetUser(user);
150
+ },
151
+ });
152
+ return home;
153
+ }
154
+ /** Checks a Loxone sign-in by connecting as that user; on success this becomes their live home. */
155
+ async signIn(user, password) {
156
+ const address = this.host.miniserver();
157
+ if (!address)
158
+ return { ok: false, reason: 'unreachable', error: 'no Miniserver is set up' };
159
+ const clientUuid = this.state.current.users[user]?.clientUuid ?? (0, state_1.loxoneClientUuid)();
160
+ const home = this.newHome(address, user, { user, password }, clientUuid);
161
+ try {
162
+ await home.ready();
163
+ }
164
+ catch (error) {
165
+ await home.close(false);
166
+ if (error instanceof loxone_ts_client_1.LoxoneAuthenticationError || /401|403|auth|password|user/i.test(error.message))
167
+ return { ok: false, reason: 'wrong' };
168
+ return { ok: false, reason: 'unreachable', error: error.message };
169
+ }
170
+ const old = this.homes.get(user);
171
+ this.homes.set(user, home);
172
+ if (old && old !== home)
173
+ await old.close(true);
174
+ return { ok: true };
175
+ }
176
+ async forgetUser(user) {
177
+ const home = this.homes.get(user);
178
+ this.homes.delete(user);
179
+ this.state.change((s) => delete s.users[user]);
180
+ if (home)
181
+ await home.close(false);
182
+ }
183
+ }
184
+ exports.LoxoneMcp = LoxoneMcp;
185
+ /** loxone-ts-client's logger, fed into the host's (its debug and trace dropped). */
186
+ function quiet(log) {
187
+ if (!log)
188
+ return undefined;
189
+ return {
190
+ trace: () => undefined,
191
+ debug: () => undefined,
192
+ info: (m) => log.debug(`loxone: ${m}`),
193
+ warn: (m) => log.warn(`loxone: ${m}`),
194
+ error: (m) => log.error(`loxone: ${m}`),
195
+ };
196
+ }
197
+ //# sourceMappingURL=LoxoneMcp.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"LoxoneMcp.js","sourceRoot":"","sources":["../src/LoxoneMcp.ts"],"names":[],"mappings":";;;AACA,oEAAoE;AACpE,wEAAiF;AACjF,uDAA0E;AAC1E,oDAAiE;AACjE,wCAA6D;AAC7D,gDAAwD;AACxD,0DAA0E;AAC1E,kDAAuE;AAEvE,4CAAiE;AACjE,6CAA+F;AAC/F,yCAA8C;AAC9C,uCAAoC;AAEpC,kEAAkE;AACrD,QAAA,YAAY,GAAG;;;;4GAIgF,CAAC;AAO7G;;;;;GAKG;AACH,MAAa,SAAS;IAQD;IAPF,GAAG,CAAqB;IACxB,KAAK,CAAc;IACnB,KAAK,CAAc;IACnB,IAAI,CAAiB;IACrB,KAAK,GAAG,IAAI,GAAG,EAAsB,CAAC;IAEvD,YACmB,IAAa,EAC9B,UAA4B,EAAE;QADb,SAAI,GAAJ,IAAI,CAAS;QAG9B,IAAI,CAAC,GAAG,GAAG,IAAI,CAAC,GAAG,CAAC;QACpB,IAAI,CAAC,KAAK,GAAG,IAAI,mBAAW,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;QACzC,IAAI,CAAC,KAAK,GAAG,IAAI,yBAAW,CAAC,IAAI,CAAC,KAAK,EAAE,IAAI,CAAC,GAAG,CAAC,CAAC;QACnD,IAAI,CAAC,IAAI,GAAG,IAAI,+BAAc,CAC5B,IAAI,CAAC,KAAK,EACV;YACE,UAAU,EAAE,IAAI,CAAC,UAA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