Skip to main content

crates_docs/tools/docs/
mod.rs

1//! Document query tools module
2
3pub mod cache;
4pub mod html;
5pub mod lookup_crate;
6pub mod lookup_item;
7pub mod search;
8
9use crate::cache::Cache;
10use std::sync::Arc;
11
12/// Document service
13pub struct DocService {
14    client: reqwest::Client,
15    cache: Arc<dyn Cache>,
16    doc_cache: cache::DocCache,
17}
18
19impl DocService {
20    /// Create a new document service
21    pub fn new(cache: Arc<dyn Cache>) -> Self {
22        let doc_cache = cache::DocCache::new(cache.clone());
23        Self {
24            client: reqwest::Client::builder()
25                .user_agent(format!("CratesDocsMCP/{}", crate::VERSION))
26                .timeout(std::time::Duration::from_secs(30))
27                .build()
28                .expect("Failed to create HTTP client"),
29            cache,
30            doc_cache,
31        }
32    }
33
34    /// Get HTTP client
35    #[must_use]
36    pub fn client(&self) -> &reqwest::Client {
37        &self.client
38    }
39
40    /// Get cache
41    #[must_use]
42    pub fn cache(&self) -> &Arc<dyn Cache> {
43        &self.cache
44    }
45
46    /// Get document cache
47    #[must_use]
48    pub fn doc_cache(&self) -> &cache::DocCache {
49        &self.doc_cache
50    }
51}
52
53impl Default for DocService {
54    fn default() -> Self {
55        let cache = Arc::new(crate::cache::memory::MemoryCache::new(1000));
56        Self::new(cache)
57    }
58}
59
60/// Re-export tools
61pub use lookup_crate::LookupCrateTool;
62pub use lookup_item::LookupItemTool;
63pub use search::SearchCratesTool;