use std::sync::Arc;
use crate::session_environment::SessionEnvironment;
use config::McpConfig;
pub(crate) mod bearer_client;
mod bundle;
pub(crate) mod catalog;
pub(crate) mod client;
pub(crate) mod config;
pub(crate) mod definition;
pub(crate) mod display;
pub(crate) mod elicitation;
pub(crate) mod elicitation_form;
pub(crate) mod exported_name;
mod host;
mod http_client;
pub(crate) mod inflight;
pub(crate) mod oauth;
mod probe;
mod probe_redaction;
mod probe_stores;
pub(crate) mod progress;
pub(crate) mod prompt_command;
mod reload_tool;
pub(crate) mod report;
pub(crate) mod result;
pub(crate) mod roots;
pub(crate) mod secret_tool;
pub(crate) mod secrets;
pub(crate) mod session;
mod sightings;
mod stdio_watch;
mod tool;
pub(crate) mod validate;
pub(crate) use catalog::{
McpCatalog, McpCatalogError, McpCompletionSupport, McpResource, McpResourceContent,
};
pub(crate) use elicitation::McpElicitationSupport;
pub(crate) use oauth::McpAuthorizationMode;
pub(crate) use report::{
McpLoadMode, McpServerReport, McpServerStatus, McpSessionReport, McpSessionSummary,
McpToolReport, McpTransportSummary,
};
pub(crate) use roots::McpRoots;
pub(crate) use validate::{
parse_remote_url, parse_remote_url_with, validate_environment_header_names, validate_identity,
validate_literal_headers, validate_oauth_client, validate_secret_header_names,
validate_secret_name, validate_stdio_environment, McpHttpSecurity,
};
pub(crate) use bundle::{McpBundle, McpReload, McpReloadChanges};
pub(crate) use host::{McpChanges, McpDiscovery, McpHost, McpReloadError};
pub(crate) use probe::{probe, McpProbeSecrets, McpProbeStoredSecrets, McpProbeTokens};
pub(crate) use reload_tool::McpReloadBundle;
pub(crate) use secret_tool::McpSecretBundle;
pub(crate) use sightings::McpSightings;
#[derive(Clone, Copy, Debug, Default, PartialEq, Eq)]
pub(crate) enum McpSecretAsks {
Available,
#[default]
Unavailable,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
pub(crate) enum McpSessionPlan {
Connect,
Inventory(McpLoadMode),
}
#[derive(Clone)]
pub(crate) struct McpSessionOptions {
pub(crate) max_output_bytes: usize,
pub(crate) roots: McpRoots,
pub(crate) authorization: McpAuthorizationMode,
services: session::McpSessionServices,
environment: SessionEnvironment,
secrets: Arc<dyn rho_providers::credentials::CredentialStore>,
oauth_tokens: Option<Arc<dyn rho_providers::credentials::CredentialStore>>,
sightings: McpSightings,
}
impl std::fmt::Debug for McpSessionOptions {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter
.debug_struct("McpSessionOptions")
.field("max_output_bytes", &self.max_output_bytes)
.field("roots", &self.roots)
.field("authorization", &self.authorization)
.field("services", &self.services)
.field("environment", &self.environment)
.finish_non_exhaustive()
}
}
impl McpSessionOptions {
pub(crate) fn new(
max_output_bytes: usize,
roots: McpRoots,
authorization: McpAuthorizationMode,
environment: SessionEnvironment,
) -> Self {
Self {
max_output_bytes: max_output_bytes.max(1),
roots,
authorization,
services: session::McpSessionServices {
elicitation: McpElicitationSupport::Unavailable,
},
environment,
secrets: Arc::new(crate::credential_store::UntrackedCredentialStore),
oauth_tokens: None,
sightings: McpSightings::process(),
}
}
pub(crate) fn with_secret_store(
mut self,
store: Arc<dyn rho_providers::credentials::CredentialStore>,
) -> Self {
self.secrets = store;
self
}
fn with_oauth_token_store(
mut self,
store: Arc<dyn rho_providers::credentials::CredentialStore>,
) -> Self {
self.oauth_tokens = Some(store);
self
}
fn oauth_tokens(&self) -> Arc<dyn rho_providers::credentials::CredentialStore> {
self.oauth_tokens
.clone()
.unwrap_or_else(|| self.environment.untracked_credentials())
}
pub(crate) fn with_elicitation(mut self, support: McpElicitationSupport) -> Self {
self.services.elicitation = support;
self
}
}
pub(crate) struct McpConnectOutcome {
pub(crate) report: McpSessionReport,
pub(crate) bundle: Option<McpBundle>,
pub(crate) catalog: McpCatalog,
}
impl McpConnectOutcome {
pub(crate) async fn run(
plan: McpSessionPlan,
config: &McpConfig,
options: McpSessionOptions,
) -> Self {
match plan {
McpSessionPlan::Connect => McpBundle::connect(config, options).await,
McpSessionPlan::Inventory(mode) => Self {
report: McpSessionReport::from_config_unloaded(config, mode),
bundle: None,
catalog: McpCatalog::default(),
},
}
}
}
#[cfg(test)]
static MCP_RUNTIME_CONSTRUCTIONS: std::sync::atomic::AtomicUsize =
std::sync::atomic::AtomicUsize::new(0);
#[cfg(test)]
static MCP_CONNECT_TEST_LOCK: tokio::sync::Mutex<()> = tokio::sync::Mutex::const_new(());
#[cfg(test)]
#[path = "mcp_tests.rs"]
mod tests;