Skip to main content

bacnet_mcp/
lib.rs

1//! A [Model Context Protocol](https://modelcontextprotocol.io) server for
2//! BACnet sites (#2066), so an AI agent host (Claude Code, Codex and
3//! others) can discover devices and read them through the same engine and
4//! request limits as the `bacnet` tool's terminal UI, and, when a profile
5//! opts in, write through the TUI's preview tiers, ledger and audit log
6//! (#2068).
7//!
8//! The server is built on the official `rmcp` SDK and targets the
9//! 2026-07-28 revision of the protocol, while still answering clients that
10//! open with the older `initialize` handshake. `bacnet mcp serve --stdio`
11//! (the CLI's `mcp` feature) runs it; `docs/design/mcp.md` has the design.
12//!
13//! - Every tool reaches the network only through
14//!   [`bacnet_ops::engine::Engine`], under its per-device gate and global
15//!   rate, a rate per network, and a token bucket per principal
16//!   ([`Policy`]). Each result reports what it cost.
17//! - Device-supplied text comes back in an untrusted envelope: cleaned of
18//!   control and bidirectional characters, defanged and capped.
19//! - Results are paged with cursors signed by a per-process key.
20//! - Passive mode builds no client and lists only the tools that send
21//!   nothing.
22//! - Writes are off by default. With `mcp_writes = "elicit"` the client's
23//!   confirmation may approve a T1 write and a plan grant the writes it
24//!   names; T2 and T3 need a verifiable approver. The confirmation state is
25//!   sealed for its caller, single use and short-lived.
26//!
27//! Stdout carries only JSON-RPC: this crate never prints, and its logs go
28//! through `tracing`, which the host process points at stderr.
29
30mod context;
31mod cursor;
32mod errors;
33mod follow;
34mod legacy;
35mod listen;
36pub mod policy;
37mod prompts;
38mod resources;
39mod server;
40mod tools;
41mod untrusted;
42mod value;
43mod writes;
44
45pub use policy::Policy;
46pub use server::{McpServer, ServeError};
47
48#[cfg(test)]
49mod tests;