fix(server): return valid preview action results (#5966)
Co-authored-by: duncan-vc <[email protected]>
This commit is contained in:
1 parent
402c9e0748
commit
551f4c99c1
4 files changed
+54
-20
No files matched your search
@@ -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)),
|
||||
);
|
||||
@@ -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) =>
|
||||
|
||||
@@ -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.",
|
||||
});
|
||||
}
|
||||
});
|
||||
@@ -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"),
|
||||
|
||||
Reference in new issue
Block a user