Skip to content

Commit 6dcb273

Browse files
feat(q_cli): support 'q mcp' subcommand via qchat forwarding (#1836)
* 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 --------- Co-authored-by: Brandon Kiser <[email protected]>
1 parent 983e071 commit 6dcb273

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

crates/q_cli/src/cli/mod.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ pub enum CliRootCommands {
200200
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
201201
args: Vec<String>,
202202
},
203+
/// Model Context Protocol (MCP)
204+
Mcp {
205+
/// Args for the MCP subcommand (passed through to `qchat mcp …`)
206+
#[arg(trailing_var_arg = true, allow_hyphen_values = true)]
207+
args: Vec<String>,
208+
},
203209
/// Inline shell completions
204210
#[command(subcommand)]
205211
Inline(inline::InlineSubcommand),
@@ -235,6 +241,7 @@ impl CliRootCommands {
235241
CliRootCommands::Version { .. } => "version",
236242
CliRootCommands::Dashboard => "dashboard",
237243
CliRootCommands::Chat { .. } => "chat",
244+
CliRootCommands::Mcp { .. } => "mcp",
238245
CliRootCommands::Inline(_) => "inline",
239246
}
240247
}
@@ -344,15 +351,16 @@ impl Cli {
344351
CliRootCommands::Telemetry(subcommand) => subcommand.execute().await,
345352
CliRootCommands::Version { changelog } => Self::print_version(changelog),
346353
CliRootCommands::Dashboard => launch_dashboard(false).await,
347-
CliRootCommands::Chat { args } => Self::execute_chat(Some(args), true).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,
348356
CliRootCommands::Inline(subcommand) => subcommand.execute(&cli_context).await,
349357
},
350358
// Root command
351-
None => Self::execute_chat(None, true).await,
359+
None => Self::execute_chat("chat", None, true).await,
352360
}
353361
}
354362

355-
pub async fn execute_chat(args: Option<Vec<String>>, enforce_login: bool) -> Result<ExitCode> {
363+
pub async fn execute_chat(subcmd: &str, args: Option<Vec<String>>, enforce_login: bool) -> Result<ExitCode> {
356364
if enforce_login {
357365
assert_logged_in().await?;
358366
}
@@ -369,8 +377,7 @@ impl Cli {
369377
}
370378

371379
let mut cmd = tokio::process::Command::new(home_local_bin()?.join(CHAT_BINARY_NAME));
372-
cmd.arg("chat");
373-
380+
cmd.arg(subcmd);
374381
if let Some(args) = args {
375382
cmd.args(args);
376383
}

crates/q_cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ fn main() -> Result<ExitCode> {
4343

4444
// Hack as clap doesn't expose a custom command help.
4545
if subcommand.as_deref() == Some("chat") && args.any(|arg| ["--help", "-h"].contains(&arg.as_str())) {
46-
runtime.block_on(cli::Cli::execute_chat(Some(vec!["--help".to_owned()]), true))?;
46+
runtime.block_on(cli::Cli::execute_chat("chat", Some(vec!["--help".to_owned()]), true))?;
4747
}
4848

4949
let parsed = match cli::Cli::try_parse() {

0 commit comments

Comments
 (0)