Skip to main content

Bridge

Struct Bridge 

Source
pub struct Bridge { /* private fields */ }
Expand description

A stdio session forwarded to a shared server.

Besides the frames, the bridge keeps two things it saw pass through: the client’s initialize, so that a session can be re-opened without the client noticing, and the arguments of every accepted announcement the client has made, so that what the client said it was working on outlives the server it said it to. An announcement was the one fact that died with a server: on 2026-09-09 a session’s intent vanished from the board when its transport was re-established, and eight peers could not see it for three hours. The bridge is the one place that sees both the announcement and the reconnection, so the bridge replays them — after a re-attach through Bridge::reinitialize, and, for a takeover, through Bridge::announcements onto the new server’s own board.

Every announcement, one per claim name, and not merely the last one: a client may hold several claims at once, and replaying only the most recent would restore one of them and quietly drop the rest — which is the same loss the replay exists to prevent, arriving by a different route.

Implementations§

Source§

impl Bridge

Source

pub fn new(url: String) -> Self

A bridge to the server at url, with no session yet, waiting REQUEST_TIMEOUT for each answer.

Source

pub fn with_timeout(url: String, timeout: Duration) -> Self

A bridge to the server at url that waits timeout for each answer. A call that outlasts it is BridgeError::Unanswered: it was sent, and whether it ran is unknown.

use majordomus_cli::mcp::bridge::Bridge;
use std::time::Duration;
let bridge = Bridge::with_timeout("http://127.0.0.1:8741".into(), Duration::from_secs(5));
assert_eq!(bridge.url(), "http://127.0.0.1:8741");
Source

pub fn announcements(&self) -> impl Iterator<Item = &Value>

The arguments of every announcement the server accepted, one per claim name, in name order: what a takeover replays onto the new server’s board.

Empty when the client has announced nothing, which is every bridge that has only just been made — nothing has passed through it yet to be remembered.

use majordomus_cli::mcp::bridge::Bridge;
let bridge = Bridge::new("http://127.0.0.1:8741/mcp".into());
assert_eq!(bridge.announcements().count(), 0);
Source

pub fn url(&self) -> &str

The server’s URL.

Source

pub fn client(&self) -> Option<&ClientInfo>

What the client said in initialize, once it has.

Source

pub fn move_to(&mut self, url: String)

Point the bridge at another server; the next message opens a session there.

Source

pub fn handle(&mut self, message: &Value) -> Result<Option<Value>, BridgeError>

Forward one message; None when the server had nothing to say (a notification).

Source

pub fn reinitialize(&mut self) -> Result<(), BridgeError>

Open a new session with the initialize the client sent earlier. A no-op when it has not sent one yet.

Source

pub fn heartbeat(&mut self) -> Result<(), BridgeError>

Keep the session alive.

Source

pub fn close(&mut self)

End the session on the server; the client has gone.

Trait Implementations§

Source§

impl Debug for Bridge

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

§

impl<T> Instrument for T

§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided [Span], returning an Instrumented wrapper. Read more
§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<T> WithSubscriber for T

§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a [WithDispatch] wrapper. Read more
§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a [WithDispatch] wrapper. Read more