use rmcp::{
ServerHandler,
handler::server::tool::ToolRouter,
model::{ServerCapabilities, ServerInfo},
tool_handler,
};
use crate::obs::ObsClient;
use crate::tools::register_tools;
#[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.",
)
}
}