Skip to content

Commit ea22d38

Browse files
fix(server): device_open by id reports a failed host; npm guidance says to restart
Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent e5870dd commit ea22d38

3 files changed

Lines changed: 33 additions & 17 deletions

File tree

‎apps/server/src/device/DeviceToolchain.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export class DeviceToolchainInstallError extends Schema.TaggedError<DeviceToolch
4343
) {
4444
override get message(): string {
4545
if (this.reason === "npm_not_found")
46-
return "Device support needs npm, which is not on the T3 server's PATH. Install Node.js, which includes npm, then retry.";
46+
return "Device support needs npm, which is not on the T3 server's PATH. Install npm (it comes with Node.js from nodejs.org), restart T3 Code, then retry.";
4747
const suffix = this.exitCode === undefined ? "" : ` (exit code ${this.exitCode})`;
4848
return `Installing ${this.tool} failed while ${this.step}${suffix}.`;
4949
}

‎apps/server/src/mcp/McpDeviceToolkit.test.ts‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -281,22 +281,25 @@ it.effect("device_open reports a failed host's setup error instead of no devices
281281
const layerFailed = Layer.mock(DeviceService.DeviceService)({
282282
state: Effect.succeed(failedState),
283283
list: Effect.succeed(failedState),
284+
locateDevice: () => Effect.succeedNone,
284285
open: () => Effect.die("Must not open a device on a host whose setup failed"),
285286
});
286287
return Effect.gen(function* () {
287288
const server = yield* McpServer.McpServer;
288-
const result = yield* server
289-
.callTool({ name: "device_open", arguments: { platform: "android" } })
290-
.pipe(
291-
Effect.provideService(McpInvocationContext.McpInvocationContext, invocation(["device"])),
292-
Effect.provideService(McpSchema.McpServerClient, client),
293-
);
294-
const text = result.content
295-
.flatMap((entry) => (entry.type === "text" ? [entry.text] : []))
296-
.join("\n");
297-
expect(result.isError).toBe(true);
298-
expect(text).not.toContain("No android devices were found");
299-
expect(text).toContain(failure);
289+
for (const args of [{ platform: "android" }, { deviceId: "Pixel_API_35", hostId: "local" }]) {
290+
const result = yield* server
291+
.callTool({ name: "device_open", arguments: args })
292+
.pipe(
293+
Effect.provideService(McpInvocationContext.McpInvocationContext, invocation(["device"])),
294+
Effect.provideService(McpSchema.McpServerClient, client),
295+
);
296+
const text = result.content
297+
.flatMap((entry) => (entry.type === "text" ? [entry.text] : []))
298+
.join("\n");
299+
expect(result.isError).toBe(true);
300+
expect(text).not.toContain("No android devices were found");
301+
expect(text).toContain(failure);
302+
}
300303
}).pipe(
301304
Effect.scoped,
302305
Effect.provide(

‎apps/server/src/mcp/toolkits/device/handlers.ts‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,15 @@ const mapLocateErrors = <A, R>(
121121
}),
122122
);
123123

124+
const failedHostDetails = (
125+
state: { readonly hostStatuses: DeviceServiceState["hostStatuses"] },
126+
hostIds: ReadonlyArray<string>,
127+
) =>
128+
hostIds.flatMap((id) => {
129+
const status = state.hostStatuses[id];
130+
return status?.status === "failed" && status.detail ? [status.detail] : [];
131+
});
132+
124133
const pickDevice = Effect.fn("handlers.pickDevice")(function* (
125134
state: {
126135
readonly hosts: ReadonlyArray<DeviceHostSummary>;
@@ -138,8 +147,12 @@ const pickDevice = Effect.fn("handlers.pickDevice")(function* (
138147
const devices = yield* DeviceService.DeviceService;
139148
const located = yield* devices.locateDevice({ deviceId, hostId }).pipe(mapLocateErrors);
140149
if (Option.isSome(located)) return located.value;
150+
const failures = failedHostDetails(
151+
state,
152+
hostId === undefined ? Object.keys(state.hostStatuses) : [hostId],
153+
);
141154
return yield* new DeviceToolUnavailableError({
142-
reason: `No device ${deviceId} on ${hostId === undefined ? "any host" : hostName(state.hosts.find((host) => host.id === hostId) ?? { id: hostId })}. Call device_list for current ids.`,
155+
reason: `No device ${deviceId} on ${hostId === undefined ? "any host" : hostName(state.hosts.find((host) => host.id === hostId) ?? { id: hostId })}. ${failures.length > 0 ? failures.join(" ") : "Call device_list for current ids."}`,
143156
});
144157
}
145158
const hostId = input.hostId ?? LOCAL_DEVICE_HOST_ID;
@@ -149,11 +162,11 @@ const pickDevice = Effect.fn("handlers.pickDevice")(function* (
149162
(input.platform === undefined || device.platform === input.platform),
150163
);
151164
if (candidates.length === 0) {
152-
const status = state.hostStatuses[hostId];
165+
const [failure] = failedHostDetails(state, [hostId]);
153166
return yield* new DeviceToolUnavailableError({
154167
reason:
155-
status?.status === "failed" && status.detail
156-
? status.detail
168+
failure !== undefined
169+
? failure
157170
: input.platform === undefined
158171
? "No simulators or emulators were found. Call device_list to see why."
159172
: `No ${input.platform} devices were found on host ${hostId}. Call device_list to see why.`,

0 commit comments

Comments
 (0)