@thinremote/thinr-cli 1.3.1 → 1.3.3

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/CHANGELOG.md CHANGED
@@ -1,5 +1,40 @@
1
1
  # Changelog
2
2
 
3
+ ## [1.3.3] - 2026-09-24
4
+
5
+ ### Changed
6
+
7
+ - MCP tools take the target device as `device_id`. A tool argument named
8
+ `device` never reaches this server through Claude Desktop's remote-devices
9
+ bridge, which claims that name for its own call routing and strips it, so
10
+ every tool needing a device failed with `device is required` however the
11
+ caller spelled the call, while tools without one worked. Reproduced on one
12
+ machine with one binary: a direct JSON-RPC call succeeded, the same call
13
+ through Claude Desktop arrived without the field, and renaming the argument
14
+ fixed it with nothing else changed. `device` is no longer accepted.
15
+
16
+ ## [1.3.2] - 2026-09-24
17
+
18
+ ### Fixed
19
+
20
+ - Device properties and device status now honour the `user` argument.
21
+ `thinr_property_get`, `thinr_property_set` and the playbook `property`
22
+ actions accepted it but addressed the active profile's own account, the
23
+ same gap fixed for resources in 1.3.1.
24
+
25
+ ### Changed
26
+
27
+ - Account-scoped API paths are built in one place (`lib/paths.js`): the
28
+ `/v{1,2,3}/users/{account}` prefixes and the device prefix, all resolving
29
+ the account through a single `resolveUser`. Five modules carried private
30
+ copies of the same three lines and four more interpolated the account by
31
+ hand. A test fails the build if any module starts doing that again, which
32
+ is what keeps the account from being silently dropped: omitting it
33
+ produces a URL that works against your own account and only breaks when
34
+ acting on behalf of another.
35
+ - Not-found errors from properties and status name the account they looked
36
+ in, matching the resource helpers.
37
+
3
38
  ## [1.3.1] - 2026-09-24
4
39
 
5
40
  ### Fixed
package/lib/alarms.js CHANGED
@@ -1,10 +1,6 @@
1
1
  import api from './api.js';
2
2
  import { apiError } from './errors.js';
3
- import { requireConfig } from './config.js';
4
-
5
- function resolveUser(user) {
6
- return user || requireConfig().username;
7
- }
3
+ import { v1 } from './paths.js';
8
4
 
9
5
  // Backend enums (see backend/src/thinger/features/alarms/alarm_rule.hpp).
10
6
  // Exported so the dashboard can render labels/colors without re-deriving
