obs-mcp 0.2.0

OBS Studio control server for AI assistants via MCP and the OBS WebSocket protocol
Documentation
//! The MCP server: tool router over the generated OBS tool table.

use rmcp::{
    ServerHandler,
    handler::server::tool::ToolRouter,
    model::{ServerCapabilities, ServerInfo},
    tool_handler,
};

use crate::obs::ObsClient;
use crate::tools::register_tools;

/// The obs-mcp server: exposes one tool per OBS WebSocket request through a
/// table-driven tool router, backed by a shared OBS client.
#[derive(Clone)]
pub struct ObsMcpServer {
    tool_router: ToolRouter<Self>,
}

impl ObsMcpServer {
    pub fn new() -> Self {
        let client = ObsClient::from_env();
        let mut tool_router = ToolRouter::new();
        register_tools(&mut tool_router, &client);
        Self { tool_router }
    }
}

impl Default for ObsMcpServer {
    fn default() -> Self {
        Self::new()
    }
}

#[tool_handler(router = self.tool_router)]
impl ServerHandler for ObsMcpServer {
    fn get_info(&self) -> ServerInfo {
        ServerInfo::new(ServerCapabilities::builder().enable_tools().build()).with_instructions(
            "OBS Studio control server speaking the OBS WebSocket v5 protocol. \
             Typical flow: obs-get-status to check the connection, obs-get-scene-list / \
             obs-get-input-list to inspect the current scene graph, obs-set-current-scene / \
             obs-create-scene to manage scenes, obs-start-stream / obs-stop-stream / \
             obs-start-record / obs-stop-record for output control, obs-set-input-mute / \
             obs-set-input-volume for audio, and obs-trigger-transition for studio mode. \
             If a request fails because OBS is not running, start OBS with the WebSocket \
             server enabled (Tools > WebSocket Server Settings) and retry; the connection \
             re-establishes automatically.",
        )
    }
}