@devries-cameron20 / t3code Mirror · read-only / commits / 551f4c99c1
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 24, 16:30 UTC

fix(server): return valid preview action results (#5966)

Co-authored-by: duncan-vc <247855047+duncan-vc@users.noreply.github.com>

duncan-vc committed Aug 15, 2026 at 05:04 UTC 551f4c99c1c42c767daea1f2920cfc8fbc78a1cb
4 files changed +54 -20
apps/server/src/mcp/McpHttpServer.test.ts
+23 -9
@@ -219,6 +219,11 @@ it.effect("registers annotated tools and preserves authenticated request context
219 expect(clickTool?.tool.annotations?.readOnlyHint).toBe(false);
220 expect(clickTool?.tool.annotations?.destructiveHint).toBe(true);
221 expect(clickTool?.tool.annotations?.openWorldHint).toBe(true);
222 + expect(clickTool?.tool.outputSchema).toEqual({
223 + type: "object",
224 + additionalProperties: false,
225 + description: "The preview action completed successfully.",
226 + });
227
228 const navigateTool = server.tools.find(({ tool }) => tool.name === "preview_navigate");
229 expect(navigateTool?.tool.annotations?.destructiveHint).toBe(false);
@@ -260,15 +265,24 @@ it.effect("registers annotated tools and preserves authenticated request context
265 alternateTabId,
266 );
267
263 - const press = yield* server
264 - .callTool({ name: "preview_press", arguments: { key: "Enter" } })
265 - .pipe(
266 - Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
267 - Effect.provideService(McpSchema.McpServerClient, client),
268 - );
269 - expect(press.isError).toBe(false);
270 - expect(press.structuredContent).toBeNull();
271 - expect(press.content).toEqual([{ type: "text", text: "null" }]);
268 + const actionRequests = [
269 + { name: "preview_click", arguments: { x: 10, y: 10 } },
270 + { name: "preview_type", arguments: { text: "Hello" } },
271 + { name: "preview_press", arguments: { key: "Enter" } },
272 + { name: "preview_scroll", arguments: { deltaY: 100 } },
273 + { name: "preview_wait_for", arguments: { text: "Example" } },
274 + ];
275 + for (const request of actionRequests) {
276 + const result = yield* server
277 + .callTool(request)
278 + .pipe(
279 + Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
280 + Effect.provideService(McpSchema.McpServerClient, client),
281 + );
282 + expect(result.isError).toBe(false);
283 + expect(result.structuredContent).toEqual({});
284 + expect(result.content).toEqual([{ type: "text", text: "{}" }]);
285 + }
286 }),
287 ).pipe(Effect.provide(TestLayer)),
288 );
apps/server/src/mcp/toolkits/preview/handlers.ts
+5 -6
@@ -72,15 +72,14 @@ const handlers = {
72 invokeTargeted<PreviewAutomationSetColorSchemeResult>("setColorScheme", input),
73 preview_snapshot: (input) => invokeTargeted<PreviewAutomationSnapshot>("snapshot", input ?? {}),
74 preview_click: (input) =>
75 - invokeTargeted<void>("click", input, input.timeoutMs).pipe(Effect.as(null)),
76 - preview_type: (input) =>
77 - invokeTargeted<void>("type", input, input.timeoutMs).pipe(Effect.as(null)),
78 - preview_press: (input) => invokeTargeted<void>("press", input).pipe(Effect.as(null)),
79 - preview_scroll: (input) => invokeTargeted<void>("scroll", input).pipe(Effect.as(null)),
75 + invokeTargeted<void>("click", input, input.timeoutMs).pipe(Effect.as({})),
76 + preview_type: (input) => invokeTargeted<void>("type", input, input.timeoutMs).pipe(Effect.as({})),
77 + preview_press: (input) => invokeTargeted<void>("press", input).pipe(Effect.as({})),
78 + preview_scroll: (input) => invokeTargeted<void>("scroll", input).pipe(Effect.as({})),
79 preview_evaluate: (input) =>
80 invokeTargeted<unknown>("evaluate", input).pipe(Effect.map((result) => result ?? null)),
81 preview_wait_for: (input) =>
83 - invokeTargeted<void>("waitFor", input, input.timeoutMs).pipe(Effect.as(null)),
82 + invokeTargeted<void>("waitFor", input, input.timeoutMs).pipe(Effect.as({})),
83 preview_recording_start: (input) =>
84 invokeTargeted<PreviewAutomationRecordingStatus>("recordingStart", input ?? {}),
85 preview_recording_stop: (input) =>
apps/server/src/mcp/toolkits/preview/tools.test.ts
+17
@@ -55,3 +55,20 @@ it("exports provider-compatible object schemas with described parameters", () =>
55 }
56 }
57 });
58 +
59 +it("exports exact object result schemas for preview actions", () => {
60 + const actionNames = [
61 + "preview_click",
62 + "preview_type",
63 + "preview_press",
64 + "preview_scroll",
65 + "preview_wait_for",
66 + ] as const;
67 + for (const name of actionNames) {
68 + expect(Tool.getJsonSchemaFromSchema(PreviewToolkit.tools[name].successSchema)).toEqual({
69 + type: "object",
70 + additionalProperties: false,
71 + description: "The preview action completed successfully.",
72 + });
73 + }
74 +});
apps/server/src/mcp/toolkits/preview/tools.ts
+9 -5
@@ -29,6 +29,10 @@ const dependencies = [
29 PreviewAutomationBroker.PreviewAutomationBroker,
30 ];
31
32 +const PreviewActionResult = Schema.Record(Schema.String, Schema.Never).annotate({
33 + description: "The preview action completed successfully.",
34 +});
35 +
36 const browserTool = <T extends Tool.Any>(tool: T): T =>
37 tool.annotate(Tool.OpenWorld, true).annotate(Tool.Destructive, true) as T;
38
@@ -117,7 +121,7 @@ export const PreviewClickTool = browserTool(
121 description:
122 "Click exactly one target in the tab selected by tabId, or this agent session's current tab when omitted. Prefer a Playwright locator; selector accepts legacy CSS; x and y must be supplied together.",
123 parameters: PreviewAutomationClickInput,
120 - success: Schema.Null,
124 + success: PreviewActionResult,
125 failure: PreviewAutomationError,
126 dependencies,
127 }).annotate(Tool.Title, "Click preview page"),
@@ -128,7 +132,7 @@ export const PreviewTypeTool = browserTool(
132 description:
133 "Insert literal text into one input in the tab selected by tabId, or this agent session's current tab when omitted. Prefer a Playwright locator; set clear=true to replace existing text.",
134 parameters: PreviewAutomationTypeInput,
131 - success: Schema.Null,
135 + success: PreviewActionResult,
136 failure: PreviewAutomationError,
137 dependencies,
138 }).annotate(Tool.Title, "Type into preview page"),
@@ -139,7 +143,7 @@ export const PreviewPressTool = browserTool(
143 description:
144 "Press one keyboard key in the tab selected by tabId, or this agent session's current tab when omitted. Examples: {key:'Enter'}, {key:'Escape'}, or {key:'a',modifiers:['Meta']}.",
145 parameters: PreviewAutomationPressInput,
142 - success: Schema.Null,
146 + success: PreviewActionResult,
147 failure: PreviewAutomationError,
148 dependencies,
149 }).annotate(Tool.Title, "Press key in preview page"),
@@ -150,7 +154,7 @@ export const PreviewScrollTool = safeBrowserTool(
154 description:
155 "Scroll the tab selected by tabId, or this agent session's current tab when omitted. Positive deltaY scrolls down and positive deltaX scrolls right; a locator/selector targets a container.",
156 parameters: PreviewAutomationScrollInput,
153 - success: Schema.Null,
157 + success: PreviewActionResult,
158 failure: PreviewAutomationError,
159 dependencies,
160 }).annotate(Tool.Title, "Scroll preview page"),
@@ -172,7 +176,7 @@ export const PreviewWaitForTool = readonlyBrowserTool(
176 description:
177 "Wait in the tab selected by tabId, or this agent session's current tab when omitted, until all supplied locator, selector, text, and URL conditions match.",
178 parameters: PreviewAutomationWaitForInput,
175 - success: Schema.Null,
179 + success: PreviewActionResult,
180 failure: PreviewAutomationError,
181 dependencies,
182 }).annotate(Tool.Title, "Wait for preview page condition"),