davinci-resolve-mcp 5.3.3 → 5.4.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/CHANGELOG.md CHANGED
@@ -2,6 +2,48 @@
2
2
 
3
3
  Release history for the DaVinci Resolve MCP Server. The latest release is summarized in the root README; older entries live here to keep the README focused.
4
4
 
5
+ ## What's New in v5.4.0 — Optional transport provider for play state and captures during playback
6
+
7
+ From #385.
8
+
9
+ ### Added
10
+
11
+ On Resolve 19.x the scripting API has no Play, Stop or IsPlaying. The server can see the playhead move, but can't tell playing from paused, can't press transport, and can't stop playback to take an exact frame. A site that has another way in (UI automation, a frame tap in the viewer, a control-surface bridge) can now plug it in without the server knowing how it works.
12
+
13
+ - **`RESOLVE_MCP_TRANSPORT_PROVIDER`** names a local executable, or a JSON argv such as `["python3", "-m", "my_transport"]`. `RESOLVE_MCP_TRANSPORT_PROVIDER_CWD` sets its working directory. The provider prints one JSON object per call. The contract is documented in `src/utils/transport_provider.py`.
14
+ - **`resolve_control(action="transport_status")`** returns the provider's play state (`playing_forward`, `playing_reverse`, `looping`, `paused` or `unknown`) and whether its channels agreed.
15
+ - **`resolve_control(action="transport_press", transport_action=...)`** presses forward, reverse, stop, play/pause, loop, mute, or a frame or second step. The action comes from a closed list, and a verdict of `ok` means the provider saw the effect, not just that it sent the press.
16
+ - **`timeline_frame` capture takes `during_playback`.** `refuse` is the default and behaves exactly as before. `live` returns the provider's newest frame without stopping playback. `pause` has the provider pause (and confirm it), export the exact frame, and restore the play state. Playback is never paused unless `pause` is asked for. The provider's metadata follows the image as `{"capture": {...}}`.
17
+ - When a provider is configured, the `PLAYBACK_ACTIVE` remediation names the two new capture options.
18
+
19
+ ### Fails closed
20
+
21
+ - With no provider set, or with an empty value, a missing file or a malformed array, every transport call returns `PROVIDER_MISSING`. Nothing changes for servers that don't set the variable.
22
+ - A provider's exit status is never read as success; its own verdict is returned as it is.
23
+ - A capture is read only from the path the server gave the provider. A provider that names another file is refused (`PROVIDER_PATH_MISMATCH`), and one that reports `ok` with no file is downgraded.
24
+ - `max_width` and ffmpeg are checked before the provider runs, so `pause` never stops playback for a capture that was going to fail anyway.
25
+
26
+ ### Not verified here
27
+
28
+ - The provider path was run live on Resolve Studio 19.1.3 against a site provider before the review fixes: the paused state came back with two independent signals agreeing, and an unset variable returned `PROVIDER_MISSING`. The review fixes (path pinning, early refusals, error categories) are covered by offline tests only.
29
+ - No provider ships with this package. Without one, the new actions return `PROVIDER_MISSING`.
30
+
31
+ ## What's New in v5.3.4 — House-style conventions for word-by-word subtitles and motion graphics
32
+
33
+ From #374 by @nisee22. Adapted on landing.
34
+
35
+ ### Added
36
+
37
+ - **The house-style skill records its first two conventions.**
38
+ - **Word-by-word subtitles:** split the existing cards into one word each instead of transcribing again, and write an SRT for the editor to import. Each card's own time span is shared between its words by length, and each word stays on screen for at least 3 frames.
39
+ - **Motion graphics:** build a native Fusion comp that fills the whole 9:16 frame, instead of a pre-rendered PNG sequence laid over the speaker. Build the comp on its own 1080x1920 timeline, then place that timeline on the main one with `AppendToTimeline`, using `trackIndex` and `recordFrame`.
40
+
41
+ The one change made on landing was copying the edit into `.agents/skills/house-style/SKILL.md`. The PR had only edited the `.claude` copy, and the two copies must match.
42
+
43
+ ### Not verified here
44
+
45
+ - Documentation only; no tool behaviour changes.
46
+
5
47
  ## What's New in v5.3.3 — DRP timeline start frame and timecode agree
