Files
wanderbooks/crates/ledger-mcp/src/lib.rs
T
swaitsandClaude Sonnet 5.5 f7f75fb380 feat(mcp): open and close one book while the server runs, and say who is connected
The desktop app is a window with a tab per company (plan/p15-app-and-relay.md
3.1, D-77, D-78): a company must be reachable by agents exactly while its tab
is open, so the books server can now open and close ONE book at run time
instead of opening every book at start and closing only with the process.

Close is ordered so that a call either ran completely (and is in the journal)
or was refused unrun: the book's door (a per-book gate every route enters
before it touches the book, its access log included) is shut and the book is
listed closed, so no new call gets in; SharedStore::close stops tools
starting and waits for those that did; the gate is waited empty for the
upload, download, export and MCP handlers inside; sessions end; the last
backup of the server's own close runs; and the store is let go, releasing
its writer lock. Only then is 'closed' answered. Another book's door, store
and sessions are never touched or waited on.

A closed book is a state of its own (not a problem): listed closed, and a
call for it is told apart from one for a book that does not exist, on the MCP,
upload, download and export routes, in words an agent can relay. Start gains
--open all|none|IDS (default all).

Sessions: a small in-memory board per book (sessions.rs) keeps what the
client said at initialize, the agent's self-report, calls running and the
last call, joined with the sessions the server already binds to tokens; the
admin 'sessions' request lists the token's NAME, never its text or hash, and
doctor prints it. Backups of a book let go push and record nothing more.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-20 09:02:02 -07:00

51 lines
1.4 KiB
Rust

//! `ledger-mcp`: the AI-first bookkeeping interface. It is served one way
//! (plan D-44): by the books server, `wanderbooks server` ([`local`]),
//! every book of the data root on the root's local sockets, which agents
//! reach through the bridge `wanderbooks mcp --book ID`. Files come in only
//! as uploads and go out only as downloads: never through an agent's
//! context (D-46).
pub mod access;
pub mod admin;
pub mod backup;
mod handbook;
pub mod ipc;
pub mod local;
pub mod opening;
mod policy;
pub mod scopes;
mod server;
mod sessions;
mod settings;
mod tin_files;
mod types;
pub use server::{NOT_RUN_CLOSING, NOT_RUN_CLOSING_CODE};
/// How a mode of the one executable stops when it can't go on: the
/// reason is already printed on stderr, and the number is the process's
/// exit code (2: a bad argument). A library never ends the process
/// itself, so the books it opened are closed properly on the way out;
/// the executable turns this into the exit.
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Exit(pub i32);
impl std::fmt::Display for Exit {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "exit code {}", self.0)
}
}
impl std::error::Error for Exit {}
#[cfg(test)]
mod exit_tests {
use super::Exit;
#[test]
fn an_exit_says_its_code() {
assert_eq!(Exit(2).to_string(), "exit code 2");
assert_eq!(Exit(1).to_string(), "exit code 1");
}
}