use std::time::Duration;
use rmcp::model::Icon;
#[derive(Debug, Clone, PartialEq)]
pub struct Config {
pub port: u16,
pub name: String,
pub version: String,
pub title: Option<String>,
pub description: Option<String>,
pub website_url: Option<String>,
pub icons: Option<Vec<Icon>>,
pub instructions: Option<String>,
pub sse_keep_alive: Option<Duration>,
}
impl Config {
pub fn new(port: u16, name: impl Into<String>, version: impl Into<String>) -> Self {
Self {
port,
name: name.into(),
version: version.into(),
title: None,
description: None,
website_url: None,
icons: None,
instructions: None,
sse_keep_alive: Some(Duration::from_secs(15)),
}
}
pub fn with_title(mut self, title: impl Into<String>) -> Self {
self.title = Some(title.into());
self
}
pub fn with_description(mut self, description: impl Into<String>) -> Self {
self.description = Some(description.into());
self
}
pub fn with_website_url(mut self, website_url: impl Into<String>) -> Self {
self.website_url = Some(website_url.into());
self
}
pub fn with_icons(mut self, icons: impl IntoIterator<Item = Icon>) -> Self {
self.icons = Some(icons.into_iter().collect());
self
}
pub fn with_instructions(mut self, instructions: impl Into<String>) -> Self {
self.instructions = Some(instructions.into());
self
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn identity_is_required_and_the_rest_is_not() {
let config = Config::new(8080, "hello-channel", "0.1.6");
assert_eq!(config.port, 8080);
assert_eq!(config.name, "hello-channel");
assert_eq!(config.version, "0.1.6");
assert_eq!(config.title, None);
assert_eq!(config.description, None);
assert_eq!(config.website_url, None);
assert_eq!(config.icons, None);
assert_eq!(config.instructions, None);
}
#[test]
fn the_optional_reporting_fields_are_settable() {
let config = Config::new(1, "n", "v")
.with_title("Title")
.with_description("What it does")
.with_website_url("https://objectiveai.dev")
.with_instructions("Call greet.");
assert_eq!(config.title.as_deref(), Some("Title"));
assert_eq!(config.description.as_deref(), Some("What it does"));
assert_eq!(config.website_url.as_deref(), Some("https://objectiveai.dev"));
assert_eq!(config.instructions.as_deref(), Some("Call greet."));
}
}