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("Server start error: {0}")]
19    ServerStartError(String),
20    #[error("Invalid options: {0}")]
21    InvalidServerOptions(String),
22    #[error("{0}")]
23    SslCertError(String),
24}
25
26impl IntoResponse for TransportServerError {
27    //consume self and returns a Response
28    fn into_response(self) -> axum::response::Response {
29        let mut response = StatusCode::INTERNAL_SERVER_ERROR.into_response();
30        response.extensions_mut().insert(self);
31        response
32    }
33}