rust_mcp_sdk/hyper_servers/
error.rs

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