@tmhs/screencast-mcp 0.48.1 → 0.49.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.
Files changed (50) hide show
  1. package/README.md +12 -9
  2. package/dist/cli.js +8 -7
  3. package/dist/context.js +33 -0
  4. package/dist/index.js +42 -27
  5. package/dist/resources.js +26 -0
  6. package/dist/server.js +2 -0
  7. package/dist/setup.js +7 -6
  8. package/dist/tools/addMarker.js +2 -2
  9. package/dist/tools/callout.js +6 -7
  10. package/dist/tools/contactSheet.js +3 -2
  11. package/dist/tools/deleteRecording.js +119 -0
  12. package/dist/tools/indexRecording.js +6 -6
  13. package/dist/tools/pauseRecording.js +3 -3
  14. package/dist/tools/redactRegion.js +6 -7
  15. package/dist/tools/sampleFrames.js +10 -6
  16. package/dist/tools/startRecording.js +11 -5
  17. package/dist/tools/stepGuide.js +12 -8
  18. package/dist/tools/stopRecording.js +7 -3
  19. package/dist/tools/waitForChange.js +13 -45
  20. package/dist/utils/audioDevices.js +2 -2
  21. package/dist/utils/callout.js +6 -2
  22. package/dist/utils/capabilities.js +2 -1
  23. package/dist/utils/consent.js +2 -2
  24. package/dist/utils/errors.js +4 -4
  25. package/dist/utils/ffmpeg.js +14 -1
  26. package/dist/utils/images.js +4 -4
  27. package/dist/utils/jobs.js +2 -9
  28. package/dist/utils/lifecycle.js +13 -31
  29. package/dist/utils/media.js +29 -8
  30. package/dist/utils/monitors.js +2 -2
  31. package/dist/utils/narrate.js +3 -3
  32. package/dist/utils/ocr.js +3 -3
  33. package/dist/utils/ocrScan.js +33 -19
  34. package/dist/utils/paths.js +3 -0
  35. package/dist/utils/pause.js +3 -3
  36. package/dist/utils/pool.js +29 -0
  37. package/dist/utils/recorder.js +7 -6
  38. package/dist/utils/recordingFiles.js +32 -0
  39. package/dist/utils/replay.js +21 -34
  40. package/dist/utils/retention.js +14 -14
  41. package/dist/utils/roots.js +2 -1
  42. package/dist/utils/sessions.js +58 -14
  43. package/dist/utils/targetList.js +2 -1
  44. package/dist/utils/toolSpec.js +6 -0
  45. package/dist/utils/toolsets.js +1 -0
  46. package/dist/utils/waitLoop.js +50 -0
  47. package/dist/utils/wgc.js +27 -0
  48. package/dist/utils/windows.js +2 -2
  49. package/dist/wgcRecorder.js +7 -10
  50. package/package.json +2 -2
package/README.md CHANGED
@@ -4,7 +4,7 @@
4
4
 
5
5
  **An MCP server that lets an agent record the screen, _watch_ the footage, and make minimal ffmpeg edits — over stdio, on Windows.**
6
6
 
7
- Capture the desktop, a monitor, a window, or a region; sample a recording into frames the agent can actually look at; trim, crop, redact, annotate, zoom toward clicks, and export for GitHub or social. No cloud service, no telemetry: ffmpeg and ffprobe behind <!--tool-count-->58<!--/tool-count--> typed tools.
7
+ Capture the desktop, a monitor, a window, or a region; sample a recording into frames the agent can actually look at; trim, crop, redact, annotate, zoom toward clicks, and export for GitHub or social. No cloud service, no telemetry: ffmpeg and ffprobe behind <!--tool-count-->59<!--/tool-count--> typed tools.
8
8
 
