mod driver;
mod handler;
mod multiplexer;
mod transport;
#[cfg(test)]
mod tests;
use std::time::Duration;
use serde_json::Value;
pub use driver::{McpClientDriver, create_mcp_client_driver};
pub(super) const DEFAULT_REQUEST_TIMEOUT: Duration = Duration::from_secs(30);
pub(super) const DEFAULT_PHASE_TIMEOUT: Duration = Duration::from_secs(60);
pub(super) const POST_ACTION_IDLE_TIMEOUT: Duration = Duration::from_millis(250);
pub(super) const INIT_TIMEOUT: Duration = Duration::from_secs(30);
pub(super) const SERVER_REQUEST_BUFFER_SIZE: usize = 64;
pub(super) const SERVER_REQUEST_BUFFER_WARNING: usize = SERVER_REQUEST_BUFFER_SIZE / 4;
pub(super) const HTTP_MESSAGE_BUFFER_SIZE: usize = 256;
pub(super) const NOTIFICATION_BUFFER_SIZE: usize = 128;
pub(super) const HANDLER_EVENT_BUFFER_SIZE: usize = 128;
#[derive(Debug)]
pub(super) enum McpClientMessage {
Response {
id: Value,
method: String,
result: Value,
is_error: bool,
request_params: Option<Value>,
},
Notification {
method: String,
params: Option<Value>,
},
ServerRequest {
id: Value,
method: String,
params: Option<Value>,
},
}
#[derive(Debug)]
pub(super) struct PendingRequest {
pub(super) method: String,
pub(super) params: Option<Value>,
}
#[derive(Debug)]
pub(super) struct CorrelatedResponse {
pub(super) method: String,
pub(super) result: Value,
pub(super) is_error: bool,
pub(super) request_params: Option<Value>,
}
#[derive(Debug)]
pub(super) struct NotificationMessage {
pub(super) method: String,
pub(super) params: Option<Value>,
}
#[derive(Debug)]
pub(super) struct ServerRequestMessage {
pub(super) id: Value,
pub(super) method: String,
pub(super) params: Option<Value>,
}
#[derive(Debug, Clone)]
pub(super) enum MultiplexerClosed {
TransportEof,
TransportError(String),
Cancelled,
}
impl std::fmt::Display for MultiplexerClosed {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
match self {
Self::TransportEof => write!(f, "transport EOF"),
Self::TransportError(e) => write!(f, "transport error: {e}"),
Self::Cancelled => write!(f, "cancelled"),
}
}
}
#[derive(Debug)]
pub(super) struct HandlerState {
pub(super) state: Value,
}