@iobroker/mcp-server 1.3.0 → 1.5.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.
- package/README.md +92 -9
- package/build/inProcessClient.d.ts +10 -0
- package/build/inProcessClient.js +4 -11
- package/build/inProcessClient.js.map +1 -1
- package/build/index.d.ts +118 -18
- package/build/index.js +1419 -126
- package/build/index.js.map +1 -1
- package/build/types.d.ts +28 -2
- package/build/types.js +14 -0
- package/build/types.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -109,16 +109,44 @@ permissions regardless of which user authenticated. Give the Default User an ioB
|
|
|
109
109
|
the ACLs the MCP client should have.
|
|
110
110
|
|
|
111
111
|
### Permissions
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
112
|
+
All options that change the system are **off** by default; turn on only what the MCP client really needs.
|
|
113
|
+
|
|
114
|
+
**States and objects**
|
|
115
|
+
- **Allow setting states**: Allow MCP clients to write state values and to acknowledge system notifications (the
|
|
116
|
+
`set_state`, `set_states` and `clear_notifications` tools). Default: **on**. Which states can be written is
|
|
117
|
+
decided by the ACLs of the Default User. `set_states` checks the write permission of all states first and writes
|
|
118
|
+
nothing if one of them is not writable.
|
|
115
119
|
- **Mark setting states as destructive** (`setStateDestructive`): Declare `set_state` and `set_states` with
|
|
116
120
|
`destructiveHint: true`, so MCP clients can warn before a state is written. Default: **on**. When off, both tools
|
|
117
121
|
are declared as non-destructive writes (`readOnlyHint` stays `false`); whether a client still asks for
|
|
118
122
|
confirmation then depends on the client.
|
|
119
|
-
- **Allow object/file changes
|
|
120
|
-
`delete_object`, `create_state`, `create_scene`, `
|
|
121
|
-
tools). Default: **off**.
|
|
123
|
+
- **Allow object/file changes** (`allowObjectChange`): Allow MCP clients to create/modify/delete objects, aliases
|
|
124
|
+
and files (the `set_object`, `delete_object`, `create_state`, `create_scene`, `create_alias`, `write_file`,
|
|
125
|
+
`delete_file`, `rename_file` and `mkdir` tools). Default: **off**.
|
|
126
|
+
|
|
127
|
+
**System**
|
|
128
|
+
- **Allow controlling instances** (`allowInstanceControl`): Start, stop and restart adapter instances and change
|
|
129
|
+
their log level (`start_instance`, `stop_instance`, `restart_instance`, `set_log_level`). Default: **off**.
|
|
130
|
+
- **Allow managing adapters** (`allowAdapterManagement`): Add and delete instances and upgrade adapters from the
|
|
131
|
+
repository (`add_instance`, `delete_instance`, `upgrade_adapter`). Default: **off**.
|
|
132
|
+
- **Allow changing scripts** (`allowScriptChange`): Create, change, start/stop and delete scripts of the
|
|
133
|
+
javascript adapter and run code once (`set_script`, `enable_script`, `delete_script`, `run_script`). Reading
|
|
134
|
+
scripts (`list_scripts`, `get_script`) is always possible. Scripts run with full access to ioBroker. Default:
|
|
135
|
+
**off**.
|
|
136
|
+
- **Allow messages to adapters** (`sendToAllowlist`): Adapters (`telegram`) or instances (`backitup.0`) the
|
|
137
|
+
`send_to` tool may send messages to, separated by commas; `*` allows all. Default: empty, then there is no
|
|
138
|
+
`send_to` tool.
|
|
139
|
+
|
|
140
|
+
**Safety**
|
|
141
|
+
- **Ask for confirmation before dangerous actions** (`confirmDangerous`): MCP clients that support
|
|
142
|
+
[elicitation](https://modelcontextprotocol.io/specification/2025-06-18/client/elicitation) ask the user before an
|
|
143
|
+
object or instance is deleted, an instance stopped, an adapter upgraded or installed, a script saved or run, or a
|
|
144
|
+
message sent. Clients without elicitation rely on the `destructiveHint` of the tools and their own confirmation.
|
|
145
|
+
Default: **on**.
|
|
146
|
+
- **Allow download/upload links** (`transferLinks`): Tools may hand out short-lived links for data that is too large
|
|
147
|
+
for an MCP message, see [Large results and files](#large-results-and-files). Default: **on**.
|
|
148
|
+
|
|
149
|
+
**Developers**
|
|
122
150
|
- **Allow installing packages (developers only)** (`allowPackageInstall`): Offer the `install_package` tool, which
|
|
123
151
|
installs an adapter package on an ioBroker host - from npm, GitHub, a URL or a `.tgz` file - exactly like
|
|
124
152
|
*Install from custom URL / file* in ioBroker.admin (`iobroker url ...`). Default: **off**. This option is only
|
|
@@ -157,24 +185,43 @@ Point your MCP client at:
|
|
|
157
185
|
| `list_rooms` | List rooms (`enum.rooms.*`) with localized names and member details; optional `language` and `withIcons` |
|
|
158
186
|
| `list_functions` | List functions (`enum.functions.*`) with localized names and member details; optional `language` and `withIcons` |
|
|
159
187
|
| `history_query` | Query historical values (requires a history adapter); aggregations: `raw`, `min`, `max`, `avg`, `sum`, `count`, `minmax`, `percentile`, `quantile`, `integral` |
|
|
160
|
-
| `read_file` | Read a file from an adapter file storage (optional base64); large files are read in chunks via `offset`/`length` (default 512 KiB per call) — the result carries `size`, `truncated` and `nextOffset`
|
|
188
|
+
| `read_file` | Read a file from an adapter file storage (optional base64); large files are read in chunks via `offset`/`length` (default 512 KiB per call) — the result carries `size`, `truncated` and `nextOffset`; `download: true` returns a download link instead |
|
|
161
189
|
| `list_files` | List a directory in an adapter file storage |
|
|
162
190
|
| `file_exists` | Check whether a file exists in an adapter file storage |
|
|
163
191
|
| `get_logs` | Retrieve recent ioBroker log lines; optional filters by `level` (error/warn/info/debug), source `adapter` and start time (`from_ts`) |
|
|
164
192
|
| `write_log` | Write a message to the ioBroker log |
|
|
165
193
|
| `system_info` | Get system and js-controller information |
|
|
194
|
+
| `list_adapter_updates` | List installed adapters that have a newer version in the active repository |
|
|
195
|
+
| `list_notifications` | List the system notifications of the hosts (the bell in admin): disk space, crashed adapters, ... |
|
|
196
|
+
| `list_scripts` | List the scripts of the javascript adapter (without source) |
|
|
197
|
+
| `get_script` | Read a script including its source |
|
|
166
198
|
| `ping_host` | Diagnose connectivity to a network device: ICMP ping to `host` plus an optional TCP connect to `port` — useful to investigate adapter `ETIMEDOUT`/connection errors |
|
|
167
199
|
| `set_state` | Set the value of a state (value coerced to the state type) — requires *Allow setting states* |
|
|
168
200
|
| `set_states` | Set multiple states in one call (for scenes/group actions like "all lights off") — requires *Allow setting states* |
|
|
201
|
+
| `clear_notifications` | Acknowledge system notifications, optionally of one scope/category/instance — requires *Allow setting states* |
|
|
169
202
|
| `set_object` | Create/update an object (merges common/native) — requires *Allow object/file changes* |
|
|
170
203
|
| `delete_object` | Delete an object, optionally with all children — requires *Allow object/file changes* |
|
|
171
204
|
| `create_state` | Create a new state object with type/role/unit/min/max and optional initial value — requires *Allow object/file changes* |
|
|
172
205
|
| `create_scene` | Create or update a scene for the ioBroker `scenes` adapter (state/value pairs applied together) — requires *Allow object/file changes* |
|
|
173
|
-
| `
|
|
206
|
+
| `create_alias` | Create an alias (`alias.0.*`) pointing to a state, optionally with a separate write state — requires *Allow object/file changes* |
|
|
207
|
+
| `write_file` | Write a file to an adapter file storage, from `content` or from a file uploaded via `prepare_upload` (`upload_id`) — requires *Allow object/file changes* |
|
|
174
208
|
| `delete_file` | Delete a file from an adapter file storage — requires *Allow object/file changes* |
|
|
175
209
|
| `rename_file` | Rename/move a file within the same adapter file storage — requires *Allow object/file changes* |
|
|
176
210
|
| `mkdir` | Create a directory in an adapter file storage — requires *Allow object/file changes* |
|
|
177
|
-
| `
|
|
211
|
+
| `prepare_upload` | Get a one-time upload link for a file that is too large for a tool argument (e.g. a `.tgz`), for clients that can run shell commands — requires *Allow download/upload links* and *Allow object/file changes* or *Allow installing packages* |
|
|
212
|
+
| `install_package` | Install an adapter package (npm, GitHub, URL, `.tgz` from the file storage, as base64 or uploaded via `prepare_upload`) on a host and restart its enabled instances — requires *Allow installing packages*, developers only |
|
|
213
|
+
| `start_instance` | Start (enable) an instance — requires *Allow controlling instances* |
|
|
214
|
+
| `stop_instance` | Stop (disable) an instance — requires *Allow controlling instances* |
|
|
215
|
+
| `restart_instance` | Restart a running instance — requires *Allow controlling instances* |
|
|
216
|
+
| `set_log_level` | Change the log level of an instance, temporarily or persistently — requires *Allow controlling instances* |
|
|
217
|
+
| `add_instance` | Create an instance of an adapter from the repository (`iobroker add`) — requires *Allow managing adapters* |
|
|
218
|
+
| `delete_instance` | Delete an instance with its objects and states (`iobroker del`) — requires *Allow managing adapters* |
|
|
219
|
+
| `upgrade_adapter` | Upgrade an adapter to the repository or a given version (`iobroker upgrade`) — requires *Allow managing adapters* |
|
|
220
|
+
| `set_script` | Create a JavaScript/TypeScript script or change its source — requires *Allow changing scripts* |
|
|
221
|
+
| `enable_script` | Start or stop a script — requires *Allow changing scripts* |
|
|
222
|
+
| `delete_script` | Delete a script — requires *Allow changing scripts* |
|
|
223
|
+
| `run_script` | Run code once in the javascript adapter and return its log output (javascript ≥ 10.1.0) — requires *Allow changing scripts* |
|
|
224
|
+
| `send_to` | Send a message to an adapter instance (`sendTo`) and return the answer — only instances in *Allow messages to adapters* |
|
|
178
225
|
|
|
179
226
|
All object/state access runs with the permissions of the configured **Default User**. The write tools are only
|
|
180
227
|
registered when their respective permission option is enabled.
|
|
@@ -184,6 +231,33 @@ Every tool declares a JSON input schema and all four MCP behaviour hints (`readO
|
|
|
184
231
|
for confirmation before a writing tool runs. All reading tools are `readOnlyHint: true`; `ping_host` is the only
|
|
185
232
|
tool with `openWorldHint: true`, because it talks to hosts outside of ioBroker.
|
|
186
233
|
|
|
234
|
+
### Large results and files
|
|
235
|
+
MCP clients reject tool results above 1 MiB, and a model cannot pass megabytes of base64 as a tool argument. So:
|
|
236
|
+
|
|
237
|
+
- **Every result stays below the limit.** Lists (`get_states`, `search_objects`, `list_files`, `list_scripts`,
|
|
238
|
+
`history_query`) return as many entries as fit and add `truncated`, `total`, `nextOffset` and a `hint`; call
|
|
239
|
+
again with `offset` set to `nextOffset` for the next part. `get_logs` keeps the newest lines. Any other result
|
|
240
|
+
that is too large is replaced by a download link, or by an error asking to narrow the request down.
|
|
241
|
+
- **Download links** (`download_url`): a cut list carries a link to all of its entries as JSON, and `read_file`
|
|
242
|
+
with `download: true` returns a link to the whole file. Clients that can run shell commands (e.g. Claude Code)
|
|
243
|
+
fetch it with `curl -o <file> "<download_url>"`.
|
|
244
|
+
- **Upload links**: `prepare_upload` returns a link and an `upload_id`. The client uploads the file with
|
|
245
|
+
`curl -T <file> "<url>"` (`PUT` or `POST`, raw body, up to 100 MB) and passes the `upload_id` to `write_file` or
|
|
246
|
+
`install_package`. A link can be used once.
|
|
247
|
+
|
|
248
|
+
The links are `<mcp endpoint>/transfer/<token>`: the random token is the credential, so they work without the
|
|
249
|
+
login of the MCP endpoint, and they expire after 15 minutes. They are built from the address the client used, or
|
|
250
|
+
from *Public URL*. They are not available in-process (ioBroker.admin) and as a web extension with authentication
|
|
251
|
+
enabled in the web adapter, because the web adapter asks for a login first; the tools then say so.
|
|
252
|
+
|
|
253
|
+
### Prompts
|
|
254
|
+
MCP clients offer these as ready-made commands (e.g. as slash commands):
|
|
255
|
+
|
|
256
|
+
- `diagnose_adapter` (`instance`) - find out why an instance does not work: status, log, notifications,
|
|
257
|
+
connectivity and available updates.
|
|
258
|
+
- `room_overview` (`room`) - summary of the devices of a room and anything unusual.
|
|
259
|
+
- `create_automation` (`description`) - turn a description into a script for the javascript adapter.
|
|
260
|
+
|
|
187
261
|
### Resources & live updates (SSE)
|
|
188
262
|
|
|
189
263
|
States and objects are also exposed as MCP **resources** using the canonical ioBroker URI scheme, so clients
|
|
@@ -233,6 +307,15 @@ client calls it and its result is verified:
|
|
|
233
307
|
Placeholder for the next version (at the beginning of the line):
|
|
234
308
|
### **WORK IN PROGRESS**
|
|
235
309
|
-->
|
|
310
|
+
### 1.5.0 (2026-10-24)
|
|
311
|
+
* (@GermanBluefox) Tool results are kept below the 1 MiB limit of MCP clients: lists are paged with `offset`, other results are replaced by a download link
|
|
312
|
+
* (@GermanBluefox) Added download links (`read_file` with `download: true`, complete lists) and upload links (`prepare_upload`, used by `write_file` and `install_package`) for large data (option `transferLinks`)
|
|
313
|
+
|
|
314
|
+
### 1.4.0 (2026-10-23)
|
|
315
|
+
* (@GermanBluefox) Added tools to control instances, manage adapters, read/change/run scripts, read and acknowledge notifications, create aliases and send messages to adapters, each behind its own option (off by default)
|
|
316
|
+
* (@GermanBluefox) Added the prompts `diagnose_adapter`, `room_overview` and `create_automation`
|
|
317
|
+
* (@GermanBluefox) Dangerous actions ask the user for a confirmation if the client supports elicitation (option `confirmDangerous`)
|
|
318
|
+
|
|
236
319
|
### 1.3.0 (2026-10-23)
|
|
237
320
|
* (@GermanBluefox) Added the `install_package` tool (opt-in `allowPackageInstall`, only for developers): installs an adapter package from npm, GitHub, a URL or a `.tgz` file on a host
|
|
238
321
|
|
|
@@ -57,11 +57,21 @@ export interface InProcessMcpOptions {
|
|
|
57
57
|
setStateDestructive?: boolean;
|
|
58
58
|
/** Allow the object/file-changing tools (`create_state`, `set_object`, ...) (default: false). */
|
|
59
59
|
allowObjectChange?: boolean;
|
|
60
|
+
/** Allow starting/stopping/restarting instances and changing their log level (default: false). */
|
|
61
|
+
allowInstanceControl?: boolean;
|
|
62
|
+
/** Allow adding/deleting instances and upgrading adapters from the repository (default: false). */
|
|
63
|
+
allowAdapterManagement?: boolean;
|
|
60
64
|
/**
|
|
61
65
|
* Allow the `install_package` tool, which installs adapter packages on a host (default: false).
|
|
62
66
|
* Only relevant for adapter developers.
|
|
63
67
|
*/
|
|
64
68
|
allowPackageInstall?: boolean;
|
|
69
|
+
/** Allow creating/changing/deleting/running scripts of the javascript adapter (default: false). */
|
|
70
|
+
allowScriptChange?: boolean;
|
|
71
|
+
/** Adapters or instances `send_to` may address, comma separated, `*` for all (default: none, no tool). */
|
|
72
|
+
sendToAllowlist?: string;
|
|
73
|
+
/** Ask the user before dangerous actions if the client supports elicitation (default: true). */
|
|
74
|
+
confirmDangerous?: boolean;
|
|
65
75
|
/** Name reported to the server by the embedded client. */
|
|
66
76
|
clientName?: string;
|
|
67
77
|
/** Version reported to the server by the embedded client. */
|
package/build/inProcessClient.js
CHANGED
|
@@ -23,21 +23,14 @@ const index_1 = __importDefault(require("./index"));
|
|
|
23
23
|
* @returns a facade to list/call tools and to tear the connection down again
|
|
24
24
|
*/
|
|
25
25
|
async function createInProcessMcp(options) {
|
|
26
|
-
const
|
|
27
|
-
|
|
28
|
-
defaultUser: options.defaultUser,
|
|
29
|
-
language: options.language,
|
|
30
|
-
allowSetState: options.allowSetState,
|
|
31
|
-
allowObjectChange: options.allowObjectChange,
|
|
32
|
-
setStateDestructive: options.setStateDestructive,
|
|
33
|
-
allowPackageInstall: options.allowPackageInstall,
|
|
34
|
-
});
|
|
26
|
+
const { clientName, clientVersion, ...embedOptions } = options;
|
|
27
|
+
const mcp = index_1.default.createEmbedded(embedOptions);
|
|
35
28
|
const server = mcp.createInProcessServer();
|
|
36
29
|
const [clientTransport, serverTransport] = inMemory_js_1.InMemoryTransport.createLinkedPair();
|
|
37
30
|
await server.connect(serverTransport);
|
|
38
31
|
const client = new index_js_1.Client({
|
|
39
|
-
name:
|
|
40
|
-
version:
|
|
32
|
+
name: clientName || 'iobroker-inprocess-client',
|
|
33
|
+
version: clientVersion || '1.0.0',
|
|
41
34
|
}, { capabilities: {} });
|
|
42
35
|
await client.connect(clientTransport);
|
|
43
36
|
return {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"inProcessClient.js","sourceRoot":"","sources":["../src/inProcessClient.ts"],"names":[],"mappings":";;;;;
|
|
1
|
+
{"version":3,"file":"inProcessClient.js","sourceRoot":"","sources":["../src/inProcessClient.ts"],"names":[],"mappings":";;;;;AAsHA,gDAmDC;AAzKD;;;;;;;;GAQG;AACH,wEAAmE;AACnE,uEAA0E;AAC1E,oDAAgC;AAqGhC;;;;;GAKG;AACI,KAAK,UAAU,kBAAkB,CAAC,OAA4B;IACjE,MAAM,EAAE,UAAU,EAAE,aAAa,EAAE,GAAG,YAAY,EAAE,GAAG,OAAO,CAAC;IAC/D,MAAM,GAAG,GAAG,eAAS,CAAC,cAAc,CAAC,YAAY,CAAC,CAAC;IAEnD,MAAM,MAAM,GAAG,GAAG,CAAC,qBAAqB,EAAE,CAAC;IAC3C,MAAM,CAAC,eAAe,EAAE,eAAe,CAAC,GAAG,+BAAiB,CAAC,gBAAgB,EAAE,CAAC;IAChF,MAAM,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAEtC,MAAM,MAAM,GAAG,IAAI,iBAAM,CACrB;QACI,IAAI,EAAE,UAAU,IAAI,2BAA2B;QAC/C,OAAO,EAAE,aAAa,IAAI,OAAO;KACpC,EACD,EAAE,YAAY,EAAE,EAAE,EAAE,CACvB,CAAC;IACF,MAAM,MAAM,CAAC,OAAO,CAAC,eAAe,CAAC,CAAC;IAEtC,OAAO;QACH,KAAK,CAAC,SAAS;YACX,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,SAAS,EAAE,CAAC;YACrC,OAAO,CAAC,GAAG,CAAC,KAAK,IAAI,EAAE,CAAC,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;gBAClC,IAAI,EAAE,IAAI,CAAC,IAAI;gBACf,WAAW,EAAE,IAAI,CAAC,WAAW;gBAC7B,WAAW,EAAG,IAAI,CAAC,WAAuC,IAAI,EAAE,IAAI,EAAE,QAAQ,EAAE,UAAU,EAAE,EAAE,EAAE;gBAChG,KAAK,EAAE,IAAI,CAAC,KAAK;gBACjB,WAAW,EAAE,IAAI,CAAC,WAAW;aAChC,CAAC,CAAC,CAAC;QACR,CAAC;QACD,KAAK,CAAC,QAAQ,CAAC,IAAY,EAAE,IAA8B;YACvD,MAAM,GAAG,GAAG,MAAM,MAAM,CAAC,QAAQ,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,IAAI,EAAE,EAAE,CAAC,CAAC;YACnE,MAAM,MAAM,GAAI,GAAG,CAAC,OAA0C,IAAI,EAAE,CAAC;YACrE,MAAM,IAAI,GAAG,MAAM;iBACd,MAAM,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAI,KAAK,MAAM,IAAI,OAAO,KAAK,CAAC,IAAI,KAAK,QAAQ,CAAC;iBACxE,GAAG,CAAC,KAAK,CAAC,EAAE,CAAC,KAAK,CAAC,IAAc,CAAC;iBAClC,IAAI,CAAC,IAAI,CAAC,CAAC;YAChB,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,CAAC,CAAC,GAAG,CAAC,OAAO,EAAE,CAAC;QAC5C,CAAC;QACD,KAAK,CAAC,KAAK;YACP,IAAI,CAAC;gBACD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACzB,CAAC;YAAC,MAAM,CAAC;gBACL,SAAS;YACb,CAAC;YACD,IAAI,CAAC;gBACD,MAAM,MAAM,CAAC,KAAK,EAAE,CAAC;YACzB,CAAC;YAAC,MAAM,CAAC;gBACL,SAAS;YACb,CAAC;YACD,GAAG,CAAC,MAAM,EAAE,CAAC;QACjB,CAAC;KACJ,CAAC;AACN,CAAC"}
|
package/build/index.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { Server as HttpServer } from 'node:http';
|
|
|
2
2
|
import type { Server as HttpsServer } from 'node:https';
|
|
3
3
|
import { type Express } from 'express';
|
|
4
4
|
import { McpServer as McpSdkServer } from '@modelcontextprotocol/sdk/server/mcp.js';
|
|
5
|
+
import { type McpPermissions } from './types';
|
|
5
6
|
import { createInProcessMcp } from './inProcessClient';
|
|
6
7
|
export default class McpServer {
|
|
7
8
|
private readonly adapter;
|
|
@@ -40,21 +41,27 @@ export default class McpServer {
|
|
|
40
41
|
private oauth2?;
|
|
41
42
|
/** Installations started by `install_package`, keyed by the `cmdExec` session id. */
|
|
42
43
|
private readonly cmdSessions;
|
|
44
|
+
/** Path of the MCP endpoint, e.g. `/mcp`. */
|
|
45
|
+
private readonly mcpPath;
|
|
46
|
+
/**
|
|
47
|
+
* Whether tools may hand out download/upload links (`<mcp>/transfer/<token>`). Needs our own HTTP
|
|
48
|
+
* routes; not as a web extension with authentication, where the web adapter asks for a login first.
|
|
49
|
+
*/
|
|
50
|
+
private readonly linksAvailable;
|
|
51
|
+
/** Why links are not available, for the answer of the tools. */
|
|
52
|
+
private readonly linksUnavailableReason;
|
|
53
|
+
/** Active download and upload links, keyed by their token. */
|
|
54
|
+
private readonly transfers;
|
|
55
|
+
/** Temporary folder for the files of the links, created on first use. */
|
|
56
|
+
private transferDir?;
|
|
57
|
+
private transferTimer?;
|
|
43
58
|
constructor(server: HttpServer | HttpsServer | null, webSettings: {
|
|
44
59
|
secure?: boolean;
|
|
45
60
|
port?: number | string;
|
|
46
61
|
defaultUser?: string;
|
|
47
62
|
auth?: boolean;
|
|
48
63
|
language?: ioBroker.Languages;
|
|
49
|
-
|
|
50
|
-
allowSetState?: boolean;
|
|
51
|
-
/** Explicit override for the destructive hint of `set_state`/`set_states` (embedded mode). */
|
|
52
|
-
setStateDestructive?: boolean;
|
|
53
|
-
/** Explicit override for the object/file-changing tool permission (embedded mode). */
|
|
54
|
-
allowObjectChange?: boolean;
|
|
55
|
-
/** Explicit override for the package installation permission (embedded mode). */
|
|
56
|
-
allowPackageInstall?: boolean;
|
|
57
|
-
}, adapter: ioBroker.Adapter, instanceSettings: ioBroker.InstanceObject | null, app?: Express);
|
|
64
|
+
} & Partial<McpPermissions>, adapter: ioBroker.Adapter, instanceSettings: ioBroker.InstanceObject | null, app?: Express);
|
|
58
65
|
/**
|
|
59
66
|
* Build a fresh MCP SDK server with all ioBroker tools registered, ready to be connected to an
|
|
60
67
|
* arbitrary transport. Used for in-process embedding (e.g. by ioBroker.admin) over an
|
|
@@ -71,20 +78,12 @@ export default class McpServer {
|
|
|
71
78
|
* @param options.adapter The host adapter into which the MCP server is embedded. Used for receiving state/object changes and logs, and for performing actions with the host adapter's permissions.
|
|
72
79
|
* @param options.defaultUser Default user
|
|
73
80
|
* @param options.language Language
|
|
74
|
-
* @param options.allowSetState Allow the state-writing tools `set_state`/`set_states` (opt-out, default true)
|
|
75
|
-
* @param options.allowObjectChange Allow the object/file-changing tools (opt-in, default false)
|
|
76
|
-
* @param options.setStateDestructive Declare `set_state`/`set_states` as destructive (default true)
|
|
77
|
-
* @param options.allowPackageInstall Allow the `install_package` tool (opt-in, default false, developers only)
|
|
78
81
|
*/
|
|
79
82
|
static createEmbedded(options: {
|
|
80
83
|
adapter: ioBroker.Adapter;
|
|
81
84
|
defaultUser?: `system.user.${string}`;
|
|
82
85
|
language?: ioBroker.Languages;
|
|
83
|
-
|
|
84
|
-
allowObjectChange?: boolean;
|
|
85
|
-
setStateDestructive?: boolean;
|
|
86
|
-
allowPackageInstall?: boolean;
|
|
87
|
-
}): McpServer;
|
|
86
|
+
} & Partial<McpPermissions>): McpServer;
|
|
88
87
|
private initRoutes;
|
|
89
88
|
/**
|
|
90
89
|
* Guard for the MCP endpoint when authentication is enabled (standalone mode). By the time this
|
|
@@ -190,6 +189,7 @@ export default class McpServer {
|
|
|
190
189
|
* Create a new MCP SDK server with all ioBroker tools registered.
|
|
191
190
|
*
|
|
192
191
|
* @param subscriptions the per-session set of subscribed state ids (mutated by subscribe/unsubscribe)
|
|
192
|
+
* @param baseUrl public address of this server, for download/upload links (none in-process)
|
|
193
193
|
*/
|
|
194
194
|
private createServer;
|
|
195
195
|
/** Build the result entry for one state. */
|
|
@@ -309,6 +309,106 @@ export default class McpServer {
|
|
|
309
309
|
* ioBroker.admin installs from a custom URL or a .tgz file, and wait for the result.
|
|
310
310
|
*/
|
|
311
311
|
private installPackage;
|
|
312
|
+
/** Normalize a host name (with or without `system.host.`) and check that the host exists. */
|
|
313
|
+
private resolveHost;
|
|
314
|
+
/**
|
|
315
|
+
* Run an ioBroker CLI command on a host via `cmdExec` and wait for its exit code. The host reports
|
|
316
|
+
* the output and the exit code as messages to this instance, see {@link onMessage}.
|
|
317
|
+
*
|
|
318
|
+
* @param host host name without `system.host.`
|
|
319
|
+
* @param command the CLI arguments, e.g. `upgrade hue@3.9.0`
|
|
320
|
+
* @param timeoutSeconds how long to wait; the command keeps running on the host after that
|
|
321
|
+
* @param files files sent along with the command (the command refers to them by name)
|
|
322
|
+
*/
|
|
323
|
+
private runHostCommand;
|
|
324
|
+
/** Request something from a host (`getNotifications`, ...) and wait for the answer. */
|
|
325
|
+
private hostRequest;
|
|
326
|
+
/** Like admin after an installation: touching the instance objects makes the controller restart them. */
|
|
327
|
+
private restartAdapterInstances;
|
|
328
|
+
/** Read an instance object by its short id (`hue.0`) or full id (`system.adapter.hue.0`). */
|
|
329
|
+
private getInstance;
|
|
330
|
+
/** Start (enable) or stop (disable) an instance. */
|
|
331
|
+
private setInstanceEnabled;
|
|
332
|
+
/** Restart a running instance. */
|
|
333
|
+
private restartInstance;
|
|
334
|
+
/**
|
|
335
|
+
* Change the log level of an instance: temporarily via its `logLevel` state (no restart, until the
|
|
336
|
+
* next start), or persistently in the instance object (restarts the instance).
|
|
337
|
+
*/
|
|
338
|
+
private setLogLevel;
|
|
339
|
+
/** Check an adapter name, as the CLI receives it as an argument. */
|
|
340
|
+
private static checkAdapterName;
|
|
341
|
+
/** Create an instance of an adapter (installs the adapter from the repository if necessary). */
|
|
342
|
+
private addInstance;
|
|
343
|
+
/** Delete an instance with its objects and states (on the host it runs on). */
|
|
344
|
+
private deleteInstance;
|
|
345
|
+
/** Upgrade an installed adapter to the repository version (or the given one). */
|
|
346
|
+
private upgradeAdapter;
|
|
347
|
+
/** List the installed adapters that have a newer version in the active repository. */
|
|
348
|
+
private listAdapterUpdates;
|
|
349
|
+
/**
|
|
350
|
+
* Read the JSON of the active repositories from `system.repositories` (or of all repositories if none
|
|
351
|
+
* is marked active). An adapter present in several repos is kept once (first/active repo wins). This
|
|
352
|
+
* matters when the user has custom repos active next to the default one.
|
|
353
|
+
*/
|
|
354
|
+
private getRepositoryJson;
|
|
355
|
+
/** Read the current notifications of one or all hosts, one entry per category and instance. */
|
|
356
|
+
private listNotifications;
|
|
357
|
+
/** Acknowledge (delete) notifications on a host, optionally only of one scope/category/instance. */
|
|
358
|
+
private clearNotifications;
|
|
359
|
+
/**
|
|
360
|
+
* Normalize a script id: `script.js.common.lights`, `common.lights` or `lights` (folder `common`).
|
|
361
|
+
* Every segment is reduced to the characters the javascript editor uses for ids.
|
|
362
|
+
*/
|
|
363
|
+
private static scriptId;
|
|
364
|
+
/** Summary of a script object, optionally with its source. */
|
|
365
|
+
private scriptInfo;
|
|
366
|
+
/** Read a script object, failing if it is missing or not a script. */
|
|
367
|
+
private getScriptObject;
|
|
368
|
+
/** List the scripts of the javascript adapter (without their source). */
|
|
369
|
+
private listScripts;
|
|
370
|
+
/**
|
|
371
|
+
* Create a script or change the source of an existing one. Blockly and Rules scripts keep their
|
|
372
|
+
* blocks in the source, so they are not changed. New scripts start disabled unless `enabled` is given.
|
|
373
|
+
*/
|
|
374
|
+
private setScript;
|
|
375
|
+
/** Enable (start) or disable (stop) a script. */
|
|
376
|
+
private enableScript;
|
|
377
|
+
/** Delete a script. */
|
|
378
|
+
private deleteScript;
|
|
379
|
+
/**
|
|
380
|
+
* Run code once in the javascript adapter (its `execute` message) and return what it logged. Nothing
|
|
381
|
+
* is stored; timers and subscriptions are cleaned up after `timeout`.
|
|
382
|
+
*/
|
|
383
|
+
private runScript;
|
|
384
|
+
/** Whether `send_to` may address this instance (by adapter name, instance or `*`). */
|
|
385
|
+
private isSendToAllowed;
|
|
386
|
+
/** Send a message to an adapter instance (`sendTo`) and return its answer. */
|
|
387
|
+
private sendToInstance;
|
|
388
|
+
/**
|
|
389
|
+
* Create an alias (`alias.0.*`) that points to another state. Type, role, unit and limits are copied
|
|
390
|
+
* from the target unless given.
|
|
391
|
+
*/
|
|
392
|
+
private createAlias;
|
|
393
|
+
/**
|
|
394
|
+
* Create a download link for `data`, or an upload link when `data` is undefined, and return its
|
|
395
|
+
* token. The file lives in a temporary folder until the link expires (or the upload is used).
|
|
396
|
+
*/
|
|
397
|
+
private createTransfer;
|
|
398
|
+
/** The public URL of a download or upload link. */
|
|
399
|
+
private transferUrl;
|
|
400
|
+
/** Remove a link and its file. */
|
|
401
|
+
private removeTransfer;
|
|
402
|
+
/** Remove the expired links. */
|
|
403
|
+
private cleanupTransfers;
|
|
404
|
+
/** `GET <mcp>/transfer/<token>`: send the file of a download link. */
|
|
405
|
+
private handleDownload;
|
|
406
|
+
/** `PUT`/`POST <mcp>/transfer/<token>`: receive the file of an upload link (raw body, e.g. `curl -T`). */
|
|
407
|
+
private handleUpload;
|
|
408
|
+
/** Write the raw body of a request to a file and return its size. */
|
|
409
|
+
private static receiveBody;
|
|
410
|
+
/** Get a received upload by its id, failing if it is unknown, expired or still empty. */
|
|
411
|
+
private getUpload;
|
|
312
412
|
/** Resolve the member ids of a room/function enum matched by id or (localized) name. */
|
|
313
413
|
private getEnumMembers;
|
|
314
414
|
/** Normalize an ioBroker name (string or {en, de, ...}) to a plain string. */
|