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>
This commit is contained in:
1 parent
526c27233e
commit
f7f75fb380
10 files changed
+1414
-97
No files matched your search
@@ -74,6 +74,8 @@ pub struct BooksServer {
|
||||
exports: ledger_store::exports::Exports,
|
||||
/// The books' backups (backup.rs).
|
||||
backups: Arc<crate::backup::Backups>,
|
||||
/// Who is connected, and what each is doing (sessions.rs).
|
||||
board: Arc<crate::sessions::Board>,
|
||||
/// How these books are kept from agents (plan 3.8, P9a): what
|
||||
/// `books.start` reports.
|
||||
isolation: Isolation,
|
||||
@@ -128,6 +130,8 @@ pub(crate) struct Served {
|
||||
pub(crate) uploads: ledger_store::uploads::Uploads,
|
||||
pub(crate) exports: ledger_store::exports::Exports,
|
||||
pub(crate) backups: Arc<crate::backup::Backups>,
|
||||
/// Its live sessions' board (sessions.rs), read by the admin socket.
|
||||
pub(crate) board: Arc<crate::sessions::Board>,
|
||||
pub(crate) isolation: Isolation,
|
||||
}
|
||||
|
||||
@@ -178,6 +182,7 @@ impl Served {
|
||||
uploads,
|
||||
exports,
|
||||
backups,
|
||||
board: Arc::default(),
|
||||
isolation,
|
||||
})
|
||||
}
|
||||
@@ -547,6 +552,7 @@ impl BooksServer {
|
||||
uploads: served.uploads.clone(),
|
||||
exports: served.exports.clone(),
|
||||
backups: served.backups.clone(),
|
||||
board: served.board.clone(),
|
||||
isolation: served.isolation,
|
||||
}
|
||||
}
|
||||
@@ -1744,7 +1750,7 @@ impl ServerHandler for BooksServer {
|
||||
) -> Result<rmcp::model::CallToolResponse, rmcp::ErrorData> {
|
||||
use crate::access::{self, Call};
|
||||
use ledger_store::access::Outcome;
|
||||
let mut call = Call::new(&self.access, &context, "tool", &request.name);
|
||||
let mut call = Call::new(&self.access, &self.board, &context, "tool", &request.name);
|
||||
let outcome_of = |out: &Result<rmcp::model::CallToolResponse, rmcp::ErrorData>| match out {
|
||||
Ok(rmcp::model::CallToolResponse::Complete(r)) if r.is_error != Some(true) => {
|
||||
Outcome::Ok
|
||||
@@ -1944,6 +1950,23 @@ impl ServerHandler for BooksServer {
|
||||
})
|
||||
}
|
||||
|
||||
/// The client has said who it is: the session's board (sessions.rs)
|
||||
/// knows it before the session's first call.
|
||||
async fn on_initialized(&self, context: rmcp::service::NotificationContext<RoleServer>) {
|
||||
if let (Some(sid), Some(info)) = (
|
||||
crate::access::session_of(&context.extensions),
|
||||
context.peer.peer_info(),
|
||||
) {
|
||||
self.board.initialized(
|
||||
&sid,
|
||||
ledger_store::access::Client {
|
||||
name: info.client_info.name.clone(),
|
||||
version: info.client_info.version.clone(),
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
fn get_info(&self) -> ServerConfig {
|
||||
// A client connecting after a settings change sees the change
|
||||
// (never waiting for the books here; a request holding them syncs
|
||||
@@ -2011,7 +2034,7 @@ impl ServerHandler for BooksServer {
|
||||
use ledger_store::access::Outcome;
|
||||
// Reading a resource is reading the books: books:read, recorded
|
||||
// (access.rs).
|
||||
let call = Call::new(&self.access, &context, "resource", &request.uri);
|
||||
let call = Call::new(&self.access, &self.board, &context, "resource", &request.uri);
|
||||
let result = self.resource(request, &call).await;
|
||||
{
|
||||
let outcome = match &result {
|
||||
|
||||
Reference in new issue
Block a user