mcp_common/
config.rs

1//! MCP 服务配置
2
3use std::collections::HashMap;
4use crate::ToolFilter;
5
6/// MCP 服务配置
7#[derive(Clone, Debug, serde::Serialize, serde::Deserialize)]
8pub struct McpServiceConfig {
9    /// 服务名称
10    pub name: String,
11    /// 启动命令
12    pub command: String,
13    /// 命令参数
14    pub args: Option<Vec<String>>,
15    /// 环境变量
16    pub env: Option<HashMap<String, String>>,
17    /// 工具过滤配置
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub tool_filter: Option<ToolFilter>,
20}
21
22impl McpServiceConfig {
23    /// 创建新配置
24    pub fn new(name: String, command: String) -> Self {
25        Self {
26            name,
27            command,
28            args: None,
29            env: None,
30            tool_filter: None,
31        }
32    }
33
34    /// 设置参数
35    pub fn with_args(mut self, args: Vec<String>) -> Self {
36        self.args = Some(args);
37        self
38    }
39
40    /// 设置环境变量
41    pub fn with_env(mut self, env: HashMap<String, String>) -> Self {
42        self.env = Some(env);
43        self
44    }
45
46    /// 设置工具过滤器
47    pub fn with_tool_filter(mut self, filter: ToolFilter) -> Self {
48        self.tool_filter = Some(filter);
49        self
50    }
51}