@clipy/mcp 0.8.0 → 0.8.1
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/README.md +26 -3
- package/dist/index.js +301 -97
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -97,9 +97,9 @@ or the Windsurf MCP config) directly:
|
|
|
97
97
|
| `download_recording` | Download the MP4 locally so you can clip it or extract frames yourself (e.g. with ffmpeg). |
|
|
98
98
|
| `get_key_moments` | Key moments: timestamps, captions, and click coordinates. |
|
|
99
99
|
| `get_agent_context` | The full agent-context bundle (summary + key moments + transcript) as markdown. |
|
|
100
|
-
| `record` | **Record a web app headlessly** and upload it as a Clipy recording; returns its share + agent-context URLs. Accepts a `type` (recording kind), `viewports` (sweep several screen sizes into one video), `storageState`/`initScript` (record behind a login), and timestamped `notes` that become the (silent) recording's transcript. Needs Playwright in this server's environment and an `ingest`-scoped key (see below). |
|
|
101
|
-
| `start_recording` | **Start a recording session** that keeps recording while you work (drive the page with your own browser tools, run commands, …). Accepts `type`, `storageState`/`initScript`, and `exposeCdp` (get a CDP endpoint to drive the recorded page). Auto-stops + uploads at `maxSeconds` (default 600) so it can never run away. |
|
|
102
|
-
| `add_marker` | Drop a narration marker into the active session (live clock, or backdate with `atSeconds`) — markers become the recording's transcript chapters. Can also **verify** on-screen state (`assertSelector` / `assertText` (requires a selector) / `assertUrl`, `failMode`);
|
|
100
|
+
| `record` | **Record a web app headlessly** and upload it as a Clipy recording; returns its share + agent-context URLs. Accepts a `type` (recording kind), `viewports` (sweep several screen sizes into one video), `storageState`/`userDataDir`/`initScript` (record behind a login), and timestamped `notes` that become the (silent) recording's transcript. Needs Playwright in this server's environment and an `ingest`-scoped key (see below). |
|
|
101
|
+
| `start_recording` | **Start a recording session** that keeps recording while you work (drive the page with your own browser tools, run commands, …). Accepts `type`, `storageState`/`userDataDir`/`initScript`, and `exposeCdp` (get a CDP endpoint + in-page `window.__clipyMark`/`window.__clipyChapter` bridge to drive the recorded page). Auto-stops + uploads at `maxSeconds` (default 600) so it can never run away. |
|
|
102
|
+
| `add_marker` | Drop a narration marker into the active session (live clock, or backdate with `atSeconds`) — markers become the recording's transcript chapters. Can also **verify** on-screen state (`assertSelector` / `assertText` (requires a selector) / `assertUrl`, `failMode`); an assertion is annotated as a pass (✓), an explicit failure (✗, can abort the session), or **unverified** (⚠, when it couldn't be evaluated — never a silent pass). Navigations + console errors are added automatically as `[auto]` marks. |
|
|
103
103
|
| `add_chapter` | Drop a `=== CHAPTER: <label> ===` boundary into the active session — split a recording into named sections (ideal for before/after demos). |
|
|
104
104
|
| `stop_recording` | Finish the session: close the browser, upload, return the share + agent-context URLs. |
|
|
105
105
|
| `abort_recording` | Discard the active session; nothing is uploaded. |
|
|
@@ -133,6 +133,14 @@ per viewport pass), `name`, `description`, `type` (recording kind — `bug_repor
|
|
|
133
133
|
each pass slow-scrolled and auto-chaptered), `storageState` / `initScript` (paths, never
|
|
134
134
|
logged), `notes`, and `width`/`height` (default 1280×720, ignored when `viewports` is set).
|
|
135
135
|
|
|
136
|
+
**Recording behind a login.** `storageState` seeds exactly what its JSON contains (cookies +
|
|
137
|
+
localStorage) but can't reproduce a whole browser identity (IndexedDB, service workers, some
|
|
138
|
+
cross-origin auth). For a full identity, produce a storageState with an interactive login
|
|
139
|
+
(`npx playwright open --save-storage=state.json <login-url>`) and pass its path, **or** pass
|
|
140
|
+
`userDataDir` pointed at a **dedicated** Chromium profile directory — one no running browser
|
|
141
|
+
is using (a live/locked profile is refused). `storageState` and `userDataDir` are mutually
|
|
142
|
+
exclusive.
|
|
143
|
+
|
|
136
144
|
### Driving the recorded page over CDP (`start_recording` + `exposeCdp: true`)
|
|
137
145
|
|
|
138
146
|
Pass `exposeCdp: true` to `start_recording` and the recording browser opens a Chrome
|
|
@@ -153,6 +161,21 @@ is `contexts()[0].pages()[0]` (a new context you open won't be captured); `page.
|
|
|
153
161
|
reads `null` over a CDP attach; and to change the viewport use `newCDPSession` +
|
|
154
162
|
`Emulation.setDeviceMetricsOverride`, not `setViewportSize`.
|
|
155
163
|
|
|
164
|
+
**In-page bridge (zero extra tool calls).** When `exposeCdp` is on, the recorded page also
|
|
165
|
+
exposes `window.__clipyMark(text, opts?)` and `window.__clipyChapter(label)`, so your CDP
|
|
166
|
+
driver can drop asserted marks/chapters from inside the page:
|
|
167
|
+
|
|
168
|
+
```js
|
|
169
|
+
await page.evaluate(() =>
|
|
170
|
+
window.__clipyMark("saved the form", { assertSelector: ".toast", assertText: "Saved" }),
|
|
171
|
+
);
|
|
172
|
+
await page.evaluate(() => window.__clipyChapter("AFTER — fix applied"));
|
|
173
|
+
```
|
|
174
|
+
|
|
175
|
+
`opts` mirrors `add_marker` (`assertSelector` / `assertText` / `assertUrl` / `failMode`);
|
|
176
|
+
`assertText` requires `assertSelector` (the call rejects otherwise), and a failed assert with
|
|
177
|
+
`failMode: "abort"` discards the session — same annotations and tally as the tools.
|
|
178
|
+
|
|
156
179
|
## Config
|
|
157
180
|
|
|
158
181
|
| Env var | Required | Default | Notes |
|
package/dist/index.js
CHANGED
|
@@ -24,7 +24,7 @@
|
|
|
24
24
|
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
25
25
|
import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
|
|
26
26
|
import { z } from "zod";
|
|
27
|
-
import { closeSync, createWriteStream, mkdirSync, openSync, readFileSync, readSync, rmSync, statSync } from "node:fs";
|
|
27
|
+
import { closeSync, createWriteStream, mkdirSync, openSync, readdirSync, readFileSync, readSync, rmSync, statSync } from "node:fs";
|
|
28
28
|
import { randomUUID } from "node:crypto";
|
|
29
29
|
import { createServer } from "node:net";
|
|
30
30
|
import { tmpdir } from "node:os";
|
|
@@ -33,7 +33,7 @@ import { Readable } from "node:stream";
|
|
|
33
33
|
import { pipeline } from "node:stream/promises";
|
|
34
34
|
const API_URL = (process.env.CLIPY_API_URL || "https://clipy.online").replace(/\/+$/, "");
|
|
35
35
|
const API_KEY = process.env.CLIPY_API_KEY;
|
|
36
|
-
const SERVER_VERSION = "0.8.
|
|
36
|
+
const SERVER_VERSION = "0.8.1";
|
|
37
37
|
// The key is checked lazily (per tool call, not at startup) so the server can
|
|
38
38
|
// start and answer introspection (initialize / tools/list) in keyless
|
|
39
39
|
// environments like directory health checks.
|
|
@@ -375,7 +375,8 @@ const CDP_DRIVER_NOTE = "Drive the recorded page with your own Playwright: chrom
|
|
|
375
375
|
"Gotchas: (1) the page being recorded is browser.contexts()[0].pages()[0] — a NEW context/page you open is NOT captured; " +
|
|
376
376
|
"(2) page.viewportSize() reads null over a CDP attach; " +
|
|
377
377
|
"(3) to change the viewport use page.context().newCDPSession(page) + Emulation.setDeviceMetricsOverride, not setViewportSize; " +
|
|
378
|
-
"(4) close your connection (browser.close()) when done — it only detaches, the recording keeps going."
|
|
378
|
+
"(4) close your connection (browser.close()) when done — it only detaches, the recording keeps going. " +
|
|
379
|
+
"In-page bridge (zero extra tool calls): call window.__clipyMark(text, {assertSelector, assertText, assertUrl, failMode}) to drop an asserted mark and window.__clipyChapter(label) for a chapter — from the recorded page, e.g. await page.evaluate(() => window.__clipyMark('saved', {assertSelector:'.toast', assertText:'Saved'})); assertText requires assertSelector (the call rejects otherwise), and a failed assert with failMode:'abort' discards the session.";
|
|
379
380
|
// --- URL-glob matching (add_marker assertUrl) ------------------------------
|
|
380
381
|
// `**` matches anything (including `/`); `*` matches within a path segment.
|
|
381
382
|
function globToRegExp(glob) {
|
|
@@ -461,6 +462,81 @@ function validateInitScriptFile(p) {
|
|
|
461
462
|
}
|
|
462
463
|
return resolved;
|
|
463
464
|
}
|
|
465
|
+
/** Validate a userDataDir (a whole Chromium profile) — resolves, confirms it's a
|
|
466
|
+
* directory, and REFUSES a live/locked profile (Chrome leaves SingletonLock /
|
|
467
|
+
* SingletonSocket while running). Returns the absolute path. */
|
|
468
|
+
function validateUserDataDir(p) {
|
|
469
|
+
const resolved = resolve(p);
|
|
470
|
+
let st;
|
|
471
|
+
try {
|
|
472
|
+
st = statSync(resolved);
|
|
473
|
+
}
|
|
474
|
+
catch {
|
|
475
|
+
throw new Error(`userDataDir not found: ${resolved}`);
|
|
476
|
+
}
|
|
477
|
+
if (!st.isDirectory())
|
|
478
|
+
throw new Error(`userDataDir is not a directory: ${resolved}`);
|
|
479
|
+
let entries;
|
|
480
|
+
try {
|
|
481
|
+
entries = readdirSync(resolved);
|
|
482
|
+
}
|
|
483
|
+
catch {
|
|
484
|
+
throw new Error(`userDataDir is not readable: ${resolved}`);
|
|
485
|
+
}
|
|
486
|
+
// Match by NAME (these are often symlinks/sockets that statSync can't follow).
|
|
487
|
+
if (entries.includes("SingletonLock") || entries.includes("SingletonSocket")) {
|
|
488
|
+
throw new Error(`userDataDir looks like a LIVE Chrome profile — found a Singleton lock in ${resolved}. ` +
|
|
489
|
+
`Close that browser, or point userDataDir at a DEDICATED profile directory no running browser is using. ` +
|
|
490
|
+
`Driving a locked profile fails and risks corrupting it.`);
|
|
491
|
+
}
|
|
492
|
+
return resolved;
|
|
493
|
+
}
|
|
494
|
+
/** First line of an error message, trimmed — keeps annotations/logs one-line. */
|
|
495
|
+
function firstLine(message) {
|
|
496
|
+
return (message ?? "").split("\n")[0].trim();
|
|
497
|
+
}
|
|
498
|
+
/** Race a promise against a timeout so a hung page.evaluate can't wedge a mark. */
|
|
499
|
+
function withTimeout(p, ms, message) {
|
|
500
|
+
return Promise.race([
|
|
501
|
+
p,
|
|
502
|
+
new Promise((_, reject) => setTimeout(() => reject(new Error(message)), ms)),
|
|
503
|
+
]);
|
|
504
|
+
}
|
|
505
|
+
/** Open the recording context + page. Persistent (userDataDir) mode uses
|
|
506
|
+
* launchPersistentContext (a whole browser profile, no separate Browser
|
|
507
|
+
* handle); otherwise launch + newContext, optionally seeded with storageState.
|
|
508
|
+
* initScript applies either way; storageState and userDataDir are mutually
|
|
509
|
+
* exclusive and validated before this is called. */
|
|
510
|
+
async function openCaptureContext(chromium, opts) {
|
|
511
|
+
const args = [
|
|
512
|
+
"--no-sandbox",
|
|
513
|
+
"--disable-dev-shm-usage",
|
|
514
|
+
...(opts.cdpPort ? [`--remote-debugging-port=${opts.cdpPort}`] : []),
|
|
515
|
+
];
|
|
516
|
+
if (opts.userDataDir) {
|
|
517
|
+
const context = await chromium.launchPersistentContext(opts.userDataDir, {
|
|
518
|
+
headless: true,
|
|
519
|
+
args,
|
|
520
|
+
viewport: opts.viewport,
|
|
521
|
+
recordVideo: { dir: opts.recordDir, size: opts.recordSize },
|
|
522
|
+
});
|
|
523
|
+
if (opts.initScriptPath)
|
|
524
|
+
await context.addInitScript({ path: opts.initScriptPath });
|
|
525
|
+
const existing = context.pages();
|
|
526
|
+
const page = existing.length > 0 ? existing[0] : await context.newPage();
|
|
527
|
+
return { context, page, browser: null };
|
|
528
|
+
}
|
|
529
|
+
const browser = await chromium.launch({ headless: true, args });
|
|
530
|
+
const context = await browser.newContext({
|
|
531
|
+
viewport: opts.viewport,
|
|
532
|
+
recordVideo: { dir: opts.recordDir, size: opts.recordSize },
|
|
533
|
+
...(opts.storageStatePath ? { storageState: opts.storageStatePath } : {}),
|
|
534
|
+
});
|
|
535
|
+
if (opts.initScriptPath)
|
|
536
|
+
await context.addInitScript({ path: opts.initScriptPath });
|
|
537
|
+
const page = await context.newPage();
|
|
538
|
+
return { context, page, browser };
|
|
539
|
+
}
|
|
464
540
|
/**
|
|
465
541
|
* Streams a captured WebM through the raw-upload pipeline
|
|
466
542
|
* (initiate → chunks → finalize → complete). Shared by the one-shot `record`
|
|
@@ -996,7 +1072,7 @@ server.tool("get_agent_context", "ONE-CALL CONTEXT BUNDLE for a recording: metad
|
|
|
996
1072
|
return fail(e.message);
|
|
997
1073
|
}
|
|
998
1074
|
});
|
|
999
|
-
server.tool("record", "Record a web app HEADLESSLY and upload it as a Clipy recording, then return its share link + agent-context URL. Use this to capture the outcome of work you just did — e.g. after building a feature, record the running app so it can be shared or read back. Opens the given URL in a headless Chromium (works in cloud sandboxes, no display needed), records for `durationSeconds`, and streams the video into Clipy's pipeline. Set `type` so the summary reads the recording correctly, `viewports` to sweep multiple screen sizes into one video, and `storageState`/`initScript` to record behind a login. Requires (1) Playwright installed in this MCP server's environment (`npm i -g playwright && npx playwright install chromium`) and (2) the CLIPY_API_KEY to carry the 'ingest' scope. Recording the REAL Mac screen or a specific window (ScreenCaptureKit, real logged-in browser) is CLI-only — `clipy record --source mac-screen --window \"<app>\"` — and not available via MCP. Quick per-cookie / per-localStorage-key injection (the CLI's `--cookie` / `--local-storage`) is a CLI-only convenience; `storageState` covers the same need here. After it returns, call wait_for_artifacts then get_agent_context to read the transcript/summary.", {
|
|
1075
|
+
server.tool("record", "Record a web app HEADLESSLY and upload it as a Clipy recording, then return its share link + agent-context URL. Use this to capture the outcome of work you just did — e.g. after building a feature, record the running app so it can be shared or read back. Opens the given URL in a headless Chromium (works in cloud sandboxes, no display needed), records for `durationSeconds`, and streams the video into Clipy's pipeline. Set `type` so the summary reads the recording correctly, `viewports` to sweep multiple screen sizes into one video, and `storageState`/`initScript`/`userDataDir` to record behind a login. Requires (1) Playwright installed in this MCP server's environment (`npm i -g playwright && npx playwright install chromium`) and (2) the CLIPY_API_KEY to carry the 'ingest' scope. Recording the REAL Mac screen or a specific window (ScreenCaptureKit, real logged-in browser) is CLI-only — `clipy record --source mac-screen --window \"<app>\"` — and not available via MCP. Quick per-cookie / per-localStorage-key injection (the CLI's `--cookie` / `--local-storage`) is a CLI-only convenience; `storageState` covers the same need here. Auth note: `storageState` seeds exactly what it contains (cookies + localStorage) but can't reproduce a whole browser identity (IndexedDB, service workers, some cross-origin auth); for those, produce a storageState via an interactive `npx playwright open --save-storage=state.json <login-url>` first, or use `userDataDir` pointed at a DEDICATED (never live) profile directory. After it returns, call wait_for_artifacts then get_agent_context to read the transcript/summary.", {
|
|
1000
1076
|
url: z.string().describe("The http(s) URL to open and record (e.g. http://localhost:3000)."),
|
|
1001
1077
|
durationSeconds: z
|
|
1002
1078
|
.number()
|
|
@@ -1026,14 +1102,18 @@ server.tool("record", "Record a web app HEADLESSLY and upload it as a Clipy reco
|
|
|
1026
1102
|
storageState: z
|
|
1027
1103
|
.string()
|
|
1028
1104
|
.optional()
|
|
1029
|
-
.describe("Path to a Playwright storageState JSON (cookies + localStorage) to record behind a login. Passed unchanged to the browser context; its contents are never logged."),
|
|
1105
|
+
.describe("Path to a Playwright storageState JSON (cookies + localStorage) to record behind a login. Passed unchanged to the browser context; its contents are never logged. Mutually exclusive with userDataDir."),
|
|
1106
|
+
userDataDir: z
|
|
1107
|
+
.string()
|
|
1108
|
+
.optional()
|
|
1109
|
+
.describe("Path to a DEDICATED Chromium user-data (profile) directory to record with a full browser identity — launched via launchPersistentContext. Use a profile NO running browser is using (a live/locked profile is refused). Mutually exclusive with storageState."),
|
|
1030
1110
|
initScript: z
|
|
1031
1111
|
.string()
|
|
1032
1112
|
.optional()
|
|
1033
1113
|
.describe("Path to a JS file run in the page before every navigation (context.addInitScript) — e.g. to seed localStorage or stub an API. Contents are never logged."),
|
|
1034
1114
|
width: z.number().int().min(320).max(3840).optional().describe("Viewport + video width (default 1280). Ignored when `viewports` is set."),
|
|
1035
1115
|
height: z.number().int().min(240).max(2160).optional().describe("Viewport + video height (default 720). Ignored when `viewports` is set."),
|
|
1036
|
-
}, async ({ url, durationSeconds, name, description, type, viewports, notes, storageState, initScript, width, height }) => {
|
|
1116
|
+
}, async ({ url, durationSeconds, name, description, type, viewports, notes, storageState, userDataDir, initScript, width, height }) => {
|
|
1037
1117
|
// Validate the URL before spinning up a browser.
|
|
1038
1118
|
let target;
|
|
1039
1119
|
try {
|
|
@@ -1072,11 +1152,17 @@ server.tool("record", "Record a web app HEADLESSLY and upload it as a Clipy reco
|
|
|
1072
1152
|
width: Math.max(...passes.map((v) => v.width)),
|
|
1073
1153
|
height: Math.max(...passes.map((v) => v.height)),
|
|
1074
1154
|
};
|
|
1155
|
+
if (userDataDir && storageState) {
|
|
1156
|
+
return fail("userDataDir and storageState are mutually exclusive — userDataDir launches a whole persistent profile; storageState seeds a fresh context. Pick one.");
|
|
1157
|
+
}
|
|
1075
1158
|
let storageStatePath;
|
|
1159
|
+
let userDataDirPath;
|
|
1076
1160
|
let initScriptPath;
|
|
1077
1161
|
try {
|
|
1078
1162
|
if (storageState)
|
|
1079
1163
|
storageStatePath = validateStorageStateFile(storageState);
|
|
1164
|
+
if (userDataDir)
|
|
1165
|
+
userDataDirPath = validateUserDataDir(userDataDir);
|
|
1080
1166
|
if (initScript)
|
|
1081
1167
|
initScriptPath = validateInitScriptFile(initScript);
|
|
1082
1168
|
}
|
|
@@ -1100,19 +1186,16 @@ server.tool("record", "Record a web app HEADLESSLY and upload it as a Clipy reco
|
|
|
1100
1186
|
try {
|
|
1101
1187
|
// ── Capture ──
|
|
1102
1188
|
let videoPath;
|
|
1103
|
-
const
|
|
1104
|
-
|
|
1105
|
-
|
|
1189
|
+
const opened = await openCaptureContext(chromium, {
|
|
1190
|
+
userDataDir: userDataDirPath,
|
|
1191
|
+
viewport: { width: frame.width, height: frame.height },
|
|
1192
|
+
recordDir: dir,
|
|
1193
|
+
recordSize: frame,
|
|
1194
|
+
storageStatePath,
|
|
1195
|
+
initScriptPath,
|
|
1106
1196
|
});
|
|
1197
|
+
const { context, page } = opened;
|
|
1107
1198
|
try {
|
|
1108
|
-
const context = await browser.newContext({
|
|
1109
|
-
viewport: { width: frame.width, height: frame.height },
|
|
1110
|
-
recordVideo: { dir, size: frame },
|
|
1111
|
-
...(storageStatePath ? { storageState: storageStatePath } : {}),
|
|
1112
|
-
});
|
|
1113
|
-
if (initScriptPath)
|
|
1114
|
-
await context.addInitScript({ path: initScriptPath });
|
|
1115
|
-
const page = await context.newPage();
|
|
1116
1199
|
// captureStart is set AFTER the first meaningful paint so notes and pass
|
|
1117
1200
|
// marks aren't anchored to the blank t=0 a compiling app shows.
|
|
1118
1201
|
let captureStart = 0;
|
|
@@ -1154,7 +1237,12 @@ server.tool("record", "Record a web app HEADLESSLY and upload it as a Clipy reco
|
|
|
1154
1237
|
videoPath = await video.path();
|
|
1155
1238
|
}
|
|
1156
1239
|
finally {
|
|
1157
|
-
|
|
1240
|
+
// Non-persistent: close the browser (also closes the context). Persistent:
|
|
1241
|
+
// no browser handle — make sure the context is closed either way.
|
|
1242
|
+
if (opened.browser)
|
|
1243
|
+
await opened.browser.close().catch(() => { });
|
|
1244
|
+
else
|
|
1245
|
+
await opened.context.close().catch(() => { });
|
|
1158
1246
|
}
|
|
1159
1247
|
// ── Upload through the same pipeline the web/desktop clients use ──
|
|
1160
1248
|
const userNotes = (notes ?? []).map((n) => ({
|
|
@@ -1235,15 +1323,16 @@ function finishSession(session, mode) {
|
|
|
1235
1323
|
if (!video)
|
|
1236
1324
|
throw new Error("browser did not produce a video");
|
|
1237
1325
|
const videoPath = await video.path();
|
|
1238
|
-
await session.browser
|
|
1326
|
+
await session.browser?.close().catch(() => { });
|
|
1239
1327
|
const collected = [...session.marks];
|
|
1240
1328
|
// If any assertions ran, lead the transcript with a verification summary
|
|
1241
|
-
// at 0ms so a reader sees the pass/fail tally up front.
|
|
1242
|
-
const assertionsRan = session.assertPassed + session.assertFailed;
|
|
1329
|
+
// at 0ms so a reader sees the pass/fail/unverified tally up front.
|
|
1330
|
+
const assertionsRan = session.assertPassed + session.assertFailed + session.assertUnverified;
|
|
1243
1331
|
if (assertionsRan > 0) {
|
|
1332
|
+
const unverifiedClause = session.assertUnverified > 0 ? `, ${session.assertUnverified} unverified` : "";
|
|
1244
1333
|
collected.unshift({
|
|
1245
1334
|
startMs: 0,
|
|
1246
|
-
text: `[verification] ${assertionsRan}
|
|
1335
|
+
text: `[verification] ${assertionsRan} assertion${assertionsRan === 1 ? "" : "s"}: ${session.assertPassed} passed, ${session.assertFailed} failed${unverifiedClause}`,
|
|
1247
1336
|
});
|
|
1248
1337
|
}
|
|
1249
1338
|
const notes = collected.sort((a, b) => a.startMs - b.startMs);
|
|
@@ -1264,7 +1353,11 @@ function finishSession(session, mode) {
|
|
|
1264
1353
|
};
|
|
1265
1354
|
}
|
|
1266
1355
|
finally {
|
|
1267
|
-
|
|
1356
|
+
// Persistent mode has no browser handle; make sure the context is closed.
|
|
1357
|
+
if (session.browser)
|
|
1358
|
+
await session.browser.close().catch(() => { });
|
|
1359
|
+
else
|
|
1360
|
+
await session.context.close().catch(() => { });
|
|
1268
1361
|
try {
|
|
1269
1362
|
rmSync(session.tmpDir, { recursive: true, force: true });
|
|
1270
1363
|
}
|
|
@@ -1295,18 +1388,22 @@ server.tool("start_recording", "Start a RECORDING SESSION: opens the given URL i
|
|
|
1295
1388
|
exposeCdp: z
|
|
1296
1389
|
.boolean()
|
|
1297
1390
|
.optional()
|
|
1298
|
-
.describe("Open a Chrome DevTools Protocol endpoint on the recording browser (default false) so you can drive the page (navigate/click/type) with your own Playwright WHILE it records. When on, the result returns cdpHttpUrl + cdpUrl and driver notes. OFF by default (while open, any local process can attach). The env var CLIPY_DISABLE_CDP=1 is a hard kill switch that forces it off."),
|
|
1391
|
+
.describe("Open a Chrome DevTools Protocol endpoint on the recording browser (default false) so you can drive the page (navigate/click/type) with your own Playwright WHILE it records. When on, the result returns cdpHttpUrl + cdpUrl and driver notes, AND the recorded page exposes window.__clipyMark(text, {assertSelector, assertText, assertUrl, failMode}) + window.__clipyChapter(label) so a CDP driver can drop asserted marks/chapters with zero extra tool calls. OFF by default (while open, any local process can attach). The env var CLIPY_DISABLE_CDP=1 is a hard kill switch that forces it off."),
|
|
1299
1392
|
storageState: z
|
|
1300
1393
|
.string()
|
|
1301
1394
|
.optional()
|
|
1302
|
-
.describe("Path to a Playwright storageState JSON (cookies + localStorage) to record behind a login. Passed unchanged to the browser context; its contents are never logged."),
|
|
1395
|
+
.describe("Path to a Playwright storageState JSON (cookies + localStorage) to record behind a login. Passed unchanged to the browser context; its contents are never logged. Mutually exclusive with userDataDir."),
|
|
1396
|
+
userDataDir: z
|
|
1397
|
+
.string()
|
|
1398
|
+
.optional()
|
|
1399
|
+
.describe("Path to a DEDICATED Chromium user-data (profile) directory to record with a full browser identity (launchPersistentContext). Use a profile NO running browser is using (a live/locked profile is refused). Mutually exclusive with storageState."),
|
|
1303
1400
|
initScript: z
|
|
1304
1401
|
.string()
|
|
1305
1402
|
.optional()
|
|
1306
1403
|
.describe("Path to a JS file run in the page before every navigation (context.addInitScript). Contents are never logged."),
|
|
1307
1404
|
width: z.number().int().min(320).max(3840).optional().describe("Viewport + video width (default 1280)."),
|
|
1308
1405
|
height: z.number().int().min(240).max(2160).optional().describe("Viewport + video height (default 720)."),
|
|
1309
|
-
}, async ({ url, name, description, type, maxSeconds, exposeCdp, storageState, initScript, width, height }) => {
|
|
1406
|
+
}, async ({ url, name, description, type, maxSeconds, exposeCdp, storageState, userDataDir, initScript, width, height }) => {
|
|
1310
1407
|
let target;
|
|
1311
1408
|
try {
|
|
1312
1409
|
target = new URL(url);
|
|
@@ -1330,11 +1427,17 @@ server.tool("start_recording", "Start a RECORDING SESSION: opens the given URL i
|
|
|
1330
1427
|
return fail(recordingKindError(type));
|
|
1331
1428
|
recordingKind = kind;
|
|
1332
1429
|
}
|
|
1430
|
+
if (userDataDir && storageState) {
|
|
1431
|
+
return fail("userDataDir and storageState are mutually exclusive — userDataDir launches a whole persistent profile; storageState seeds a fresh context. Pick one.");
|
|
1432
|
+
}
|
|
1333
1433
|
let storageStatePath;
|
|
1434
|
+
let userDataDirPath;
|
|
1334
1435
|
let initScriptPath;
|
|
1335
1436
|
try {
|
|
1336
1437
|
if (storageState)
|
|
1337
1438
|
storageStatePath = validateStorageStateFile(storageState);
|
|
1439
|
+
if (userDataDir)
|
|
1440
|
+
userDataDirPath = validateUserDataDir(userDataDir);
|
|
1338
1441
|
if (initScript)
|
|
1339
1442
|
initScriptPath = validateInitScriptFile(initScript);
|
|
1340
1443
|
}
|
|
@@ -1359,22 +1462,16 @@ server.tool("start_recording", "Start a RECORDING SESSION: opens the given URL i
|
|
|
1359
1462
|
const wantCdp = !!exposeCdp && !cdpDisabled;
|
|
1360
1463
|
try {
|
|
1361
1464
|
const cdpPort = wantCdp ? await pickFreePort().catch(() => 0) : 0;
|
|
1362
|
-
const
|
|
1363
|
-
|
|
1364
|
-
args: [
|
|
1365
|
-
"--no-sandbox",
|
|
1366
|
-
"--disable-dev-shm-usage",
|
|
1367
|
-
...(cdpPort ? [`--remote-debugging-port=${cdpPort}`] : []),
|
|
1368
|
-
],
|
|
1369
|
-
});
|
|
1370
|
-
const context = await browser.newContext({
|
|
1465
|
+
const opened = await openCaptureContext(chromium, {
|
|
1466
|
+
userDataDir: userDataDirPath,
|
|
1371
1467
|
viewport: { width: w, height: h },
|
|
1372
|
-
|
|
1373
|
-
|
|
1468
|
+
recordDir: tmpDirPath,
|
|
1469
|
+
recordSize: { width: w, height: h },
|
|
1470
|
+
storageStatePath,
|
|
1471
|
+
initScriptPath,
|
|
1472
|
+
cdpPort: cdpPort || undefined,
|
|
1374
1473
|
});
|
|
1375
|
-
|
|
1376
|
-
await context.addInitScript({ path: initScriptPath });
|
|
1377
|
-
const page = await context.newPage();
|
|
1474
|
+
const { context, page, browser } = opened;
|
|
1378
1475
|
// Best-effort CDP discovery — the recording works even if it fails.
|
|
1379
1476
|
let cdpUrl;
|
|
1380
1477
|
let cdpHttpUrl;
|
|
@@ -1402,11 +1499,46 @@ server.tool("start_recording", "Start a RECORDING SESSION: opens the given URL i
|
|
|
1402
1499
|
marks: [],
|
|
1403
1500
|
assertPassed: 0,
|
|
1404
1501
|
assertFailed: 0,
|
|
1502
|
+
assertUnverified: 0,
|
|
1405
1503
|
cdpUrl,
|
|
1406
1504
|
cdpHttpUrl,
|
|
1407
1505
|
maxTimer: setTimeout(() => { }, 0),
|
|
1408
1506
|
finishing: null,
|
|
1409
1507
|
};
|
|
1508
|
+
// In-page CDP bridge: when CDP is exposed, install window.__clipyMark /
|
|
1509
|
+
// window.__clipyChapter so a driver attached over connectOverCDP can drop
|
|
1510
|
+
// asserted marks/chapters without any extra MCP tool call. exposeBinding
|
|
1511
|
+
// routes the page call back to THIS process (same annotations/caps as the
|
|
1512
|
+
// add_marker/add_chapter tools). Installed before navigation so it's live
|
|
1513
|
+
// on first load.
|
|
1514
|
+
if (wantCdp) {
|
|
1515
|
+
await context
|
|
1516
|
+
.exposeBinding("__clipyMark", async (_source, ...args) => {
|
|
1517
|
+
if (session.finishing)
|
|
1518
|
+
throw new Error("recording session is finishing — mark ignored");
|
|
1519
|
+
const markText = String(args[0] ?? "").slice(0, 1000);
|
|
1520
|
+
const { note, assertion, aborted } = await applyMark(session, markText, coerceMarkOpts(args[1]));
|
|
1521
|
+
return {
|
|
1522
|
+
atSeconds: Math.round(note.startMs / 100) / 10,
|
|
1523
|
+
...(assertion
|
|
1524
|
+
? assertion.status === "unverified"
|
|
1525
|
+
? { unverified: true, observed: assertion.observed }
|
|
1526
|
+
: { passed: assertion.status === "passed", observed: assertion.observed }
|
|
1527
|
+
: {}),
|
|
1528
|
+
...(aborted ? { aborted: true } : {}),
|
|
1529
|
+
};
|
|
1530
|
+
})
|
|
1531
|
+
.catch((e) => serverLog(`__clipyMark binding failed: ${firstLine(e.message)}`));
|
|
1532
|
+
await context
|
|
1533
|
+
.exposeBinding("__clipyChapter", async (_source, ...args) => {
|
|
1534
|
+
if (session.finishing)
|
|
1535
|
+
throw new Error("recording session is finishing — chapter ignored");
|
|
1536
|
+
const label = String(args[0] ?? "").trim().slice(0, 200);
|
|
1537
|
+
const note = sessionMark(session, `=== CHAPTER: ${label} ===`);
|
|
1538
|
+
return { atSeconds: Math.round(note.startMs / 100) / 10, chapter: label };
|
|
1539
|
+
})
|
|
1540
|
+
.catch((e) => serverLog(`__clipyChapter binding failed: ${firstLine(e.message)}`));
|
|
1541
|
+
}
|
|
1410
1542
|
clearTimeout(session.maxTimer);
|
|
1411
1543
|
session.maxTimer = setTimeout(() => {
|
|
1412
1544
|
// Auto-stop rail: upload the partial rather than record forever.
|
|
@@ -1473,52 +1605,135 @@ server.tool("start_recording", "Start a RECORDING SESSION: opens the given URL i
|
|
|
1473
1605
|
return fail(e.message);
|
|
1474
1606
|
}
|
|
1475
1607
|
});
|
|
1608
|
+
// --- Marker assertions ------------------------------------------------------
|
|
1609
|
+
// The session page is in-process, so an assertion is evaluated at mark time
|
|
1610
|
+
// against the live DOM/URL. The outcome is folded into the mark text so a
|
|
1611
|
+
// failure — or an inability to check — can never be misread as fact, and is
|
|
1612
|
+
// returned to the caller. Shared by add_marker AND the in-page CDP bridge.
|
|
1613
|
+
const ASSERT_EVAL_TIMEOUT_MS = 15_000;
|
|
1476
1614
|
async function runMarkerAssertions(page, a) {
|
|
1477
|
-
// One page.evaluate reads whatever the selected assertions need. `document`
|
|
1478
|
-
// is a browser global; the cast keeps it out of the (DOM-less) server lib.
|
|
1479
|
-
// assertText is always paired with assertSelector (enforced by the caller),
|
|
1480
|
-
// so text is read from the selector's element — never a weak page-body match.
|
|
1481
|
-
const probe = await page.evaluate((sel) => {
|
|
1482
|
-
const doc = globalThis.document;
|
|
1483
|
-
let selectorExists = null;
|
|
1484
|
-
let selectorText = null;
|
|
1485
|
-
if (sel && doc) {
|
|
1486
|
-
const el = doc.querySelector(sel);
|
|
1487
|
-
selectorExists = !!el;
|
|
1488
|
-
if (el)
|
|
1489
|
-
selectorText = (el.textContent || "").replace(/\s+/g, " ").trim();
|
|
1490
|
-
}
|
|
1491
|
-
return { selectorExists, selectorText };
|
|
1492
|
-
}, a.assertSelector ?? null);
|
|
1493
|
-
const url = page.url();
|
|
1494
1615
|
const expected = [];
|
|
1495
1616
|
const observed = [];
|
|
1496
|
-
let
|
|
1617
|
+
let failed = false;
|
|
1618
|
+
// URL is cheap + reliable (no page.evaluate), so check it first.
|
|
1619
|
+
if (a.assertUrl) {
|
|
1620
|
+
const url = page.url();
|
|
1621
|
+
expected.push(`url matches ${JSON.stringify(a.assertUrl)}`);
|
|
1622
|
+
observed.push(`url ${JSON.stringify(url)}`);
|
|
1623
|
+
if (!globMatch(url, a.assertUrl))
|
|
1624
|
+
failed = true;
|
|
1625
|
+
}
|
|
1626
|
+
// DOM checks need page.evaluate — which can throw (invalid selector, page
|
|
1627
|
+
// detached mid-navigation) or hang (bound by ASSERT_EVAL_TIMEOUT_MS). Either
|
|
1628
|
+
// way we must NOT report a pass we couldn't confirm — that's `unverified`.
|
|
1497
1629
|
if (a.assertSelector) {
|
|
1498
|
-
expected.push(
|
|
1630
|
+
expected.push(a.assertText
|
|
1631
|
+
? `selector ${JSON.stringify(a.assertSelector)} present with text ${JSON.stringify(a.assertText)}`
|
|
1632
|
+
: `selector ${JSON.stringify(a.assertSelector)} present`);
|
|
1633
|
+
let probe;
|
|
1634
|
+
try {
|
|
1635
|
+
probe = await withTimeout(
|
|
1636
|
+
// `document` is a browser global; the cast keeps it out of the (DOM-less)
|
|
1637
|
+
// server lib. assertText is always paired with a selector (caller-enforced).
|
|
1638
|
+
page.evaluate((sel) => {
|
|
1639
|
+
const doc = globalThis.document;
|
|
1640
|
+
let selectorExists = null;
|
|
1641
|
+
let selectorText = null;
|
|
1642
|
+
if (sel && doc) {
|
|
1643
|
+
const el = doc.querySelector(sel);
|
|
1644
|
+
selectorExists = !!el;
|
|
1645
|
+
if (el)
|
|
1646
|
+
selectorText = (el.textContent || "").replace(/\s+/g, " ").trim();
|
|
1647
|
+
}
|
|
1648
|
+
return { selectorExists, selectorText };
|
|
1649
|
+
}, a.assertSelector ?? null), ASSERT_EVAL_TIMEOUT_MS, `page.evaluate timed out after ${ASSERT_EVAL_TIMEOUT_MS / 1000}s`);
|
|
1650
|
+
}
|
|
1651
|
+
catch (e) {
|
|
1652
|
+
const reason = firstLine(e.message) || "evaluate failed";
|
|
1653
|
+
// If something else already failed definitively, the failure stands;
|
|
1654
|
+
// otherwise this claim is UNVERIFIED — never a silent pass.
|
|
1655
|
+
if (failed) {
|
|
1656
|
+
observed.push(`selector could not be evaluated (${reason})`);
|
|
1657
|
+
return { status: "failed", expected: expected.join("; "), observed: observed.join("; ") };
|
|
1658
|
+
}
|
|
1659
|
+
return { status: "unverified", expected: expected.join("; "), observed: reason };
|
|
1660
|
+
}
|
|
1499
1661
|
if (probe.selectorExists) {
|
|
1500
1662
|
observed.push("selector present");
|
|
1501
1663
|
}
|
|
1502
1664
|
else {
|
|
1503
1665
|
observed.push("selector NOT found");
|
|
1504
|
-
|
|
1666
|
+
failed = true;
|
|
1667
|
+
}
|
|
1668
|
+
if (a.assertText) {
|
|
1669
|
+
const ref = probe.selectorText ?? "";
|
|
1670
|
+
observed.push(`text ${JSON.stringify(ref.slice(0, 200))}`);
|
|
1671
|
+
if (!ref.includes(a.assertText))
|
|
1672
|
+
failed = true;
|
|
1505
1673
|
}
|
|
1506
1674
|
}
|
|
1507
|
-
|
|
1508
|
-
|
|
1509
|
-
|
|
1510
|
-
|
|
1511
|
-
|
|
1512
|
-
|
|
1513
|
-
|
|
1675
|
+
return { status: failed ? "failed" : "passed", expected: expected.join("; "), observed: observed.join("; ") };
|
|
1676
|
+
}
|
|
1677
|
+
/** Apply a mark to the session: strict assertText/assertSelector contract,
|
|
1678
|
+
* evaluate assertions, annotate the mark so pass/fail/unverified is explicit,
|
|
1679
|
+
* update the tally, and abort the session on a FAILED assert under failMode
|
|
1680
|
+
* 'abort'. Shared by the add_marker tool and the in-page CDP bridge. Throws on
|
|
1681
|
+
* the assertText-without-assertSelector contract violation (so a CDP driver
|
|
1682
|
+
* sees the rejection). */
|
|
1683
|
+
async function applyMark(session, text, opts) {
|
|
1684
|
+
if (opts.assertText && !opts.assertSelector) {
|
|
1685
|
+
throw new Error("assertText requires assertSelector — name the element whose text you're checking. A bare page-body text match is weak evidence, so it's rejected (same rule as the CLI's --assert-text / --assert-selector).");
|
|
1686
|
+
}
|
|
1687
|
+
const hasAssertion = !!(opts.assertSelector || opts.assertText || opts.assertUrl);
|
|
1688
|
+
let markText = text.trim();
|
|
1689
|
+
let assertion = null;
|
|
1690
|
+
if (hasAssertion) {
|
|
1691
|
+
try {
|
|
1692
|
+
assertion = await runMarkerAssertions(session.page, {
|
|
1693
|
+
assertSelector: opts.assertSelector,
|
|
1694
|
+
assertText: opts.assertText,
|
|
1695
|
+
assertUrl: opts.assertUrl,
|
|
1696
|
+
});
|
|
1697
|
+
}
|
|
1698
|
+
catch (e) {
|
|
1699
|
+
// Defensive: runMarkerAssertions swallows evaluate errors, but if anything
|
|
1700
|
+
// else throws, the claim is unverified — never a silent pass.
|
|
1701
|
+
assertion = { status: "unverified", expected: "assertion", observed: firstLine(e.message) || "evaluation failed" };
|
|
1702
|
+
}
|
|
1703
|
+
if (assertion.status === "passed") {
|
|
1704
|
+
session.assertPassed += 1;
|
|
1705
|
+
markText = `${markText} [assert ✓ ${assertion.observed}]`;
|
|
1706
|
+
}
|
|
1707
|
+
else if (assertion.status === "failed") {
|
|
1708
|
+
session.assertFailed += 1;
|
|
1709
|
+
markText = `${markText} [ASSERT ✗ expected ${assertion.expected}; observed ${assertion.observed}]`;
|
|
1710
|
+
}
|
|
1711
|
+
else {
|
|
1712
|
+
session.assertUnverified += 1;
|
|
1713
|
+
markText = `${markText} [ASSERT ⚠ could not evaluate — ${assertion.observed}]`;
|
|
1714
|
+
}
|
|
1514
1715
|
}
|
|
1515
|
-
|
|
1516
|
-
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1716
|
+
const note = sessionMark(session, markText, opts.atSeconds != null ? opts.atSeconds * 1000 : undefined);
|
|
1717
|
+
// failMode 'abort' discards the session ONLY on a definitive failure — never
|
|
1718
|
+
// on an unverified claim (inability to check must not nuke the recording).
|
|
1719
|
+
let aborted = false;
|
|
1720
|
+
if (assertion && assertion.status === "failed" && opts.failMode === "abort") {
|
|
1721
|
+
await finishSession(session, "abort").catch(() => { });
|
|
1722
|
+
aborted = true;
|
|
1520
1723
|
}
|
|
1521
|
-
return {
|
|
1724
|
+
return { note, assertion, aborted };
|
|
1725
|
+
}
|
|
1726
|
+
/** Coerce a bridge-supplied (untrusted) options object into typed mark opts. */
|
|
1727
|
+
function coerceMarkOpts(raw) {
|
|
1728
|
+
const o = (raw && typeof raw === "object" ? raw : {});
|
|
1729
|
+
const str = (v) => (typeof v === "string" && v.trim() ? v : undefined);
|
|
1730
|
+
const failMode = o.failMode === "abort" ? "abort" : o.failMode === "warn" ? "warn" : undefined;
|
|
1731
|
+
return {
|
|
1732
|
+
assertSelector: str(o.assertSelector),
|
|
1733
|
+
assertText: str(o.assertText),
|
|
1734
|
+
assertUrl: str(o.assertUrl),
|
|
1735
|
+
failMode,
|
|
1736
|
+
};
|
|
1522
1737
|
}
|
|
1523
1738
|
server.tool("add_marker", "Drop a live-timestamped narration marker into the active recording session ('reproduced the bug', 'the fix renders correctly at mobile width'). Markers become the recording's transcript chapters, so narrate as you work — they are how the recording stays agent-readable despite having no audio. Optionally VERIFY on-screen state at the mark: assertSelector (element must exist), assertText (that element must contain the text — requires assertSelector), assertUrl (glob match on the live URL). A failed assertion is annotated into the mark as an explicit FAILURE (never written as fact), counted into the recording's verification summary, and — with failMode 'abort' — discards the whole session. Marks default to the live recording clock; pass atSeconds to backdate one.", {
|
|
1524
1739
|
text: z.string().min(1).max(1000).describe("What is happening right now."),
|
|
@@ -1553,29 +1768,14 @@ server.tool("add_marker", "Drop a live-timestamped narration marker into the act
|
|
|
1553
1768
|
return fail("assertText requires assertSelector — name the element whose text you're checking. A bare page-body text match is weak evidence, so it's rejected (same rule as the CLI's --assert-text / --assert-selector).");
|
|
1554
1769
|
}
|
|
1555
1770
|
const session = activeSession;
|
|
1556
|
-
const
|
|
1557
|
-
|
|
1558
|
-
|
|
1559
|
-
|
|
1560
|
-
|
|
1561
|
-
|
|
1562
|
-
|
|
1563
|
-
|
|
1564
|
-
return fail(`assertion evaluation failed: ${e.message}`);
|
|
1565
|
-
}
|
|
1566
|
-
if (assertion.passed) {
|
|
1567
|
-
session.assertPassed += 1;
|
|
1568
|
-
markText = `${markText} [assert ✓ ${assertion.observed}]`;
|
|
1569
|
-
}
|
|
1570
|
-
else {
|
|
1571
|
-
session.assertFailed += 1;
|
|
1572
|
-
markText = `${markText} [ASSERT ✗ expected ${assertion.expected}; observed ${assertion.observed}]`;
|
|
1573
|
-
}
|
|
1574
|
-
}
|
|
1575
|
-
const note = sessionMark(session, markText, atSeconds != null ? atSeconds * 1000 : undefined);
|
|
1576
|
-
// failMode 'abort' on a failed assertion: discard the whole session.
|
|
1577
|
-
if (assertion && !assertion.passed && failMode === "abort") {
|
|
1578
|
-
await finishSession(session, "abort").catch(() => { });
|
|
1771
|
+
const { note, assertion, aborted } = await applyMark(session, text, {
|
|
1772
|
+
atSeconds,
|
|
1773
|
+
assertSelector,
|
|
1774
|
+
assertText,
|
|
1775
|
+
assertUrl,
|
|
1776
|
+
failMode,
|
|
1777
|
+
});
|
|
1778
|
+
if (aborted && assertion) {
|
|
1579
1779
|
return ok({
|
|
1580
1780
|
aborted: true,
|
|
1581
1781
|
assertionFailed: true,
|
|
@@ -1589,7 +1789,11 @@ server.tool("add_marker", "Drop a live-timestamped narration marker into the act
|
|
|
1589
1789
|
return ok({
|
|
1590
1790
|
atSeconds: Math.round(note.startMs / 100) / 10,
|
|
1591
1791
|
text: note.text,
|
|
1592
|
-
...(assertion
|
|
1792
|
+
...(assertion
|
|
1793
|
+
? assertion.status === "unverified"
|
|
1794
|
+
? { assertion: { verified: false, unverified: true, observed: assertion.observed }, unverified: true }
|
|
1795
|
+
: { assertion: { passed: assertion.status === "passed", observed: assertion.observed } }
|
|
1796
|
+
: {}),
|
|
1593
1797
|
totalMarkers: session.marks.length,
|
|
1594
1798
|
});
|
|
1595
1799
|
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@clipy/mcp",
|
|
3
|
-
"version": "0.8.
|
|
3
|
+
"version": "0.8.1",
|
|
4
4
|
"mcpName": "online.clipy/mcp",
|
|
5
5
|
"description": "Model Context Protocol (MCP) server for Clipy — give Claude, Cursor, and other AI agents read access to your screen recordings' transcripts, AI summaries, and key moments with frames.",
|
|
6
6
|
"license": "MIT",
|