Skip to content

Commit f083fcc

Browse files
evanliu048brandonskiser
authored andcommitted
feat(cli): support q mcp --help passthrough to qchat mcp (#1837)
* WIP * add mcp list command * add import&status&remove * fmt * add force flag in add & import * update fetch config * use sharedWritter && add ut * add mcp ut * merge refactor changes, keep all in chat_cli * revise CI * pass mcp in q_cli * parse help * ci * use any * fmt --------- Co-authored-by: Brandon Kiser <[email protected]>
1 parent 6dcb273 commit f083fcc

File tree

2 files changed

+36
-18
lines changed

2 files changed

+36
-18
lines changed

crates/q_cli/src/cli/mod.rs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ use fig_util::{
6565
system_info,
6666
};
6767
use internal::InternalSubcommand;
68+
use macos_utils::bundle::get_bundle_path_for_executable;
6869
use serde::Serialize;
6970
use tokio::signal::ctrl_c;
7071
use tracing::{
@@ -195,14 +196,16 @@ pub enum CliRootCommands {
195196
/// Open the dashboard
196197
Dashboard,
197198
/// AI assistant in your terminal
199+
#[command(disable_help_flag = true)]
198200
Chat {
199-
/// Args for the chat command
201+
/// Args for the chat subcommand
200202
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
201203
args: Vec<String>,
202204
},
203205
/// Model Context Protocol (MCP)
206+
#[command(disable_help_flag = true)]
204207
Mcp {
205-
/// Args for the MCP subcommand (passed through to `qchat mcp …`)
208+
/// Args for the MCP subcommand
206209
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
207210
args: Vec<String>,
208211
},
@@ -351,8 +354,20 @@ impl Cli {
351354
CliRootCommands::Telemetry(subcommand) => subcommand.execute().await,
352355
CliRootCommands::Version { changelog } => Self::print_version(changelog),
353356
CliRootCommands::Dashboard => launch_dashboard(false).await,
354-
CliRootCommands::Chat { args } => Self::execute_chat("chat", Some(args), true).await,
355-
CliRootCommands::Mcp { args } => Self::execute_chat("mcp", Some(args), true).await,
357+
CliRootCommands::Chat { args } => {
358+
if args.iter().any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
359+
return Self::execute_chat("chat", Some(vec!["--help".to_owned()]), false).await;
360+
}
361+
362+
Self::execute_chat("chat", Some(args), true).await
363+
},
364+
CliRootCommands::Mcp { args } => {
365+
if args.iter().any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
366+
return Self::execute_chat("mcp", Some(vec!["--help".to_owned()]), false).await;
367+
}
368+
369+
Self::execute_chat("mcp", Some(args), true).await
370+
},
356371
CliRootCommands::Inline(subcommand) => subcommand.execute(&cli_context).await,
357372
},
358373
// Root command
@@ -361,6 +376,14 @@ impl Cli {
361376
}
362377

363378
pub async fn execute_chat(subcmd: &str, args: Option<Vec<String>>, enforce_login: bool) -> Result<ExitCode> {
379+
cfg_if::cfg_if! {
380+
if #[cfg(target_os = "macos")] {
381+
let path = get_bundle_path_for_executable(CHAT_BINARY_NAME).unwrap_or(home_local_bin()?.join(CHAT_BINARY_NAME));
382+
} else {
383+
let path = home_local_bin()?.join(CHAT_BINARY_NAME);
384+
}
385+
}
386+
364387
if enforce_login {
365388
assert_logged_in().await?;
366389
}
@@ -376,7 +399,7 @@ impl Cli {
376399
}
377400
}
378401

379-
let mut cmd = tokio::process::Command::new(home_local_bin()?.join(CHAT_BINARY_NAME));
402+
let mut cmd = tokio::process::Command::new(&path);
380403
cmd.arg(subcmd);
381404
if let Some(args) = args {
382405
cmd.args(args);

crates/q_cli/src/main.rs

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,6 @@ fn main() -> Result<ExitCode> {
3333
Some("init" | "_" | "internal" | "completion" | "hook" | "chat")
3434
);
3535

36-
let runtime = if multithread {
37-
tokio::runtime::Builder::new_multi_thread()
38-
} else {
39-
tokio::runtime::Builder::new_current_thread()
40-
}
41-
.enable_all()
42-
.build()?;
43-
44-
// Hack as clap doesn't expose a custom command help.
45-
if subcommand.as_deref() == Some("chat") && args.any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
46-
runtime.block_on(cli::Cli::execute_chat("chat", Some(vec!["--help".to_owned()]), true))?;
47-
}
48-
4936
let parsed = match cli::Cli::try_parse() {
5037
Ok(cli) => cli,
5138
Err(err) => {
@@ -73,6 +60,14 @@ fn main() -> Result<ExitCode> {
7360

7461
let verbose = parsed.verbose > 0;
7562

63+
let runtime = if multithread {
64+
tokio::runtime::Builder::new_multi_thread()
65+
} else {
66+
tokio::runtime::Builder::new_current_thread()
67+
}
68+
.enable_all()
69+
.build()?;
70+
7671
let result = runtime.block_on(async {
7772
let result = parsed.execute().await;
7873
fig_telemetry::finish_telemetry().await;

0 commit comments

Comments
 (0)