pub struct HttpRequestHandler { /* private fields */ }Expand description
Handles HTTP requests containing MCP JSON-RPC messages.
This handler is designed to be integrated with any HTTP server framework. It processes incoming HTTP requests, extracts JSON-RPC messages, and returns appropriate HTTP responses.
Implementations§
Source§impl HttpRequestHandler
impl HttpRequestHandler
Sourcepub fn new() -> HttpRequestHandler
pub fn new() -> HttpRequestHandler
Creates a new HTTP request handler with default configuration.
Sourcepub fn with_config(config: HttpHandlerConfig) -> HttpRequestHandler
pub fn with_config(config: HttpHandlerConfig) -> HttpRequestHandler
Creates a new HTTP request handler with the given configuration.
Sourcepub fn config(&self) -> &HttpHandlerConfig
pub fn config(&self) -> &HttpHandlerConfig
Returns the handler configuration.
Sourcepub fn handle_options(&self, request: &HttpRequest) -> HttpResponse
pub fn handle_options(&self, request: &HttpRequest) -> HttpResponse
Handles a CORS preflight OPTIONS request.
Sourcepub fn is_origin_allowed(&self, origin: &str) -> bool
pub fn is_origin_allowed(&self, origin: &str) -> bool
Checks if the origin is allowed for CORS.
Sourcepub fn parse_request(
&self,
request: &HttpRequest,
) -> Result<JsonRpcRequest, HttpError>
pub fn parse_request( &self, request: &HttpRequest, ) -> Result<JsonRpcRequest, HttpError>
Parses a JSON-RPC request from an HTTP request.
Sourcepub fn create_response(
&self,
response: &JsonRpcResponse,
origin: Option<&str>,
) -> HttpResponse
pub fn create_response( &self, response: &JsonRpcResponse, origin: Option<&str>, ) -> HttpResponse
Creates an HTTP response from a JSON-RPC response.
Sourcepub fn error_response(&self, status: HttpStatus, message: &str) -> HttpResponse
pub fn error_response(&self, status: HttpStatus, message: &str) -> HttpResponse
Creates an error HTTP response.
Trait Implementations§
Source§impl Default for HttpRequestHandler
impl Default for HttpRequestHandler
Source§fn default() -> HttpRequestHandler
fn default() -> HttpRequestHandler
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for HttpRequestHandler
impl RefUnwindSafe for HttpRequestHandler
impl Send for HttpRequestHandler
impl Sync for HttpRequestHandler
impl Unpin for HttpRequestHandler
impl UnwindSafe for HttpRequestHandler
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
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, _span: NoopSpan) -> Self
fn instrument(self, _span: NoopSpan) -> Self
Instruments this future with a span (no-op when disabled).
Source§fn in_current_span(self) -> Self
fn in_current_span(self) -> Self
Instruments this future with the current span (no-op when disabled).