feat: added a .edit command for editing the MCP configuration file

This commit is contained in:
2026-05-18 15:14:22 -06:00
parent a3d67bfbf7
commit 696ce03ee4
2 changed files with 26 additions and 4 deletions
+12
View File
@@ -1344,6 +1344,18 @@ impl RequestContext {
Ok(()) Ok(())
} }
pub fn edit_mcp_config(&self) -> Result<()> {
let mcp_path = paths::mcp_config_file();
let editor = self.app.config.editor()?;
edit_file(&editor, &mcp_path)?;
println!(
"NOTE: Remember to restart {} for changes to '{}' to take effect",
env!("CARGO_CRATE_NAME"),
mcp_path.display(),
);
Ok(())
}
pub fn new_role(&self, app: &AppConfig, name: &str) -> Result<()> { pub fn new_role(&self, app: &AppConfig, name: &str) -> Result<()> {
if self.macro_flag { if self.macro_flag {
bail!("No role"); bail!("No role");
+14 -4
View File
@@ -45,7 +45,7 @@ pub const DEFAULT_CONTINUATION_PROMPT: &str = indoc! {"
4. Continue with the next pending item now. Call tools immediately." 4. Continue with the next pending item now. Call tools immediately."
}; };
static REPL_COMMANDS: LazyLock<[ReplCommand; 40]> = LazyLock::new(|| { static REPL_COMMANDS: LazyLock<[ReplCommand; 41]> = LazyLock::new(|| {
[ [
ReplCommand::new(".help", "Show this help guide", AssertState::pass()), ReplCommand::new(".help", "Show this help guide", AssertState::pass()),
ReplCommand::new(".info", "Show system info", AssertState::pass()), ReplCommand::new(".info", "Show system info", AssertState::pass()),
@@ -59,6 +59,11 @@ static REPL_COMMANDS: LazyLock<[ReplCommand; 40]> = LazyLock::new(|| {
"Modify configuration file", "Modify configuration file",
AssertState::False(StateFlags::AGENT), AssertState::False(StateFlags::AGENT),
), ),
ReplCommand::new(
".edit mcp-config",
"Modify the MCP servers configuration file",
AssertState::False(StateFlags::AGENT),
),
ReplCommand::new(".model", "Switch LLM model", AssertState::pass()), ReplCommand::new(".model", "Switch LLM model", AssertState::pass()),
ReplCommand::new( ReplCommand::new(
".prompt", ".prompt",
@@ -627,8 +632,13 @@ pub async fn run_repl_command(
let app = Arc::clone(&ctx.app.config); let app = Arc::clone(&ctx.app.config);
ctx.edit_agent_config(app.as_ref())?; ctx.edit_agent_config(app.as_ref())?;
} }
Some("mcp-config") => {
ctx.edit_mcp_config()?;
}
_ => { _ => {
println!(r#"Usage: .edit <config|role|session|rag-docs|agent-config>"#) println!(
r#"Usage: .edit <config|mcp-config|role|session|rag-docs|agent-config>"#
)
} }
} }
} }
@@ -1231,8 +1241,8 @@ mod tests {
} }
#[test] #[test]
fn repl_commands_has_40_entries() { fn repl_commands_has_41_entries() {
assert_eq!(REPL_COMMANDS.len(), 40); assert_eq!(REPL_COMMANDS.len(), 41);
} }
#[test] #[test]