memstead_mcp/lib.rs
1//! Memstead MCP server — exposes the Memstead engine via the Model
2//! Context Protocol over STDIO.
3//!
4//! One crate, two build configs. The default build (`mem-repo`
5//! feature on) is the full server: the multi-mem, git-backed
6//! `ServerHandler` ([`server::McpServer`]) and its tool router, plus the
7//! support modules ([`config`], [`lifecycle`], [`read_mems`],
8//! [`error_envelope`]). `--no-default-features` drops the git-branch
9//! backend, leaving the folder + archive `ServerHandler`
10//! ([`filesystem_server::FilesystemMcpServer`]) — a CI / wasm-adjacent
11//! config, not shipped.
12//!
13//! Shared building blocks used by both servers live here unconditionally:
14//! [`error_envelopes`] (validation envelope) and [`tools`] (tool
15//! parameter structs).
16//!
17//! The binary entry point ([`main.rs`](main.rs)) stays thin: argument
18//! parsing, logging, then delegation into this crate.
19
20pub mod error_envelope;
21pub mod error_envelopes;
22pub mod filesystem_server;
23pub mod tools;
24
25// Multi-mem / git-backed server, compiled into the full `memstead-mcp`
26// binary (default features); absent from the lean `--no-default-features`
27// build, which has no git-branch backend.
28#[cfg(feature = "mem-repo")]
29pub mod config;
30#[cfg(feature = "mem-repo")]
31pub mod lifecycle;
32#[cfg(feature = "mem-repo")]
33pub mod read_mems;
34#[cfg(feature = "mem-repo")]
35pub mod server;
36
37/// Acquire an engine mutex on a tool dispatch path. A poisoned lock
38/// (a prior tool call panicked) early-returns the typed
39/// `ENGINE_LOCK_POISONED` envelope instead of panicking the server —
40/// usable only inside functions returning `CallToolResult`.
41#[macro_export]
42macro_rules! lock_engine {
43 ($mutex:expr) => {
44 match $mutex.lock() {
45 Ok(guard) => guard,
46 Err(_) => return $crate::error_envelopes::engine_lock_poisoned(),
47 }
48 };
49}