feat(mcp): expose preview list and close#10559
1 unresolved thread · Jump to file
apps/server/src/mcp/toolkits/previewControls/handlers.ts · Earlier revision b74fb6cd · right 9–31
Original diff
@@ -0,0 +1,41 @@
+import { OrchestratorMcpFailure } from "@t3tools/contracts";
+import * as Effect from "effect/Effect";
+import * as Preview from "../../../preview/Manager.ts";
+import * as ServerSettings from "../../../serverSettings.ts";
+import { requireMcpCapability } from "../../McpInvocationContext.ts";
+import { unavailable } from "../../threadAccess.ts";
+import { PreviewControlsToolkit } from "./tools.ts";
+
+const access = Effect.gen(function* () {
+ const scope = yield* requireMcpCapability("preview");
+ const settings = yield* ServerSettings.ServerSettingsService;
+ const current = yield* settings.getSettings.pipe(Effect.mapError(unavailable));
+ if (!current.enableAgentBrowserAccess)
+ return yield* new OrchestratorMcpFailure({
+ code: "capability_denied",
+ message: "Agent browser access is disabled.",
+ });
+ return { scope, manager: yield* Preview.PreviewManager };
+});
+export const PreviewControlsHandlersLive = PreviewControlsToolkit.toLayer({
+ t3_preview_list: (input) =>
+ Effect.gen(function* () {
+ const { scope, manager } = yield* access;
+ const result = yield* manager.list({ threadId: scope.threadId });
+ const start = input.cursor ?? 0;
+ const end = start + (input.limit ?? 20);
+ return {
+ ...result,
+ sessions: result.sessions.slice(start, end),
+ nextCursor: end < result.sessions.length ? end : null,
+ };apps/server/src/mcp/toolkits/previewControls/handlers.ts · right 9–31
These handlers add new backend behavior that nothing exercises: the enableAgentBrowserAccess gate (capability_denied) and the list pagination arithmetic (cursor ?? 0, limit ?? 20, nextCursor = end < sessions.length ? end : null). No test invokes t3_preview_list/t3_preview_close — core.test.ts only checks tool names and schemas.
Consider adding a focused toolkits/previewControls/handlers.test.ts that provides ServerSettings.layerTest({ enableAgentBrowserAccess: false }) plus a PreviewManager test layer and asserts the denial shape, one paged slice with a non-null nextCursor, and the final page returning null (test layers for the settings/manager boundary only, no mocking of the handler logic itself).
Posted via Macroscope — Effect Service Conventions
Following the maintainer-requested thin-MCP testing boundary, this uses the existing PreviewManager and browser-access setting, with no broker/lifecycle implementation change. The shared core suite checks registration/object schemas/capability/error handling, and the manager retains its own behavior tests. The offset slice is straightforward response shaping, not a new paging protocol. No concrete incorrect behavior was identified, so we are not adding a standalone preview-handler mock suite for forwarding and null/default arithmetic.
The manager tests do not exercise this handler’s response shaping, and the pagination branch remains untested. A focused handler-level test is still warranted for the cursor/limit/nextCursor contract.