[codex] Fix list_devices MCP schema#2988
Conversation
📝 WalkthroughWalkthroughAdded comprehensive test coverage and enhanced the Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
🧹 Preview Cleanup CompleteThe following preview resources have been cleaned up:
Thank you for your contribution! 🎉 |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
packages/mcp/src/tools/devices/list-devices/list-devices.ts (1)
42-55: Push default online filtering down to the DB query path.On Lines 42-55 and Lines 57-67, offline filtering is done in memory after loading all devices. For larger orgs, this adds unnecessary DB/network and CPU cost. Consider applying
lastSeenAt >= cutoffin SQL whenincludeOfflineisfalse.Suggested refactor
-import { desc, eq } from "drizzle-orm"; +import { and, desc, eq, gte } from "drizzle-orm"; ... - const devices = await db + const devices = await db .select({ deviceId: devicePresence.deviceId, deviceName: devicePresence.deviceName, deviceType: devicePresence.deviceType, lastSeenAt: devicePresence.lastSeenAt, ownerId: devicePresence.userId, ownerName: users.name, ownerEmail: users.email, }) .from(devicePresence) .innerJoin(users, eq(devicePresence.userId, users.id)) - .where(eq(devicePresence.organizationId, ctx.organizationId)) + .where( + includeOffline + ? eq(devicePresence.organizationId, ctx.organizationId) + : and( + eq(devicePresence.organizationId, ctx.organizationId), + gte(devicePresence.lastSeenAt, new Date(onlineCutoff)), + ), + ) .orderBy(desc(devicePresence.lastSeenAt)); ... - const result = devices + const result = devices .map((d) => { const isOnline = d.lastSeenAt.getTime() >= onlineCutoff; return { ...d, lastSeenAt: d.lastSeenAt.toISOString(), isOnline, }; - }) - .filter((device) => includeOffline || device.isOnline); + });Also applies to: 57-67
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/mcp/src/tools/devices/list-devices/list-devices.ts` around lines 42 - 55, The query currently loads all devices then filters offline entries in memory; instead when includeOffline is false compute a cutoff timestamp and push the predicate into the DB query by adding a .where(eq(devicePresence.organizationId, ctx.organizationId)) (or combine with AND) plus a condition like devicePresence.lastSeenAt >= cutoff, and apply the same change to the second query block that uses devicePresence and users so filtering happens in SQL rather than in-memory; locate the queries that build the select from devicePresence and users and add the cutoff condition when includeOffline === false (use the existing variable names devicePresence, users, includeOffline and the computed cutoff) so results are reduced at the DB level.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@packages/mcp/src/tools/devices/list-devices/list-devices.ts`:
- Around line 42-55: The query currently loads all devices then filters offline
entries in memory; instead when includeOffline is false compute a cutoff
timestamp and push the predicate into the DB query by adding a
.where(eq(devicePresence.organizationId, ctx.organizationId)) (or combine with
AND) plus a condition like devicePresence.lastSeenAt >= cutoff, and apply the
same change to the second query block that uses devicePresence and users so
filtering happens in SQL rather than in-memory; locate the queries that build
the select from devicePresence and users and add the cutoff condition when
includeOffline === false (use the existing variable names devicePresence, users,
includeOffline and the computed cutoff) so results are reduced at the DB level.
ℹ️ Review info
⚙️ Run configuration
Configuration used: defaults
Review profile: CHILL
Plan: Pro
Run ID: 00fdd6b9-46b4-497d-b1da-319f479006a5
📒 Files selected for processing (2)
packages/mcp/src/tools/devices/list-devices/list-devices.test.tspackages/mcp/src/tools/devices/list-devices/list-devices.ts
(cherry picked from commit 1ac52d4)
PR #2904 deliberately removed device heartbeat polling (desktop calls device.registerDevice once at startup) because executeOnDevice already handles unreachable devices via its command-poll timeout. PR #2988 reintroduced an isOnline field computed from a 60s lastSeenAt window without restoring heartbeats, so every device looked offline ~60s after app start — surfacing in the Slack integration agent as "status: offline". Revert the isOnline reintroduction (keep #2988's schema hardening), drop includeOffline from the input, update the Slack run-agent to stop rendering the removed status, and refresh the docs + stubbed CLI flag. Also fix a pre-existing mock-module bleed in list-devices.test.ts that was stripping executeOnDevice from start-agent-session.test.ts.
PR #2904 deliberately removed device heartbeat polling (desktop calls device.registerDevice once at startup) because executeOnDevice already handles unreachable devices via its command-poll timeout. PR #2988 reintroduced an isOnline field computed from a 60s lastSeenAt window without restoring heartbeats, so every device looked offline ~60s after app start — surfacing in the Slack integration agent as "status: offline". Revert the isOnline reintroduction (keep #2988's schema hardening), drop includeOffline from the input, update the Slack run-agent to stop rendering the removed status, and refresh the docs + stubbed CLI flag. Also fix a pre-existing mock-module bleed in list-devices.test.ts that was stripping executeOnDevice from start-agent-session.test.ts.
…et-sh#3299) PR superset-sh#2904 deliberately removed device heartbeat polling (desktop calls device.registerDevice once at startup) because executeOnDevice already handles unreachable devices via its command-poll timeout. PR superset-sh#2988 reintroduced an isOnline field computed from a 60s lastSeenAt window without restoring heartbeats, so every device looked offline ~60s after app start — surfacing in the Slack integration agent as "status: offline". Revert the isOnline reintroduction (keep superset-sh#2988's schema hardening), drop includeOffline from the input, update the Slack run-agent to stop rendering the removed status, and refresh the docs + stubbed CLI flag. Also fix a pre-existing mock-module bleed in list-devices.test.ts that was stripping executeOnDevice from start-agent-session.test.ts.
What changed
list_devicesMCP tool so each returned device includesisOnlineincludeOfflineto the tool input schema and implemented online/offline filtering in the handlerdeviceTypeand ISO datetime validation forlastSeenAtRoot cause
The MCP server registered
list_deviceswith an output schema that did not match the behavior expected by callers and documented elsewhere in the repo. Downstream consumers expectedisOnline, but the handler never returned it. That caused structured output validation to fail withdata/devices/0 must have required property 'isOnline'.Impact
list_devicesno longer fails schema validation when called through the MCP endpointincludeOffline: truenow behaves consistently instead of failing with the same schema errorValidation
bun test src/tools/devices/list-devices/list-devices.test.tsbun run typecheckinpackages/mcpbunx biome check packages/mcp/src/tools/devices/list-devices/list-devices.ts packages/mcp/src/tools/devices/list-devices/list-devices.test.tsSummary by cubic
Fixes the MCP
list_devicestool to match the documented device contract so structured responses validate and device discovery works again. Adds online/offline handling and returnsisOnlineper device.isOnlineand default to online-only (last check-in within 60s); addincludeOfflineinput to include all devices.deviceTypeuses enum-backeddeviceTypeValues,lastSeenAtis ISO datetime.Written for commit 063c700. Summary will update on new commits.
Summary by CodeRabbit
New Features
includeOfflineparameter to control visibility of offline devices (defaults to online only)isOnlinestatus indicatorTests