framewatch-mcp-server 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/README.md +537 -0
- package/dist/constants.d.ts +172 -0
- package/dist/constants.js +168 -0
- package/dist/constants.js.map +1 -0
- package/dist/engine/browser.d.ts +56 -0
- package/dist/engine/browser.js +142 -0
- package/dist/engine/browser.js.map +1 -0
- package/dist/engine/differ.d.ts +88 -0
- package/dist/engine/differ.js +373 -0
- package/dist/engine/differ.js.map +1 -0
- package/dist/engine/interaction.d.ts +76 -0
- package/dist/engine/interaction.js +254 -0
- package/dist/engine/interaction.js.map +1 -0
- package/dist/engine/layers/console.d.ts +63 -0
- package/dist/engine/layers/console.js +118 -0
- package/dist/engine/layers/console.js.map +1 -0
- package/dist/engine/layers/dom.d.ts +53 -0
- package/dist/engine/layers/dom.js +282 -0
- package/dist/engine/layers/dom.js.map +1 -0
- package/dist/engine/layers/index.d.ts +95 -0
- package/dist/engine/layers/index.js +184 -0
- package/dist/engine/layers/index.js.map +1 -0
- package/dist/engine/layers/network.d.ts +62 -0
- package/dist/engine/layers/network.js +169 -0
- package/dist/engine/layers/network.js.map +1 -0
- package/dist/engine/layers/performance.d.ts +55 -0
- package/dist/engine/layers/performance.js +215 -0
- package/dist/engine/layers/performance.js.map +1 -0
- package/dist/engine/layers/probe.d.ts +50 -0
- package/dist/engine/layers/probe.js +39 -0
- package/dist/engine/layers/probe.js.map +1 -0
- package/dist/engine/layers/session.d.ts +46 -0
- package/dist/engine/layers/session.js +131 -0
- package/dist/engine/layers/session.js.map +1 -0
- package/dist/engine/recorder.d.ts +61 -0
- package/dist/engine/recorder.js +256 -0
- package/dist/engine/recorder.js.map +1 -0
- package/dist/index.d.ts +13 -0
- package/dist/index.js +125 -0
- package/dist/index.js.map +1 -0
- package/dist/tools/accessibility.d.ts +140 -0
- package/dist/tools/accessibility.js +357 -0
- package/dist/tools/accessibility.js.map +1 -0
- package/dist/tools/capture.d.ts +279 -0
- package/dist/tools/capture.js +275 -0
- package/dist/tools/capture.js.map +1 -0
- package/dist/tools/compare.d.ts +86 -0
- package/dist/tools/compare.js +247 -0
- package/dist/tools/compare.js.map +1 -0
- package/dist/tools/index.d.ts +10 -0
- package/dist/tools/index.js +25 -0
- package/dist/tools/index.js.map +1 -0
- package/dist/tools/interact.d.ts +160 -0
- package/dist/tools/interact.js +203 -0
- package/dist/tools/interact.js.map +1 -0
- package/dist/tools/responsive.d.ts +89 -0
- package/dist/tools/responsive.js +197 -0
- package/dist/tools/responsive.js.map +1 -0
- package/dist/tools/screenshot.d.ts +76 -0
- package/dist/tools/screenshot.js +117 -0
- package/dist/tools/screenshot.js.map +1 -0
- package/dist/tools/server.d.ts +89 -0
- package/dist/tools/server.js +201 -0
- package/dist/tools/server.js.map +1 -0
- package/dist/types.d.ts +123 -0
- package/dist/types.js +9 -0
- package/dist/types.js.map +1 -0
- package/dist/utils/bounded-log.d.ts +41 -0
- package/dist/utils/bounded-log.js +78 -0
- package/dist/utils/bounded-log.js.map +1 -0
- package/dist/utils/format.d.ts +56 -0
- package/dist/utils/format.js +130 -0
- package/dist/utils/format.js.map +1 -0
- package/dist/utils/image.d.ts +44 -0
- package/dist/utils/image.js +81 -0
- package/dist/utils/image.js.map +1 -0
- package/dist/utils/server-process.d.ts +84 -0
- package/dist/utils/server-process.js +251 -0
- package/dist/utils/server-process.js.map +1 -0
- package/package.json +74 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"capture.js","sourceRoot":"","sources":["../../src/tools/capture.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EACL,mBAAmB,EACnB,2BAA2B,EAC3B,kBAAkB,EAClB,mBAAmB,EACnB,gBAAgB,EAChB,uBAAuB,EACvB,mBAAmB,EACnB,kBAAkB,EAClB,cAAc,EACd,gBAAgB,EAChB,uBAAuB,EACvB,qBAAqB,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AAY,KAAK,CAAC,CAAC,CAAC,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IACvE,MAAM,SAAS,GAAG,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;IACzC,MAAM,MAAM,GAAG,cAAc,KAAK,CAAC,GAAG,UAAU,CAAC;IAEjD,IAAI,+CAA+C,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAClE,OAAO,CACL,GAAG,MAAM,mDAAmD;YAC5D,2DAA2D,SAAS,GAAG,CACxE,CAAC;IACJ,CAAC;IACD,IAAI,KAAK,CAAC,QAAQ,IAAI,yBAAyB,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;QAC9D,OAAO,GAAG,MAAM,cAAc,KAAK,CAAC,QAAQ,mCAAmC,KAAK,CAAC,mBAAmB,KAAK,CAAC;IAChH,CAAC;IACD,OAAO,GAAG,MAAM,IAAI,SAAS,EAAE,CAAC;AAClC,CAAC;AAED,MAAM,UAAU,mBAAmB,CAAC,MAAiB;IACnD,MAAM,CAAC,YAAY,CACjB,iBAAiB,EACjB;QACE,KAAK,EAAE,SAAS;QAChB,WAAW,EACT,mGAAmG;YACnG,2FAA2F;YAC3F,uGAAuG;YACvG,yEAAyE;YACzE,uGAAuG;YACvG,iGAAiG;YACjG,sGAAsG;YACtG,qCAAqC;QACvC,WAAW,EAAE,iBAAiB;QAC9B,WAAW,EAAE,EAAE,YAAY,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,KAAK,EAAE,aAAa,EAAE,IAAI,EAAE;KACxG,EACD,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,WAAW,CAAC,IAAI,CAAC,CAClC,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { Page } from \"playwright\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport {\n CAPTURE_INTERVAL_MS,\n DEFAULT_CAPTURE_DURATION_MS,\n DEFAULT_MAX_FRAMES,\n DEFAULT_SENSITIVITY,\n DEFAULT_VIEWPORT,\n MAX_CAPTURE_DURATION_MS,\n MAX_VIEWPORT_HEIGHT,\n MAX_VIEWPORT_WIDTH,\n MAX_FRAMES_CAP,\n MAX_INTERACTIONS,\n MIN_CAPTURE_DURATION_MS,\n NAVIGATION_TIMEOUT_MS,\n PAGE_INFO_TIMEOUT_MS,\n SELECTOR_TIMEOUT_MS,\n} from \"../constants.js\";\nimport { withPage } from \"../engine/browser.js\";\nimport { buildDiffCards } from \"../engine/differ.js\";\nimport { applyContext, attachLayers, summariseContext } from \"../engine/layers/index.js\";\nimport {\n CAPTURE_ACTIONS,\n describeInteraction,\n executeInteraction,\n interactionFieldShape,\n needsTouch,\n refineInteraction,\n type Interaction,\n} from \"../engine/interaction.js\";\nimport { recordFrames, type FrameRecorder } from \"../engine/recorder.js\";\nimport { formatDiffCards, type InteractionReport } from \"../utils/format.js\";\n\nexport const CAPTURE_TOOL_NAME = \"framewatch_capture\";\n\n/**\n * Re-exported where it is used: the capture summary's context lines. It lives\n * with the layers themselves now that `framewatch_interact` reports them too.\n */\nexport { summariseContext };\n\n/**\n * One step of a replayable interaction script. `delay_ms` is a wait *before*\n * the action, so a `wait` step is just a delay with nothing after it, and the\n * delays of successive steps accumulate over the recording.\n */\nexport const captureInteractionSchema = z\n .object({\n action: z.enum(CAPTURE_ACTIONS).describe(\"What to do: click, tap, type, scroll, swipe, wait or navigate\"),\n ...interactionFieldShape,\n delay_ms: z.number().int().min(0).default(0).describe(\"Wait this long (ms) before performing this action\"),\n })\n .superRefine(refineInteraction);\n\nexport const captureInputShape = {\n url: z.string().url().describe(\"URL to capture, e.g. http://localhost:3000 (http, https and file URLs are accepted)\"),\n duration_ms: z\n .number()\n .int()\n .min(MIN_CAPTURE_DURATION_MS)\n .max(MAX_CAPTURE_DURATION_MS)\n .default(DEFAULT_CAPTURE_DURATION_MS)\n .describe(\"How long to record (ms)\"),\n sensitivity: z\n .number()\n .min(0)\n .max(1)\n .default(DEFAULT_SENSITIVITY)\n .describe(\"Frame change threshold (0 = keep all, 1 = keep none). 0.06 means ~6% of grid cells must change.\"),\n max_frames: z\n .number()\n .int()\n .min(1)\n .max(MAX_FRAMES_CAP)\n .default(DEFAULT_MAX_FRAMES)\n .describe(\"Maximum diff cards to return\"),\n interval_ms: z\n .number()\n .int()\n .min(16)\n .max(2000)\n .default(CAPTURE_INTERVAL_MS)\n .describe(\"Raw frame capture interval (ms) — 100 = 10fps\"),\n viewport: z\n .object({\n width: z.number().int().min(1).max(MAX_VIEWPORT_WIDTH).default(DEFAULT_VIEWPORT.width),\n height: z.number().int().min(1).max(MAX_VIEWPORT_HEIGHT).default(DEFAULT_VIEWPORT.height),\n })\n .optional()\n .describe(\"Viewport size (defaults to 1280x720)\"),\n wait_for: z.string().optional().describe(\"CSS selector to wait for (visible) before recording starts\"),\n wait_for_timeout_ms: z\n .number()\n .int()\n .min(1)\n .default(SELECTOR_TIMEOUT_MS)\n .describe(\"Max time (ms) to wait for `wait_for` to appear (must be > 0)\"),\n interactions: z\n .array(captureInteractionSchema)\n .max(MAX_INTERACTIONS)\n .optional()\n .describe(\"Sequence of user interactions to replay during the recording\"),\n interaction_timeout_ms: z\n .number()\n .int()\n .min(1)\n .default(SELECTOR_TIMEOUT_MS)\n .describe(\"Max time (ms) an interaction step may spend waiting for its target element\"),\n include_console: z\n .boolean()\n .default(true)\n .describe(\"Attach console logs, uncaught errors and unhandled rejections to the frames they happened between\"),\n include_network: z\n .boolean()\n .default(false)\n .describe(\"Attach network requests (method, url, status, duration) to the frames they settled between\"),\n include_dom: z\n .boolean()\n .default(false)\n .describe(\"Attach a summary of the DOM mutations between frames — which elements were added, removed or restyled\"),\n include_performance: z\n .boolean()\n .default(false)\n .describe(\"Attach paint timing, largest contentful paint and layout shifts to the frames they were measured at\"),\n};\n\nexport const captureInputSchema = z.object(captureInputShape);\nexport type CaptureInput = z.input<typeof captureInputSchema>;\ntype ParsedCaptureInput = z.output<typeof captureInputSchema>;\n\n/**\n * The main FrameWatch tool: record a page for `duration_ms` and return only\n * the meaningful visual changes as diff cards (see CLAUDE.md \"Diff Cards\" and\n * \"MCP Response Format\").\n *\n * Flow: navigate (waiting only for the navigation to commit, so loading and\n * splash animations are recorded from their first frame) → optionally wait\n * for `wait_for` → record raw frames every `interval_ms`, replaying\n * `interactions` as the recording runs → smart-diff them into at most\n * `max_frames` cards → format. All failures — including invalid input — are\n * reported as `isError` results rather than thrown so the MCP client sees a\n * useful message.\n */\nexport async function capturePage(rawInput: CaptureInput): Promise<CallToolResult> {\n const parsed = captureInputSchema.safeParse(rawInput);\n if (!parsed.success) {\n const issues = parsed.error.issues.map((i) => `${i.path.join(\".\") || \"input\"}: ${i.message}`).join(\"; \");\n return errorResult(`Capture failed: invalid input — ${issues}`);\n }\n const input = parsed.data;\n const viewport = input.viewport ?? { ...DEFAULT_VIEWPORT };\n const interactions = input.interactions ?? [];\n // Touch has to be decided when the context is created, so read it off the\n // script rather than turning it on for every capture: `hasTouch` puts\n // `ontouchstart` on window, which flips feature detection in most UI\n // libraries and would silently change what a plain capture records.\n const contextOptions = needsTouch(interactions) ? { hasTouch: true } : {};\n\n const report: InteractionReport | undefined =\n interactions.length > 0 ? { total: interactions.length, completed: 0, steps: [] } : undefined;\n\n try {\n const recording = await withPage({ viewport, contextOptions }, async (page) => {\n // Layers go on before the navigation: a script that throws while the page\n // loads, the request that never comes back and first paint all happen\n // before frame 0 exists, and they are the most useful things here.\n const layers = await attachLayers(page, {\n console: input.include_console,\n network: input.include_network,\n dom: input.include_dom,\n performance: input.include_performance,\n });\n try {\n // \"commit\" rather than \"load\": splash/loading animations must be recorded from the very start.\n await page.goto(input.url, { waitUntil: \"commit\", timeout: NAVIGATION_TIMEOUT_MS });\n if (input.wait_for) {\n await page.waitForSelector(input.wait_for, { state: \"visible\", timeout: input.wait_for_timeout_ms });\n }\n const result = await recordFrames(\n page,\n { duration_ms: input.duration_ms, interval_ms: input.interval_ms },\n report && ((recorder) => replayScript(page, recorder, interactions, input.interaction_timeout_ms, report)),\n );\n // Drain the layers before anything else can close the page. `collect`\n // reads only what Node already holds, so a page that froze, navigated\n // away or crashed still yields everything it managed to report.\n const context = layers.collect(result.started_at);\n // The page may have died mid-recording (crash, closed browser). Frames\n // already captured are still worth returning, so never let reading the\n // title or url turn a partial recording into an error.\n return { ...result, context, ...(await describePage(page)) };\n } finally {\n layers.detach();\n }\n });\n\n const { cards, total_frames } = await buildDiffCards(recording.frames, {\n sensitivity: input.sensitivity,\n max_frames: input.max_frames,\n });\n applyContext(cards, recording.context);\n\n return formatDiffCards({\n cards,\n total_frames,\n duration_ms: recording.duration_ms,\n url: input.url,\n final_url: recording.finalUrl,\n title: recording.title,\n dropped: recording.dropped,\n interactions: report,\n notes: summariseContext(recording.context, cards.length),\n });\n } catch (error) {\n return errorResult(describeCaptureFailure(input, error));\n }\n}\n\n/**\n * Replay the interaction script while the recorder runs, forcing a frame after\n * every step so the differ always keeps the result of each action.\n *\n * A failing step ends the script but never the capture: the frames recorded so\n * far are the most useful thing FrameWatch can hand back (they show the state\n * the page was actually in when the selector did not match), so the failure is\n * recorded in `report` and a forced \"error\" frame is captured instead of\n * throwing. The recording then plays out the rest of its duration.\n */\nasync function replayScript(\n page: Page,\n recorder: FrameRecorder,\n interactions: Interaction[],\n timeoutMs: number,\n report: InteractionReport,\n): Promise<void> {\n for (let i = 0; i < interactions.length; i++) {\n const step = interactions[i];\n try {\n await executeInteraction(page, step, { timeout_ms: timeoutMs });\n } catch (error) {\n report.error = error instanceof Error ? error.message : String(error);\n report.failed_index = i + 1;\n await recorder.captureNow(\"error\");\n return;\n }\n report.completed++;\n report.steps.push(describeInteraction(step));\n await recorder.captureNow(\"interaction\");\n }\n}\n\n/**\n * Title and final url of a page. Both are cosmetic, so neither is allowed to\n * fail or delay the result: the page may have died during the recording, and\n * `page.title()` blocks for Playwright's full default timeout while the main\n * thread is busy — exactly the case a developer points this tool at.\n */\nasync function describePage(page: Page): Promise<{ title?: string; finalUrl?: string }> {\n if (page.isClosed()) return {};\n const finalUrl = safely(() => page.url());\n // Settle the losing side too: a page.title() that outlives the race would\n // otherwise reject unobserved when the context is closed underneath it.\n const title = page.title().catch(() => undefined);\n let timer: NodeJS.Timeout | undefined;\n const giveUp = new Promise<undefined>((resolve) => {\n timer = setTimeout(() => resolve(undefined), PAGE_INFO_TIMEOUT_MS);\n });\n try {\n return { title: await Promise.race([title, giveUp]), finalUrl };\n } finally {\n clearTimeout(timer);\n }\n}\n\nfunction safely<T>(read: () => T): T | undefined {\n try {\n return read();\n } catch {\n return undefined;\n }\n}\n\nfunction errorResult(text: string): CallToolResult {\n return { isError: true, content: [{ type: \"text\", text }] };\n}\n\n/**\n * Turn a Playwright/Node error into a one-line, actionable message. Mirrors\n * `describeFailure` in screenshot.ts: matches on the failing Playwright call\n * (the message prefix) rather than on substrings of user-supplied selectors,\n * so a navigation failure is never blamed on an element.\n */\nexport function describeCaptureFailure(\n input: Pick<ParsedCaptureInput, \"url\" | \"wait_for\" | \"wait_for_timeout_ms\">,\n error: unknown,\n): string {\n const message = error instanceof Error ? error.message : String(error);\n const firstLine = message.split(\"\\n\")[0];\n const prefix = `Capture of ${input.url} failed:`;\n\n if (/Executable doesn't exist|browserType\\.launch/i.test(message)) {\n return (\n `${prefix} Playwright's Chromium browser is not installed. ` +\n `Run \\`npx playwright install chromium\\` and try again. (${firstLine})`\n );\n }\n if (input.wait_for && /^page\\.waitForSelector:/.test(message)) {\n return `${prefix} selector \"${input.wait_for}\" did not become visible within ${input.wait_for_timeout_ms}ms.`;\n }\n return `${prefix} ${firstLine}`;\n}\n\nexport function registerCaptureTool(server: McpServer): void {\n server.registerTool(\n CAPTURE_TOOL_NAME,\n {\n title: \"Capture\",\n description:\n \"Record a web page for a few seconds and return only the meaningful visual changes as diff cards: \" +\n \"a full-frame PNG plus a crop of the changed region and its position for each kept frame. \" +\n \"Use it to check animations, splash/loading screens, transitions and anything that changes over time. \" +\n \"Lower `sensitivity` to keep more frames; `max_frames` caps the output. \" +\n \"Each frame can also carry the context for the interval that produced it: console output and uncaught \" +\n \"errors (on by default), plus network requests, DOM mutations and paint/layout-shift timing via \" +\n \"`include_network`, `include_dom` and `include_performance` — that is how you find out *why* a frame \" +\n \"looks wrong, not just that it does.\",\n inputSchema: captureInputShape,\n annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: false, openWorldHint: true },\n },\n async (args) => capturePage(args),\n );\n}\n"]}
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
export declare const COMPARE_TOOL_NAME = "framewatch_compare";
|
|
5
|
+
/** `url_a` accepts this instead of a URL, meaning "whatever framewatch_interact is looking at". */
|
|
6
|
+
export declare const CURRENT_PAGE = "current";
|
|
7
|
+
export declare const compareInputShape: {
|
|
8
|
+
url_a: z.ZodEffects<z.ZodString, string, string>;
|
|
9
|
+
url_b: z.ZodEffects<z.ZodString, string, string>;
|
|
10
|
+
wait_ms: z.ZodDefault<z.ZodNumber>;
|
|
11
|
+
wait_for: z.ZodOptional<z.ZodString>;
|
|
12
|
+
wait_for_timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
13
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
14
|
+
width: z.ZodDefault<z.ZodNumber>;
|
|
15
|
+
height: z.ZodDefault<z.ZodNumber>;
|
|
16
|
+
}, "strip", z.ZodTypeAny, {
|
|
17
|
+
width: number;
|
|
18
|
+
height: number;
|
|
19
|
+
}, {
|
|
20
|
+
width?: number | undefined;
|
|
21
|
+
height?: number | undefined;
|
|
22
|
+
}>>;
|
|
23
|
+
};
|
|
24
|
+
export declare const compareInputSchema: z.ZodObject<{
|
|
25
|
+
url_a: z.ZodEffects<z.ZodString, string, string>;
|
|
26
|
+
url_b: z.ZodEffects<z.ZodString, string, string>;
|
|
27
|
+
wait_ms: z.ZodDefault<z.ZodNumber>;
|
|
28
|
+
wait_for: z.ZodOptional<z.ZodString>;
|
|
29
|
+
wait_for_timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
30
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
31
|
+
width: z.ZodDefault<z.ZodNumber>;
|
|
32
|
+
height: z.ZodDefault<z.ZodNumber>;
|
|
33
|
+
}, "strip", z.ZodTypeAny, {
|
|
34
|
+
width: number;
|
|
35
|
+
height: number;
|
|
36
|
+
}, {
|
|
37
|
+
width?: number | undefined;
|
|
38
|
+
height?: number | undefined;
|
|
39
|
+
}>>;
|
|
40
|
+
}, "strip", z.ZodTypeAny, {
|
|
41
|
+
wait_ms: number;
|
|
42
|
+
wait_for_timeout_ms: number;
|
|
43
|
+
url_a: string;
|
|
44
|
+
url_b: string;
|
|
45
|
+
viewport?: {
|
|
46
|
+
width: number;
|
|
47
|
+
height: number;
|
|
48
|
+
} | undefined;
|
|
49
|
+
wait_for?: string | undefined;
|
|
50
|
+
}, {
|
|
51
|
+
url_a: string;
|
|
52
|
+
url_b: string;
|
|
53
|
+
viewport?: {
|
|
54
|
+
width?: number | undefined;
|
|
55
|
+
height?: number | undefined;
|
|
56
|
+
} | undefined;
|
|
57
|
+
wait_ms?: number | undefined;
|
|
58
|
+
wait_for?: string | undefined;
|
|
59
|
+
wait_for_timeout_ms?: number | undefined;
|
|
60
|
+
}>;
|
|
61
|
+
export type CompareInput = z.input<typeof compareInputSchema>;
|
|
62
|
+
type ParsedCompareInput = z.output<typeof compareInputSchema>;
|
|
63
|
+
/**
|
|
64
|
+
* Compare two pages — or the same page before and after a change — and show
|
|
65
|
+
* what moved.
|
|
66
|
+
*
|
|
67
|
+
* Returns both screenshots plus an overlay: side B with every differing pixel
|
|
68
|
+
* tinted, which is the part that turns "3.4% changed" into something a reader
|
|
69
|
+
* can act on. The comparison is the same pixel comparison the capture engine
|
|
70
|
+
* uses between frames, so a change region here means what it means there.
|
|
71
|
+
*
|
|
72
|
+
* The two sides are captured one after the other rather than at once, so both
|
|
73
|
+
* get an unloaded machine and the same `wait_ms` means the same thing for
|
|
74
|
+
* each; a difference in the result should come from the pages, not from which
|
|
75
|
+
* of them was competing for the CPU. (Which of the two goes first is decided
|
|
76
|
+
* by `"current"` — see below — not by their order in the input.)
|
|
77
|
+
*/
|
|
78
|
+
export declare function comparePages(rawInput: CompareInput): Promise<CallToolResult>;
|
|
79
|
+
/**
|
|
80
|
+
* One actionable line for a failed comparison. Mirrors `describeFailure` in
|
|
81
|
+
* screenshot.ts, with one addition: a `page.goto` failure names which of the
|
|
82
|
+
* two sides could not be opened, which is the first thing you want to know.
|
|
83
|
+
*/
|
|
84
|
+
export declare function describeCompareFailure(input: Pick<ParsedCompareInput, "url_a" | "url_b" | "wait_for" | "wait_for_timeout_ms">, error: unknown): string;
|
|
85
|
+
export declare function registerCompareTool(server: McpServer): void;
|
|
86
|
+
export {};
|
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import { CROP_PADDING_PX, DEFAULT_COMPARE_WAIT_MS, DEFAULT_VIEWPORT, MAX_VIEWPORT_HEIGHT, MAX_VIEWPORT_WIDTH, NAVIGATION_TIMEOUT_MS, PAGE_INFO_TIMEOUT_MS, SELECTOR_TIMEOUT_MS, } from "../constants.js";
|
|
3
|
+
import { getSessionPage, withPage, withSessionLock } from "../engine/browser.js";
|
|
4
|
+
import { computePixelMask, padBoundingBox } from "../engine/differ.js";
|
|
5
|
+
import { getDimensions, overlayMask, resizeForOutput, toBase64, toGrayscale } from "../utils/image.js";
|
|
6
|
+
export const COMPARE_TOOL_NAME = "framewatch_compare";
|
|
7
|
+
/** `url_a` accepts this instead of a URL, meaning "whatever framewatch_interact is looking at". */
|
|
8
|
+
export const CURRENT_PAGE = "current";
|
|
9
|
+
/**
|
|
10
|
+
* Either a URL or the literal "current". `z.string().url()` cannot express
|
|
11
|
+
* that, so the check is spelled out — and the message says both options,
|
|
12
|
+
* because "invalid url" on the word `current` is a confusing thing to read.
|
|
13
|
+
*/
|
|
14
|
+
const sideSchema = z.string().refine((value) => value === CURRENT_PAGE || isUrl(value), {
|
|
15
|
+
message: `must be a URL, or "${CURRENT_PAGE}" to use the page framewatch_interact currently has open`,
|
|
16
|
+
});
|
|
17
|
+
export const compareInputShape = {
|
|
18
|
+
url_a: sideSchema.describe(`First URL — the "before" side. Pass "${CURRENT_PAGE}" to compare against the page framewatch_interact has open, ` +
|
|
19
|
+
"in whatever state your interactions left it."),
|
|
20
|
+
url_b: sideSchema.describe('Second URL — the "after" side.'),
|
|
21
|
+
wait_ms: z
|
|
22
|
+
.number()
|
|
23
|
+
.int()
|
|
24
|
+
.min(0)
|
|
25
|
+
.default(DEFAULT_COMPARE_WAIT_MS)
|
|
26
|
+
.describe("Wait time (ms) after page load before each screenshot"),
|
|
27
|
+
wait_for: z.string().optional().describe("CSS selector to wait for (visible) on both sides before capturing"),
|
|
28
|
+
wait_for_timeout_ms: z
|
|
29
|
+
.number()
|
|
30
|
+
.int()
|
|
31
|
+
.min(1)
|
|
32
|
+
.default(SELECTOR_TIMEOUT_MS)
|
|
33
|
+
.describe("Max time (ms) to wait for `wait_for` to appear (must be > 0)"),
|
|
34
|
+
viewport: z
|
|
35
|
+
.object({
|
|
36
|
+
width: z.number().int().min(1).max(MAX_VIEWPORT_WIDTH).default(DEFAULT_VIEWPORT.width),
|
|
37
|
+
height: z.number().int().min(1).max(MAX_VIEWPORT_HEIGHT).default(DEFAULT_VIEWPORT.height),
|
|
38
|
+
})
|
|
39
|
+
.optional()
|
|
40
|
+
.describe("Viewport for both sides (defaults to 1280x720, or the open page's size when comparing against `current`)"),
|
|
41
|
+
};
|
|
42
|
+
export const compareInputSchema = z.object(compareInputShape);
|
|
43
|
+
/**
|
|
44
|
+
* Compare two pages — or the same page before and after a change — and show
|
|
45
|
+
* what moved.
|
|
46
|
+
*
|
|
47
|
+
* Returns both screenshots plus an overlay: side B with every differing pixel
|
|
48
|
+
* tinted, which is the part that turns "3.4% changed" into something a reader
|
|
49
|
+
* can act on. The comparison is the same pixel comparison the capture engine
|
|
50
|
+
* uses between frames, so a change region here means what it means there.
|
|
51
|
+
*
|
|
52
|
+
* The two sides are captured one after the other rather than at once, so both
|
|
53
|
+
* get an unloaded machine and the same `wait_ms` means the same thing for
|
|
54
|
+
* each; a difference in the result should come from the pages, not from which
|
|
55
|
+
* of them was competing for the CPU. (Which of the two goes first is decided
|
|
56
|
+
* by `"current"` — see below — not by their order in the input.)
|
|
57
|
+
*/
|
|
58
|
+
export async function comparePages(rawInput) {
|
|
59
|
+
const parsed = compareInputSchema.safeParse(rawInput);
|
|
60
|
+
if (!parsed.success) {
|
|
61
|
+
const issues = parsed.error.issues.map((i) => `${i.path.join(".") || "input"}: ${i.message}`).join("; ");
|
|
62
|
+
return errorResult(`Compare failed: invalid input — ${issues}`);
|
|
63
|
+
}
|
|
64
|
+
const input = parsed.data;
|
|
65
|
+
// The open page is the one side that cannot be resized — doing so would
|
|
66
|
+
// change the state being compared — so it is captured first whichever side
|
|
67
|
+
// it is, and its size is what the other side is then captured at. Frames of
|
|
68
|
+
// two different sizes cannot be compared pixel for pixel at all.
|
|
69
|
+
const openIsB = input.url_b === CURRENT_PAGE && input.url_a !== CURRENT_PAGE;
|
|
70
|
+
const [firstSide, secondSide] = openIsB ? [input.url_b, input.url_a] : [input.url_a, input.url_b];
|
|
71
|
+
try {
|
|
72
|
+
const first = await captureSide(input, firstSide);
|
|
73
|
+
const notes = [];
|
|
74
|
+
let viewport = input.viewport ?? { ...DEFAULT_VIEWPORT };
|
|
75
|
+
if (firstSide === CURRENT_PAGE) {
|
|
76
|
+
const open = await sizeOf(first.png);
|
|
77
|
+
if (input.viewport && (input.viewport.width !== open.width || input.viewport.height !== open.height)) {
|
|
78
|
+
notes.push(`Ignored \`viewport\` ${input.viewport.width}x${input.viewport.height}: the open page is ` +
|
|
79
|
+
`${open.width}x${open.height} and resizing it would change the state being compared. ` +
|
|
80
|
+
"Both sides were captured at the open page's size.");
|
|
81
|
+
}
|
|
82
|
+
viewport = open;
|
|
83
|
+
}
|
|
84
|
+
const second = await captureSide(input, secondSide, viewport);
|
|
85
|
+
const [a, b] = openIsB ? [second, first] : [first, second];
|
|
86
|
+
return await render(input, a, b, notes);
|
|
87
|
+
}
|
|
88
|
+
catch (error) {
|
|
89
|
+
return errorResult(describeCompareFailure(input, error));
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* Screenshot one side.
|
|
94
|
+
*
|
|
95
|
+
* A URL gets a fresh context, so nothing from the other side (or from an
|
|
96
|
+
* earlier tool call) can leak into it. "current" instead reads the page
|
|
97
|
+
* `framewatch_interact` has open, *without* touching it: the whole point of
|
|
98
|
+
* that option is to compare a hand-built state — three clicks deep into a
|
|
99
|
+
* flow — against a plain URL, and reloading or resizing it would destroy the
|
|
100
|
+
* very thing being compared.
|
|
101
|
+
*/
|
|
102
|
+
async function captureSide(input, side, viewport) {
|
|
103
|
+
if (side === CURRENT_PAGE) {
|
|
104
|
+
// Under the session lock: an interaction running in parallel would
|
|
105
|
+
// otherwise be screenshotted half way through.
|
|
106
|
+
return withSessionLock(async () => {
|
|
107
|
+
const { page } = await getSessionPage();
|
|
108
|
+
if (page.url() === "about:blank") {
|
|
109
|
+
throw new Error(`no page is open, so there is no "${CURRENT_PAGE}" state to compare — ` +
|
|
110
|
+
"use framewatch_interact first, or pass a URL here.");
|
|
111
|
+
}
|
|
112
|
+
return { png: await page.screenshot({ type: "png" }), url: page.url(), title: await safeTitle(page) };
|
|
113
|
+
});
|
|
114
|
+
}
|
|
115
|
+
return withPage({ viewport: viewport ?? input.viewport ?? { ...DEFAULT_VIEWPORT } }, async (page) => {
|
|
116
|
+
await page.goto(side, { waitUntil: "load", timeout: NAVIGATION_TIMEOUT_MS });
|
|
117
|
+
if (input.wait_for) {
|
|
118
|
+
await page.waitForSelector(input.wait_for, { state: "visible", timeout: input.wait_for_timeout_ms });
|
|
119
|
+
}
|
|
120
|
+
if (input.wait_ms > 0) {
|
|
121
|
+
await page.waitForTimeout(input.wait_ms);
|
|
122
|
+
}
|
|
123
|
+
return { png: await page.screenshot({ type: "png" }), url: page.url(), title: await safeTitle(page) };
|
|
124
|
+
});
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Build the result: a summary, both frames, and (when the two are comparable
|
|
128
|
+
* and actually differ) the overlay.
|
|
129
|
+
*
|
|
130
|
+
* Sides of different sizes are reported as such rather than being stretched to
|
|
131
|
+
* match. Rescaling one of them would resample every pixel in it, and the
|
|
132
|
+
* "differences" that came back would be the resampling, not the pages.
|
|
133
|
+
*/
|
|
134
|
+
async function render(input, a, b, notes) {
|
|
135
|
+
const [grayA, grayB] = await Promise.all([toGrayscale(a.png), toGrayscale(b.png)]);
|
|
136
|
+
const nameA = describeSide(input.url_a, a);
|
|
137
|
+
const nameB = describeSide(input.url_b, b);
|
|
138
|
+
const sameSize = grayA.width === grayB.width && grayA.height === grayB.height;
|
|
139
|
+
const lines = [];
|
|
140
|
+
let overlay;
|
|
141
|
+
let overlayNote = "";
|
|
142
|
+
if (!sameSize) {
|
|
143
|
+
lines.push(`Compared ${nameA} against ${nameB} — the two frames are different sizes ` +
|
|
144
|
+
`(${grayA.width}x${grayA.height} vs ${grayB.width}x${grayB.height}), so they cannot be compared pixel ` +
|
|
145
|
+
"for pixel. Both are below.");
|
|
146
|
+
}
|
|
147
|
+
else {
|
|
148
|
+
const diff = computePixelMask(grayA.data, grayB.data, grayA.width, grayA.height);
|
|
149
|
+
const region = diff.bbox === null ? null : padBoundingBox(diff.bbox, CROP_PADDING_PX, grayA.width, grayA.height);
|
|
150
|
+
lines.push(`Compared ${nameA} against ${nameB} at ${grayA.width}x${grayA.height} — ` +
|
|
151
|
+
`${diff.changePercent.toFixed(2)}% of pixels differ` +
|
|
152
|
+
(region === null
|
|
153
|
+
? ". The two are pixel-identical."
|
|
154
|
+
: `, all of it within ${region.x},${region.y} ${region.width}x${region.height}.`));
|
|
155
|
+
if (region !== null) {
|
|
156
|
+
overlay = await resizeForOutput(await overlayMask(b.png, diff.mask, grayA.width, grayA.height));
|
|
157
|
+
overlayNote =
|
|
158
|
+
`Diff overlay — B with every differing pixel tinted. ${diff.changedPixels} of ${diff.totalPixels} ` +
|
|
159
|
+
`pixels changed (${diff.changePercent.toFixed(2)}%), within ` +
|
|
160
|
+
`${region.x},${region.y} ${region.width}x${region.height}.`;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
const content = [{ type: "text", text: [...lines, ...notes].join("\n") }];
|
|
164
|
+
await pushFrame(content, a.png, `A — ${nameA}`);
|
|
165
|
+
await pushFrame(content, b.png, `B — ${nameB}`);
|
|
166
|
+
if (overlay) {
|
|
167
|
+
content.push({ type: "image", data: toBase64(overlay), mimeType: "image/png" });
|
|
168
|
+
content.push({ type: "text", text: overlayNote });
|
|
169
|
+
}
|
|
170
|
+
return { content };
|
|
171
|
+
}
|
|
172
|
+
async function pushFrame(content, png, label) {
|
|
173
|
+
const resized = await resizeForOutput(png);
|
|
174
|
+
const { width, height } = await getDimensions(resized);
|
|
175
|
+
content.push({ type: "image", data: toBase64(resized), mimeType: "image/png" });
|
|
176
|
+
content.push({ type: "text", text: `${label} — image ${width}x${height}` });
|
|
177
|
+
}
|
|
178
|
+
/** How a side is named in the output: where it ended up, and its title if it has one. */
|
|
179
|
+
function describeSide(requested, side) {
|
|
180
|
+
const where = requested === CURRENT_PAGE ? `the open page (${side.url})` : side.url;
|
|
181
|
+
return side.title ? `${where} "${side.title}"` : where;
|
|
182
|
+
}
|
|
183
|
+
/** Cosmetic, and never allowed to fail or stall: a busy page still gets compared. */
|
|
184
|
+
async function safeTitle(page) {
|
|
185
|
+
return Promise.race([
|
|
186
|
+
page.title().catch(() => undefined),
|
|
187
|
+
new Promise((resolve) => setTimeout(() => resolve(undefined), PAGE_INFO_TIMEOUT_MS)),
|
|
188
|
+
]);
|
|
189
|
+
}
|
|
190
|
+
async function sizeOf(png) {
|
|
191
|
+
const { width, height } = await getDimensions(png);
|
|
192
|
+
return { width, height };
|
|
193
|
+
}
|
|
194
|
+
function isUrl(value) {
|
|
195
|
+
try {
|
|
196
|
+
new URL(value);
|
|
197
|
+
return true;
|
|
198
|
+
}
|
|
199
|
+
catch {
|
|
200
|
+
return false;
|
|
201
|
+
}
|
|
202
|
+
}
|
|
203
|
+
function errorResult(text) {
|
|
204
|
+
return { isError: true, content: [{ type: "text", text }] };
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* One actionable line for a failed comparison. Mirrors `describeFailure` in
|
|
208
|
+
* screenshot.ts, with one addition: a `page.goto` failure names which of the
|
|
209
|
+
* two sides could not be opened, which is the first thing you want to know.
|
|
210
|
+
*/
|
|
211
|
+
export function describeCompareFailure(input, error) {
|
|
212
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
213
|
+
const firstLine = message.split("\n")[0];
|
|
214
|
+
const prefix = "Compare failed:";
|
|
215
|
+
if (/Executable doesn't exist|browserType\.launch/i.test(message)) {
|
|
216
|
+
return (`${prefix} Playwright's Chromium browser is not installed. ` +
|
|
217
|
+
`Run \`npx playwright install chromium\` and try again. (${firstLine})`);
|
|
218
|
+
}
|
|
219
|
+
if (/^page\.goto:/.test(message)) {
|
|
220
|
+
const side = failingSide(input, message);
|
|
221
|
+
return `${prefix} could not open ${side} — ${firstLine}`;
|
|
222
|
+
}
|
|
223
|
+
if (input.wait_for && /^page\.waitForSelector:/.test(message)) {
|
|
224
|
+
return `${prefix} selector "${input.wait_for}" did not become visible within ${input.wait_for_timeout_ms}ms.`;
|
|
225
|
+
}
|
|
226
|
+
return `${prefix} ${firstLine}`;
|
|
227
|
+
}
|
|
228
|
+
/** Playwright quotes the URL it tried in a goto failure; that says which side broke. */
|
|
229
|
+
function failingSide(input, message) {
|
|
230
|
+
if (input.url_b !== CURRENT_PAGE && message.includes(input.url_b))
|
|
231
|
+
return `url_b (${input.url_b})`;
|
|
232
|
+
if (input.url_a !== CURRENT_PAGE && message.includes(input.url_a))
|
|
233
|
+
return `url_a (${input.url_a})`;
|
|
234
|
+
return "one of the two pages";
|
|
235
|
+
}
|
|
236
|
+
export function registerCompareTool(server) {
|
|
237
|
+
server.registerTool(COMPARE_TOOL_NAME, {
|
|
238
|
+
title: "Compare",
|
|
239
|
+
description: "Compare two pages — two URLs, or the same URL before and after a code change — and show what moved. " +
|
|
240
|
+
"Returns both screenshots, the percentage of pixels that differ, the region they differ in, and an " +
|
|
241
|
+
`overlay of the second page with every changed pixel tinted. Pass "${CURRENT_PAGE}" as \`url_a\` to ` +
|
|
242
|
+
"compare against the page framewatch_interact has open, in whatever state your interactions left it.",
|
|
243
|
+
inputSchema: compareInputShape,
|
|
244
|
+
annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },
|
|
245
|
+
}, async (args) => comparePages(args));
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=compare.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"compare.js","sourceRoot":"","sources":["../../src/tools/compare.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAIxB,OAAO,EACL,eAAe,EACf,uBAAuB,EACvB,gBAAgB,EAChB,mBAAmB,EACnB,kBAAkB,EAClB,qBAAqB,EACrB,oBAAoB,EACpB,mBAAmB,GACpB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAAE,cAAc,EAAE,QAAQ,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACjF,OAAO,EAAE,gBAAgB,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAEvE,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,eAAe,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;A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,EAAE,IAAI,EAAE,eAAe,EAAE,KAAK,EAAE,cAAc,EAAE,IAAI,EAAE,aAAa,EAAE,IAAI,EAAE;KACvG,EACD,KAAK,EAAE,IAAI,EAAE,EAAE,CAAC,YAAY,CAAC,IAAI,CAAC,CACnC,CAAC;AACJ,CAAC","sourcesContent":["import { z } from \"zod\";\nimport type { Page } from \"playwright\";\nimport type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport type { CallToolResult } from \"@modelcontextprotocol/sdk/types.js\";\nimport {\n CROP_PADDING_PX,\n DEFAULT_COMPARE_WAIT_MS,\n DEFAULT_VIEWPORT,\n MAX_VIEWPORT_HEIGHT,\n MAX_VIEWPORT_WIDTH,\n NAVIGATION_TIMEOUT_MS,\n PAGE_INFO_TIMEOUT_MS,\n SELECTOR_TIMEOUT_MS,\n} from \"../constants.js\";\nimport { getSessionPage, withPage, withSessionLock } from \"../engine/browser.js\";\nimport { computePixelMask, padBoundingBox } from \"../engine/differ.js\";\nimport type { BoundingBox, Viewport } from \"../types.js\";\nimport { getDimensions, overlayMask, resizeForOutput, toBase64, toGrayscale } from \"../utils/image.js\";\n\nexport const COMPARE_TOOL_NAME = \"framewatch_compare\";\n\n/** `url_a` accepts this instead of a URL, meaning \"whatever framewatch_interact is looking at\". */\nexport const CURRENT_PAGE = \"current\";\n\n/**\n * Either a URL or the literal \"current\". `z.string().url()` cannot express\n * that, so the check is spelled out — and the message says both options,\n * because \"invalid url\" on the word `current` is a confusing thing to read.\n */\nconst sideSchema = z.string().refine((value) => value === CURRENT_PAGE || isUrl(value), {\n message: `must be a URL, or \"${CURRENT_PAGE}\" to use the page framewatch_interact currently has open`,\n});\n\nexport const compareInputShape = {\n url_a: sideSchema.describe(\n `First URL — the \"before\" side. Pass \"${CURRENT_PAGE}\" to compare against the page framewatch_interact has open, ` +\n \"in whatever state your interactions left it.\",\n ),\n url_b: sideSchema.describe('Second URL — the \"after\" side.'),\n wait_ms: z\n .number()\n .int()\n .min(0)\n .default(DEFAULT_COMPARE_WAIT_MS)\n .describe(\"Wait time (ms) after page load before each screenshot\"),\n wait_for: z.string().optional().describe(\"CSS selector to wait for (visible) on both sides before capturing\"),\n wait_for_timeout_ms: z\n .number()\n .int()\n .min(1)\n .default(SELECTOR_TIMEOUT_MS)\n .describe(\"Max time (ms) to wait for `wait_for` to appear (must be > 0)\"),\n viewport: z\n .object({\n width: z.number().int().min(1).max(MAX_VIEWPORT_WIDTH).default(DEFAULT_VIEWPORT.width),\n height: z.number().int().min(1).max(MAX_VIEWPORT_HEIGHT).default(DEFAULT_VIEWPORT.height),\n })\n .optional()\n .describe(\"Viewport for both sides (defaults to 1280x720, or the open page's size when comparing against `current`)\"),\n};\n\nexport const compareInputSchema = z.object(compareInputShape);\nexport type CompareInput = z.input<typeof compareInputSchema>;\ntype ParsedCompareInput = z.output<typeof compareInputSchema>;\n\n/** One captured side of the comparison. */\ninterface Side {\n png: Buffer;\n /** Where the shot was actually taken (after redirects), or the open page's URL. */\n url: string;\n title?: string;\n}\n\n/**\n * Compare two pages — or the same page before and after a change — and show\n * what moved.\n *\n * Returns both screenshots plus an overlay: side B with every differing pixel\n * tinted, which is the part that turns \"3.4% changed\" into something a reader\n * can act on. The comparison is the same pixel comparison the capture engine\n * uses between frames, so a change region here means what it means there.\n *\n * The two sides are captured one after the other rather than at once, so both\n * get an unloaded machine and the same `wait_ms` means the same thing for\n * each; a difference in the result should come from the pages, not from which\n * of them was competing for the CPU. (Which of the two goes first is decided\n * by `\"current\"` — see below — not by their order in the input.)\n */\nexport async function comparePages(rawInput: CompareInput): Promise<CallToolResult> {\n const parsed = compareInputSchema.safeParse(rawInput);\n if (!parsed.success) {\n const issues = parsed.error.issues.map((i) => `${i.path.join(\".\") || \"input\"}: ${i.message}`).join(\"; \");\n return errorResult(`Compare failed: invalid input — ${issues}`);\n }\n const input = parsed.data;\n\n // The open page is the one side that cannot be resized — doing so would\n // change the state being compared — so it is captured first whichever side\n // it is, and its size is what the other side is then captured at. Frames of\n // two different sizes cannot be compared pixel for pixel at all.\n const openIsB = input.url_b === CURRENT_PAGE && input.url_a !== CURRENT_PAGE;\n const [firstSide, secondSide] = openIsB ? [input.url_b, input.url_a] : [input.url_a, input.url_b];\n\n try {\n const first = await captureSide(input, firstSide);\n const notes: string[] = [];\n let viewport = input.viewport ?? { ...DEFAULT_VIEWPORT };\n\n if (firstSide === CURRENT_PAGE) {\n const open = await sizeOf(first.png);\n if (input.viewport && (input.viewport.width !== open.width || input.viewport.height !== open.height)) {\n notes.push(\n `Ignored \\`viewport\\` ${input.viewport.width}x${input.viewport.height}: the open page is ` +\n `${open.width}x${open.height} and resizing it would change the state being compared. ` +\n \"Both sides were captured at the open page's size.\",\n );\n }\n viewport = open;\n }\n\n const second = await captureSide(input, secondSide, viewport);\n const [a, b] = openIsB ? [second, first] : [first, second];\n return await render(input, a, b, notes);\n } catch (error) {\n return errorResult(describeCompareFailure(input, error));\n }\n}\n\n/**\n * Screenshot one side.\n *\n * A URL gets a fresh context, so nothing from the other side (or from an\n * earlier tool call) can leak into it. \"current\" instead reads the page\n * `framewatch_interact` has open, *without* touching it: the whole point of\n * that option is to compare a hand-built state — three clicks deep into a\n * flow — against a plain URL, and reloading or resizing it would destroy the\n * very thing being compared.\n */\nasync function captureSide(input: ParsedCompareInput, side: string, viewport?: Viewport): Promise<Side> {\n if (side === CURRENT_PAGE) {\n // Under the session lock: an interaction running in parallel would\n // otherwise be screenshotted half way through.\n return withSessionLock(async () => {\n const { page } = await getSessionPage();\n if (page.url() === \"about:blank\") {\n throw new Error(\n `no page is open, so there is no \"${CURRENT_PAGE}\" state to compare — ` +\n \"use framewatch_interact first, or pass a URL here.\",\n );\n }\n return { png: await page.screenshot({ type: \"png\" }), url: page.url(), title: await safeTitle(page) };\n });\n }\n\n return withPage({ viewport: viewport ?? input.viewport ?? { ...DEFAULT_VIEWPORT } }, async (page) => {\n await page.goto(side, { waitUntil: \"load\", timeout: NAVIGATION_TIMEOUT_MS });\n if (input.wait_for) {\n await page.waitForSelector(input.wait_for, { state: \"visible\", timeout: input.wait_for_timeout_ms });\n }\n if (input.wait_ms > 0) {\n await page.waitForTimeout(input.wait_ms);\n }\n return { png: await page.screenshot({ type: \"png\" }), url: page.url(), title: await safeTitle(page) };\n });\n}\n\n/**\n * Build the result: a summary, both frames, and (when the two are comparable\n * and actually differ) the overlay.\n *\n * Sides of different sizes are reported as such rather than being stretched to\n * match. Rescaling one of them would resample every pixel in it, and the\n * \"differences\" that came back would be the resampling, not the pages.\n */\nasync function render(input: ParsedCompareInput, a: Side, b: Side, notes: string[]): Promise<CallToolResult> {\n const [grayA, grayB] = await Promise.all([toGrayscale(a.png), toGrayscale(b.png)]);\n const nameA = describeSide(input.url_a, a);\n const nameB = describeSide(input.url_b, b);\n const sameSize = grayA.width === grayB.width && grayA.height === grayB.height;\n\n const lines: string[] = [];\n let overlay: Buffer | undefined;\n let overlayNote = \"\";\n\n if (!sameSize) {\n lines.push(\n `Compared ${nameA} against ${nameB} — the two frames are different sizes ` +\n `(${grayA.width}x${grayA.height} vs ${grayB.width}x${grayB.height}), so they cannot be compared pixel ` +\n \"for pixel. Both are below.\",\n );\n } else {\n const diff = computePixelMask(grayA.data, grayB.data, grayA.width, grayA.height);\n const region: BoundingBox | null =\n diff.bbox === null ? null : padBoundingBox(diff.bbox, CROP_PADDING_PX, grayA.width, grayA.height);\n\n lines.push(\n `Compared ${nameA} against ${nameB} at ${grayA.width}x${grayA.height} — ` +\n `${diff.changePercent.toFixed(2)}% of pixels differ` +\n (region === null\n ? \". The two are pixel-identical.\"\n : `, all of it within ${region.x},${region.y} ${region.width}x${region.height}.`),\n );\n\n if (region !== null) {\n overlay = await resizeForOutput(await overlayMask(b.png, diff.mask, grayA.width, grayA.height));\n overlayNote =\n `Diff overlay — B with every differing pixel tinted. ${diff.changedPixels} of ${diff.totalPixels} ` +\n `pixels changed (${diff.changePercent.toFixed(2)}%), within ` +\n `${region.x},${region.y} ${region.width}x${region.height}.`;\n }\n }\n\n const content: CallToolResult[\"content\"] = [{ type: \"text\", text: [...lines, ...notes].join(\"\\n\") }];\n await pushFrame(content, a.png, `A — ${nameA}`);\n await pushFrame(content, b.png, `B — ${nameB}`);\n if (overlay) {\n content.push({ type: \"image\", data: toBase64(overlay), mimeType: \"image/png\" });\n content.push({ type: \"text\", text: overlayNote });\n }\n return { content };\n}\n\nasync function pushFrame(content: CallToolResult[\"content\"], png: Buffer, label: string): Promise<void> {\n const resized = await resizeForOutput(png);\n const { width, height } = await getDimensions(resized);\n content.push({ type: \"image\", data: toBase64(resized), mimeType: \"image/png\" });\n content.push({ type: \"text\", text: `${label} — image ${width}x${height}` });\n}\n\n/** How a side is named in the output: where it ended up, and its title if it has one. */\nfunction describeSide(requested: string, side: Side): string {\n const where = requested === CURRENT_PAGE ? `the open page (${side.url})` : side.url;\n return side.title ? `${where} \"${side.title}\"` : where;\n}\n\n/** Cosmetic, and never allowed to fail or stall: a busy page still gets compared. */\nasync function safeTitle(page: Page): Promise<string | undefined> {\n return Promise.race([\n page.title().catch(() => undefined),\n new Promise<undefined>((resolve) => setTimeout(() => resolve(undefined), PAGE_INFO_TIMEOUT_MS)),\n ]);\n}\n\nasync function sizeOf(png: Buffer): Promise<Viewport> {\n const { width, height } = await getDimensions(png);\n return { width, height };\n}\n\nfunction isUrl(value: string): boolean {\n try {\n new URL(value);\n return true;\n } catch {\n return false;\n }\n}\n\nfunction errorResult(text: string): CallToolResult {\n return { isError: true, content: [{ type: \"text\", text }] };\n}\n\n/**\n * One actionable line for a failed comparison. Mirrors `describeFailure` in\n * screenshot.ts, with one addition: a `page.goto` failure names which of the\n * two sides could not be opened, which is the first thing you want to know.\n */\nexport function describeCompareFailure(\n input: Pick<ParsedCompareInput, \"url_a\" | \"url_b\" | \"wait_for\" | \"wait_for_timeout_ms\">,\n error: unknown,\n): string {\n const message = error instanceof Error ? error.message : String(error);\n const firstLine = message.split(\"\\n\")[0];\n const prefix = \"Compare failed:\";\n\n if (/Executable doesn't exist|browserType\\.launch/i.test(message)) {\n return (\n `${prefix} Playwright's Chromium browser is not installed. ` +\n `Run \\`npx playwright install chromium\\` and try again. (${firstLine})`\n );\n }\n if (/^page\\.goto:/.test(message)) {\n const side = failingSide(input, message);\n return `${prefix} could not open ${side} — ${firstLine}`;\n }\n if (input.wait_for && /^page\\.waitForSelector:/.test(message)) {\n return `${prefix} selector \"${input.wait_for}\" did not become visible within ${input.wait_for_timeout_ms}ms.`;\n }\n return `${prefix} ${firstLine}`;\n}\n\n/** Playwright quotes the URL it tried in a goto failure; that says which side broke. */\nfunction failingSide(input: Pick<ParsedCompareInput, \"url_a\" | \"url_b\">, message: string): string {\n if (input.url_b !== CURRENT_PAGE && message.includes(input.url_b)) return `url_b (${input.url_b})`;\n if (input.url_a !== CURRENT_PAGE && message.includes(input.url_a)) return `url_a (${input.url_a})`;\n return \"one of the two pages\";\n}\n\nexport function registerCompareTool(server: McpServer): void {\n server.registerTool(\n COMPARE_TOOL_NAME,\n {\n title: \"Compare\",\n description:\n \"Compare two pages — two URLs, or the same URL before and after a code change — and show what moved. \" +\n \"Returns both screenshots, the percentage of pixels that differ, the region they differ in, and an \" +\n `overlay of the second page with every changed pixel tinted. Pass \"${CURRENT_PAGE}\" as \\`url_a\\` to ` +\n \"compare against the page framewatch_interact has open, in whatever state your interactions left it.\",\n inputSchema: compareInputShape,\n annotations: { readOnlyHint: true, destructiveHint: false, idempotentHint: true, openWorldHint: true },\n },\n async (args) => comparePages(args),\n );\n}\n"]}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
+
export { registerScreenshotTool, takeScreenshot, SCREENSHOT_TOOL_NAME } from "./screenshot.js";
|
|
3
|
+
export { registerCaptureTool, capturePage, CAPTURE_TOOL_NAME } from "./capture.js";
|
|
4
|
+
export { registerInteractTool, performInteraction, INTERACT_TOOL_NAME } from "./interact.js";
|
|
5
|
+
export { registerResponsiveTool, captureResponsive, RESPONSIVE_TOOL_NAME } from "./responsive.js";
|
|
6
|
+
export { registerAccessibilityTool, auditAccessibility, ACCESSIBILITY_TOOL_NAME } from "./accessibility.js";
|
|
7
|
+
export { registerCompareTool, comparePages, COMPARE_TOOL_NAME, CURRENT_PAGE } from "./compare.js";
|
|
8
|
+
export { registerServerTools, startServer, stopServer, START_SERVER_TOOL_NAME, STOP_SERVER_TOOL_NAME, } from "./server.js";
|
|
9
|
+
/** Register every FrameWatch tool on the given server. */
|
|
10
|
+
export declare function registerAllTools(server: McpServer): void;
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { registerAccessibilityTool } from "./accessibility.js";
|
|
2
|
+
import { registerCaptureTool } from "./capture.js";
|
|
3
|
+
import { registerCompareTool } from "./compare.js";
|
|
4
|
+
import { registerInteractTool } from "./interact.js";
|
|
5
|
+
import { registerResponsiveTool } from "./responsive.js";
|
|
6
|
+
import { registerScreenshotTool } from "./screenshot.js";
|
|
7
|
+
import { registerServerTools } from "./server.js";
|
|
8
|
+
export { registerScreenshotTool, takeScreenshot, SCREENSHOT_TOOL_NAME } from "./screenshot.js";
|
|
9
|
+
export { registerCaptureTool, capturePage, CAPTURE_TOOL_NAME } from "./capture.js";
|
|
10
|
+
export { registerInteractTool, performInteraction, INTERACT_TOOL_NAME } from "./interact.js";
|
|
11
|
+
export { registerResponsiveTool, captureResponsive, RESPONSIVE_TOOL_NAME } from "./responsive.js";
|
|
12
|
+
export { registerAccessibilityTool, auditAccessibility, ACCESSIBILITY_TOOL_NAME } from "./accessibility.js";
|
|
13
|
+
export { registerCompareTool, comparePages, COMPARE_TOOL_NAME, CURRENT_PAGE } from "./compare.js";
|
|
14
|
+
export { registerServerTools, startServer, stopServer, START_SERVER_TOOL_NAME, STOP_SERVER_TOOL_NAME, } from "./server.js";
|
|
15
|
+
/** Register every FrameWatch tool on the given server. */
|
|
16
|
+
export function registerAllTools(server) {
|
|
17
|
+
registerScreenshotTool(server);
|
|
18
|
+
registerCaptureTool(server);
|
|
19
|
+
registerInteractTool(server);
|
|
20
|
+
registerResponsiveTool(server);
|
|
21
|
+
registerAccessibilityTool(server);
|
|
22
|
+
registerCompareTool(server);
|
|
23
|
+
registerServerTools(server);
|
|
24
|
+
}
|
|
25
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/tools/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,yBAAyB,EAAE,MAAM,oBAAoB,CAAC;AAC/D,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAC;AACnD,OAAO,EAAE,oBAAoB,EAAE,MAAM,eAAe,CAAC;AACrD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACzD,OAAO,EAAE,mBAAmB,EAAE,MAAM,aAAa,CAAC;AAElD,OAAO,EAAE,sBAAsB,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAC/F,OAAO,EAAE,mBAAmB,EAAE,WAAW,EAAE,iBAAiB,EAAE,MAAM,cAAc,CAAC;AACnF,OAAO,EAAE,oBAAoB,EAAE,kBAAkB,EAAE,kBAAkB,EAAE,MAAM,eAAe,CAAC;AAC7F,OAAO,EAAE,sBAAsB,EAAE,iBAAiB,EAAE,oBAAoB,EAAE,MAAM,iBAAiB,CAAC;AAClG,OAAO,EAAE,yBAAyB,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,oBAAoB,CAAC;AAC5G,OAAO,EAAE,mBAAmB,EAAE,YAAY,EAAE,iBAAiB,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAClG,OAAO,EACL,mBAAmB,EACnB,WAAW,EACX,UAAU,EACV,sBAAsB,EACtB,qBAAqB,GACtB,MAAM,aAAa,CAAC;AAErB,0DAA0D;AAC1D,MAAM,UAAU,gBAAgB,CAAC,MAAiB;IAChD,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC/B,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,oBAAoB,CAAC,MAAM,CAAC,CAAC;IAC7B,sBAAsB,CAAC,MAAM,CAAC,CAAC;IAC/B,yBAAyB,CAAC,MAAM,CAAC,CAAC;IAClC,mBAAmB,CAAC,MAAM,CAAC,CAAC;IAC5B,mBAAmB,CAAC,MAAM,CAAC,CAAC;AAC9B,CAAC","sourcesContent":["import type { McpServer } from \"@modelcontextprotocol/sdk/server/mcp.js\";\nimport { registerAccessibilityTool } from \"./accessibility.js\";\nimport { registerCaptureTool } from \"./capture.js\";\nimport { registerCompareTool } from \"./compare.js\";\nimport { registerInteractTool } from \"./interact.js\";\nimport { registerResponsiveTool } from \"./responsive.js\";\nimport { registerScreenshotTool } from \"./screenshot.js\";\nimport { registerServerTools } from \"./server.js\";\n\nexport { registerScreenshotTool, takeScreenshot, SCREENSHOT_TOOL_NAME } from \"./screenshot.js\";\nexport { registerCaptureTool, capturePage, CAPTURE_TOOL_NAME } from \"./capture.js\";\nexport { registerInteractTool, performInteraction, INTERACT_TOOL_NAME } from \"./interact.js\";\nexport { registerResponsiveTool, captureResponsive, RESPONSIVE_TOOL_NAME } from \"./responsive.js\";\nexport { registerAccessibilityTool, auditAccessibility, ACCESSIBILITY_TOOL_NAME } from \"./accessibility.js\";\nexport { registerCompareTool, comparePages, COMPARE_TOOL_NAME, CURRENT_PAGE } from \"./compare.js\";\nexport {\n registerServerTools,\n startServer,\n stopServer,\n START_SERVER_TOOL_NAME,\n STOP_SERVER_TOOL_NAME,\n} from \"./server.js\";\n\n/** Register every FrameWatch tool on the given server. */\nexport function registerAllTools(server: McpServer): void {\n registerScreenshotTool(server);\n registerCaptureTool(server);\n registerInteractTool(server);\n registerResponsiveTool(server);\n registerAccessibilityTool(server);\n registerCompareTool(server);\n registerServerTools(server);\n}\n"]}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import { z } from "zod";
|
|
2
|
+
import type { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
4
|
+
export declare const INTERACT_TOOL_NAME = "framewatch_interact";
|
|
5
|
+
export declare const interactInputShape: {
|
|
6
|
+
url: z.ZodOptional<z.ZodString>;
|
|
7
|
+
wait_ms: z.ZodDefault<z.ZodNumber>;
|
|
8
|
+
timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
9
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
10
|
+
width: z.ZodNumber;
|
|
11
|
+
height: z.ZodNumber;
|
|
12
|
+
}, "strip", z.ZodTypeAny, {
|
|
13
|
+
width: number;
|
|
14
|
+
height: number;
|
|
15
|
+
}, {
|
|
16
|
+
width: number;
|
|
17
|
+
height: number;
|
|
18
|
+
}>>;
|
|
19
|
+
include_console: z.ZodDefault<z.ZodBoolean>;
|
|
20
|
+
include_network: z.ZodDefault<z.ZodBoolean>;
|
|
21
|
+
include_dom: z.ZodDefault<z.ZodBoolean>;
|
|
22
|
+
include_performance: z.ZodDefault<z.ZodBoolean>;
|
|
23
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
24
|
+
value: z.ZodOptional<z.ZodString>;
|
|
25
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
26
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
27
|
+
delta_x: z.ZodOptional<z.ZodNumber>;
|
|
28
|
+
delta_y: z.ZodOptional<z.ZodNumber>;
|
|
29
|
+
action: z.ZodEnum<["click", "tap", "type", "scroll", "swipe", "navigate", "select", "hover"]>;
|
|
30
|
+
};
|
|
31
|
+
export declare const interactInputSchema: z.ZodEffects<z.ZodObject<{
|
|
32
|
+
url: z.ZodOptional<z.ZodString>;
|
|
33
|
+
wait_ms: z.ZodDefault<z.ZodNumber>;
|
|
34
|
+
timeout_ms: z.ZodDefault<z.ZodNumber>;
|
|
35
|
+
viewport: z.ZodOptional<z.ZodObject<{
|
|
36
|
+
width: z.ZodNumber;
|
|
37
|
+
height: z.ZodNumber;
|
|
38
|
+
}, "strip", z.ZodTypeAny, {
|
|
39
|
+
width: number;
|
|
40
|
+
height: number;
|
|
41
|
+
}, {
|
|
42
|
+
width: number;
|
|
43
|
+
height: number;
|
|
44
|
+
}>>;
|
|
45
|
+
include_console: z.ZodDefault<z.ZodBoolean>;
|
|
46
|
+
include_network: z.ZodDefault<z.ZodBoolean>;
|
|
47
|
+
include_dom: z.ZodDefault<z.ZodBoolean>;
|
|
48
|
+
include_performance: z.ZodDefault<z.ZodBoolean>;
|
|
49
|
+
selector: z.ZodOptional<z.ZodString>;
|
|
50
|
+
value: z.ZodOptional<z.ZodString>;
|
|
51
|
+
x: z.ZodOptional<z.ZodNumber>;
|
|
52
|
+
y: z.ZodOptional<z.ZodNumber>;
|
|
53
|
+
delta_x: z.ZodOptional<z.ZodNumber>;
|
|
54
|
+
delta_y: z.ZodOptional<z.ZodNumber>;
|
|
55
|
+
action: z.ZodEnum<["click", "tap", "type", "scroll", "swipe", "navigate", "select", "hover"]>;
|
|
56
|
+
}, "strip", z.ZodTypeAny, {
|
|
57
|
+
wait_ms: number;
|
|
58
|
+
action: "type" | "click" | "tap" | "scroll" | "swipe" | "navigate" | "select" | "hover";
|
|
59
|
+
include_console: boolean;
|
|
60
|
+
include_network: boolean;
|
|
61
|
+
include_dom: boolean;
|
|
62
|
+
include_performance: boolean;
|
|
63
|
+
timeout_ms: number;
|
|
64
|
+
viewport?: {
|
|
65
|
+
width: number;
|
|
66
|
+
height: number;
|
|
67
|
+
} | undefined;
|
|
68
|
+
value?: string | undefined;
|
|
69
|
+
url?: string | undefined;
|
|
70
|
+
x?: number | undefined;
|
|
71
|
+
y?: number | undefined;
|
|
72
|
+
selector?: string | undefined;
|
|
73
|
+
delta_x?: number | undefined;
|
|
74
|
+
delta_y?: number | undefined;
|
|
75
|
+
}, {
|
|
76
|
+
action: "type" | "click" | "tap" | "scroll" | "swipe" | "navigate" | "select" | "hover";
|
|
77
|
+
viewport?: {
|
|
78
|
+
width: number;
|
|
79
|
+
height: number;
|
|
80
|
+
} | undefined;
|
|
81
|
+
value?: string | undefined;
|
|
82
|
+
url?: string | undefined;
|
|
83
|
+
wait_ms?: number | undefined;
|
|
84
|
+
x?: number | undefined;
|
|
85
|
+
y?: number | undefined;
|
|
86
|
+
selector?: string | undefined;
|
|
87
|
+
delta_x?: number | undefined;
|
|
88
|
+
delta_y?: number | undefined;
|
|
89
|
+
include_console?: boolean | undefined;
|
|
90
|
+
include_network?: boolean | undefined;
|
|
91
|
+
include_dom?: boolean | undefined;
|
|
92
|
+
include_performance?: boolean | undefined;
|
|
93
|
+
timeout_ms?: number | undefined;
|
|
94
|
+
}>, {
|
|
95
|
+
wait_ms: number;
|
|
96
|
+
action: "type" | "click" | "tap" | "scroll" | "swipe" | "navigate" | "select" | "hover";
|
|
97
|
+
include_console: boolean;
|
|
98
|
+
include_network: boolean;
|
|
99
|
+
include_dom: boolean;
|
|
100
|
+
include_performance: boolean;
|
|
101
|
+
timeout_ms: number;
|
|
102
|
+
viewport?: {
|
|
103
|
+
width: number;
|
|
104
|
+
height: number;
|
|
105
|
+
} | undefined;
|
|
106
|
+
value?: string | undefined;
|
|
107
|
+
url?: string | undefined;
|
|
108
|
+
x?: number | undefined;
|
|
109
|
+
y?: number | undefined;
|
|
110
|
+
selector?: string | undefined;
|
|
111
|
+
delta_x?: number | undefined;
|
|
112
|
+
delta_y?: number | undefined;
|
|
113
|
+
}, {
|
|
114
|
+
action: "type" | "click" | "tap" | "scroll" | "swipe" | "navigate" | "select" | "hover";
|
|
115
|
+
viewport?: {
|
|
116
|
+
width: number;
|
|
117
|
+
height: number;
|
|
118
|
+
} | undefined;
|
|
119
|
+
value?: string | undefined;
|
|
120
|
+
url?: string | undefined;
|
|
121
|
+
wait_ms?: number | undefined;
|
|
122
|
+
x?: number | undefined;
|
|
123
|
+
y?: number | undefined;
|
|
124
|
+
selector?: string | undefined;
|
|
125
|
+
delta_x?: number | undefined;
|
|
126
|
+
delta_y?: number | undefined;
|
|
127
|
+
include_console?: boolean | undefined;
|
|
128
|
+
include_network?: boolean | undefined;
|
|
129
|
+
include_dom?: boolean | undefined;
|
|
130
|
+
include_performance?: boolean | undefined;
|
|
131
|
+
timeout_ms?: number | undefined;
|
|
132
|
+
}>;
|
|
133
|
+
export type InteractInput = z.input<typeof interactInputSchema>;
|
|
134
|
+
/**
|
|
135
|
+
* Perform one interaction on the current page and show what it did.
|
|
136
|
+
*
|
|
137
|
+
* Unlike every other FrameWatch tool this one is stateful on purpose: the page
|
|
138
|
+
* stays open between calls (see `getSessionPage`), which is what makes
|
|
139
|
+
* click → look → type → look iteration possible. Pass `url` to open or move
|
|
140
|
+
* the page; omit it to keep working on what is already there.
|
|
141
|
+
*
|
|
142
|
+
* The result is a two-frame diff card sequence — before, after, and the
|
|
143
|
+
* change region between them — reusing the same diff engine as
|
|
144
|
+
* `framewatch_capture` so the change bbox and crop mean the same thing in
|
|
145
|
+
* both tools.
|
|
146
|
+
*
|
|
147
|
+
* Calls are serialised through `withSessionLock`, which every tool that
|
|
148
|
+
* touches the session page shares: one page, one hand.
|
|
149
|
+
*/
|
|
150
|
+
export declare function performInteraction(rawInput: InteractInput): Promise<CallToolResult>;
|
|
151
|
+
/**
|
|
152
|
+
* Turn a failure into one actionable line. Interaction errors already name the
|
|
153
|
+
* step and the reason (see `executeInteraction`), so they are passed through
|
|
154
|
+
* with the page appended for context; everything else is a navigation or
|
|
155
|
+
* browser problem, worded as in the other tools.
|
|
156
|
+
*/
|
|
157
|
+
export declare function describeInteractFailure(input: {
|
|
158
|
+
url?: string;
|
|
159
|
+
}, error: unknown): string;
|
|
160
|
+
export declare function registerInteractTool(server: McpServer): void;
|