Skip to main content

soma_mcp_client/upstream/pool/
discovery.rs

1use crate::upstream::{CapScope, UpstreamError, UpstreamSnapshot};
2
3use super::UpstreamPool;
4
5impl UpstreamPool {
6    pub async fn discover(&self) -> Result<Vec<UpstreamSnapshot>, UpstreamError> {
7        self.refresh_all().await;
8        let snapshots = self.snapshots();
9        let bytes = serde_json::to_vec(&snapshots).map_or(usize::MAX, |bytes| bytes.len());
10        self.response_caps().enforce(CapScope::ToolsList, bytes)?;
11        Ok(snapshots)
12    }
13
14    pub async fn discover_upstream(
15        &self,
16        upstream: &str,
17    ) -> Result<UpstreamSnapshot, UpstreamError> {
18        if let Err(error) = self.ensure_connected(upstream).await {
19            self.record_discovery_error(upstream, error)?;
20        }
21        self.with_entry(upstream, |entry| Ok(entry.snapshot.clone()))
22    }
23
24    #[must_use]
25    pub fn subject_scoped_discovery_limit(&self) -> usize {
26        self.discovery_concurrency()
27    }
28}
29
30#[cfg(test)]
31#[path = "discovery_tests.rs"]
32mod tests;