use std::collections::HashSet;
#[derive(Debug, Clone)]
pub struct McpConfig {
pub name: String,
pub version: String,
pub description: Option<String>,
pub tools_enabled: bool,
pub allowed_tags: HashSet<String>,
pub allowed_path_prefixes: Vec<String>,
pub admin_token: Option<String>,
pub expose_detailed_errors: bool,
pub max_tools: usize,
pub invocation_mode: InvocationMode,
pub tool_policy: ToolPolicy,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ToolPolicy {
All,
#[default]
ReadOnly,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum InvocationMode {
#[default]
Proxy,
InProcess,
Auto,
}
impl Default for McpConfig {
fn default() -> Self {
Self {
name: "rustapi-mcp".to_string(),
version: "0.0.0".to_string(),
description: None,
tools_enabled: true,
allowed_tags: HashSet::new(),
allowed_path_prefixes: vec![],
admin_token: None,
expose_detailed_errors: false,
max_tools: 256,
invocation_mode: InvocationMode::Proxy,
tool_policy: ToolPolicy::ReadOnly, }
}
}
impl McpConfig {
pub fn new() -> Self {
Self::default()
}
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = name.into();
self
}
pub fn version(mut self, version: impl Into<String>) -> Self {
self.version = version.into();
self
}
pub fn description(mut self, desc: impl Into<String>) -> Self {
self.description = Some(desc.into());
self
}
pub fn enable_tools(mut self, enabled: bool) -> Self {
self.tools_enabled = enabled;
self
}
pub fn allowed_tags<I, S>(mut self, tags: I) -> Self
where
I: IntoIterator<Item = S>,
S: Into<String>,
{
self.allowed_tags = tags.into_iter().map(Into::into).collect();
self
}
pub fn allow_path_prefix(mut self, prefix: impl Into<String>) -> Self {
self.allowed_path_prefixes.push(prefix.into());
self
}
pub fn admin_token(mut self, token: impl Into<String>) -> Self {
self.admin_token = Some(token.into());
self
}
pub fn expose_detailed_errors(mut self, expose: bool) -> Self {
self.expose_detailed_errors = expose;
self
}
pub fn max_tools(mut self, max: usize) -> Self {
self.max_tools = max;
self
}
pub fn invocation_mode(mut self, mode: InvocationMode) -> Self {
self.invocation_mode = mode;
self
}
pub fn tool_policy(mut self, policy: ToolPolicy) -> Self {
self.tool_policy = policy;
self
}
}