Skip to content

Commit ea85485

Browse files
chaynaborsevanliu048brandonskiser
authored
feat(cli): support q mcp --help passthrough to qchat mcp (#1837) (#1839)
* 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: evanliu048 <[email protected]> Co-authored-by: Brandon Kiser <[email protected]>
1 parent ead1908 commit ea85485

File tree

2 files changed

+29
-17
lines changed

2 files changed

+29
-17
lines changed

crates/q_cli/src/cli/mod.rs

Lines changed: 21 additions & 4 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,15 +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)
204206
#[command(disable_help_flag = true)]
205207
Mcp {
206-
/// Args for the MCP subcommand (passed through to `qchat mcp …`)
208+
/// Args for the MCP subcommand
207209
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
208210
args: Vec<String>,
209211
},
@@ -352,11 +354,18 @@ impl Cli {
352354
CliRootCommands::Telemetry(subcommand) => subcommand.execute().await,
353355
CliRootCommands::Version { changelog } => Self::print_version(changelog),
354356
CliRootCommands::Dashboard => launch_dashboard(false).await,
355-
CliRootCommands::Chat { args } => Self::execute_chat("chat", 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+
},
356364
CliRootCommands::Mcp { args } => {
357365
if args.iter().any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
358366
return Self::execute_chat("mcp", Some(vec!["--help".to_owned()]), false).await;
359367
}
368+
360369
Self::execute_chat("mcp", Some(args), true).await
361370
},
362371
CliRootCommands::Inline(subcommand) => subcommand.execute(&cli_context).await,
@@ -367,6 +376,14 @@ impl Cli {
367376
}
368377

369378
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+
370387
if enforce_login {
371388
assert_logged_in().await?;
372389
}
@@ -382,7 +399,7 @@ impl Cli {
382399
}
383400
}
384401

385-
let mut cmd = tokio::process::Command::new(home_local_bin()?.join(CHAT_BINARY_NAME));
402+
let mut cmd = tokio::process::Command::new(&path);
386403
cmd.arg(subcmd);
387404
if let Some(args) = args {
388405
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)