Skip to content

Commit c48d442

Browse files
committed
fix: correct get_device_state endpoint to use device UUID not userId
Critical fix for tool 10: - Renamed: get_device_states → get_device_state (singular) - Fixed endpoint: /state/devId/{deviceUuid} not /state/devId/{userId} - Tool now gets state of ONE specific device by UUID - Input changed from {} to {uuid: string} We have 2 separate APIs for single device state: 1. /state/devId/{deviceUuid} - Get by device UUID (tool 10) 2. /state/{locationUuid}/{macAddress} - Get by MAC address (tool 12) And 1 API for multiple devices: 3. /state/{locationUuid} - Get all devices in location (tool 11) Updated TOOLS.md documentation to reflect correct usage.
1 parent 4869f4e commit c48d442

File tree

2 files changed

+60
-40
lines changed

2 files changed

+60
-40
lines changed

docs/TOOLS.md

Lines changed: 46 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -265,36 +265,40 @@ Delete a device permanently. **Cannot be undone.**
265265

266266
## Device State (3 tools)
267267

268-
### 10. get_device_states
268+
### 10. get_device_state
269269

270-
Get current states of ALL devices in the system.
270+
Get current state of a specific device by UUID.
271271

272272
**Input:**
273273

274274
```json
275-
{}
275+
{
276+
"uuid": "abc-123"
277+
}
276278
```
277279

278280
**Output:**
279281

280282
```json
281-
[
282-
{
283-
"uuid": "abc-123",
284-
"mac": "AA:BB:CC:DD:EE:FF",
285-
"loc": "location-id",
286-
"devId": "device-id",
287-
"state": {
288-
"deviceId": {
289-
"elementId": {
290-
"1": [1, 1], // ON_OFF: ON
291-
"28": [28, 700] // BRIGHTNESS: 700
292-
}
283+
{
284+
"uuid": "abc-123",
285+
"mac": "AA:BB:CC:DD:EE:FF",
286+
"loc": "location-id",
287+
"devId": "device-id",
288+
"state": {
289+
"deviceId": {
290+
"1": {
291+
"1": [1, 1], // Element 1: ON_OFF: ON
292+
"31": [31, 0, 0, 0] // Element 1: COLOR_HSV
293+
},
294+
"2": {
295+
"1": [1, 1], // Element 2: ON_OFF: ON
296+
"28": [28, 700] // Element 2: BRIGHTNESS: 700
293297
}
294-
},
295-
"updatedAt": "2026-02-12T10:00:00Z"
296-
}
297-
]
298+
}
299+
},
300+
"updatedAt": "2026-02-12T10:00:00Z"
301+
}
298302
```
299303

300304
**State Structure:**
@@ -310,11 +314,28 @@ Get states of all devices in a specific location.
310314

311315
```json
312316
{
313-
"locationUuid": "loc-123" // Use _id from list_locations
317+
"locationUuid": "loc-123" // Use uuid from list_locations
314318
}
315319
```
316320

317-
**Output:** Same structure as `get_device_states` but filtered by location.
321+
**Output:** Array of device state objects (same structure as `get_device_state`).
322+
323+
```json
324+
[
325+
{
326+
"uuid": "abc-123",
327+
"mac": "AA:BB:CC:DD:EE:FF",
328+
"loc": "location-id",
329+
"state": {...}
330+
},
331+
{
332+
"uuid": "def-456",
333+
"mac": "11:22:33:44:55:66",
334+
"loc": "location-id",
335+
"state": {...}
336+
}
337+
]
338+
```
318339

319340
### 12. get_device_state_by_mac
320341

@@ -504,7 +525,7 @@ Common device attributes (from `device-attr-and-control.csv`):
504525
{"tool": "control_device_simple", "uuid": "abc-123", "action": "set_brightness", "value": 700}
505526

506527
// Step 4: Check state (wait 2-3 seconds)
507-
{"tool": "get_device_states"}
528+
{"tool": "get_device_state", "uuid": "abc-123"}
508529
```
509530

510531
### Example 3: Control Air Conditioner
@@ -604,9 +625,9 @@ The control API only publishes MQTT messages - it doesn't guarantee device state
604625

605626
### State Endpoints
606627

607-
- `GET /iot-core/state/devId/{devId}` - All device states
608-
- `GET /iot-core/state/{locationUuid}` - States by location
609-
- `GET /iot-core/state/{locationUuid}/{macAddress}` - State by MAC
628+
- `GET /iot-core/state/devId/{deviceUuid}` - Single device state by UUID
629+
- `GET /iot-core/state/{locationUuid}` - All device states in a location
630+
- `GET /iot-core/state/{locationUuid}/{macAddress}` - Single device state by MAC address
610631

611632
### Control Endpoint
612633

src/mcp/services/mcp.service.ts

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -843,15 +843,17 @@ export class McpService {
843843
},
844844
);
845845

846-
// Tool 10: get_device_states - Get states for all devices
846+
// Tool 10: get_device_state - Get state of a single device by UUID
847847
server.registerTool(
848-
'get_device_states',
848+
'get_device_state',
849849
{
850850
description:
851-
'Get current states of all IoT devices. Returns state information including attributes, values, and last update times for all devices in the system.',
852-
inputSchema: z.object({}),
851+
'Get current state of a specific IoT device by its UUID. Returns state information including attributes, values, and last update time for the device.',
852+
inputSchema: z.object({
853+
uuid: z.string().describe('Device UUID (unique identifier)'),
854+
}),
853855
},
854-
async (_, extra) => {
856+
async ({ uuid }, extra) => {
855857
const sessionKey = extra?.sessionId || 'default';
856858
const connectionState = this.connectionStates.get(sessionKey);
857859

@@ -860,29 +862,26 @@ export class McpService {
860862
}
861863

862864
try {
863-
this.logger.debug(`[get_device_states] Fetching all device states`);
864-
const states = await this.apiClient.get(
865-
`/state/devId/${connectionState.userId}`,
866-
connectionState.token,
867-
);
865+
this.logger.debug(`[get_device_state] Fetching state for device: ${uuid}`);
866+
const state = await this.apiClient.get(`/state/devId/${uuid}`, connectionState.token);
868867

869-
this.logger.log(`[get_device_states] Retrieved states successfully`);
868+
this.logger.log(`[get_device_state] Retrieved device state successfully`);
870869

871870
return {
872871
content: [
873872
{
874873
type: 'text' as const,
875-
text: JSON.stringify(states, null, 2),
874+
text: JSON.stringify(state, null, 2),
876875
},
877876
],
878877
};
879878
} catch (error) {
880-
this.logger.error('[get_device_states] Failed:', error);
879+
this.logger.error('[get_device_state] Failed:', error);
881880
return {
882881
content: [
883882
{
884883
type: 'text' as const,
885-
text: `Failed to get device states: ${error.message}`,
884+
text: `Failed to get device state: ${error.message}`,
886885
},
887886
],
888887
isError: true,
@@ -1304,7 +1303,7 @@ export class McpService {
13041303
);
13051304

13061305
this.logger.log(
1307-
'MCP tools registered successfully: login, search, fetch, list_devices, list_locations, list_groups, get_device, update_device, delete_device, get_device_states, get_location_state, get_device_state_by_mac, control_device, control_device_simple',
1306+
'MCP tools registered successfully: login, search, fetch, list_devices, list_locations, list_groups, get_device, update_device, delete_device, get_device_state, get_location_state, get_device_state_by_mac, control_device, control_device_simple',
13081307
);
13091308
}
13101309
}

0 commit comments

Comments
 (0)