pub struct CratesDocsServer { /* private fields */ }Expand description
Crates Docs MCP 服务器
主服务器结构体,管理配置、工具注册表和缓存。 支持多种传输协议:stdio、HTTP、SSE、Hybrid。
§字段
config: 应用配置tool_registry: 工具注册表cache: 缓存实例
Implementations§
Source§impl CratesDocsServer
impl CratesDocsServer
Sourcepub async fn new_async(config: AppConfig) -> Result<Self>
pub async fn new_async(config: AppConfig) -> Result<Self>
创建新的服务器实例(异步)
§参数
config- 应用配置
§错误
如果缓存创建失败,返回错误
§注意
支持内存缓存和 Redis 缓存(需要启用 cache-redis feature)。
§示例
use crates_docs::{AppConfig, CratesDocsServer};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let config = AppConfig::default();
let server = CratesDocsServer::new_async(config).await?;
Ok(())
}Sourcepub fn tool_registry(&self) -> &Arc<ToolRegistry>
pub fn tool_registry(&self) -> &Arc<ToolRegistry>
获取工具注册表
Sourcepub fn server_info(&self) -> InitializeResult
pub fn server_info(&self) -> InitializeResult
获取服务器信息
返回 MCP 初始化结果,包含服务器元数据和能力信息
Trait Implementations§
Source§impl Clone for CratesDocsServer
impl Clone for CratesDocsServer
Source§fn clone(&self) -> CratesDocsServer
fn clone(&self) -> CratesDocsServer
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for CratesDocsServer
impl !RefUnwindSafe for CratesDocsServer
impl Send for CratesDocsServer
impl Sync for CratesDocsServer
impl Unpin for CratesDocsServer
impl UnsafeUnpin for CratesDocsServer
impl !UnwindSafe for CratesDocsServer
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more