pub struct McpHttpHandler { /* private fields */ }Implementations§
Source§impl McpHttpHandler
impl McpHttpHandler
pub fn new() -> Self
pub fn add_middleware<M: Middleware>(&mut self, middleware: M)
Source§impl McpHttpHandler
impl McpHttpHandler
Sourcepub async fn handle_sse_connection(
&self,
state: Arc<McpAppState>,
sse_message_endpoint: Option<&str>,
) -> TransportServerResult<Response<BoxBody<Bytes, TransportServerError>>>
pub async fn handle_sse_connection( &self, state: Arc<McpAppState>, sse_message_endpoint: Option<&str>, ) -> TransportServerResult<Response<BoxBody<Bytes, TransportServerError>>>
Handles an MCP connection using the SSE (Server-Sent Events) transport.
This function serves as the entry point for initializing and managing a client connection
over SSE when the sse feature is enabled.
§Arguments
state- Shared application state required to manage the MCP session.sse_message_endpoint- Optional message endpoint to override the default SSE route (default:/messages).
§Features
This function is only available when the sse feature is enabled.
Sourcepub async fn handle_sse_message(
&self,
request: Request<&str>,
state: Arc<McpAppState>,
) -> TransportServerResult<Response<BoxBody<Bytes, TransportServerError>>>
pub async fn handle_sse_message( &self, request: Request<&str>, state: Arc<McpAppState>, ) -> TransportServerResult<Response<BoxBody<Bytes, TransportServerError>>>
Handles incoming MCP messages from the client after an SSE connection is established.
This function processes a message sent by the client as part of an active SSE session. It:
- Extracts the
sessionIdfrom the request query parameters. - Locates the corresponding session’s transmit channel.
- Forwards the incoming message payload to the MCP transport stream for consumption.
§Arguments
request- The HTTP request containing the message body and query parameters (includingsessionId).state- Shared application state, including access to the session store.
§Returns
TransportServerResult<http::Response<GenericBody>>:- Returns a
202 AcceptedHTTP response if the message is successfully forwarded. - Returns an error if the session ID is missing, invalid, or if any I/O issues occur while processing the message.
- Returns a
§Errors
SessionIdMissing: if thesessionIdquery parameter is not present.SessionIdInvalid: if the session ID does not map to a valid session in the session store.StreamIoError: if an error occurs while writing to the stream.HttpError: if constructing the HTTP response fails.
Sourcepub async fn handle_streamable_http(
&self,
request: Request<&str>,
state: Arc<McpAppState>,
) -> TransportServerResult<Response<BoxBody<Bytes, TransportServerError>>>
pub async fn handle_streamable_http( &self, request: Request<&str>, state: Arc<McpAppState>, ) -> TransportServerResult<Response<BoxBody<Bytes, TransportServerError>>>
Handles incoming MCP messages over the StreamableHTTP transport.
It supports GET, POST, and DELETE methods for handling streaming operations, and performs optional
DNS rebinding protection if it is configured.
§Arguments
request- The HTTP request from the client, including method, headers, and optional body.state- Shared application state, including configuration and session management.
§Behavior
- If DNS rebinding protection is enabled via the app state, the function checks the request headers.
If dns protection fails, a
403 Forbiddenresponse is returned. - Dispatches the request to method-specific handlers based on the HTTP method:
GET→handle_http_getPOST→handle_http_postDELETE→handle_http_delete
- Returns
405 Method Not Allowedfor unsupported methods.
§Returns
- A
TransportServerResultwrapping an HTTP response indicating success or failure of the operation.
Trait Implementations§
Source§impl Clone for McpHttpHandler
impl Clone for McpHttpHandler
Source§fn clone(&self) -> McpHttpHandler
fn clone(&self) -> McpHttpHandler
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for McpHttpHandler
impl !RefUnwindSafe for McpHttpHandler
impl Send for McpHttpHandler
impl Sync for McpHttpHandler
impl Unpin for McpHttpHandler
impl !UnwindSafe for McpHttpHandler
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
Mutably borrows from an owned value. Read more