mcpmesh_local_api/lib.rs
1//! Talk to a running [mcpmesh](https://github.com/counterpunchtech/mcpmesh) daemon from Rust.
2//!
3//! This crate is the `mcpmesh-local/1` control seam: the typed wire vocabulary of the daemon's
4//! local control endpoint (requests, results, and the live-stream frames), the platform rule for
5//! finding that endpoint ([`paths`]), and — behind the `client` feature — an async client that
6//! speaks it. It links **no networking stack**: embedders (UIs, plugins, scripts) drive the
7//! daemon without pulling the mesh transport.
8//!
9//! The full protocol (framing, method-by-method semantics, the identity contract) is documented in
10//! [`docs/local-protocol.md`](https://github.com/counterpunchtech/mcpmesh/blob/main/docs/local-protocol.md).
11//! To RUN a node in-process instead of driving a daemon, see
12//! [`mcpmesh-node`](https://docs.rs/mcpmesh-node) — its `Node::control()` returns this same
13//! [`ControlClient`] over an in-memory pipe.
14//!
15//! # Quickstart (feature `client`)
16//!
17#![cfg_attr(feature = "client", doc = "```no_run")]
18#![cfg_attr(not(feature = "client"), doc = "```ignore")]
19//! # async fn quickstart() -> Result<(), mcpmesh_local_api::client::ClientError> {
20//! let mut daemon = mcpmesh_local_api::connect_control_default().await?;
21//! let status = daemon.status().await?;
22//! for peer in &status.peers {
23//! println!("{} shares: {}", peer.name, peer.services.join(", "));
24//! }
25//! # Ok(())
26//! # }
27//! ```
28//!
29//! [`connect_control_default`] dials the platform default endpoint (a unix socket, or a named
30//! pipe on Windows — the one rule in [`paths::default_endpoint`]); [`ControlClient`] then offers
31//! a typed helper per control method (`status`, `invite`, `pair`, `subscribe`, …), with
32//! [`ControlClient::request`] as the raw escape hatch for forward compatibility.
33//!
34//! # Features
35//!
36//! | Feature | Adds | Dependencies |
37//! |-----------|-------------------------------------------------------------------------|--------------|
38//! | *(none)* | The wire vocabulary ([`protocol`]) + endpoint resolution ([`paths`]) | serde only |
39//! | `client` | [`ControlClient`]: connect, typed request helpers, the typed [`client::StreamSubscription`] live stream | + tokio |
40//! | `service` | The plugin seam ([`service`]): local endpoint bind + same-user gate, `[services.*]` self-registration | + rustix, tracing |
41
42/// This crate's version — the mcpmesh release train the `mcpmesh` binary ships on.
43/// Embedders that bundle the daemon binary pin both to ONE version and use this const
44/// as the expected `stack_version` anchor for the daemon they spawned.
45pub const VERSION: &str = env!("CARGO_PKG_VERSION");
46
47/// The canonical transport-vocabulary blocklist (spec §1.5/§17), shipped in-crate so
48/// embedders' surface-leak suites assert against the ONE canonical copy instead of
49/// forking it. JSON object with `substring_banned`, `token_banned`, `carve_outs`.
50pub const TRANSPORT_VOCABULARY: &str = include_str!("../fixtures/transport-vocabulary.json");
51
52/// Platform paths + endpoint resolution — featureless/std-only, so any consumer
53/// resolves the daemon endpoint from the ONE rule.
54pub mod paths;
55pub mod principals;
56pub mod protocol;
57pub use principals::principal_set;
58pub use protocol::{
59 API_MINOR, API_NAME, API_VERSION, ActiveSession, AuditKind, AuditListParams, AuditListResult,
60 AuditPruneParams, AuditPruneResult, AuditRecord, AuditSummaryResult, BackendKind, BackendSpec,
61 BlobDirection, BlobFetchCancelParams, BlobFetchCancelResult, BlobFetchParams, BlobFetchResult,
62 BlobGrantParams, BlobListParams, BlobPublishParams, BlobPublishResult, BlobRepublishParams,
63 BlobRevokeParams, BlobScopeList, BlobTransferState, BlobUnpublishParams, ERR_BLOB_WITHDRAWN,
64 ERR_CANCELLED, ERR_INVITE_EXPIRED, ERR_INVITE_NAME_CONFLICT, ERR_INVITE_NOT_LIVE,
65 ERR_INVITE_REFUSED, ERR_INVITER_MISMATCH, ERR_INVITER_UNREACHABLE, ERR_NICKNAME_TAKEN,
66 ERR_NO_SUCH_BLOB, ERR_NO_SUCH_SERVICE, ERR_SELF_ENROLL_NOT_OFFERED, ERR_TOO_MANY_INFLIGHT,
67 Hello, InviteParams, InviteResult, MAX_BLOB_SOURCES, MAX_INFLIGHT, MAX_INVITE_USES,
68 OpenSessionParams, OrgApproveParams, OrgApproveResult, OrgCreateParams, OrgCreateResult,
69 OrgJoinCodeParams, OrgJoinCodeResult, OrgJoinParams, OrgJoinResult, OrgRevokeParams,
70 OrgRevokeResult, PairParams, PairResult, PeerAddParams, PeerDiagnosticsParams,
71 PeerDiagnosticsResult, PeerEndorseParams, PeerEndorseResult, PeerInfo, PeerIntroduceParams,
72 PeerPath, PeerReachability, PeerRemoveParams, PeerRenameParams, PeerServicesParams,
73 PeerServicesResult, PresencePeer, ReachabilitySource, RecentPairing, RegisterServiceParams,
74 RelayInfo, Request, RosterInstallParams, RosterInstallResult, RosterMember, RosterMemberDevice,
75 RosterMembersResult, RosterStatus, ScopeInfo, SelfNetwork, ServiceAllowParams, ServiceInfo,
76 SetAppMetadataParams, SetNicknameParams, SetRelaysParams, SetRelaysResult, SetRosterUrlParams,
77 StatusResult, StorageInfo, StreamFrame, UnregisterServiceParams, method_of, one_use,
78};
79
80#[cfg(feature = "client")]
81pub mod client;
82#[cfg(feature = "client")]
83pub mod codec;
84
85/// The platform local-endpoint seam: connect/bind/accept/authorize.
86#[cfg(feature = "client")]
87pub mod transport;
88#[cfg(feature = "client")]
89pub use client::{
90 ControlClient, ControlRead, ControlWrite, StreamSubscription, connect_control,
91 connect_control_default, connect_control_io,
92};
93
94/// The shared plugin-platform seam (kb, loc, …): local endpoint faces, THE audience-authz
95/// expansion, `[services.*]` self-registration, and the `*-local/1` JSON-RPC conventions.
96#[cfg(feature = "service")]
97pub mod service;