rust_mcp_sdk/hyper_servers/
error.rs

1use std::net::AddrParseError;
2
3use axum::{http::StatusCode, response::IntoResponse};
4use thiserror::Error;
5
6pub type TransportServerResult<T> = core::result::Result<T, TransportServerError>;
7
8#[derive(Debug, Error, Clone)]
9pub enum TransportServerError {
10    #[error("'sessionId' query string is missing!")]
11    SessionIdMissing,
12    #[error("No session found for the given ID: {0}.")]
13    SessionIdInvalid(String),
14    #[error("Stream IO Error: {0}.")]
15    StreamIoError(String),
16    #[error("{0}")]
17    AddrParseError(#[from] AddrParseError),
18    #[error("{0}")]
19    HttpError(String),
20    #[error("Server start error: {0}")]
21    ServerStartError(String),
22    #[error("Invalid options: {0}")]
23    InvalidServerOptions(String),
24    #[error("{0}")]
25    SslCertError(String),
26    #[error("{0}")]
27    TransportError(String),
28}
29
30impl IntoResponse for TransportServerError {
31    //consume self and returns a Response
32    fn into_response(self) -> axum::response::Response {
33        let mut response = StatusCode::INTERNAL_SERVER_ERROR.into_response();
34        response.extensions_mut().insert(self);
35        response
36    }
37}