pub struct ProgressReporter { /* private fields */ }Expand description
A handle that long-running tool handlers call to emit progress
notifications during their work. Wraps the
crate::mcp_session::SessionState that owns the broadcast channel
- replay buffer; calls into
SessionState::publish_eventfor the actual fan-out.
Cloneable so handlers can move it across tokio::spawn boundaries
(the underlying Arc<SessionState> + token clone are cheap).
Constructed only when the dispatch path has BOTH an attached
Arc<SessionState> AND a parsed _meta.progressToken. Callers
(dispatch_tool + downstream handlers) accept Option<ProgressReporter>
and skip reporting silently when it’s None.
Implementations§
Source§impl ProgressReporter
impl ProgressReporter
Sourcepub fn new(session: Arc<SessionState>, token: ProgressToken) -> Self
pub fn new(session: Arc<SessionState>, token: ProgressToken) -> Self
Build a reporter wired to a session + the client’s token. Sole
caller today is McpDispatcher::handle_tools_call (and tests).
Sourcepub fn token(&self) -> &ProgressToken
pub fn token(&self) -> &ProgressToken
Echo the original wire-shape token back to the client. Used by
the GET stream sink to correlate progress events with in-flight
tools/call requests on the JSON-RPC reply side.
Sourcepub fn report(
&self,
progress: u64,
total: Option<u64>,
message: Option<&str>,
) -> u64
pub fn report( &self, progress: u64, total: Option<u64>, message: Option<&str>, ) -> u64
Publish one notifications/progress envelope to the session’s
event stream. The envelope:
{
"jsonrpc": "2.0",
"method": "notifications/progress",
"params": {
"progressToken": <client's original token>,
"progress": <current>,
"total": <expected total or null>,
"message": <optional human-readable string or null>
}
}Returns the per-session event id assigned by
SessionState::publish_event so callers can correlate the
emit with the resulting stream entry. Lossy on the broadcast
side (no live subscriber = silent drop) but lossless to the
replay buffer.
Trait Implementations§
Source§impl Clone for ProgressReporter
impl Clone for ProgressReporter
Source§fn clone(&self) -> ProgressReporter
fn clone(&self) -> ProgressReporter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreAuto Trait Implementations§
impl Freeze for ProgressReporter
impl !RefUnwindSafe for ProgressReporter
impl Send for ProgressReporter
impl Sync for ProgressReporter
impl Unpin for ProgressReporter
impl UnsafeUnpin for ProgressReporter
impl !UnwindSafe for ProgressReporter
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more