feat(app): features screen with tool switches and MCP servers; v2 drops host file and screen tools

- Settings `features` (weather, webSearch, meals) and `mcpServers` (name, command, args, env names,
  enabled), edited on the new 기능 screen. The tools of a feature that is off go into the brain's
  `disabled_tools`; only enabled MCP servers go into its `mcps`.
- MCP environment values (API keys) live only in the encrypted secrets (`mcp:<server>:<NAME>`),
  shown as stored or not, masked in logs, removed with their server, and reach the worker only in
  `JARVIS_MCP_ENV`, which the brain takes out of its environment before giving each server its own.
- `enabled_builtin_tools(cfg)` is the one list the router, toolSearchTool and the executor use, so
  a turned-off tool is neither offered nor run, also when the model names it.
- The v2 brain never offers v1's `localFiles` (home folder read/write/delete) and `screenshot`:
  anyone in the voice or chat channels could ask for them. Screen viewing comes in M7.
- The brain connects MCP servers on its own thread and logs each outcome without debug logging.
- Stored secrets are masked in the log hub as soon as the data folder is found.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
javis-bot
2026-11-13 09:56:17 +09:00
parent d4bd4acfe9
commit 3ef4281180
23 changed files with 717 additions and 39 deletions

View File

@@ -85,6 +85,25 @@ pub struct LlmSettings {
pub context: u32,
}
/// The brain's built-in features (admin.spec.md, "Features and MCP servers"); each is on by default.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct FeatureSettings {
pub weather: bool,
pub web_search: bool,
pub meals: bool,
}
/// An MCP server the brain starts (stdio). The values of `env` are in the secrets, never here.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct McpServerSettings {
pub name: String,
pub command: String,
pub args: Vec<String>,
/// Names of the environment variables it gets (their values are secrets).
pub env: Vec<String>,
pub enabled: bool,
}
#[derive(Debug, Clone, PartialEq)]
pub struct Settings {
pub discord: DiscordSettings,
@@ -100,6 +119,8 @@ pub struct Settings {
/// `hello`; the worker validates them, the settings screens check them first (admin.spec.md).
pub memory: Map<String, Value>,
pub llm: LlmSettings,
pub features: FeatureSettings,
pub mcp_servers: Vec<McpServerSettings>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
@@ -143,6 +164,8 @@ impl Default for Settings {
response: PolicySettings::default(),
memory: Map::new(),
llm: LlmSettings { url: None, port: 8080, context: 32768 },
features: FeatureSettings { weather: true, web_search: true, meals: true },
mcp_servers: vec![],
}
}
}
@@ -454,9 +477,70 @@ pub fn parse_settings(raw: &Value) -> Result<Settings, SettingsError> {
Some(_) => return err("memory must be an object"),
},
llm: parse_llm(raw, &d.llm)?,
features: {
let f = section(raw, "features")?;
FeatureSettings {
weather: get_bool(f, "weather", "features", d.features.weather)?,
web_search: get_bool(f, "webSearch", "features", d.features.web_search)?,
meals: get_bool(f, "meals", "features", d.features.meals)?,
}
},
mcp_servers: parse_mcp_servers(raw)?,
})
}
/// An MCP server name: 1-32 letters, digits, `-` or `_`, without `__` (the brain names a server's
/// tools `<server>__<tool>`).
fn valid_mcp_name(s: &str) -> bool {
(1..=32).contains(&s.len()) && s.bytes().all(|b| b.is_ascii_alphanumeric() || b == b'-' || b == b'_') && !s.contains("__")
}
/// An environment variable name: a letter or `_`, then letters, digits or `_`.
fn valid_env_name(s: &str) -> bool {
let mut b = s.bytes();
b.next().is_some_and(|c| c.is_ascii_alphabetic() || c == b'_') && b.all(|c| c.is_ascii_alphanumeric() || c == b'_')
&& s.len() <= 64
}
fn parse_mcp_servers(raw: &Map<String, Value>) -> Result<Vec<McpServerSettings>, SettingsError> {
let list = match raw.get("mcpServers") {
None => return Ok(vec![]),
Some(Value::Array(a)) => a,
Some(_) => return err("mcpServers must be a list"),
};
let mut out: Vec<McpServerSettings> = Vec::new();
for (i, v) in list.iter().enumerate() {
let path = format!("mcpServers[{i}]");
let Value::Object(m) = v else { return err(format!("{path} must be an object")) };
let name = get_str(Some(m), "name", &path, "")?.trim().to_owned();
if !valid_mcp_name(&name) {
return err(format!("{path}.name must be 1-32 letters, digits, - or _ (no __)"));
}
if out.iter().any(|s| s.name == name) {
return err(format!("{path}.name is listed twice"));
}
let command = get_str(Some(m), "command", &path, "")?.trim().to_owned();
if command.is_empty() {
return err(format!("{path}.command must not be empty"));
}
let env = clean_words(get_str_list(Some(m), "env", &path, &[])?);
if let Some(bad) = env.iter().find(|n| !valid_env_name(n)) {
return err(format!("{path}.env has a name that is not an environment variable: {bad}"));
}
if env.iter().enumerate().any(|(j, n)| env[..j].contains(n)) {
return err(format!("{path}.env lists a name twice"));
}
out.push(McpServerSettings {
name,
command,
args: get_str_list(Some(m), "args", &path, &[])?,
env,
enabled: get_bool(Some(m), "enabled", &path, true)?,
});
}
Ok(out)
}
fn parse_llm(raw: &Map<String, Value>, d: &LlmSettings) -> Result<LlmSettings, SettingsError> {
let l = section(raw, "llm")?;
let url = match l.and_then(|m| m.get("url")) {
@@ -631,6 +715,38 @@ mod tests {
}
}
#[test]
fn features_and_mcp_servers_are_read_and_checked() {
let s = parse_settings(&json!({}));
assert_eq!(s.unwrap().features, FeatureSettings { weather: true, web_search: true, meals: true });
let s = parse_settings(&json!({
"features": {"weather": false, "meals": false},
"mcpServers": [{"name": "brave", "command": "npx", "args": ["-y", "brave"], "env": ["BRAVE_API_KEY", " "]},
{"name": "time-2", "command": "uvx", "enabled": false}]
})).unwrap();
assert_eq!(s.features, FeatureSettings { weather: false, web_search: true, meals: false });
assert_eq!(s.mcp_servers, vec![
McpServerSettings { name: "brave".into(), command: "npx".into(), args: vec!["-y".into(), "brave".into()],
env: vec!["BRAVE_API_KEY".into()], enabled: true },
McpServerSettings { name: "time-2".into(), command: "uvx".into(), args: vec![], env: vec![], enabled: false },
]);
let cases = [
(json!({"features": {"weather": "no"}}), "features.weather"),
(json!({"mcpServers": {}}), "mcpServers"),
(json!({"mcpServers": [{"name": "a__b", "command": "x"}]}), "mcpServers[0].name"),
(json!({"mcpServers": [{"name": "", "command": "x"}]}), "mcpServers[0].name"),
(json!({"mcpServers": [{"name": "a b", "command": "x"}]}), "mcpServers[0].name"),
(json!({"mcpServers": [{"name": "a", "command": "x"}, {"name": "a", "command": "y"}]}), "mcpServers[1].name"),
(json!({"mcpServers": [{"name": "a", "command": " "}]}), "mcpServers[0].command"),
(json!({"mcpServers": [{"name": "a", "command": "x", "env": ["1KEY"]}]}), "mcpServers[0].env"),
(json!({"mcpServers": [{"name": "a", "command": "x", "env": ["K", "K"]}]}), "mcpServers[0].env"),
];
for (raw, key) in cases {
let e = parse_settings(&raw).unwrap_err();
assert!(e.0.contains(key), "{raw} -> {e}");
}
}
#[test]
fn null_ids_clear_them() {
let s = parse_settings(&json!({"discord": {"guildId": null, "voiceChannelId": null}})).unwrap();