use std::collections::HashMap;
use crate::error::Error;
use super::{Server, ServerOptions, ServerCapabilities, ServerService};
pub struct ServerBuilder {
options: ServerOptions,
}
impl Default for ServerBuilder {
fn default() -> Self {
Self {
options: ServerOptions::default(),
}
}
}
impl ServerBuilder {
pub fn new() -> Self {
Self::default()
}
pub fn with_implementation(mut self, name: impl Into<String>, version: impl Into<String>) -> Self {
self.options.implementation.name = name.into();
self.options.implementation.version = version.into();
self
}
pub fn with_instructions(mut self, instructions: impl Into<String>) -> Self {
self.options.instructions = Some(instructions.into());
self
}
pub fn with_auto_acknowledge_ping(mut self, enable: bool) -> Self {
self.options.auto_acknowledge_ping = enable;
self
}
pub fn with_default_timeout(mut self, timeout_ms: u64) -> Self {
self.options.default_timeout_ms = timeout_ms;
self
}
pub fn with_logging(mut self, enable: bool) -> Self {
self.options.capabilities.logging = enable;
self
}
pub fn with_completions(mut self, enable: bool) -> Self {
self.options.capabilities.completions = enable;
self
}
pub fn with_prompts(mut self, enable: bool) -> Self {
self.options.capabilities.prompts = enable;
self
}
pub fn with_prompts_list_changed(mut self, enable: bool) -> Self {
self.options.capabilities.prompts_list_changed = enable;
self
}
pub fn with_resources(mut self, enable: bool) -> Self {
self.options.capabilities.resources = enable;
self
}
pub fn with_resources_list_changed(mut self, enable: bool) -> Self {
self.options.capabilities.resources_list_changed = enable;
self
}
pub fn with_resources_subscribe(mut self, enable: bool) -> Self {
self.options.capabilities.resources_subscribe = enable;
self
}
pub fn with_tools(mut self, enable: bool) -> Self {
self.options.capabilities.tools = enable;
self
}
pub fn with_tools_list_changed(mut self, enable: bool) -> Self {
self.options.capabilities.tools_list_changed = enable;
self
}
pub fn with_experimental(mut self, name: impl Into<String>, value: serde_json::Value) -> Self {
self.options.capabilities.experimental.insert(name.into(), value);
self
}
pub fn build(
self,
service: Box<dyn ServerService + Send + Sync>,
) -> Result<(Server, tokio::sync::mpsc::Receiver<super::ServerEvent>), Error> {
Ok(Server::new(self.options, service))
}
}