9
9
  **For developers who want their coding agent to see and prove UI changes on Windows**: bug repros, UI verification, and demo clips the agent records, checks, and edits itself. Capture is Windows-only; the watch and edit tools work on any OS with ffmpeg. Free for non-commercial use ([CC BY-NC-ND 4.0](#license)); [why not OBS, Playwright, or a screenshot MCP?](#why-not-just)
10
10
 
@@ -42,6 +42,8 @@ The fastest path: `npx -y @tmhs/screencast-mcp setup` checks FFmpeg 8, OCR, and
42
42
 
43
43
  **You need** Windows 10 or 11, [Node.js](https://nodejs.org) 22+, and **FFmpeg 8 or newer** on `PATH` (`winget install Gyan.FFmpeg`, the full build). Older builds run most tools, but `transcribe` (the `whisper` filter) and `backend: "wgc"` (`gfxcapture`) need FFmpeg 8, and essentials or distro builds can lack them (Ubuntu LTS `apt install ffmpeg` gives 6.x). Capture is Windows-only; the watch, edit, and produce tools work anywhere ffmpeg runs. After connecting, ask the agent to run `doctor`: it reports the ffmpeg version, the filters and devices it has, OCR, and anything missing.
44
44
 
45
+ **Windows on ARM64** is in progress (#246): CI runs a non-blocking `windows-11-arm` job. gyan.dev ships no arm64 FFmpeg, so use BtbN's `winarm64-gpl` FFmpeg 8 build; it has `gdigrab`, `gfxcapture` and `drawtext` but no `whisper` or libvpx, so `transcribe` and `.webm` output need another build. `doctor` reports `arch` and what is missing.
46
+
45
47
  **Add it to your client:**
46
48
 
47
49
  | Client | How |
@@ -73,7 +75,7 @@ The core is the **watch loop**: the agent records, samples the footage into fram
73
75
  ## Tools
74
76
 
75
77
  <!-- tools:start -->
76
- 58 tools in 6 toolsets, generated from the server's own schemas by `npm run docs` (do not edit between the markers). Each name links to its reference page with every parameter, an example call, and what it returns; [`mcp-tools.json`](mcp-tools.json) is the same list as JSON, and [`llms-full.txt`](https://tmhsdigital.github.io/screencast-mcp/llms-full.txt) all of it in one file.
78
+ 59 tools in 6 toolsets, generated from the server's own schemas by `npm run docs` (do not edit between the markers). Each name links to its reference page with every parameter, an example call, and what it returns; [`mcp-tools.json`](mcp-tools.json) is the same list as JSON, and [`llms-full.txt`](https://tmhsdigital.github.io/screencast-mcp/llms-full.txt) all of it in one file.
77
79
 
78
80
  ### Core
79
81
 
@@ -92,6 +94,7 @@ Record or screenshot the desktop, a monitor, a window, or a region. Every captur
92
94
  | --- | --- |
93
95
  | [`start_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/start_recording.html) | Start a background screen recording. Returns a session id; finalize it with stop_recording. Never auto-starts. |
94
96
  | [`stop_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/stop_recording.html) | Stop a recording gracefully so the file is finalized; returns the path and duration. |
97
+ | [`delete_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/delete_recording.html) | Delete a finished recording with its sidecars (event log, webcam, transcript, index, markers, pause parts) and registry entries; reports bytes freed. Asks the user first when the client supports it. Edits made from it are kept. |
95
98
  | [`pause_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/pause_recording.html) | Pause a recording; until resume_recording nothing is captured, and the gap is left out of the file, events, and markers. |
96
99
  | [`resume_recording`](https://tmhsdigital.github.io/screencast-mcp/tools/resume_recording.html) | Resume a paused recording (same target and settings). |
97
100
  | [`save_replay`](https://tmhsdigital.github.io/screencast-mcp/tools/save_replay.html) | Save the last N seconds of a replay buffer (start_recording replayBufferSec) to an mp4; the buffer keeps running. |
@@ -137,7 +140,7 @@ Cut, convert, compress, and redact. A tool that writes a file refuses to replace
137
140
  | [`clip`](https://tmhsdigital.github.io/screencast-mcp/tools/clip.html) | Extract several frame-exact segments, each to its own file. For one segment, trim does the same. |
138
141
  | [`cut_idle`](https://tmhsdigital.github.io/screencast-mcp/tools/cut_idle.html) | Remove dead air: cut stretches where the screen is frozen (and silent), keeping a short pad. Returns the time saved. |
139
142
  | [`cut_by_transcript`](https://tmhsdigital.github.io/screencast-mcp/tools/cut_by_transcript.html) | Edit a video by its transcript: cut quoted text, cue numbers, or fillers. Also writes the re-timed .srt. |
140
- | [`redact_region`](https://tmhsdigital.github.io/screencast-mcp/tools/redact_region.html) | Cover given rectangles in a video (e.g. secrets on screen). Not automatic detection: find them with find_text redact: true. Off-frame regions are rejected. |
143
+ | [`redact_region`](https://tmhsdigital.github.io/screencast-mcp/tools/redact_region.html) | Cover given rectangles in a video or screenshot (e.g. secrets on screen). Not automatic detection: find them with find_text redact: true. Off-frame regions are rejected. |
141
144
  | [`pipeline`](https://tmhsdigital.github.io/screencast-mcp/tools/pipeline.html) | Run several edits (trim, crop, scale, speed, cut_idle, redact, callout, keystroke_overlay, cursor, reframe, zoom, backdrop, audio, burn_subtitles, then optionally export_preset or export_gif) in one ffmpeg pass: one re-encode, no intermediate files. Prefer it over chaining edit tools; a recipe does the usual polish in one call. |
142
145
 
143
146
  ### Produce
@@ -147,7 +150,7 @@ Annotate, frame, and assemble a finished piece. Tools that combine clips normali
147
150
  | Tool | What it does |
148
151
  | --- | --- |
149
152
  | [`overlay`](https://tmhsdigital.github.io/screencast-mcp/tools/overlay.html) | Composite an image or video (logo, watermark, picture-in-picture) onto a video at a pixel position, optionally scaled and time-limited; keeps the base's audio and length. |
150
- | [`callout`](https://tmhsdigital.github.io/screencast-mcp/tools/callout.html) | Annotate a video with timed boxes, text labels, and arrows. Fallback fonts used are listed in fallbackFonts; characters no font covers are reported in warnings. |
153
+ | [`callout`](https://tmhsdigital.github.io/screencast-mcp/tools/callout.html) | Annotate a video or screenshot with timed boxes, text labels, and arrows. Fallback fonts used are listed in fallbackFonts; characters no font covers are reported in warnings. |
151
154
  | [`keystroke_overlay`](https://tmhsdigital.github.io/screencast-mcp/tools/keystroke_overlay.html) | Burn keycast-style badges for shortcuts, clicks, and typing from the recording's input event log (start_recording events: true). Never shows typed text: the log has none. |
152
155
  | [`cursor`](https://tmhsdigital.github.io/screencast-mcp/tools/cursor.html) | Draw a smoothed, scaled cursor that hides when idle from the event log of a start_recording cursor: "events" recording (no OS cursor in the video), with click ripples and an optional spotlight. |
153
156
  | [`backdrop`](https://tmhsdigital.github.io/screencast-mcp/tools/backdrop.html) | Frame a video or screenshot on a gradient, color, or wallpaper with padding, rounded corners, and a drop shadow, optionally on a 16:9/1:1/9:16/4:5 canvas. |
@@ -192,7 +195,7 @@ Every capture tool takes one `target` string: `full`, `monitor:<index>`, `window
192
195
  | `SCREENCAST_MAX_RECORDING_SEC` | `3600` | Default recording cap (`0` disables it) |
193
196
  | `SCREENCAST_JOB_TIMEOUT_MS` | scales with length | Override the edit job timeout |
194
197
  | `SCREENCAST_WHISPER_MODEL` | none | whisper.cpp model for `transcribe` |
195
- | `SCREENCAST_RETENTION_DAYS` | off | Delete screenshots, frames, and leftover raw event logs older than this many days at startup (never recordings or edits) |
198
+ | `SCREENCAST_RETENTION_DAYS` | off | Delete screenshots, frames, leftover raw event logs, and `index_recording` indexes older than this many days at startup (never recordings or edits; an index is rebuilt by running `index_recording` again) |
196
199
  | `SCREENCAST_PS_TIMEOUT_MS` | 20000 (OCR 60000) | Limit for the PowerShell helpers that list monitors and windows and run OCR |
197
200
  | `SCREENCAST_CONFIRM_CAPTURE` | off | Set to `1` to ask the user to confirm every live capture through MCP elicitation; clients without elicitation are refused |
198
201
  | `SCREENCAST_TOOLSETS` | `all` | Comma-separated toolsets to expose; the rest are not loaded, which shrinks the tool list the agent pays for on every turn (`core` is always on) |
@@ -201,7 +204,7 @@ Every capture tool takes one `target` string: `full`, `monitor:<index>`, `window
201
204
  <!-- toolsets:start -->
202
205
  | Toolset | Tools |
203
206
  | --- | --- |
204
- | `capture` | `start_recording`, `stop_recording`, `pause_recording`, `resume_recording`, `save_replay`, `list_sessions`, `get_session`, `read_events`, `add_marker`, `screenshot`, `list_audio_devices`, `list_video_devices`, `list_targets` |
207
+ | `capture` | `start_recording`, `stop_recording`, `delete_recording`, `pause_recording`, `resume_recording`, `save_replay`, `list_sessions`, `get_session`, `read_events`, `add_marker`, `screenshot`, `list_audio_devices`, `list_video_devices`, `list_targets` |
205
208
  | `watch` | `review_recording`, `player_frames`, `sample_frames`, `contact_sheet`, `screen_diff`, `wait_for_change`, `find_text`, `index_recording`, `search_recording` |
206
209
  | `edit` | `trim`, `concat`, `convert`, `export_gif`, `crop`, `scale`, `speed`, `compress`, `clip`, `cut_idle`, `cut_by_transcript`, `redact_region`, `pipeline` |
207
210
  | `produce` | `overlay`, `callout`, `keystroke_overlay`, `cursor`, `backdrop`, `burn_subtitles`, `chapters`, `xfade_transition`, `assemble_highlights`, `title_card`, `reframe`, `zoom`, `export_preset`, `bug_report`, `step_guide` |
@@ -219,16 +222,16 @@ Every capture tool takes one `target` string: `full`, `monitor:<index>`, `window
219
222
  with:
220
223
  command: npm run test:e2e
221
224
  ```
222
- - **Prompts and resources:** the server also ships MCP prompts that clients show as slash commands (`bug-repro-clip`, `file-bug-report`, `document-steps`, `demo-gif`, `verify-ui-change`, `review-recording`) and `screencast://sessions` resources for attaching recordings without a filesystem tool.
225
+ - **Prompts and resources:** the server also ships MCP prompts that clients show as slash commands (`bug-repro-clip`, `file-bug-report`, `document-steps`, `demo-gif`, `verify-ui-change`, `review-recording`) and `screencast://sessions` resources for attaching recordings without a filesystem tool. A client can subscribe to the list or one session and is notified when it changes, such as a recording that stopped at its cap.
223
226
  - **Threat model and Windows notes:** what capture can expose, and how window, monitor, WGC, and system-audio capture behave, are on the [docs home page](https://tmhsdigital.github.io/screencast-mcp/#threat-model).
224
227
 
225
228
  ## Privacy
226
229
 
227
230
  - **No network requests, no telemetry.** The server runs ffmpeg, ffprobe, and PowerShell locally and talks to your client over stdio. OCR (`find_text`) and speech (`narrate`) use the engines built into Windows.
228
231
  - **What a tool returns goes to your model provider.** Inline frames, OCR text, and event summaries reach your agent like any tool result; files on disk stay on disk unless a tool returns them or you share them.
229
- - **Everything is stored under `SCREENCAST_HOME`** (`recordings/`, `screenshots/`, `frames/`, `edits/`, `sessions.json`) unless a call names another path. `find_text`, `wait_for_change`, and `screen_diff` delete their captures after the call by default.
232
+ - **Everything is stored under `SCREENCAST_HOME`** (`recordings/`, `screenshots/`, `frames/`, `edits/`, `sessions.json`) unless a call names another path. `find_text` and `wait_for_change` delete their captures after the call by default (`keep: true` keeps them); `screen_diff` compares existing images and captures nothing.
230
233
  - **The event log never records typed text.** Only with `start_recording` `events: true` (or `cursor: "events"`), and only while that recording runs: clicks, scrolls, and cursor positions system-wide, and typing as bursts on a 0.5 s grid with no key names (`keys: "shortcuts"` also names Ctrl/Alt/Win chords). There is no microphone capture; system audio only with `audio.source` = `system`.
231
- - **Deleting data.** Delete files under `SCREENCAST_HOME`, or set `SCREENCAST_RETENTION_DAYS`; recordings and edits are never deleted automatically.
234
+ - **Deleting data.** `delete_recording` removes a recording with its sidecars (event log, webcam, transcript, index with its screen text, markers) and registry entry, asking you first when the client supports it. Otherwise delete files under `SCREENCAST_HOME`, or set `SCREENCAST_RETENTION_DAYS`; recordings and edits are never deleted automatically.
232
235
 
233
236
  ## Contributing
234
237
 
package/dist/cli.js CHANGED
@@ -8,6 +8,7 @@ import { createServer } from "./server.js";
8
8
  import { MAX_RECORDING_CAP_SEC } from "./utils/targets.js";
9
9
  import { DEFAULT_ERROR_PATTERN, DEFAULT_SECRET_PATTERN, MAX_ERROR_LINES, maskSecrets } from "./utils/bugReport.js";
10
10
  import { defaultSetupDeps, parseSetupArgs, runSetup, SETUP_USAGE } from "./setup.js";
11
+ import { errorMessage } from "./utils/errors.js";
11
12
  const VERSION = createRequire(import.meta.url)("../package.json").version;
12
13
  export class CliUsageError extends Error {
13
14
  }
@@ -174,7 +175,7 @@ export function parseCliArgs(argv, env = process.env) {
174
175
  return { kind: "setup", options: parseSetupArgs(rest) };
175
176
  }
176
177
  catch (err) {
177
- throw new CliUsageError(err instanceof Error ? err.message : String(err));
178
+ throw new CliUsageError(errorMessage(err));
178
179
  }
179
180
  }
180
181
  default:
@@ -241,7 +242,7 @@ export function parseToolArgs(raw, readFile = (p) => readFileSync(p, "utf8")) {
241
242
  value = JSON.parse(text);
242
243
  }
243
244
  catch (err) {
244
- throw new CliUsageError(`Tool arguments are not valid JSON: ${err instanceof Error ? err.message : String(err)}`);
245
+ throw new CliUsageError(`Tool arguments are not valid JSON: ${errorMessage(err)}`);
245
246
  }
246
247
  if (typeof value !== "object" || value === null || Array.isArray(value)) {
247
248
  throw new CliUsageError("Tool arguments must be a JSON object.");
@@ -354,7 +355,7 @@ export async function runRecord(opts, io = defaultIo, deps = defaultRecordDeps)
354
355
  io.err(`screencast-mcp: recording ${opts.target} to ${String(started.outputPath)}\n`);
355
356
  }
356
357
  catch (err) {
357
- warn(`recording did not start, running the command without it: ${err instanceof Error ? err.message : String(err)}`);
358
+ warn(`recording did not start, running the command without it: ${errorMessage(err)}`);
358
359
  }
359
360
  const began = deps.now();
360
361
  evidence.exitCode = await deps.run(opts.command);
@@ -372,7 +373,7 @@ export async function runRecord(opts, io = defaultIo, deps = defaultRecordDeps)
372
373
  warn(early);
373
374
  }
374
375
  catch (err) {
375
- warn(`stop_recording failed: ${err instanceof Error ? err.message : String(err)}`);
376
+ warn(`stop_recording failed: ${errorMessage(err)}`);
376
377
  }
377
378
  }
378
379
  const failed = evidence.exitCode !== 0;
@@ -390,7 +391,7 @@ export async function runRecord(opts, io = defaultIo, deps = defaultRecordDeps)
390
391
  evidence.gif = String(gif.outputPath);
391
392
  }
392
393
  catch (err) {
393
- warn(`export_gif failed: ${err instanceof Error ? err.message : String(err)}`);
394
+ warn(`export_gif failed: ${errorMessage(err)}`);
394
395
  }
395
396
  }
396
397
  if (opts.contactSheet) {
@@ -404,7 +405,7 @@ export async function runRecord(opts, io = defaultIo, deps = defaultRecordDeps)
404
405
  evidence.contactSheet = String(sheet.outputPath);
405
406
  }
406
407
  catch (err) {
407
- warn(`contact_sheet failed: ${err instanceof Error ? err.message : String(err)}`);
408
+ warn(`contact_sheet failed: ${errorMessage(err)}`);
408
409
  }
409
410
  }
410
411
  }
@@ -453,7 +454,7 @@ async function ocrErrors(client, recording, durationSec, lastSec, outDir, warn)
453
454
  return errorLines(matches);
454
455
  }
455
456
  catch (err) {
456
- warn(`OCR of error lines failed: ${err instanceof Error ? err.message : String(err)}`);
457
+ warn(`OCR of error lines failed: ${errorMessage(err)}`);
457
458
  return null;
458
459
  }
459
460
  finally {
package/dist/context.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { SessionStore } from "./utils/sessions.js";
2
2
  import { registryPath } from "./utils/paths.js";
3
+ import { ScreencastError } from "./utils/errors.js";
3
4
  let store = null;
4
5
  export function getStore() {
5
6
  if (!store) {
@@ -15,3 +16,35 @@ export function markShuttingDown() {
15
16
  export function isShuttingDown() {
16
17
  return shuttingDown;
17
18
  }
19
+ let startsInFlight = 0;
20
+ let onStartsIdle = [];
21
+ export function beginStart() {
22
+ if (shuttingDown)
23
+ throw new ScreencastError("The server is shutting down; the recording was not started.");
24
+ startsInFlight++;
25
+ let released = false;
26
+ return () => {
27
+ if (released)
28
+ return;
29
+ released = true;
30
+ startsInFlight--;
31
+ if (startsInFlight === 0) {
32
+ const waiters = onStartsIdle;
33
+ onStartsIdle = [];
34
+ for (const w of waiters)
35
+ w();
36
+ }
37
+ };
38
+ }
39
+ export function startsSettled(timeoutMs) {
40
+ if (startsInFlight === 0)
41
+ return Promise.resolve(true);
42
+ return new Promise((resolve) => {
43
+ const timer = setTimeout(() => resolve(false), timeoutMs);
44
+ timer.unref?.();
45
+ onStartsIdle.push(() => {
46
+ clearTimeout(timer);
47
+ resolve(true);
48
+ });
49
+ });
50
+ }
package/dist/index.js CHANGED
@@ -1,15 +1,18 @@
1
1
  #!/usr/bin/env node
2
2
  import { StdioServerTransport } from "@modelcontextprotocol/sdk/server/stdio.js";
3
3
  import { isCliInvocation, runCli } from "./cli.js";
4
- import { getStore, isShuttingDown, markShuttingDown } from "./context.js";
5
- import { requireFfmpeg } from "./utils/ffmpeg.js";
4
+ import { getStore, isShuttingDown, markShuttingDown, startsSettled } from "./context.js";
5
+ import { probeDuration, requireFfmpeg } from "./utils/ffmpeg.js";
6
6
  import { abortEditJobs } from "./utils/jobs.js";
7
- import { probeDuration, stopAll } from "./utils/lifecycle.js";
7
+ import { stopAll } from "./utils/lifecycle.js";
8
8
  import { createServer } from "./server.js";
9
9
  import { pruneCaptures, retentionDays, RETENTION_ENV } from "./utils/retention.js";
10
10
  import { cleanupReplayDirs } from "./utils/replay.js";
11
- const server = createServer();
11
+ import { errorMessage } from "./utils/errors.js";
12
+ const START_SETTLE_MS = 10_000;
12
13
  async function main() {
14
+ const server = createServer();
15
+ installServerHandlers();
13
16
  try {
14
17
  const reaped = getStore().reapOrphans();
15
18
  if (reaped.length > 0) {
@@ -17,7 +20,7 @@ async function main() {
17
20
  }
18
21
  }
19
22
  catch (err) {
20
- process.stderr.write(`Orphan reaping skipped: ${err instanceof Error ? err.message : String(err)}\n`);
23
+ process.stderr.write(`Orphan reaping skipped: ${errorMessage(err)}\n`);
21
24
  }
22
25
  try {
23
26
  const live = getStore()
@@ -28,17 +31,20 @@ async function main() {
28
31
  process.stderr.write(`Removed ${removed} leftover replay buffer(s).\n`);
29
32
  }
30
33
  catch (err) {
31
- process.stderr.write(`Replay buffer cleanup skipped: ${err instanceof Error ? err.message : String(err)}\n`);
34
+ process.stderr.write(`Replay buffer cleanup skipped: ${errorMessage(err)}\n`);
32
35
  }
36
+ const transport = new StdioServerTransport();
37
+ await server.connect(transport);
33
38
  const days = retentionDays();
34
39
  if (days !== null) {
35
- const pruned = pruneCaptures(days);
36
- if (pruned.removed > 0) {
37
- process.stderr.write(`Deleted ${pruned.removed} capture file(s) older than ${days} day(s) (${RETENTION_ENV}).\n`);
38
- }
40
+ pruneCaptures(days).then((pruned) => {
41
+ if (pruned.removed > 0) {
42
+ process.stderr.write(`Deleted ${pruned.removed} capture file(s) older than ${days} day(s) (${RETENTION_ENV}).\n`);
43
+ }
44
+ }, (err) => {
45
+ process.stderr.write(`Retention prune failed: ${errorMessage(err)}\n`);
46
+ });
39
47
  }
40
- const transport = new StdioServerTransport();
41
- await server.connect(transport);
42
48
  process.stdin.on("end", () => void shutdown("client disconnected"));
43
49
  process.stdin.on("close", () => void shutdown("client disconnected"));
44
50
  server.server.onclose = () => void shutdown("transport closed");
@@ -46,24 +52,29 @@ async function main() {
46
52
  process.on(sig, () => void shutdown(sig));
47
53
  }
48
54
  }
49
- process.stdout.on("error", (err) => {
50
- if (err.code !== "EPIPE")
51
- process.stderr.write(`stdout error: ${err.message}\n`);
52
- void shutdown("client pipe closed");
53
- });
54
- process.on("uncaughtException", (err) => {
55
- process.stderr.write(`Uncaught exception: ${err.stack ?? err.message}\n`);
56
- void shutdown("uncaught exception", 1);
57
- });
58
- process.on("unhandledRejection", (reason) => {
59
- process.stderr.write(`Unhandled rejection: ${reason instanceof Error ? (reason.stack ?? reason.message) : String(reason)}\n`);
60
- });
55
+ function installServerHandlers() {
56
+ process.stdout.on("error", (err) => {
57
+ if (err.code !== "EPIPE")
58
+ process.stderr.write(`stdout error: ${err.message}\n`);
59
+ void shutdown("client pipe closed");
60
+ });
61
+ process.on("uncaughtException", (err) => {
62
+ process.stderr.write(`Uncaught exception: ${err.stack ?? err.message}\n`);
63
+ void shutdown("uncaught exception", 1);
64
+ });
65
+ process.on("unhandledRejection", (reason) => {
66
+ process.stderr.write(`Unhandled rejection: ${reason instanceof Error ? (reason.stack ?? reason.message) : String(reason)}\n`);
67
+ });
68
+ }
61
69
  async function shutdown(reason, exitCode = 0) {
62
70
  if (isShuttingDown())
63
71
  return;
64
72
  markShuttingDown();
65
73
  const edits = abortEditJobs();
66
74
  try {
75
+ if (!(await startsSettled(START_SETTLE_MS))) {
76
+ process.stderr.write(`Shutdown (${reason}): a start_recording call did not finish within ${START_SETTLE_MS / 1000}s.\n`);
77
+ }
67
78
  const store = getStore();
68
79
  if (store.activeIds().length > 0) {
69
80
  let ffprobe = null;
@@ -72,12 +83,12 @@ async function shutdown(reason, exitCode = 0) {
72
83
  }
73
84
  catch {
74
85
  }
75
- const stopped = await stopAll(store, (path) => ffprobe ? probeDuration(ffprobe, path) : Promise.resolve(null));
86
+ const stopped = await stopAll(store, (path) => ffprobe ? probeDuration(path, { ffprobe }) : Promise.resolve(null));
76
87
  process.stderr.write(`Shutdown (${reason}): stopped ${stopped.length} recording(s).\n`);
77
88
  }
78
89
  }
79
90
  catch (err) {
80
- process.stderr.write(`Shutdown cleanup failed: ${err instanceof Error ? err.message : String(err)}\n`);
91
+ process.stderr.write(`Shutdown cleanup failed: ${errorMessage(err)}\n`);
81
92
  }
82
93
  const cancelled = await edits;
83
94
  if (cancelled > 0)
@@ -85,11 +96,15 @@ async function shutdown(reason, exitCode = 0) {
85
96
  process.exit(exitCode);
86
97
  }
87
98
  const fatal = (error) => {
88
- process.stderr.write(`Fatal error: ${error instanceof Error ? error.message : String(error)}\n`);
99
+ process.stderr.write(`Fatal error: ${errorMessage(error)}\n`);
89
100
  process.exit(1);
90
101
  };
91
102
  const argv = process.argv.slice(2);
92
103
  if (isCliInvocation(argv)) {
104
+ process.stdout.on("error", (err) => {
105
+ if (err.code !== "EPIPE")
106
+ process.stderr.write(`stdout error: ${err.message}\n`);
107
+ });
93
108
  runCli(argv).then((code) => process.exit(code), fatal);
94
109
  }
95
110
  else {
package/dist/resources.js CHANGED
@@ -1,5 +1,6 @@
1
1
  import { existsSync, rmSync } from "node:fs";
2
2
  import { ResourceTemplate } from "@modelcontextprotocol/sdk/server/mcp.js";
3
+ import { SubscribeRequestSchema, UnsubscribeRequestSchema } from "@modelcontextprotocol/sdk/types.js";
3
4
  import { getStore, isShuttingDown } from "./context.js";
4
5
  import { ScreencastError } from "./utils/errors.js";
5
6
  import { runFfmpeg, probeMedia } from "./utils/ffmpeg.js";
@@ -55,6 +56,16 @@ export function registerResources(server) {
55
56
  rmSync(frame, { force: true });
56
57
  }
57
58
  });
59
+ const subscribed = new Map();
60
+ server.server.registerCapabilities({ resources: { subscribe: true } });
61
+ server.server.setRequestHandler(SubscribeRequestSchema, (req) => {
62
+ subscribed.set(req.params.uri, resourceSnapshot(req.params.uri));
63
+ return {};
64
+ });
65
+ server.server.setRequestHandler(UnsubscribeRequestSchema, (req) => {
66
+ subscribed.delete(req.params.uri);
67
+ return {};
68
+ });
58
69
  getStore().onChange(() => {
59
70
  if (isShuttingDown() || !server.isConnected())
60
71
  return;
@@ -63,5 +74,20 @@ export function registerResources(server) {
63
74
  }
64
75
  catch {
65
76
  }
77
+ for (const [uri, before] of subscribed) {
78
+ const now = resourceSnapshot(uri);
79
+ if (now === before)
80
+ continue;
81
+ subscribed.set(uri, now);
82
+ server.server.sendResourceUpdated({ uri }).catch(() => {
83
+ });
84
+ }
66
85
  });
67
86
  }
87
+ export function resourceSnapshot(uri) {
88
+ if (uri === "screencast://sessions")
89
+ return JSON.stringify(getStore().list());
90
+ const m = /^screencast:\/\/sessions\/([^/]+)$/.exec(uri);
91
+ const s = m ? getStore().get(decodeURIComponent(m[1])) : undefined;
92
+ return s ? JSON.stringify(s) : null;
93
+ }
package/dist/server.js CHANGED
@@ -3,6 +3,7 @@ import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
3
3
  import { parseToolsets, serverInstructions, SELECTABLE_TOOLSETS, toolsetOf, } from "./utils/toolsets.js";
4
4
  import { register as registerStartRecording } from "./tools/startRecording.js";
5
5
  import { register as registerStopRecording } from "./tools/stopRecording.js";
6
+ import { register as registerDeleteRecording } from "./tools/deleteRecording.js";
6
7
  import { register as registerSaveReplay } from "./tools/saveReplay.js";
7
8
  import { register as registerPauseRecording } from "./tools/pauseRecording.js";
8
9
  import { register as registerResumeRecording } from "./tools/resumeRecording.js";
@@ -79,6 +80,7 @@ export function createServer(options = {}) {
79
80
  const tools = captureRegisteredTools(server);
80
81
  registerStartRecording(server);
81
82
  registerStopRecording(server);
83
+ registerDeleteRecording(server);
82
84
  registerPauseRecording(server);
83
85
  registerResumeRecording(server);
84
86
  registerSaveReplay(server);
package/dist/setup.js CHANGED
@@ -3,6 +3,7 @@ import { copyFileSync, existsSync, mkdirSync, readFileSync, writeFileSync } from
3
3
  import { homedir } from "node:os";
4
4
  import { dirname, join } from "node:path";
5
5
  import { createInterface } from "node:readline/promises";
6
+ import { errorMessage } from "./utils/errors.js";
6
7
  export const CLIENT_IDS = ["claude-desktop", "claude-code", "cursor", "vscode"];
7
8
  export const SETUP_USAGE = `setup options:
8
9
  --yes answer yes: install FFmpeg and write client configs without asking
@@ -113,7 +114,7 @@ export function mergeServerConfig(existing, key, name, entry, force = false) {
113
114
  parsed = JSON.parse(existing.charCodeAt(0) === 0xfeff ? existing.slice(1) : existing);
114
115
  }
115
116
  catch (err) {
116
- return { status: "invalid", reason: `not plain JSON (${err instanceof Error ? err.message : String(err)})` };
117
+ return { status: "invalid", reason: `not plain JSON (${errorMessage(err)})` };
117
118
  }
118
119
  if (typeof parsed !== "object" || parsed === null || Array.isArray(parsed)) {
119
120
  return { status: "invalid", reason: "the file is not a JSON object" };
@@ -209,7 +210,7 @@ async function configureJsonClient(client, opts, deps) {
209
210
  text = fs.readFile(client.path);
210
211
  }
211
212
  catch (err) {
212
- deps.out(` ${client.name}: could not read ${client.path}: ${err instanceof Error ? err.message : String(err)}\n`);
213
+ deps.out(` ${client.name}: could not read ${client.path}: ${errorMessage(err)}\n`);
213
214
  return false;
214
215
  }
215
216
  }
@@ -248,7 +249,7 @@ async function configureJsonClient(client, opts, deps) {
248
249
  return true;
249
250
  }
250
251
  catch (err) {
251
- deps.out(` ${client.name}: could not write ${client.path}: ${err instanceof Error ? err.message : String(err)}\n`);
252
+ deps.out(` ${client.name}: could not write ${client.path}: ${errorMessage(err)}\n`);
252
253
  return false;
253
254
  }
254
255
  }
@@ -293,7 +294,7 @@ export async function runSetup(opts, deps) {
293
294
  report = await deps.doctor();
294
295
  }
295
296
  catch (err) {
296
- deps.err(`screencast-mcp: the doctor checks failed to run: ${err instanceof Error ? err.message : String(err)}\n`);
297
+ deps.err(`screencast-mcp: the doctor checks failed to run: ${errorMessage(err)}\n`);
297
298
  return 1;
298
299
  }
299
300
  for (const line of checklist(report, deps.env, deps.platform))
@@ -317,7 +318,7 @@ export async function runSetup(opts, deps) {
317
318
  const res = await deps.exec("winget", WINGET_FFMPEG).catch((err) => ({
318
319
  code: 1,
319
320
  stdout: "",
320
- stderr: err instanceof Error ? err.message : String(err),
321
+ stderr: errorMessage(err),
321
322
  }));
322
323
  if (res.code === 0)
323
324
  say(" FFmpeg installed. Open a new terminal so PATH picks it up, then run setup again.\n");
@@ -355,7 +356,7 @@ export async function runSetup(opts, deps) {
355
356
  await deps.open(gif).catch(() => undefined);
356
357
  }
357
358
  catch (err) {
358
- say(` the test clip failed: ${err instanceof Error ? err.message : String(err)}\n`);
359
+ say(` the test clip failed: ${errorMessage(err)}\n`);
359
360
  return 1;
360
361
  }
361
362
  }
@@ -1,6 +1,6 @@
1
1
  import { z } from "zod";
2
2
  import { existsSync } from "node:fs";
3
- import { errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
3
+ import { errorMessage, errorResponse, okResponse, ScreencastError } from "../utils/errors.js";
4
4
  import { looseOutput } from "../utils/toolSpec.js";
5
5
  import { assertOutputAllowed } from "../utils/paths.js";
6
6
  import { cleanLabel, insertMarker, markerTimeSec, markersPath, readMarkers, writeMarkers, MAX_LABEL, } from "../utils/chapters.js";
@@ -61,7 +61,7 @@ export function register(server) {
61
61
  sidecar = writeMarkers(record.outputPath, markers, args.sessionId);
62
62
  }
63
63
  catch (err) {
64
- warning = `Saved in the session, but the sidecar ${sidecar} could not be written: ${err.message}`;
64
+ warning = `Saved in the session, but the sidecar ${sidecar} could not be written: ${errorMessage(err)}`;
65
65
  }
66
66
  return okResponse({
67
67
  sessionId: args.sessionId,
@@ -8,7 +8,7 @@ import { requireFfmpeg } from "../utils/ffmpeg.js";
8
8
  import { runEditJob, probeDuration } from "../utils/jobs.js";
9
9
  import { buildCalloutArgs } from "../utils/callout.js";
10
10
  import { prepareCalloutAssets } from "../utils/calloutAssets.js";
11
- import { editOutputExt, assertEditContainer } from "../utils/media.js";
11
+ import { stillEdit } from "../utils/media.js";
12
12
  import { resolveOutput, subdir, stamp, rand } from "../utils/paths.js";
13
13
  const timing = {
14
14
  from: z.number().nonnegative().optional(),
@@ -52,7 +52,7 @@ export const calloutItemSchema = z.discriminatedUnion("type", [
52
52
  }),
53
53
  ]);
54
54
  const inputSchema = {
55
- input: z.string().min(1).describe("Path to the source video."),
55
+ input: z.string().min(1).describe("Path to the source video or image (png/jpg; from/to are ignored for an image)."),
56
56
  items: z
57
57
  .array(calloutItemSchema)
58
58
  .min(1)
@@ -66,7 +66,7 @@ const inputSchema = {
66
66
  export function register(server) {
67
67
  server.registerTool("callout", {
68
68
  title: "Add Callouts",
69
- description: "Annotate a video with timed boxes, text labels, and arrows. Fallback fonts used are listed in " +
69
+ description: "Annotate a video or screenshot with timed boxes, text labels, and arrows. Fallback fonts used are listed in " +
70
70
  "fallbackFonts; characters no font covers are reported in warnings.",
71
71
  inputSchema,
72
72
  outputSchema: OUTPUT_PATH,
@@ -78,14 +78,13 @@ export function register(server) {
78
78
  throw new ScreencastError(`Input file not found: ${args.input}`);
79
79
  }
80
80
  const items = args.items;
81
- assertEditContainer(args.output);
82
- const ext = editOutputExt(args.input);
81
+ const { still, ext } = stillEdit(args.input, args.output);
83
82
  const output = resolveOutput(args.output, subdir("edits"), `callout-${stamp()}-${rand()}${ext}`, args.overwrite);
84
83
  const work = mkdtempSync(join(tmpdir(), "screencast-callout-"));
85
84
  try {
86
85
  const assets = await prepareCalloutAssets(items, work, "", args.fontFile);
87
- const ffArgs = buildCalloutArgs(args.input, output, items, assets);
88
- await runEditJob(ffArgs, { output, durationSec: await probeDuration(args.input), extra });
86
+ const ffArgs = buildCalloutArgs(args.input, output, items, assets, undefined, still);
87
+ await runEditJob(ffArgs, { output, durationSec: still ? null : await probeDuration(args.input), extra });
89
88
  return okResponse({
90
89
  outputPath: output,
91
90
  callouts: items.length,
@@ -11,6 +11,7 @@ import { evenTimes, formatTimecode, sheetGrid, buildTileArgs, buildSheetArgs, bu
11
11
  import { bundledFontPath } from "../utils/fonts.js";
12
12
  import { resolveOutput, subdir, stamp, rand, sequencePattern } from "../utils/paths.js";
13
13
  import { encodeInlineImages, DEFAULT_MAX_IMAGE_WIDTH } from "../utils/images.js";
14
+ import { mapPool } from "../utils/pool.js";
14
15
  const inputSchema = {
15
16
  input: z.string().min(1).describe("Path to the source video."),
16
17
  count: z
@@ -60,12 +61,12 @@ export async function renderContactSheet(input, times, output, opts, signal) {
60
61
  const work = mkdtempSync(join(tmpdir(), "screencast-sheet-"));
61
62
  try {
62
63
  const font = bundledFontPath("bold");
63
- for (const [i, t] of times.entries()) {
64
+ await mapPool(times, async (t, i) => {
64
65
  const labelFile = join(work, `label_${i}.txt`);
65
66
  writeFileSync(labelFile, formatTimecode(t));
66
67
  const tile = join(work, `tile_${String(i).padStart(3, "0")}.png`);
67
68
  await runFfmpeg(buildTileArgs(input, t, tile, opts.tileWidth, font, labelFile), 60_000, { signal });
68
- }
69
+ });
69
70
  await runFfmpeg(buildSheetArgs(sequencePattern(work, "tile_%03d.png"), grid, output), 60_000, { signal });
70
71
  }
71
72
  finally {