Files
deckcraft/crates/mcp/src/lib.rs
T
Dylan M. Taylor 748c1465f1 platform-w4: net change of 3 commits
- platform-w4: written from its sheet
- platform-w4: repair 1
- platform-w4: review fixes (review-1)
2026-11-27 14:51:30 +00:00

40 lines
1.6 KiB
Rust

//! DeckCraft's MCP server.
//!
//! [Model Context Protocol](https://modelcontextprotocol.io) over stdio: newline-delimited
//! JSON-RPC 2.0, hand-written (no async runtime). The server exposes DeckCraft as a set of MCP
//! tools and resources and forwards everything to a [`Backend`]:
//!
//! - `Remote` authenticates with a running desktop app's per-launch token through the framework's
//! JSON-lines control client. Start the app with `deckcraft --control 7979 --control-token-file PATH`
//! and pass that file to the client with `--control-token-file PATH` (see `docs/control-protocol.md`).
//! - [`Headless`] hosts an in-process [`deckcraft_engine::Session`] and implements the
//! engine-level control-channel methods itself (rendering pages with `deckcraft-render`), so
//! agents can build layouts and look at them without a window.
//!
//! Entry points: [`Server::serve`] (stdio loop) and [`Server::handle_line`] (one message).
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
#![forbid(unsafe_code)]
mod backend;
mod headless;
mod server;
mod tools;
pub use backend::Backend;
#[cfg(not(target_arch = "wasm32"))]
pub use backend::Remote;
pub use headless::Headless;
pub use server::{PROTOCOL_VERSION, Server};
pub use tools::{ToolResult, call_tool, tool_definitions};
/// Default control-channel port of the desktop app.
pub const DEFAULT_PORT: u16 = 7979;
/// `"7979"` → `"127.0.0.1:7979"`; `"host:port"` is kept as is.
pub fn control_addr(s: &str) -> String {
if s.parse::<u16>().is_ok() { format!("127.0.0.1:{s}") } else { s.to_string() }
}
#[cfg(test)]
mod tests;