Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
bacccf8
test(mcp): RED typed tool schema and structured result contract (#4445)
zackees Nov 9, 2026
a86793e
feat(mcp): typed tools, structured domain errors and schema snapshot …
zackees Nov 9, 2026
b23483d
docs(mcp): format generated schema by tool for review (#4445)
zackees Nov 9, 2026
c79b261
fix(mcp): preserve readiness errors and accurate operation hints (#4445)
zackees Nov 9, 2026
f988eb2
fix(mcp): retain legacy JSON text ordering and output descriptions (#…
zackees Nov 9, 2026
a11ee2a
test(mcp): RED device and pipeline counter baseline contract (#4446)
zackees Nov 9, 2026
bacedb8
feat(mcp): device, media and measured pipeline control (#4446)
zackees Nov 9, 2026
55af673
fix(mcp): guard camera readiness and track metric generations (#4446)
zackees Nov 9, 2026
278a1b1
style(mcp): format native readiness contract (#4446)
zackees Nov 9, 2026
861014e
test(mcp): RED deterministic condition waits and deadlines (#4447)
zackees Nov 9, 2026
7320a13
feat(mcp): bounded typed waits and start auto-wait (#4447)
zackees Nov 9, 2026
5213498
fix(mcp): reject late condition satisfaction after oversleep (#4447)
zackees Nov 9, 2026
2a04faf
Merge remote-tracking branch 'origin/master' into infra/control-api-d…
zackees Nov 9, 2026
3f1ef1c
fix(mcp): bind calldata ABI without linking OBS implementations (#4446)
zackees Nov 9, 2026
4cf6042
Merge branch 'infra/control-api-domains' into infra/control-api-wait
zackees Nov 9, 2026
1ab4670
Merge remote-tracking branch 'origin/master' into infra/control-api-d…
zackees Nov 10, 2026
a02b707
Merge branch 'infra/control-api-domains' into infra/control-api-wait
zackees Nov 10, 2026
7748417
Merge remote-tracking branch 'origin/master' into infra/control-api-wait
zackees Nov 10, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/features.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ not get a line.

### Headless and automation

- **Bounded MCP waits.** Agents can wait for typed output/source/media/metric
conditions and request automatic waits on starts, without GUI interaction or
fixed sleeps. Timeouts return the last observation. *All*, 2026-11-09.
Issue [#4447](https://github.com/obs-rust/obs-studio/issues/4447),
PR [#4454](https://github.com/obs-rust/obs-studio/pull/4454).

- **Virtual device and media control.** MCP can start/stop Virtual Camera, inspect
its paired mic, restart media, inspect pipeline graphs and read/reset measured
stage counters. Unmeasured device/sync values stay null. *All* (device support
Expand Down
9 changes: 5 additions & 4 deletions docs/rust-port/control-api.schema.json

Large diffs are not rendered by default.

27 changes: 25 additions & 2 deletions rust/obs-mcp/src/backend/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,12 @@ impl ObsBackend {
}
impl ControlBackend for ObsBackend {
fn vcam_start(&self, request: StartInput) -> Result<VcamStatus, ToolError> {
if crate::tools::waiting::WaitBackend::cancelled(self) {
return Err(ToolError::not_ready("OBS control is shutting down"));
}
if request.wait {
crate::tools::waiting::validate_timeout(request.timeout_ms)?;
}
if !crate::ffi::has_video() {
return Err(ToolError::not_ready(
"Virtual Camera requires initialized video",
Expand All @@ -73,8 +79,25 @@ impl ControlBackend for ObsBackend {
output.start().map_err(ToolError::processing)?;
}
let status = self.vcam_status(EmptyInput::default())?;
if request.wait && !status.active {
return Err(ToolError::not_ready("Virtual Camera has not become active"));
if request.wait {
use crate::tools::waiting::{
Condition, OutputName, OutputState, SystemClock, WaitInput, run_wait,
};
let result = run_wait(
self,
WaitInput {
condition: Condition::OutputState {
output: OutputName::Vcam,
state: OutputState::Active,
},
timeout_ms: request.timeout_ms,
},
&SystemClock::default(),
)?;
if !result.satisfied {
return Err(ToolError::not_ready("Virtual Camera start timed out"));
}
return self.vcam_status(EmptyInput::default());
}
Ok(status)
}
Expand Down
9 changes: 9 additions & 0 deletions rust/obs-mcp/src/backend/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ pub struct ObsBackend {
output_error: Option<String>,
cpu: Option<CpuUsage>,
camera: RefCell<Option<Output>>,
cancellation: Option<std::sync::Arc<std::sync::atomic::AtomicBool>>,
baseline: RefCell<Option<crate::tools::control::StatsBaseline>>,
}

Expand All @@ -81,6 +82,7 @@ impl ObsBackend {
output_error: None,
cpu: CpuUsage::start(),
camera: RefCell::new(None),
cancellation: None,
baseline: RefCell::new(None),
}
}
Expand Down Expand Up @@ -137,6 +139,8 @@ impl ObsBackend {
screenshot::register(&mut tools, &capture);
let control: Rc<dyn crate::tools::control::ControlBackend> = Rc::clone(backend) as _;
crate::tools::control::register(&mut tools, &control);
let waiting: Rc<dyn crate::tools::waiting::WaitBackend> = Rc::clone(backend) as _;
crate::tools::waiting::register(&mut tools, &waiting);

let mut resources = ResourceRegistry::new();
resources::scenes::register(&mut resources, &scenes, &sources);
Expand Down Expand Up @@ -342,6 +346,9 @@ fn narrow(value: f64) -> f32 {
}

impl OutputBackend for ObsBackend {
fn control_cancelled(&self) -> bool {
crate::tools::waiting::WaitBackend::cancelled(self)
}
fn start_output(&self, request: OutputRequest) -> Result<ActiveOutput, ToolError> {
let output = self.output(request.kind).map_err(ToolError::not_ready)?;
if !output.active() {
Expand Down Expand Up @@ -480,3 +487,5 @@ impl StatsBackend for ObsBackend {
}

mod control;

mod waiting;
83 changes: 83 additions & 0 deletions rust/obs-mcp/src/backend/waiting.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
//! Wait observations over unchanged libobs queries.
use super::{ObsBackend, Source};
use crate::server::ToolError;
use crate::tools::EmptyInput;
use crate::tools::control::ControlBackend;
use crate::tools::outputs::{OutputBackend, OutputKind};
use crate::tools::waiting::{
Condition, LastValue, Metric, Observation, ObserveInput, OutputName, OutputState, WaitBackend,
};
impl ObsBackend {
/// Cancels pending waits when an in-app host shuts down.
#[must_use]
pub fn with_cancellation(
mut self,
flag: std::sync::Arc<std::sync::atomic::AtomicBool>,
) -> Self {
self.cancellation = Some(flag);
self
}
}
impl WaitBackend for ObsBackend {
fn cancelled(&self) -> bool {
self.cancellation
.as_ref()
.is_some_and(|flag| flag.load(std::sync::atomic::Ordering::Acquire))
}
#[allow(
clippy::cast_precision_loss,
reason = "interactive stage measurements and xrun counts are far below 2^53"
)]
fn observe(&self, request: &ObserveInput) -> Result<Observation, ToolError> {
let (satisfied, value) = match &request.condition {
Condition::OutputState { output, state } => {
let active = match output {
OutputName::Record => Some(self.status(OutputKind::Record).active),
OutputName::Stream => Some(self.status(OutputKind::Stream).active),
OutputName::Vcam => Some(self.vcam_status(EmptyInput {})?.active),
OutputName::Vmic => self.vmic_status(EmptyInput {})?.active,
};
(
active == Some(matches!(state, OutputState::Active)),
LastValue::Output { active },
)
}
Condition::SourceActive { name } => {
let source = Source::by_name(name);
let active = source.as_ref().is_some_and(Source::active);
(
active,
LastValue::Source {
present: source.is_some(),
active,
},
)
}
Condition::MediaState { name, state } => {
let current = Source::by_name(name).map(|source| source.media().state);
(current == Some(*state), LastValue::Media { state: current })
}
Condition::StatAtMost { metric, value } => {
let stats = self.stats_get(EmptyInput {})?;
let current = match metric {
Metric::RenderFrameTimeNs => (stats.stages.render.live
&& stats.render.average_frame_time_ns > 0)
.then_some(stats.render.average_frame_time_ns as f64),
Metric::RenderFramesDropped => Some(stats.render.render_skipped_frames as f64),
Metric::VcamLatencyMaxNs => stats.stages.vcam.latency_max_ns.map(|v| v as f64),
Metric::VmicLatencyMaxNs => stats.stages.vmic.latency_max_ns.map(|v| v as f64),
Metric::VmicXruns => stats.stages.vmic.xruns.map(|v| v as f64),
Metric::AvOffsetAbsMs => stats.end_to_end.av_offset_ms.map(f64::abs),
};
(
crate::tools::waiting::metric_at_most(current, *value),
LastValue::Stat {
metric: *metric,
value: current,
},
)
}
};
Ok(Observation { satisfied, value })
}
}
6 changes: 6 additions & 0 deletions rust/obs-mcp/src/ffi/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ struct Calldata {
use std::ffi::{CStr, c_char, c_int, c_void};

unsafe extern "C" {
fn obs_source_active(source: *const sys::obs_source_t) -> bool;
fn obs_source_get_output_flags(source: *const sys::obs_source_t) -> u32;
fn obs_source_media_restart(source: *mut sys::obs_source_t);
fn obs_source_media_get_state(source: *mut sys::obs_source_t) -> c_int;
Expand Down Expand Up @@ -74,6 +75,11 @@ impl Drop for Params {
}
}
impl Source {
pub fn active(&self) -> bool {
// SAFETY: the source reference remains live during the query.
unsafe { obs_source_active(self.0.as_ptr()) }
}

pub fn restart_media(&self) -> Result<(), String> {
// SAFETY: owns a live source reference; the flag is OBS_SOURCE_CONTROLLABLE_MEDIA.
if unsafe { obs_source_get_output_flags(self.0.as_ptr()) } & (1 << 13) == 0 {
Expand Down
4 changes: 4 additions & 0 deletions rust/obs-mcp/src/tools/control.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ pub struct StartInput {
/// Wait until the output reports active.
#[serde(default)]
pub wait: bool,
/// Auto-wait deadline in milliseconds.
#[serde(default = "super::waiting::default_timeout_ms")]
pub timeout_ms: u64,
/// Enable the paired microphone before a stopped output starts.
#[serde(default = "enabled")]
pub audio_enabled: bool,
Expand All @@ -29,6 +32,7 @@ impl Default for StartInput {
fn default() -> Self {
Self {
wait: false,
timeout_ms: super::waiting::DEFAULT_TIMEOUT_MS,
audio_enabled: true,
audio_track: 1,
}
Expand Down
3 changes: 3 additions & 0 deletions rust/obs-mcp/src/tools/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,11 @@ pub fn schema_snapshot() -> serde_json::Value {
tools.extend(outputs::schemas());
tools.extend(screenshot::schemas());
tools.extend(control::schemas());
tools.extend(waiting::schemas());
tools.sort_by(|a, b| a["name"].as_str().cmp(&b["name"].as_str()));
serde_json::json!({"tools": tools, "toolError": schemars::schema_for!(crate::server::ToolError)})
}

pub mod control;

pub mod waiting;
109 changes: 103 additions & 6 deletions rust/obs-mcp/src/tools/outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,52 @@ pub struct OutputStatus {
/// Methods take `&self`: libobs owns the state, so implementations use their
/// own interior mutability.
pub trait OutputBackend {
/// Whether the owning control host is shutting down.
fn control_cancelled(&self) -> bool {
false
}
/// Starts with optional bounded auto-wait.
/// # Errors
/// Reports start failure or an auto-wait timeout.
fn start_with_wait(&self, request: OutputStartRequest) -> Result<ActiveOutput, ToolError> {
use super::waiting::{
Condition, OutputName, OutputState, SystemClock, WaitInput, run_wait, validate_timeout,
};
if request.options.wait {
validate_timeout(request.options.timeout_ms)?;
}
if self.control_cancelled() {
return Err(ToolError::not_ready("OBS control is shutting down"));
}
let state = self.start_output(OutputRequest { kind: request.kind })?;
if !request.options.wait {
return Ok(state);
}
let output = match request.kind {
OutputKind::Record => OutputName::Record,
OutputKind::Stream => OutputName::Stream,
};
let result = run_wait(
&OutputWait {
backend: self,
kind: request.kind,
},
WaitInput {
condition: Condition::OutputState {
output,
state: OutputState::Active,
},
timeout_ms: request.options.timeout_ms,
},
&SystemClock::default(),
)?;
if result.satisfied {
Ok(ActiveOutput { active: true })
} else {
Err(ToolError::not_ready("output start timed out"))
}
}

/// Typed idempotent start.
/// # Errors
/// Reports a processing failure.
Expand Down Expand Up @@ -94,13 +140,14 @@ typed_tool!(
RecordStart,
"record_start",
OutputBackend,
EmptyInput,
OutputStartInput,
ActiveOutput,
IDEMPOTENT,
"Start recording.",
|backend, _input| {
backend.start_output(OutputRequest {
|backend, input| {
backend.start_with_wait(OutputStartRequest {
kind: OutputKind::Record,
options: input,
})
}
);
Expand Down Expand Up @@ -136,13 +183,14 @@ typed_tool!(
StreamStart,
"stream_start",
OutputBackend,
EmptyInput,
OutputStartInput,
ActiveOutput,
IDEMPOTENT,
"Start streaming.",
|backend, _input| {
backend.start_output(OutputRequest {
|backend, input| {
backend.start_with_wait(OutputStartRequest {
kind: OutputKind::Stream,
options: input,
})
}
);
Expand Down Expand Up @@ -216,3 +264,52 @@ pub struct OutputRequest {
/// Output to operate on.
pub kind: OutputKind,
}

/// Auto-wait options for recording/streaming starts.
#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)]
#[serde(deny_unknown_fields)]
pub struct OutputStartInput {
/// Wait for the output to report active.
#[serde(default)]
pub wait: bool,
/// Bounded wait deadline.
#[serde(default = "super::waiting::default_timeout_ms")]
pub timeout_ms: u64,
}
impl Default for OutputStartInput {
fn default() -> Self {
Self {
wait: false,
timeout_ms: super::waiting::DEFAULT_TIMEOUT_MS,
}
}
}
/// Backend start request.
pub struct OutputStartRequest {
/// Output selector.
pub kind: OutputKind,
/// Auto-wait options.
pub options: OutputStartInput,
}

struct OutputWait<'a, B: OutputBackend + ?Sized> {
backend: &'a B,
kind: OutputKind,
}
impl<B: OutputBackend + ?Sized> super::waiting::WaitBackend for OutputWait<'_, B> {
fn cancelled(&self) -> bool {
self.backend.control_cancelled()
}
fn observe(
&self,
_: &super::waiting::ObserveInput,
) -> Result<super::waiting::Observation, ToolError> {
let active = self.backend.status(self.kind).active;
Ok(super::waiting::Observation {
satisfied: active,
value: super::waiting::LastValue::Output {
active: Some(active),
},
})
}
}
Loading
Loading