feat(mcp): save preview snapshots to disk on request #9261
Closedjakeleventhal(GitHub profile, opens in a new tab)wants to merge 10 commits into
main fromrefs/pull/9261/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted
github-actions[bot](GitHub profile, opens in a new tab) added labelssize:L
- apps/server/src/mcp/McpHttpServer.ts line 139OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -98,0 +119,21 @@119+ .toLowerCase()120+ .replace(/[^a-z0-9]+/g, "-")121+ .replace(/^-+|-+$/g, "")122+ .slice(0, MAX_SCREENSHOT_SITE_SLUG_LENGTH)123+ .replace(/-+$/g, "");124+ return slug || "site";125+ } catch {126+ return "site";127+ }128+};129+130+/** Writes a snapshot PNG under the browser artifacts directory and returns its path. */131+const saveScreenshot = Effect.fn("McpHttpServer.saveScreenshot")(function* (132+ pageUrl: string,133+ data: Uint8Array,134+) {135+ const config = yield* ServerConfig;136+ const fileSystem = yield* FileSystem.FileSystem;137+ const path = yield* Path.Path;138+ const millis = yield* Clock.currentTimeMillis;139+ const fileName = `browser-screenshot-${screenshotSiteSlug(pageUrl)}-${millis.toString(36)}.png`;
- apps/server/src/mcp/McpHttpServer.ts line 17OutdatedResolvedby jakeleventhal(GitHub profile, opens in a new tab)@@ -1,12 +1,17 @@11 import * as Cause from "effect/Cause";2+import * as Clock from "effect/Clock";23 import * as Context from "effect/Context";34 import * as Effect from "effect/Effect";5+import * as FileSystem from "effect/FileSystem";46 import * as Layer from "effect/Layer";57 import * as Option from "effect/Option";8+import * as Path from "effect/Path";9+import * as Schema from "effect/Schema";610 import * as Sink from "effect/Sink";711 import * as Stream from "effect/Stream";812 import type * as Types from "effect/Types";913 import { McpProtocol, McpSchema, McpServer, Tool } from "effect/unstable/ai";1014 import { HttpRouter, HttpServerRequest, HttpServerResponse } from "effect/unstable/http";11151216 import packageJson from "../../package.json" with { type: "json" };17+import { ServerConfig } from "../config.ts";
- apps/server/src/mcp/toolkits/preview/tools.ts line 112OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -111 +112 @@111112 export const PreviewSnapshotTool = readonlyBrowserTool(
- apps/server/src/mcp/McpHttpServer.ts line 140OutdatedResolvedby coderabbitai[bot](GitHub profile, opens in a new tab)@@ -97,0 +120,21 @@120+ .toLowerCase()121+ .replace(/[^a-z0-9]+/g, "-")122+ .replace(/^-+|-+$/g, "")123+ .slice(0, MAX_SCREENSHOT_SITE_SLUG_LENGTH)124+ .replace(/-+$/g, "");125+ return slug || "site";126+ } catch {127+ return "site";128+ }129+};130+131+/** Writes a snapshot PNG under the browser artifacts directory and returns its path. */132+const saveScreenshot = Effect.fn("McpHttpServer.saveScreenshot")(function* (133+ pageUrl: string,134+ data: Uint8Array,135+) {136+ const config = yield* ServerConfig.ServerConfig;137+ const fileSystem = yield* FileSystem.FileSystem;138+ const path = yield* Path.Path;139+ const millis = yield* Clock.currentTimeMillis;140+ const fileName = `browser-screenshot-${screenshotSiteSlug(pageUrl)}-${millis.toString(36)}.png`;
juliusmarminge closed this
Sign in to join this conversation.



macroscopeapp[bot](GitHub profile, opens in a new tab) reviewed