@@ -114,7 +110,6 @@ export async function getAlarmInstances({
114
110
  sort,
115
111
  order,
116
112
  } = {}) {
117
- const apiUser = resolveUser(user);
118
113
  const params = new URLSearchParams();
119
114
  params.set('count', String(count));
120
115
  params.set('index', String(index));
@@ -124,9 +119,7 @@ export async function getAlarmInstances({
124
119
  appendMulti(params, 'state', state);
125
120
  appendMulti(params, 'severity', severity);
126
121
  try {
127
- const res = await api.get(
128
- `/v1/users/${apiUser}/alarms/instances?${params.toString()}`,
129
- );
122
+ const res = await api.get(`${v1(user)}/alarms/instances?${params.toString()}`);
130
123
  return Array.isArray(res.data) ? res.data : [];
131
124
  } catch (e) {
132
125
  throw apiError(e);
@@ -137,9 +130,8 @@ export async function getAlarmInstances({
137
130
  // server seeds zeros for every known state so consumers can render a
138
131
  // stable layout without null-checks.
139
132
  export async function getAlarmInstanceStats({ user = null } = {}) {
140
- const apiUser = resolveUser(user);
141
133
  try {
142
- const res = await api.get(`/v1/users/${apiUser}/alarms/instances/stats`);
134
+ const res = await api.get(`${v1(user)}/alarms/instances/stats`);
143
135
  return res.data || {};
144
136
  } catch (e) {
145
137
  throw apiError(e);
@@ -147,11 +139,8 @@ export async function getAlarmInstanceStats({ user = null } = {}) {
147
139
  }
148
140
 
149
141
  export async function getAlarmInstance(instance, { user = null } = {}) {
150
- const apiUser = resolveUser(user);
151
142
  try {
152
- const res = await api.get(
153
- `/v1/users/${apiUser}/alarms/instances/${encodeURIComponent(instance)}`,
154
- );
143
+ const res = await api.get(`${v1(user)}/alarms/instances/${encodeURIComponent(instance)}`);
155
144
  return res.data;
156
145
  } catch (e) {
157
146
  throw apiError(e, { notFound: `Alarm instance not found: ${instance}` });
@@ -162,10 +151,9 @@ export async function getAlarmInstance(instance, { user = null } = {}) {
162
151
  // (see UPDATE_SCHEMA in alarms_instances.cpp): name, description, state,
163
152
  // annotation, reactivation. Anything else is rejected.
164
153
  export async function updateAlarmInstance(instance, body, { user = null } = {}) {
165
- const apiUser = resolveUser(user);
166
154
  try {
167
155
  const res = await api.put(
168
- `/v1/users/${apiUser}/alarms/instances/${encodeURIComponent(instance)}`,
156
+ `${v1(user)}/alarms/instances/${encodeURIComponent(instance)}`,
169
157
  body,
170
158
  );
171
159
  return res.data;
@@ -175,11 +163,8 @@ export async function updateAlarmInstance(instance, body, { user = null } = {})
175
163
  }
176
164
 
177
165
  export async function deleteAlarmInstance(instance, { user = null } = {}) {
178
- const apiUser = resolveUser(user);
179
166
  try {
180
- await api.delete(
181
- `/v1/users/${apiUser}/alarms/instances/${encodeURIComponent(instance)}`,
182
- );
167
+ await api.delete(`${v1(user)}/alarms/instances/${encodeURIComponent(instance)}`);
183
168
  return true;
184
169
  } catch (e) {
185
170
  throw apiError(e, { notFound: `Alarm instance not found: ${instance}` });
@@ -187,14 +172,11 @@ export async function deleteAlarmInstance(instance, { user = null } = {}) {
187
172
  }
188
173
 
189
174
  export async function getAlarmRules({ user = null, count = 200, index = 0 } = {}) {
190
- const apiUser = resolveUser(user);
191
175
  const params = new URLSearchParams();
192
176
  params.set('count', String(count));
193
177
  params.set('index', String(index));
194
178
  try {
195
- const res = await api.get(
196
- `/v1/users/${apiUser}/alarms/rules?${params.toString()}`,
197
- );
179
+ const res = await api.get(`${v1(user)}/alarms/rules?${params.toString()}`);
198
180
  return Array.isArray(res.data) ? res.data : [];
199
181
  } catch (e) {
200
182
  throw apiError(e);
@@ -202,11 +184,8 @@ export async function getAlarmRules({ user = null, count = 200, index = 0 } = {}
202
184
  }
203
185
 
204
186
  export async function getAlarmRule(rule, { user = null } = {}) {
205
- const apiUser = resolveUser(user);
206
187
  try {
207
- const res = await api.get(
208
- `/v1/users/${apiUser}/alarms/rules/${encodeURIComponent(rule)}`,
209
- );
188
+ const res = await api.get(`${v1(user)}/alarms/rules/${encodeURIComponent(rule)}`);
210
189
  return res.data;
211
190
  } catch (e) {
212
191
  throw apiError(e, { notFound: `Alarm rule not found: ${rule}` });
@@ -217,9 +196,8 @@ export async function getAlarmRule(rule, { user = null } = {}) {
217
196
  // `name`, `enabled` and an optional `config` object — see CREATE_SCHEMA
218
197
  // in alarms_rules.cpp for the full shape.
219
198
  export async function createAlarmRule(body, { user = null } = {}) {
220
- const apiUser = resolveUser(user);
221
199
  try {
222
- const res = await api.post(`/v1/users/${apiUser}/alarms/rules`, body);
200
+ const res = await api.post(`${v1(user)}/alarms/rules`, body);
223
201
  return res.data;
224
202
  } catch (e) {
225
203
  throw apiError(e);
@@ -227,12 +205,8 @@ export async function createAlarmRule(body, { user = null } = {}) {
227
205
  }
228
206
 
229
207
  export async function updateAlarmRule(rule, body, { user = null } = {}) {
230
- const apiUser = resolveUser(user);
231
208
  try {
232
- const res = await api.put(
233
- `/v1/users/${apiUser}/alarms/rules/${encodeURIComponent(rule)}`,
234
- body,
235
- );
209
+ const res = await api.put(`${v1(user)}/alarms/rules/${encodeURIComponent(rule)}`, body);
236
210
  return res.data;
237
211
  } catch (e) {
238
212
  throw apiError(e, { notFound: `Alarm rule not found: ${rule}` });
@@ -240,11 +214,8 @@ export async function updateAlarmRule(rule, body, { user = null } = {}) {
240
214
  }
241
215
 
242
216
  export async function deleteAlarmRule(rule, { user = null } = {}) {
243
- const apiUser = resolveUser(user);
244
217
  try {
245
- await api.delete(
246
- `/v1/users/${apiUser}/alarms/rules/${encodeURIComponent(rule)}`,
247
- );
218
+ await api.delete(`${v1(user)}/alarms/rules/${encodeURIComponent(rule)}`);
248
219
  return true;
249
220
  } catch (e) {
250
221
  throw apiError(e, { notFound: `Alarm rule not found: ${rule}` });
package/lib/auth.js CHANGED
@@ -7,6 +7,7 @@ import { label, success, warning, error as errorStyle, info } from './format.js'
7
7
 
8
8
  import api, { setBaseURL } from './api.js';
9
9
  import { OAUTH, TIMEOUTS } from './constants.js';
10
+ import { v1 } from './paths.js';
10
11
 
11
12
  const OAUTH_CLIENT_ID = OAUTH.CLIENT_ID;
12
13
  const OAUTH_DEVICE_CODE_TIMEOUT_MS = TIMEOUTS.OAUTH_DEVICE_CODE_MS;
@@ -89,14 +90,14 @@ async function authenticateWithUserPass() {
89
90
  // Replace any existing token with a fresh permanent one
90
91
  spinner.text = 'Preparing user token...';
91
92
  try {
92
- await api.delete(`/v1/users/${username}/tokens/ThinRemote`);
93
+ await api.delete(`${v1(username)}/tokens/ThinRemote`);
93
94
  } catch (error) {
94
95
  if (error.response && error.response.status !== 404) throw error;
95
96
  }
96
97
 
97
98
  spinner.text = 'Creating new user token...';
98
99
  const createTokenResponse = await api.post(
99
- `/v1/users/${username}/tokens`,
100
+ `${v1(username)}/tokens`,
100
101
  {
101
102
  enabled: true,
102
103
  allow: { '*': { '*': '*' } },
@@ -234,7 +235,7 @@ export async function deleteToken() {
234
235
  const spinner = ora('Deleting user token...').start();
235
236
 
236
237
  try {
237
- await api.delete(`/v1/users/${config.username}/tokens/ThinRemote`);
238
+ await api.delete(`${v1(config.username)}/tokens/ThinRemote`);
238
239
  spinner.succeed('Token deleted successfully');
239
240
  } catch (error) {
240
241
  if (error.response && error.response.status === 404) {
package/lib/bucket.js CHANGED
@@ -1,10 +1,6 @@
1
1
  import api from './api.js';
2
2
  import { apiError } from './errors.js';
3
- import { requireConfig } from './config.js';
4
-
5
- function resolveUser(user) {
6
- return user || requireConfig().username;
7
- }
3
+ import { v2, v3 } from './paths.js';
8
4
 
9
5
  /**
10
6
  * Query an arbitrary time-series bucket declared in a product profile.
@@ -60,7 +56,6 @@ export async function getBucketData({
60
56
  group_by,
61
57
  } = {}) {
62
58
  if (!bucket) throw new Error('bucket is required');
63
- const apiUser = resolveUser(user);
64
59
  const params = { items, sort };
65
60
  if (minutes) {
66
61
  params.min_ts = Date.now() - minutes * 60 * 1000;
@@ -75,8 +70,8 @@ export async function getBucketData({
75
70
  if (fields) params.fields = fields;
76
71
 
77
72
  const url = device
78
- ? `/v3/users/${apiUser}/devices/${device}/buckets/${bucket}/data`
79
- : `/v2/users/${apiUser}/buckets/${bucket}/data`;
73
+ ? `${v3(user)}/devices/${device}/buckets/${bucket}/data`
74
+ : `${v2(user)}/buckets/${bucket}/data`;
80
75
 
81
76
  try {
82
77
  const res = await api.get(url, { params });
@@ -2,6 +2,7 @@
2
2
  import WebSocket from 'ws';
3
3
  import { randomUUID } from 'crypto';
4
4
  import { TIMEOUTS } from './constants.js';
5
+ import { device } from './paths.js';
5
6
 
6
7
  /**
7
8
  * One-shot execution of a shell command on a device over the IOTMP
@@ -79,7 +80,7 @@ export class CommandStream {
79
80
  const { server, apiUser, deviceId, cmd, timeout } = this.opts;
80
81
  const params = new URLSearchParams({ cmd });
81
82
  if (timeout && timeout > 0) params.set('timeout', String(timeout));
82
- return `wss://${server}/v3/users/${apiUser}/devices/${deviceId}/resources/${this.resource}?${params}`;
83
+ return `wss://${server}${device(apiUser, deviceId)}/resources/${this.resource}?${params}`;
83
84
  }
84
85
 
85
86
  _openSocket() {
package/lib/config.js CHANGED
@@ -164,6 +164,15 @@ export function readConfig() {
164
164
  * via classifyError. Replaces the same boilerplate that used to live
165
165
  * at the top of every helper in lib/.
166
166
  */
167
+ /**
168
+ * The account an API call is addressed to: an explicit one when acting on
169
+ * behalf of another account, the active profile's own otherwise. Single
170
+ * source of truth — every path in lib/paths.js goes through it.
171
+ */
172
+ export function resolveUser(user) {
173
+ return user || requireConfig().username;
174
+ }
175
+
167
176
  export function requireConfig() {
168
177
  const config = readConfig();
169
178
  if (!config.token || !config.server || !config.username) {
package/lib/console.js CHANGED
@@ -3,6 +3,7 @@ import { requireConfig } from './config.js';
3
3
  import { ensureFreshToken } from './auth.js';
4
4
  import api from './api.js';
5
5
  import { warning, error as errorStyle } from './format.js';
6
+ import { device } from './paths.js';
6
7
 
7
8
  /**
8
9
  * Creates a WebSocket connection to a device terminal. Returns a
@@ -14,9 +15,10 @@ import { warning, error as errorStyle } from './format.js';
14
15
  * never calls process.exit.
15
16
  *
16
17
  * @param {string} deviceId - The ID of the device to connect to
18
+ * @param {string} [user] - Account that owns the device (defaults to the active profile)
17
19
  * @returns {Promise<number>} Exit code (0 on clean close)
18
20
  */
19
- export async function connectToDeviceConsole(deviceId) {
21
+ export async function connectToDeviceConsole(deviceId, user) {
20
22
  const config = requireConfig();
21
23
 
22
24
  // WS handshakes lack the refresh-on-401 retry that api.js gives
@@ -25,7 +27,7 @@ export async function connectToDeviceConsole(deviceId) {
25
27
  const token = (await ensureFreshToken()) || config.token;
26
28
 
27
29
  const sessionId = createUUID();
28
- const wsUrl = `wss://${config.server}/v3/users/${config.username}/devices/${deviceId}/resources/$terminal/${sessionId}?raw=1`;
30
+ const wsUrl = `wss://${config.server}${device(user, deviceId)}/resources/$terminal/${sessionId}?raw=1`;
29
31
  const ws = new WebSocket(wsUrl, {
30
32
  headers: { Authorization: `Bearer ${token}` },
31
33
  });
@@ -46,7 +48,7 @@ export async function connectToDeviceConsole(deviceId) {
46
48
  return new Promise((resolve, reject) => {
47
49
  ws.on('open', () => {
48
50
  updateTerminalSize(
49
- config,
51
+ user,
50
52
  deviceId,
51
53
  sessionId,
52
54
  process.stdout.columns,
@@ -55,7 +57,7 @@ export async function connectToDeviceConsole(deviceId) {
55
57
 
56
58
  process.stdout.on('resize', () => {
57
59
  updateTerminalSize(
58
- config,
60
+ user,
59
61
  deviceId,
60
62
  sessionId,
61
63
  process.stdout.columns,
@@ -130,15 +132,15 @@ export async function connectToDeviceConsole(deviceId) {
130
132
 
131
133
  /**
132
134
  * Update terminal size on remote device
133
- * @param {Object} config - Configuration object
135
+ * @param {string|undefined} user - Account that owns the device
134
136
  * @param {string} deviceId - Device ID
135
137
  * @param {string} sessionId - Session ID
136
138
  * @param {number} cols - Number of columns
137
139
  * @param {number} rows - Number of rows
138
140
  */
139
- async function updateTerminalSize(config, deviceId, sessionId, cols, rows) {
141
+ async function updateTerminalSize(user, deviceId, sessionId, cols, rows) {
140
142
  try {
141
- const url = `/v3/users/${config.username}/devices/${deviceId}/resources/$terminal/${sessionId}/params`;
143
+ const url = `${device(user, deviceId)}/resources/$terminal/${sessionId}/params`;
142
144
 
143
145
  await api.post(url, {
144
146
  size: {
@@ -3,6 +3,7 @@ import WebSocket from 'ws';
3
3
  import { readConfig } from '../config.js';
4
4
  import { refreshToken } from '../auth.js';
5
5
  import { debugCount, debugLog } from '../debug-log.js';
6
+ import { v2 } from '../paths.js';
6
7
 
7
8
  // Single shared websocket to /v2/users/{user}/events. Both fleet
8
9
  // monitoring and product metrics live on the same endpoint with the
@@ -99,14 +100,18 @@ class EventStream {
99
100
  // background; await it here so the next attempt uses the fresh
100
101
  // token instead of racing the HTTP interceptor's refresh.
101
102
  if (this._refreshing) {
102
- try { await this._refreshing; } catch { /* fall through; readConfig may still have a usable token */ }
103
+ try {
104
+ await this._refreshing;
105
+ } catch {
106
+ /* fall through; readConfig may still have a usable token */
107
+ }
103
108
  }
104
109
  if (this.disposed) return;
105
110
  const config = readConfig();
106
111
  if (!config?.server || !config?.token || !config?.username) return;
107
- const url = `wss://${config.server}/v2/users/${config.username}/events?authorization=${config.token}`;
112
+ const url = `wss://${config.server}${v2(config.username)}/events?authorization=${config.token}`;
108
113
  debugLog('ws:events', 'connecting', {
109
- endpoint: `wss://${config.server}/v2/users/${config.username}/events`,
114
+ endpoint: `wss://${config.server}${v2(config.username)}/events`,
110
115
  pending_subs: this.subs.size,
111
116
  });
112
117
  const ws = new WebSocket(url);
@@ -132,7 +137,9 @@ class EventStream {
132
137
  // fully resubscribed socket — they can rely on new events landing.
133
138
  if (isReconnect) {
134
139
  for (const h of this.reconnectHandlers) {
135
- try { h(); } catch (err) {
140
+ try {
141
+ h();
142
+ } catch (err) {
136
143
  debugLog('ws:events', 'reconnect-handler-error', {
137
144
  error: err?.message || String(err),
138
145
  });
package/lib/device-api.js CHANGED
@@ -1,9 +1,10 @@
1
1
  import api from './api.js';
2
- import { requireConfig } from './config.js';
2
+ import { requireConfig, resolveUser } from './config.js';
3
3
  import { BYTES, TIMEOUTS } from './constants.js';
4
4
  import { CommandStream } from './command-stream.js';
5
5
  import { ensureFreshToken, refreshToken } from './auth.js';
6
6
  import { Readable } from 'node:stream';
7
+ import { device } from './paths.js';
7
8
 
8
9
  // Directory endpoints on the agent expect a trailing slash so it can
9
10
  // distinguish "list this directory" from "read a file with this name".
@@ -16,9 +17,10 @@ const withLeadingSlash = (p) => (p.startsWith('/') ? p : `/${p}`);
16
17
 
17
18
  export function createDeviceAPI(deviceId, options = {}) {
18
19
  const config = requireConfig();
19
- const apiUser = options.user || config.username;
20
- const resourcePath = `/v3/users/${apiUser}/devices/${deviceId}/resources`;
21
- const filesPath = `/v3/users/${apiUser}/devices/${deviceId}/files`;
20
+ const apiUser = resolveUser(options.user);
21
+ const base = device(apiUser, deviceId);
22
+ const resourcePath = `${base}/resources`;
23
+ const filesPath = `${base}/files`;
22
24
 
23
25
  async function callResource(resource, payload = null, opts = {}) {
24
26
  const url = `${resourcePath}/${resource}`;
package/lib/devices.js CHANGED
@@ -1,10 +1,8 @@
1
- import { requireConfig } from './config.js';
2
1
  import api from './api.js';
3
2
  import { apiError } from './errors.js';
3
+ import { v1 } from './paths.js';
4
4
 
5
5
  export async function getDevices(filter, user = null) {
6
- const config = requireConfig();
7
- const apiUser = user || config.username;
8
6
  let devices = [];
9
7
 
10
8
  let queryParametersString = '';
@@ -14,7 +12,7 @@ export async function getDevices(filter, user = null) {
14
12
 
15
13
  try {
16
14
  const count = 50;
17
- const url = `/v1/users/${apiUser}/devices?count=${count}&${queryParametersString}`;
15
+ const url = `${v1(user)}/devices?count=${count}&${queryParametersString}`;
18
16
  let index = 0;
19
17
  let res_length = 0;
20
18
 
@@ -37,10 +35,8 @@ export async function getDevices(filter, user = null) {
37
35
  // connection state…). For device-side data — system_info, monitoring —
38
36
  // hit the agent resources directly instead.
39
37
  export async function getDevice(deviceId, user = null) {
40
- const config = requireConfig();
41
- const apiUser = user || config.username;
42
38
  try {
43
- const response = await api.get(`/v1/users/${apiUser}/devices/${deviceId}`);
39
+ const response = await api.get(`${v1(user)}/devices/${deviceId}`);
44
40
  return response.data || {};
45
41
  } catch (error) {
46
42
  throw apiError(error, { notFound: `Device not found: ${deviceId}` });
@@ -50,10 +46,8 @@ export async function getDevice(deviceId, user = null) {
50
46
  // Idempotent: returns true if the device record was removed, false if it
51
47
  // was already absent. Other failures (auth, network) propagate as apiError.
52
48
  export async function deleteDevice(deviceId, user = null) {
53
- const config = requireConfig();
54
- const apiUser = user || config.username;
55
49
  try {
56
- await api.delete(`/v1/users/${apiUser}/devices/${deviceId}`);
50
+ await api.delete(`${v1(user)}/devices/${deviceId}`);
57
51
  return true;
58
52
  } catch (error) {
59
53
  if (error.response?.status === 404) return false;
@@ -43,9 +43,7 @@ function normalizeSeverityInput(value) {
43
43
  for (const v of arr) {
44
44
  const parsed = parseAlarmSeverity(v);
45
45
  if (parsed === undefined) {
46
- throw inputError(
47
- `Unknown alarm severity "${v}". Valid: low, medium, high, critical.`,
48
- );
46
+ throw inputError(`Unknown alarm severity "${v}". Valid: low, medium, high, critical.`);
49
47
  }
50
48
  out.push(parsed);
51
49
  }
@@ -195,7 +193,8 @@ async function toolAlarmInstanceUpdate(args) {
195
193
  content: [
196
194
  {
197
195
  type: 'text',
198
- text: `Updated ${args.instance} → state=${stateLabel}` +
196
+ text:
197
+ `Updated ${args.instance} → state=${stateLabel}` +
199
198
  (updated?.annotation ? `, annotation="${updated.annotation}"` : ''),
200
199
  },
201
200
  ],
@@ -228,9 +227,7 @@ async function toolAlarmRules(args) {
228
227
  return `${enabled} ${id}${name}${desc}`;
229
228
  });
230
229
  return {
231
- content: [
232
- { type: 'text', text: `${rules.length} alarm rule(s):\n${lines.join('\n')}` },
233
- ],
230
+ content: [{ type: 'text', text: `${rules.length} alarm rule(s):\n${lines.join('\n')}` }],
234
231
  isError: false,
235
232
  };
236
233
  }
@@ -9,7 +9,7 @@ async function toolBucketRead(args) {
9
9
  );
10
10
  const data = await getBucketData({
11
11
  bucket: args.bucket,
12
- device: args.device,
12
+ device: args.device_id,
13
13
  user: args.user,
14
14
  items: args.items || 10,
15
15
  sort: args.sort || 'desc',
@@ -22,9 +22,7 @@ async function toolBucketRead(args) {
22
22
  group_by: args.group_by,
23
23
  });
24
24
  const text =
25
- Array.isArray(data) && data.length === 0
26
- ? 'No data'
27
- : JSON.stringify(data, null, 2);
25
+ Array.isArray(data) && data.length === 0 ? 'No data' : JSON.stringify(data, null, 2);
28
26
  return {
29
27
  content: [{ type: 'text', text }],
30
28
  isError: false,
@@ -49,10 +47,9 @@ Custom buckets may not share the \`monitoring\` schema — don't assume a \`devi
49
47
  description:
50
48
  'Bucket ID as declared in the product profile (e.g. "monitoring", or a custom one like "sensors", "events").',
51
49
  },
52
- device: {
50
+ device_id: {
53
51
  type: 'string',
54
- description:
55
- 'Device ID. Omit for a one-row-per-device fleet view.',
52
+ description: 'Device ID. Omit for a one-row-per-device fleet view.',
56
53
  },
57
54
  items: {
58
55
  type: 'number',
@@ -61,8 +58,7 @@ Custom buckets may not share the \`monitoring\` schema — don't assume a \`devi
61
58
  },
62
59
  minutes: {
63
60
  type: 'number',
64
- description:
65
- 'Get data from the last N minutes. Alternative to min_ts/max_ts.',
61
+ description: 'Get data from the last N minutes. Alternative to min_ts/max_ts.',
66
62
  },
67
63
  min_ts: { type: 'number', description: 'Minimum timestamp in milliseconds' },
68
64
  max_ts: {
@@ -39,7 +39,7 @@ async function toolDevices(args) {
39
39
  }
40
40
 
41
41
  async function toolDeviceInfo(args) {
42
- const { api: deviceApi } = getAPI(args.device, args.user);
42
+ const { api: deviceApi } = getAPI(args.device_id, args.user);
43
43
  const parts = [];
44
44
 
45
45
  // Server-side record first — surfaces the assigned product,
@@ -47,7 +47,7 @@ async function toolDeviceInfo(args) {
47
47
  // can't see. Best effort: don't fail the whole tool if the
48
48
  // record can't be read.
49
49
  try {
50
- const record = await getDevice(args.device, args.user);
50
+ const record = await getDevice(args.device_id, args.user);
51
51
  const meta = [];
52
52
  if (record.device) meta.push(`device: ${record.device}`);
53
53
  if (record.name) meta.push(`name: ${record.name}`);
@@ -120,7 +120,7 @@ async function toolDeviceInfo(args) {
120
120
  }
121
121
 
122
122
  async function toolDeviceSetProduct(args) {
123
- const device = args.device;
123
+ const device = args.device_id;
124
124
  if (!device) throw inputError('device is required');
125
125
  if (args.product === undefined || args.product === null)
126
126
  throw inputError('product is required (pass "" to unassign)');
@@ -133,7 +133,7 @@ async function toolDeviceSetProduct(args) {
133
133
  }
134
134
 
135
135
  async function toolDeviceDelete(args) {
136
- const device = args.device;
136
+ const device = args.device_id;
137
137
  if (!device) throw inputError('device is required');
138
138
  const removed = await deleteDevice(device, args.user);
139
139
  return {
@@ -182,10 +182,10 @@ export const tools = [
182
182
  inputSchema: {
183
183
  type: 'object',
184
184
  properties: {
185
- device: { type: 'string', description: 'Device ID' },
185
+ device_id: { type: 'string', description: 'Device ID' },
186
186
  user: { type: 'string', description: 'API user' },
187
187
  },
188
- required: ['device'],
188
+ required: ['device_id'],
189
189
  },
190
190
  handler: toolDeviceInfo,
191
191
  },
@@ -196,14 +196,14 @@ export const tools = [
196
196
  inputSchema: {
197
197
  type: 'object',
198
198
  properties: {
199
- device: { type: 'string', description: 'Device ID' },
199
+ device_id: { type: 'string', description: 'Device ID' },
200
200
  product: {
201
201
  type: 'string',
202
202
  description: 'Product ID to assign, or empty string "" to unassign.',
203
203
  },
204
204
  user: { type: 'string', description: 'API user' },
205
205
  },
206
- required: ['device', 'product'],
206
+ required: ['device_id', 'product'],
207
207
  },
208
208
  handler: toolDeviceSetProduct,
209
209
  },
@@ -214,10 +214,10 @@ export const tools = [
214
214
  inputSchema: {
215
215
  type: 'object',
216
216
  properties: {
217
- device: { type: 'string', description: 'Device ID to delete.' },
217
+ device_id: { type: 'string', description: 'Device ID to delete.' },
218
218
  user: { type: 'string', description: 'API user' },
219
219
  },
220
- required: ['device'],
220
+ required: ['device_id'],
221
221
  },
222
222
  handler: toolDeviceDelete,
223
223
  },