Skip to content

Open-source Grok Bot alternative for named AI teammates. Local-first desktop, web, and mobile clients with per-bot tools, instructions, and memory. Independent fork of T3 Code.

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

duncan-vc551f4c99c1c4
diff --git a/apps/server/src/mcp/McpHttpServer.test.ts b/apps/server/src/mcp/McpHttpServer.test.ts
index fe902f4e9..fa2880f9c 100644
--- a/apps/server/src/mcp/McpHttpServer.test.ts
+++ b/apps/server/src/mcp/McpHttpServer.test.ts
@@ -219,6 +219,11 @@ it.effect("registers annotated tools and preserves authenticated request context
expect(clickTool?.tool.annotations?.readOnlyHint).toBe(false);
expect(clickTool?.tool.annotations?.destructiveHint).toBe(true);
expect(clickTool?.tool.annotations?.openWorldHint).toBe(true);
+ expect(clickTool?.tool.outputSchema).toEqual({
+ type: "object",
+ additionalProperties: false,
+ description: "The preview action completed successfully.",
+ });
const navigateTool = server.tools.find(({ tool }) => tool.name === "preview_navigate");
expect(navigateTool?.tool.annotations?.destructiveHint).toBe(false);
@@ -260,15 +265,24 @@ it.effect("registers annotated tools and preserves authenticated request context
alternateTabId,
);
- const press = yield* server
- .callTool({ name: "preview_press", arguments: { key: "Enter" } })
- .pipe(
- Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
- Effect.provideService(McpSchema.McpServerClient, client),
- );
- expect(press.isError).toBe(false);
- expect(press.structuredContent).toBeNull();
- expect(press.content).toEqual([{ type: "text", text: "null" }]);
+ const actionRequests = [
+ { name: "preview_click", arguments: { x: 10, y: 10 } },
+ { name: "preview_type", arguments: { text: "Hello" } },
+ { name: "preview_press", arguments: { key: "Enter" } },
+ { name: "preview_scroll", arguments: { deltaY: 100 } },
+ { name: "preview_wait_for", arguments: { text: "Example" } },
+ ];
+ for (const request of actionRequests) {
+ const result = yield* server
+ .callTool(request)
+ .pipe(
+ Effect.provideService(McpInvocationContext.McpInvocationContext, invocation),
+ Effect.provideService(McpSchema.McpServerClient, client),
+ );
+ expect(result.isError).toBe(false);
+ expect(result.structuredContent).toEqual({});
+ expect(result.content).toEqual([{ type: "text", text: "{}" }]);
+ }
}),
).pipe(Effect.provide(TestLayer)),
);
diff --git a/apps/server/src/mcp/toolkits/preview/handlers.ts b/apps/server/src/mcp/toolkits/preview/handlers.ts
index 1c7ff6f9c..25be8b363 100644
--- a/apps/server/src/mcp/toolkits/preview/handlers.ts
+++ b/apps/server/src/mcp/toolkits/preview/handlers.ts
@@ -72,15 +72,14 @@ const handlers = {
invokeTargeted<PreviewAutomationSetColorSchemeResult>("setColorScheme", input),
preview_snapshot: (input) => invokeTargeted<PreviewAutomationSnapshot>("snapshot", input ?? {}),
preview_click: (input) =>
- invokeTargeted<void>("click", input, input.timeoutMs).pipe(Effect.as(null)),
- preview_type: (input) =>
- invokeTargeted<void>("type", input, input.timeoutMs).pipe(Effect.as(null)),
- preview_press: (input) => invokeTargeted<void>("press", input).pipe(Effect.as(null)),
- preview_scroll: (input) => invokeTargeted<void>("scroll", input).pipe(Effect.as(null)),
+ invokeTargeted<void>("click", input, input.timeoutMs).pipe(Effect.as({})),
+ preview_type: (input) => invokeTargeted<void>("type", input, input.timeoutMs).pipe(Effect.as({})),
+ preview_press: (input) => invokeTargeted<void>("press", input).pipe(Effect.as({})),
+ preview_scroll: (input) => invokeTargeted<void>("scroll", input).pipe(Effect.as({})),
preview_evaluate: (input) =>
invokeTargeted<unknown>("evaluate", input).pipe(Effect.map((result) => result ?? null)),
preview_wait_for: (input) =>
- invokeTargeted<void>("waitFor", input, input.timeoutMs).pipe(Effect.as(null)),
+ invokeTargeted<void>("waitFor", input, input.timeoutMs).pipe(Effect.as({})),
preview_recording_start: (input) =>
invokeTargeted<PreviewAutomationRecordingStatus>("recordingStart", input ?? {}),
preview_recording_stop: (input) =>
diff --git a/apps/server/src/mcp/toolkits/preview/tools.test.ts b/apps/server/src/mcp/toolkits/preview/tools.test.ts
index 652c20e6a..2cdc67ad7 100644
--- a/apps/server/src/mcp/toolkits/preview/tools.test.ts
+++ b/apps/server/src/mcp/toolkits/preview/tools.test.ts
@@ -55,3 +55,20 @@ it("exports provider-compatible object schemas with described parameters", () =>
}
}
});
+
+it("exports exact object result schemas for preview actions", () => {
+ const actionNames = [
+ "preview_click",
+ "preview_type",
+ "preview_press",
+ "preview_scroll",
+ "preview_wait_for",
+ ] as const;
+ for (const name of actionNames) {
+ expect(Tool.getJsonSchemaFromSchema(PreviewToolkit.tools[name].successSchema)).toEqual({
+ type: "object",
+ additionalProperties: false,
+ description: "The preview action completed successfully.",
+ });
+ }
+});
diff --git a/apps/server/src/mcp/toolkits/preview/tools.ts b/apps/server/src/mcp/toolkits/preview/tools.ts
index a94d2b056..3baf56a79 100644
--- a/apps/server/src/mcp/toolkits/preview/tools.ts
+++ b/apps/server/src/mcp/toolkits/preview/tools.ts
@@ -29,6 +29,10 @@ const dependencies = [
PreviewAutomationBroker.PreviewAutomationBroker,
];
+const PreviewActionResult = Schema.Record(Schema.String, Schema.Never).annotate({
+ description: "The preview action completed successfully.",
+});
+
const browserTool = <T extends Tool.Any>(tool: T): T =>
tool.annotate(Tool.OpenWorld, true).annotate(Tool.Destructive, true) as T;
@@ -117,7 +121,7 @@ export const PreviewClickTool = browserTool(
description:
"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.",
parameters: PreviewAutomationClickInput,
- success: Schema.Null,
+ success: PreviewActionResult,
failure: PreviewAutomationError,
dependencies,
}).annotate(Tool.Title, "Click preview page"),
@@ -128,7 +132,7 @@ export const PreviewTypeTool = browserTool(
description:
"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.",
parameters: PreviewAutomationTypeInput,
- success: Schema.Null,
+ success: PreviewActionResult,
failure: PreviewAutomationError,
dependencies,
}).annotate(Tool.Title, "Type into preview page"),
@@ -139,7 +143,7 @@ export const PreviewPressTool = browserTool(
description:
"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']}.",
parameters: PreviewAutomationPressInput,
- success: Schema.Null,
+ success: PreviewActionResult,
failure: PreviewAutomationError,
dependencies,
}).annotate(Tool.Title, "Press key in preview page"),
@@ -150,7 +154,7 @@ export const PreviewScrollTool = safeBrowserTool(
description:
"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.",
parameters: PreviewAutomationScrollInput,
- success: Schema.Null,
+ success: PreviewActionResult,
failure: PreviewAutomationError,
dependencies,
}).annotate(Tool.Title, "Scroll preview page"),
@@ -172,7 +176,7 @@ export const PreviewWaitForTool = readonlyBrowserTool(
description:
"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.",
parameters: PreviewAutomationWaitForInput,
- success: Schema.Null,
+ success: PreviewActionResult,
failure: PreviewAutomationError,
dependencies,
}).annotate(Tool.Title, "Wait for preview page condition"),