6
48
 
7
49
  From #384.
package/README.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  English | [简体中文](README.zh-CN.md) | [繁體中文](README.zh-TW.md)
4
4
 
5
- [![Version](https://img.shields.io/badge/version-5.3.3-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
5
+ [![Version](https://img.shields.io/badge/version-5.4.0-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
6
6
  [![npm](https://img.shields.io/npm/v/davinci-resolve-mcp.svg?label=npm&color=CB3837)](https://www.npmjs.com/package/davinci-resolve-mcp)
7
7
  [![API Coverage](https://img.shields.io/badge/API%20Coverage-100%25-brightgreen.svg)](docs/reference/api-coverage.md)
8
8
  [![Tools](https://img.shields.io/badge/MCP%20Tools-37%20(390%20full)-blue.svg)](#server-modes)
package/README.zh-CN.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](README.md) | 简体中文 | [繁體中文](README.zh-TW.md)
4
4
 
5
- [![Version](https://img.shields.io/badge/version-5.3.3-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
5
+ [![Version](https://img.shields.io/badge/version-5.4.0-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
6
6
  [![npm](https://img.shields.io/npm/v/davinci-resolve-mcp.svg?label=npm&color=CB3837)](https://www.npmjs.com/package/davinci-resolve-mcp)
7
7
  [![API Coverage](https://img.shields.io/badge/API%20Coverage-100%25-brightgreen.svg)](docs/reference/api-coverage.md)
8
8
  [![Tools](https://img.shields.io/badge/MCP%20Tools-37%20(390%20full)-blue.svg)](#服务器模式)
@@ -12,7 +12,7 @@
12
12
  [![Python](https://img.shields.io/badge/python-3.10+-green.svg)](https://www.python.org/downloads/)
13
13
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
14
14
 
15
- > 本翻译对应 v5.3.3 版 README。如与英文原版有出入,以 [英文原版](README.md) 为准。
15
+ > 本翻译对应 v5.4.0 版 README。如与英文原版有出入,以 [英文原版](README.md) 为准。
16
16
 
17
17
  一个 Model Context Protocol (MCP) 服务器,让 AI 助手通过官方脚本 API 控制 DaVinci Resolve Studio(达芬奇)。它提供完整的 API 覆盖,外加带护栏的工作流助手,涵盖剪辑、媒体池整理、渲染设置、审阅标记、调色、Fusion、Fairlight、项目生命周期任务、扩展开发,以及不碰源媒体的媒体分析。
18
18
 
package/README.zh-TW.md CHANGED
@@ -2,7 +2,7 @@
2
2
 
3
3
  [English](README.md) | [简体中文](README.zh-CN.md) | 繁體中文
4
4
 
5
- [![Version](https://img.shields.io/badge/version-5.3.3-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
5
+ [![Version](https://img.shields.io/badge/version-5.4.0-blue.svg)](https://github.com/samuelgursky/davinci-resolve-mcp/releases)
6
6
  [![npm](https://img.shields.io/npm/v/davinci-resolve-mcp.svg?label=npm&color=CB3837)](https://www.npmjs.com/package/davinci-resolve-mcp)
7
7
  [![API Coverage](https://img.shields.io/badge/API%20Coverage-100%25-brightgreen.svg)](docs/reference/api-coverage.md)
8
8
  [![Tools](https://img.shields.io/badge/MCP%20Tools-37%20(390%20full)-blue.svg)](#伺服器模式)
@@ -12,7 +12,7 @@
12
12
  [![Python](https://img.shields.io/badge/python-3.10+-green.svg)](https://www.python.org/downloads/)
13
13
  [![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://opensource.org/licenses/MIT)
14
14
 
15
- > 本翻譯對應 v5.3.3 版 README。如與英文原版有出入,以[英文原版](README.md)為準。
15
+ > 本翻譯對應 v5.4.0 版 README。如與英文原版有出入,以[英文原版](README.md)為準。
16
16
 
17
17
  一個 Model Context Protocol(MCP)伺服器,讓 AI 助理透過官方腳本 API 控制 DaVinci Resolve Studio。它提供完整的 API 覆蓋,並附上有防護機制的工作流程輔助工具,涵蓋剪輯、媒體池整理、算圖輸出設定、審閱標記、調色、Fusion、Fairlight、專案生命週期作業、擴充功能開發,以及不更動原始素材的媒體分析。
18
18
 
package/docs/SKILL.md CHANGED
@@ -1981,6 +1981,12 @@ metadata. (For the raw camera file instead, use
1981
1981
  `frame` is the absolute timeline frame. Omit both to capture the playhead.
1982
1982
  - The page-switching routes (`render`, `thumbnail`, `still`) refuse while
1983
1983
  playback is running; `allow_during_playback=true` overrides.
1984
+ - `during_playback` needs an external transport provider
1985
+ (`RESOLVE_MCP_TRANSPORT_PROVIDER`): `live` takes the provider's newest frame
1986
+ without stopping playback, and `pause` has the provider pause (confirmed),
1987
+ export the exact frame and restore the play state. The default, `refuse`,
1988
+ is the behaviour above. With no provider set, both return `PROVIDER_MISSING`.
1989
+ No provider ships with the server.
1984
1990
 
1985
1991
  The playhead, page, current timeline and Gallery are restored. The `render` route
1986
1992
  additionally touches project render settings and puts them back: render mode,
@@ -2592,7 +2598,11 @@ was stuck in a viewer render loop. 19.x has no transport API, so the server
2592
2598
  cannot stop playback. `resolve_control open_page` / `restore_state`,
2593
2599
  `gallery_stills grab_and_export` and the page-switching `timeline_frame` routes
2594
2600
  refuse with `PLAYBACK_ACTIVE` when the playhead is moving; ask the user to stop
2595
- playback (Space or K). `allow_during_playback=true` overrides.
2601
+ playback (Space or K). `allow_during_playback=true` overrides. Where a site
2602
+ has configured a transport provider (`RESOLVE_MCP_TRANSPORT_PROVIDER`),
2603
+ `resolve_control transport_status` reports the play state and
2604
+ `transport_press` can stop it; a press verdict of `ok` means the provider saw
2605
+ the effect.
2596
2606
 
2597
2607
  **A transform write that reads back can still not render** — On a clip with
2598
2608
  Inspector keyframes (an AAF import can bring them), `SetProperty('ZoomX', v)`
package/install.py CHANGED
@@ -37,7 +37,7 @@ from src.utils.update_check import (
37
37
 
38
38
  # ─── Version ──────────────────────────────────────────────────────────────────
39
39
 
40
- VERSION = "5.3.3"
40
+ VERSION = "5.4.0"
41
41
  # Only hard floor: mcp[cli] requires Python 3.10+. There is no upper bound —
42
42
  # Resolve's scripting bridge loads into newer interpreters on recent builds
43
43
  # (Python 3.14 verified against Resolve Studio 20.3.2). Older Resolve builds
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "davinci-resolve-mcp",
3
- "version": "5.3.3",
3
+ "version": "5.4.0",
4
4
  "description": "NPM bootstrapper for the DaVinci Resolve MCP Server.",
5
5
  "license": "MIT",
6
6
  "author": "Samuel Gursky <samgursky@gmail.com>",
@@ -94,7 +94,7 @@ if not logging.getLogger().handlers:
94
94
  handlers=[logging.StreamHandler()],
95
95
  )
96
96
 
97
- VERSION = "5.3.3"
97
+ VERSION = "5.4.0"
98
98
  logger = logging.getLogger("davinci-resolve-mcp")
99
99
  logger.info(f"Starting DaVinci Resolve MCP Server v{VERSION}")
100
100
  logger.info(f"Detected platform: {get_platform()}")
package/src/server.py CHANGED
@@ -11,7 +11,7 @@ Usage:
11
11
  python src/server.py --full # Start the 377-tool granular server instead
12
12
  """
13
13
 
14
- VERSION = "5.3.3"
14
+ VERSION = "5.4.0"
15
15
 
16
16
  import base64
17
17
  import os
@@ -72,6 +72,7 @@ from src.utils import typed_api_search
72
72
  from src.utils import lut_files
73
73
  from src.utils import resolve_writes as _resolve_writes
74
74
  from src.utils import playback_guard as _playback_guard
75
+ from src.utils import transport_provider as _transport_provider
75
76
  from src.utils.mcp_stdio import run_fastmcp_stdio
76
77
  from src.utils.api_truth import lookup_api_truth, VERIFIED_ON as _API_TRUTH_VERIFIED_ON
77
78
  from src.utils import clip_colors as _clip_colors
@@ -17823,6 +17824,15 @@ def _playhead_frame_capture(p: Dict[str, Any]):
17823
17824
  if requested == "preview" and not p.get("max_width", p.get("maxWidth")):
17824
17825
  p = dict(p)
17825
17826
  p["max_width"] = 1280
17827
+ during = str(p.get("during_playback", "refuse") or "refuse").lower()
17828
+ if during not in ("refuse", "live", "pause"):
17829
+ return _err(f"during_playback must be 'refuse', 'live' or 'pause'; got {during!r}",
17830
+ code="INVALID_PARAM", category="invalid_input")
17831
+ if during != "refuse":
17832
+ if p.get("timecode") or p.get("frame") is not None or p.get("timeline_name", p.get("timelineName")):
17833
+ return _err("during_playback captures the frame on screen now; timecode, frame and timeline_name "
17834
+ "do not apply", code="INVALID_PARAM", category="invalid_input")
17835
+ return _provider_frame_capture(p, during)
17826
17836
  proj, tl, err = _get_tl()
17827
17837
  if err:
17828
17838
  return err
@@ -17888,6 +17898,58 @@ def _playhead_frame_capture(p: Dict[str, Any]):
17888
17898
  return _capture_with_teardown(result, teardown)
17889
17899
 
17890
17900
 
17901
+ def _provider_frame_capture(p: Dict[str, Any], mode: str):
17902
+ """Capture through the external transport provider (src/utils/transport_provider.py).
17903
+
17904
+ mode 'live': the newest frame the provider holds, tagged with the timeline frame it carries; the transport is not
17905
+ touched, so playback goes on. mode 'pause': the provider pauses (and confirms it), exports the exact frame, and
17906
+ restores the play state. Returns [image, {"capture": provider metadata}] or an error.
17907
+ """
17908
+ if not _transport_provider.available():
17909
+ why = _transport_provider.provider_argv()[1]
17910
+ return _err(f"during_playback={mode!r} needs a transport provider: {why}", code="PROVIDER_MISSING",
17911
+ category="precondition",
17912
+ remediation="Set RESOLVE_MCP_TRANSPORT_PROVIDER, or capture with the default "
17913
+ "during_playback='refuse' after stopping playback.")
17914
+ # Everything that can refuse is checked before the provider runs: in 'pause' mode the provider stops the
17915
+ # operator's playback, and that must not happen for a capture that was always going to fail afterwards.
17916
+ max_width = p.get("max_width", p.get("maxWidth"))
17917
+ if max_width not in (None, "", 0):
17918
+ try:
17919
+ max_width = int(max_width)
17920
+ except (TypeError, ValueError):
17921
+ max_width = -1
17922
+ if max_width <= 0:
17923
+ return _err(f"max_width must be a positive integer; got {p.get('max_width', p.get('maxWidth'))!r}",
17924
+ code="INVALID_PARAM", category="invalid_input")
17925
+ else:
17926
+ max_width = None
17927
+ if not shutil.which("ffmpeg"):
17928
+ return _err("during_playback captures need ffmpeg to transcode the provider's frame, and ffmpeg is not on "
17929
+ "PATH", code="FFMPEG_MISSING", category="precondition",
17930
+ remediation="Install ffmpeg, or stop playback and capture with the default during_playback.")
17931
+ base =_resolve_safe_dir(os.path.join(tempfile.gettempdir(), "resolve-frame-captures"))
17932
+ folder = os.path.join(base, f"{STILL_STAGING_PREFIX}{_uuid.uuid4().hex}")
17933
+ os.makedirs(folder, exist_ok=True)
17934
+ try:
17935
+ path = os.path.join(folder, "frame.jpg" if mode == "live" else "frame.png")
17936
+ meta = _transport_provider.capture(path, mode)
17937
+ if not meta.get("ok"):
17938
+ return _err(meta.get("error") or meta.get("why") or "the transport provider did not capture a frame",
17939
+ code=meta.get("code") or "PROVIDER_CAPTURE_FAILED", category="api_error",
17940
+ state={k: v for k, v in meta.items() if k not in ("path",)})
17941
+ out_format = "jpg" if str(p.get("format", "jpg")).lower() in ("jpg", "jpeg") else "png"
17942
+ # `path`, never meta["path"]: transport_provider.capture refuses a provider that names another file.
17943
+ data, ff_err = _ffmpeg_scale_to_bytes(path, max_width, out_format)
17944
+ if ff_err:
17945
+ return _err(f"Failed to transcode the provider's frame: {ff_err}", code="RESCALE_FAILED",
17946
+ category="api_error")
17947
+ info = {k: v for k, v in meta.items() if k != "path"}
17948
+ return [Image(data=data, format=out_format), {"capture": info}]
17949
+ finally:
17950
+ shutil.rmtree(folder, ignore_errors=True)
17951
+
17952
+
17891
17953
  def _playback_refusal(p: Optional[Dict[str, Any]], what: str, *, tl=None, resolve=None):
17892
17954
  """A PLAYBACK_ACTIVE error when the transport is running, else None.
17893
17955
 
@@ -19177,6 +19239,16 @@ def resolve_control(action: str, params: Optional[Dict[str, Any]] = None) -> Dic
19177
19239
  Omit symbol for every recorded gate this build does not clear.
19178
19240
  verification_stats() -> {stats} — readback-verification tally
19179
19241
  (verified/contradicted/unverified) since server start (no connection needed).
19242
+ transport_status() -> provider's {state, verified, agree, position, ...}
19243
+ — Is Resolve playing forward, in reverse, looping, or paused? Needs an external
19244
+ transport provider (RESOLVE_MCP_TRANSPORT_PROVIDER, see
19245
+ src/utils/transport_provider.py); the scripting API on 19.x cannot tell.
19246
+ Without one: PROVIDER_MISSING. The provider's verdict is returned as is:
19247
+ 'verified' false means fewer than two of its channels agreed.
19248
+ transport_press(transport_action) -> provider's {verdict: ok|failed|refused, ...}
19249
+ — forward, reverse, stop, play_pause, loop, mute, step_frame_forward/back,
19250
+ step_second_forward/back, through the provider. A verdict of ok means the
19251
+ provider saw the effect, not merely that it sent the press.
19180
19252
  report_issue(kind, title, summary, steps?, expected?, actual?, error?, tool?,
19181
19253
  tool_action?, use_case?, proposal?, include_environment?)
19182
19254
  -> {title, body, labels, url, url_truncated, redactions, submitted: false, next_step}
@@ -19277,6 +19349,17 @@ def resolve_control(action: str, params: Optional[Dict[str, Any]] = None) -> Dic
19277
19349
  — List active agent tool execution lifecycle hooks and their enabled status (no connection needed).
19278
19350
  """
19279
19351
  p = _params(params)
19352
+ if action in ("transport_status", "transport_press"):
19353
+ if action == "transport_status":
19354
+ out, verdict_key = _transport_provider.status(), "state"
19355
+ else:
19356
+ out = _transport_provider.press(str(p.get("transport_action") or p.get("op") or ""))
19357
+ verdict_key = "verdict"
19358
+ # A provider's own verdict passes through as it is, even a failed one. Only this module's errors (no
19359
+ # provider, a bad action, a provider that printed nothing usable) become an error envelope.
19360
+ if verdict_key not in out and "error" in out and "code" in out:
19361
+ return _err(out["error"], code=out["code"], category=_transport_provider.error_category(out["code"]))
19362
+ return out
19280
19363
 
19281
19364
  # api_truth is a static knowledge lookup — no Resolve connection needed, and
19282
19365
  # that property is worth keeping: it is the one call that still answers when
@@ -19760,7 +19843,7 @@ def resolve_control(action: str, params: Optional[Dict[str, Any]] = None) -> Dic
19760
19843
  if err:
19761
19844
  return _err(err)
19762
19845
  return {"success": bool(r.ExportUserPreferencesPreset(clean["name"], clean["path"]))}
19763
- return _unknown(action, ["is_studio","get_keyboard_presets","get_current_keyboard_preset","launch","runtime_mode","get_version","search_api","describe_api","api_surface","api_truth","check_version_support","verification_stats","report_issue","job_status","list_jobs","get_execution_trace","get_execution","list_recent_executions","begin_execution","end_execution","export_execution_report","clear_executions","inspect_operation","list_lifecycle_hooks","mcp_update_status","set_mcp_update_policy","ignore_mcp_update","snooze_mcp_update","clear_mcp_update_preferences","get_page","open_page","get_keyframe_mode","set_keyframe_mode","quit","get_fairlight_presets","set_high_priority","disable_background_tasks_for_current_session","list_user_preferences_presets","save_user_preferences_preset","load_user_preferences_preset","delete_user_preferences_preset","import_user_preferences_preset","export_user_preferences_preset","open_control_panel","control_panel_status","close_control_panel","save_state","restore_state"])
19846
+ return _unknown(action, ["transport_status","transport_press","is_studio","get_keyboard_presets","get_current_keyboard_preset","launch","runtime_mode","get_version","search_api","describe_api","api_surface","api_truth","check_version_support","verification_stats","report_issue","job_status","list_jobs","get_execution_trace","get_execution","list_recent_executions","begin_execution","end_execution","export_execution_report","clear_executions","inspect_operation","list_lifecycle_hooks","mcp_update_status","set_mcp_update_policy","ignore_mcp_update","snooze_mcp_update","clear_mcp_update_preferences","get_page","open_page","get_keyframe_mode","set_keyframe_mode","quit","get_fairlight_presets","set_high_priority","disable_background_tasks_for_current_session","list_user_preferences_presets","save_user_preferences_preset","load_user_preferences_preset","delete_user_preferences_preset","import_user_preferences_preset","export_user_preferences_preset","open_control_panel","control_panel_status","close_control_panel","save_state","restore_state"])
19764
19847
 
19765
19848
 
19766
19849
  # ─── V2 C4: Per-field corrections with provenance + changelog ────────────────
@@ -29507,6 +29590,14 @@ def timeline_frame(action: str, params: Optional[Dict[str, Any]] = None) -> Any:
29507
29590
  format jpg (default), png, or tif.
29508
29591
  timeline_name Capture from a different timeline; it is made current for
29509
29592
  the read and the original is restored afterwards.
29593
+ during_playback 'refuse' (default): the behaviour below. 'live': the newest
29594
+ frame from an external transport provider, tagged with the
29595
+ timeline frame it carries, without stopping playback. 'pause':
29596
+ the provider pauses (confirmed), exports the exact frame and
29597
+ restores the play state. Both need RESOLVE_MCP_TRANSPORT_PROVIDER
29598
+ (src/utils/transport_provider.py), else PROVIDER_MISSING; the
29599
+ metadata follows the image as {"capture": {...}}. Never pauses
29600
+ unless 'pause' is asked for.
29510
29601
  allow_during_playback The page-switching routes ('render', 'thumbnail',
29511
29602
  'still') refuse while playback is running (PLAYBACK_ACTIVE):
29512
29603
  a page switch during playback has hung Resolve. true
@@ -64,6 +64,12 @@ def current_timeline(resolve):
64
64
 
65
65
  def refusal_detail(what: str, state: Dict[str, Any]) -> Dict[str, Any]:
66
66
  """The pieces of a PLAYBACK_ACTIVE error, for the caller's own _err()."""
67
+ from src.utils import transport_provider # local: keeps this module importable alone
68
+ provider_hint = (
69
+ " A transport provider is configured: timeline_frame capture with "
70
+ "during_playback='live' takes the newest frame without stopping playback, "
71
+ "and during_playback='pause' pauses, exports the exact frame and resumes."
72
+ ) if transport_provider.available() else ""
67
73
  return {
68
74
  "message": (
69
75
  f"Playback is running in Resolve, so {what} was not attempted. A page "
@@ -74,6 +80,7 @@ def refusal_detail(what: str, state: Dict[str, Any]) -> Dict[str, Any]:
74
80
  "remediation": (
75
81
  "Stop playback in Resolve (Space or K) and retry. The scripting API has no "
76
82
  f"call that stops it. Pass {OVERRIDE_PARAM}=true to go ahead anyway."
83
+ + provider_hint
77
84
  ),
78
85
  "state": state,
79
86
  }
@@ -0,0 +1,136 @@
1
+ """An optional, external transport provider: a local program that can see and drive Resolve's transport.
2
+
3
+ The scripting API on Resolve 19.x has no Play, Stop or IsPlaying (see playback_guard.py), so this server cannot
4
+ tell play from pause beyond the playhead moving, and cannot stop playback to take an exact frame. A site that has
5
+ another way in (UI automation, a frame tap, a control surface bridge) can plug it in here without this server
6
+ knowing how it works.
7
+
8
+ Configure with RESOLVE_MCP_TRANSPORT_PROVIDER: the path of an executable, or a JSON array argv
9
+ (e.g. ["python3", "-m", "my_transport"], run with RESOLVE_MCP_TRANSPORT_PROVIDER_CWD as its working directory).
10
+ Unset or empty means no provider, and every call here returns a PROVIDER_MISSING error.
11
+
12
+ The provider is called once per request and prints ONE JSON object on stdout:
13
+
14
+ status -> {"state": "playing_forward|playing_reverse|looping|paused|unknown",
15
+ "verified": bool, "agree": [channel...], "position": {...}, ...}
16
+ press <action> -> {"verdict": "ok|failed|refused", ...} action: forward, reverse, stop,
17
+ play_pause, loop, mute, step_frame_forward, step_frame_back, ...
18
+ capture-live <path> -> {"ok": bool, "path": ..., "timelineFrame": int, "tc": ..., "ageMs": ...}
19
+ (the newest frame the provider has, without touching the transport)
20
+ capture-exact <path> [--pause-ok]
21
+ -> {"ok": bool, "path": ..., "timelineFrame": int, "restored": bool, ...}
22
+
23
+ This server never treats a provider's exit status or a "pressed" as proof: it returns the provider's own verdict
24
+ fields as they are, and a capture is returned as an image only when the file the provider names exists.
25
+ """
26
+ from __future__ import annotations
27
+
28
+ import json
29
+ import os
30
+ import shlex
31
+ import subprocess
32
+ from typing import Any, Dict, List, Optional, Tuple
33
+
34
+ ENV = "RESOLVE_MCP_TRANSPORT_PROVIDER"
35
+ ENV_CWD = "RESOLVE_MCP_TRANSPORT_PROVIDER_CWD"
36
+ TIMEOUT_S = 20.0
37
+ PRESS_ACTIONS = (
38
+ "forward", "reverse", "stop", "play_pause", "loop", "mute",
39
+ "step_frame_forward", "step_frame_back", "step_second_forward", "step_second_back",
40
+ )
41
+
42
+
43
+ def provider_argv() -> Tuple[Optional[List[str]], Optional[str]]:
44
+ """(argv, None) when a usable provider is configured, else (None, why). Empty counts as unset."""
45
+ raw = (os.environ.get(ENV) or "").strip()
46
+ if not raw:
47
+ return None, f"{ENV} is not set"
48
+ if raw.startswith("["):
49
+ try:
50
+ argv = json.loads(raw)
51
+ except ValueError:
52
+ return None, f"{ENV} is not a valid JSON array"
53
+ if not (isinstance(argv, list) and argv and all(isinstance(a, str) and a for a in argv)):
54
+ return None, f"{ENV} must be a non-empty array of strings"
55
+ return argv, None
56
+ if not (os.path.isfile(raw) and os.access(raw, os.X_OK)):
57
+ return None, f"{ENV} names {raw!r}, which is not an executable file"
58
+ return [raw], None
59
+
60
+
61
+ def available() -> bool:
62
+ return provider_argv()[0] is not None
63
+
64
+
65
+ def call(args: List[str], timeout: float = TIMEOUT_S) -> Dict[str, Any]:
66
+ """Run the provider with `args`. Returns its JSON object, or {"error": ..., "code": ...}."""
67
+ argv, why = provider_argv()
68
+ if argv is None:
69
+ return {"error": why, "code": "PROVIDER_MISSING"}
70
+ cwd = (os.environ.get(ENV_CWD) or "").strip() or None
71
+ if cwd and not os.path.isdir(cwd):
72
+ return {"error": f"{ENV_CWD} names {cwd!r}, which is not a directory", "code": "PROVIDER_MISSING"}
73
+ try:
74
+ proc = subprocess.run(argv + list(args), stdin=subprocess.DEVNULL, capture_output=True, text=True,
75
+ encoding="utf-8", errors="replace",
76
+ timeout=timeout, cwd=cwd)
77
+ except subprocess.TimeoutExpired:
78
+ return {"error": f"transport provider did not answer within {timeout:.0f} s", "code": "PROVIDER_TIMEOUT"}
79
+ except OSError as exc:
80
+ return {"error": f"transport provider could not start: {exc}", "code": "PROVIDER_FAILED"}
81
+ line = next((l for l in reversed(proc.stdout.splitlines()) if l.strip().startswith("{")), None)
82
+ if not line:
83
+ return {"error": "transport provider printed no JSON object", "code": "PROVIDER_FAILED",
84
+ "stderr": proc.stderr[-400:], "exit": proc.returncode, "argv": shlex.join(argv + list(args))}
85
+ try:
86
+ out = json.loads(line)
87
+ except ValueError:
88
+ return {"error": "transport provider printed invalid JSON", "code": "PROVIDER_FAILED"}
89
+ if not isinstance(out, dict):
90
+ return {"error": "transport provider printed JSON that is not an object", "code": "PROVIDER_FAILED"}
91
+ out.setdefault("providerExit", proc.returncode)
92
+ return out
93
+
94
+
95
+ def status() -> Dict[str, Any]:
96
+ return call(["status"])
97
+
98
+
99
+ def press(action: str) -> Dict[str, Any]:
100
+ if action not in PRESS_ACTIONS:
101
+ return {"error": f"action must be one of {list(PRESS_ACTIONS)}; got {action!r}", "code": "INVALID_ACTION"}
102
+ return call(["press", action])
103
+
104
+
105
+ def capture(path: str, mode: str) -> Dict[str, Any]:
106
+ """mode 'live' (newest frame, transport untouched) or 'pause' (pause, exact export, restore)."""
107
+ if mode == "live":
108
+ out = call(["capture-live", path])
109
+ elif mode == "pause":
110
+ out = call(["capture-exact", path, "--pause-ok"], timeout=40.0)
111
+ else:
112
+ return {"error": f"mode must be 'live' or 'pause'; got {mode!r}", "code": "INVALID_MODE"}
113
+ if not out.get("ok"):
114
+ return out
115
+ # The frame is read only from the path this server asked for. A provider that names some other file is refused
116
+ # rather than followed: that file sits outside the staging folder the caller cleans up, and a provider must not
117
+ # be able to have the server return an arbitrary file on disk as the image.
118
+ named = out.get("path")
119
+ if named and os.path.realpath(str(named)) != os.path.realpath(path):
120
+ out["ok"] = False
121
+ out["error"] = "the provider wrote its frame somewhere other than the path it was given"
122
+ out["code"] = "PROVIDER_PATH_MISMATCH"
123
+ elif not os.path.isfile(path):
124
+ out["ok"] = False
125
+ out["error"] = "the provider reported ok but no file exists at the path it was given"
126
+ out["code"] = "PROVIDER_FAILED"
127
+ return out
128
+
129
+
130
+ def error_category(code: str) -> str:
131
+ """The structured-error category for a code this module returns."""
132
+ if code in ("INVALID_ACTION", "INVALID_MODE"):
133
+ return "invalid_input"
134
+ if code == "PROVIDER_MISSING":
135
+ return "precondition"
136
+ return "api_error"