Skip to content

Commit b7033ed

Browse files
authored
fix: Add support for passing "args" to MCP configuration when using q mcp add (#262)
* add args * remove json * CI * support more --agrs * revert tip * Remove mcp.json file
1 parent 24b8104 commit b7033ed

File tree

3 files changed

+47
-20
lines changed

3 files changed

+47
-20
lines changed

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 29 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -417,25 +417,35 @@ const SMALL_SCREEN_WELCOME_TEXT: &str = color_print::cstr! {"<em>Welcome to <cya
417417
const RESUME_TEXT: &str = color_print::cstr! {"<em>Picking up where we left off...</em>"};
418418

419419
// Only show the model-related tip for now to make users aware of this feature.
420-
const ROTATING_TIPS: [&str; 3] = [
421-
// color_print::cstr! {"You can resume the last conversation from your current directory by launching with
422-
// <green!>q chat --resume</green!>"}, color_print::cstr! {"Get notified whenever Q CLI finishes responding.
423-
// Just run <green!>q settings chat.enableNotifications true</green!>"}, color_print::cstr! {"You can use
424-
// <green!>/editor</green!> to edit your prompt with a vim-like experience"}, color_print::cstr!
425-
// {"<green!>/usage</green!> shows you a visual breakdown of your current context window usage"},
426-
// color_print::cstr! {"Get notified whenever Q CLI finishes responding. Just run <green!>q settings
427-
// chat.enableNotifications true</green!>"}, color_print::cstr! {"You can execute bash commands by typing
428-
// <green!>!</green!> followed by the command"}, color_print::cstr! {"Q can use tools without asking for
429-
// confirmation every time. Give <green!>/tools trust</green!> a try"}, color_print::cstr! {"You can
430-
// programmatically inject context to your prompts by using hooks. Check out <green!>/context hooks
431-
// help</green!>"}, color_print::cstr! {"You can use <green!>/compact</green!> to replace the conversation
432-
// history with its summary to free up the context space"}, color_print::cstr! {"If you want to file an issue
433-
// to the Q CLI team, just tell me, or run <green!>q issue</green!>"}, color_print::cstr! {"You can enable
434-
// custom tools with <green!>MCP servers</green!>. Learn more with /help"}, color_print::cstr! {"You can
435-
// specify wait time (in ms) for mcp server loading with <green!>q settings mcp.initTimeout {timeout in
436-
// int}</green!>. Servers that takes longer than the specified time will continue to load in the background. Use
437-
// /tools to see pending servers."}, color_print::cstr! {"You can see the server load status as well as any
438-
// warnings or errors associated with <green!>/mcp</green!>"},
420+
const ROTATING_TIPS: [&str; 16] = [
421+
color_print::cstr! {"You can resume the last conversation from your current directory by launching with
422+
<green!>q chat --resume</green!>"},
423+
color_print::cstr! {"Get notified whenever Q CLI finishes responding.
424+
Just run <green!>q settings chat.enableNotifications true</green!>"},
425+
color_print::cstr! {"You can use
426+
<green!>/editor</green!> to edit your prompt with a vim-like experience"},
427+
color_print::cstr! {"<green!>/usage</green!> shows you a visual breakdown of your current context window usage"},
428+
color_print::cstr! {"Get notified whenever Q CLI finishes responding. Just run <green!>q settings
429+
chat.enableNotifications true</green!>"},
430+
color_print::cstr! {"You can execute bash commands by typing
431+
<green!>!</green!> followed by the command"},
432+
color_print::cstr! {"Q can use tools without asking for
433+
confirmation every time. Give <green!>/tools trust</green!> a try"},
434+
color_print::cstr! {"You can
435+
programmatically inject context to your prompts by using hooks. Check out <green!>/context hooks
436+
help</green!>"},
437+
color_print::cstr! {"You can use <green!>/compact</green!> to replace the conversation
438+
history with its summary to free up the context space"},
439+
color_print::cstr! {"If you want to file an issue
440+
to the Q CLI team, just tell me, or run <green!>q issue</green!>"},
441+
color_print::cstr! {"You can enable
442+
custom tools with <green!>MCP servers</green!>. Learn more with /help"},
443+
color_print::cstr! {"You can
444+
specify wait time (in ms) for mcp server loading with <green!>q settings mcp.initTimeout {timeout in
445+
int}</green!>. Servers that takes longer than the specified time will continue to load in the background. Use
446+
/tools to see pending servers."},
447+
color_print::cstr! {"You can see the server load status as well as any
448+
warnings or errors associated with <green!>/mcp</green!>"},
439449
color_print::cstr! {"Use <green!>/model</green!> to select the model to use for this conversation"},
440450
color_print::cstr! {"Set a default model by running <green!>q settings chat.defaultModel MODEL</green!>. Run <green!>/model</green!> to learn more."},
441451
color_print::cstr! {"Run <green!>/prompts</green!> to learn how to build & run repeatable workflows"},

crates/chat-cli/src/cli/mcp.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ use std::path::PathBuf;
44
use std::process::ExitCode;
55

66
use clap::{
7+
ArgAction,
78
Args,
89
ValueEnum,
910
};
@@ -85,6 +86,9 @@ pub struct AddArgs {
8586
/// The command used to launch the server
8687
#[arg(long)]
8788
pub command: String,
89+
/// Arguments to pass to the command
90+
#[arg(long, action = ArgAction::Append, allow_hyphen_values = true, value_delimiter = ',')]
91+
pub args: Vec<String>,
8892
/// Where to add the server to.
8993
#[arg(long, value_enum)]
9094
pub scope: Option<Scope>,
@@ -121,6 +125,7 @@ impl AddArgs {
121125
let merged_env = self.env.into_iter().flatten().collect::<HashMap<_, _>>();
122126
let tool: CustomToolConfig = serde_json::from_value(serde_json::json!({
123127
"command": self.command,
128+
"args": self.args,
124129
"env": merged_env,
125130
"timeout": self.timeout.unwrap_or(default_timeout()),
126131
"disabled": self.disabled,
@@ -454,6 +459,11 @@ mod tests {
454459
AddArgs {
455460
name: "local".into(),
456461
command: "echo hi".into(),
462+
args: vec![
463+
"awslabs.eks-mcp-server".to_string(),
464+
"--allow-write".to_string(),
465+
"--allow-sensitive-data-access".to_string(),
466+
],
457467
env: vec![],
458468
timeout: None,
459469
scope: None,
@@ -492,12 +502,19 @@ mod tests {
492502
"test_server",
493503
"--command",
494504
"test_command",
505+
"--args",
506+
"awslabs.eks-mcp-server,--allow-write,--allow-sensitive-data-access",
495507
"--env",
496508
"key1=value1,key2=value2"
497509
],
498510
RootSubcommand::Mcp(McpSubcommand::Add(AddArgs {
499511
name: "test_server".to_string(),
500512
command: "test_command".to_string(),
513+
args: vec![
514+
"awslabs.eks-mcp-server".to_string(),
515+
"--allow-write".to_string(),
516+
"--allow-sensitive-data-access".to_string(),
517+
],
501518
scope: None,
502519
env: vec![
503520
[

crates/q_cli/src/cli/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ impl Cli {
369369
},
370370
CliRootCommands::Mcp { args } => {
371371
if args.iter().any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
372-
return Self::execute_chat("mcp", Some(vec!["--help".to_owned()]), false).await;
372+
return Self::execute_chat("mcp", Some(args), false).await;
373373
}
374374

375375
Self::execute_chat("mcp", Some(args), true).await

0 commit comments

Comments
 (0)