pub struct JsonRpcDispatcher<'a> { /* private fields */ }Expand description
JSON-RPC 2.0 dispatcher for MCP stdio transport.
Implementations§
Source§impl<'a> JsonRpcDispatcher<'a>
impl<'a> JsonRpcDispatcher<'a>
Sourcepub fn dispatch_authenticated(
&self,
request: &str,
auth_header: Option<&str>,
) -> Option<String>
pub fn dispatch_authenticated( &self, request: &str, auth_header: Option<&str>, ) -> Option<String>
Dispatch a request, checking the Authorization header if auth is configured.
Returns a JSON-RPC -32001 error response when auth fails.
Pass None for auth_header when no header is present (stdio transport).
Sourcepub fn dispatch(&self, request: &str) -> Option<String>
pub fn dispatch(&self, request: &str) -> Option<String>
Dispatch a JSON-RPC request (single or batch) and return the response.
Sourcepub async fn dispatch_async(&self, request: &str) -> Option<String>
pub async fn dispatch_async(&self, request: &str) -> Option<String>
Dispatch a JSON-RPC request, awaiting async tool handlers.
Identical to JsonRpcDispatcher::dispatch except that tools/call
resolves through McpServer::call_tool_async, so tools registered
with set_async_handler work. The synchronous Self::dispatch
cannot invoke them — prefer this one whenever the server has any
async handler.
Sourcepub async fn dispatch_authenticated_async(
&self,
request: &str,
auth_header: Option<&str>,
) -> Option<String>
pub async fn dispatch_authenticated_async( &self, request: &str, auth_header: Option<&str>, ) -> Option<String>
Self::dispatch_authenticated with async tool handler support.
Sourcepub fn run_stdio(&self) -> Result<()>
pub fn run_stdio(&self) -> Result<()>
Run the stdio transport loop: read lines from stdin, dispatch, write to stdout.
Tools registered with set_async_handler are NOT callable from this
loop — use Self::run_stdio_async when the server has any.
§Errors
Fails immediately (InvalidInput) when the server has any async-only
tool: every call to it would otherwise return isError at runtime and
look like a handler bug.
Sourcepub async fn run_stdio_async(&self) -> Result<()>
pub async fn run_stdio_async(&self) -> Result<()>
Self::run_stdio for servers with async tool handlers.
Reads stdin with blocking I/O between awaits — an MCP stdio server is a dedicated process, so occupying the calling task is intended. Drive it from a runtime’s blocking-friendly context (e.g. a dedicated task).
Auto Trait Implementations§
impl<'a> !RefUnwindSafe for JsonRpcDispatcher<'a>
impl<'a> !UnwindSafe for JsonRpcDispatcher<'a>
impl<'a> Freeze for JsonRpcDispatcher<'a>
impl<'a> Send for JsonRpcDispatcher<'a>
impl<'a> Sync for JsonRpcDispatcher<'a>
impl<'a> Unpin for JsonRpcDispatcher<'a>
impl<'a> UnsafeUnpin for JsonRpcDispatcher<'a>
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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
impl<T> ErasedDestructor for Twhere
T: 'static,
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 moreSource§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::RequestSource§impl<T> Pointable for T
impl<T> Pointable for T
Source§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> Read<Exclusive, BecauseExclusive> for Twhere
T: ?Sized,
Source§impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
impl<SS, SP> SupersetOf<SS> for SPwhere
SS: SubsetOf<SP>,
Source§fn to_subset(&self) -> Option<SS>
fn to_subset(&self) -> Option<SS>
self from the equivalent element of its
superset. Read moreSource§fn is_in_subset(&self) -> bool
fn is_in_subset(&self) -> bool
self is actually part of its subset T (and can be converted to it).Source§fn to_subset_unchecked(&self) -> SS
fn to_subset_unchecked(&self) -> SS
self.to_subset but without any property checks. Always succeeds.Source§fn from_subset(element: &SS) -> SP
fn from_subset(element: &SS) -> SP
self to the equivalent element of its superset.