Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions crates/chat-cli/src/cli/chat/command.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ pub enum Command {
path: String,
force: bool,
},
Mcp,
}

#[derive(Debug, Clone, PartialEq, Eq)]
Expand Down Expand Up @@ -837,6 +838,7 @@ impl Command {
}
Self::Save { path, force }
},
"mcp" => Self::Mcp,
unknown_command => {
let looks_like_path = {
let after_slash_command_str = parts[1..].join(" ");
Expand Down
52 changes: 51 additions & 1 deletion crates/chat-cli/src/cli/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ use token_counter::{
use tokio::signal::ctrl_c;
use tool_manager::{
GetPromptError,
LoadingRecord,
McpServerConfig,
PromptBundle,
ToolManager,
Expand Down Expand Up @@ -204,7 +205,7 @@ const WELCOME_TEXT: &str = color_print::cstr! {"<cyan!>
const SMALL_SCREEN_WELCOME_TEXT: &str = color_print::cstr! {"<em>Welcome to <cyan!>Amazon Q</cyan!>!</em>"};
const RESUME_TEXT: &str = color_print::cstr! {"<em>Picking up where we left off...</em>"};

const ROTATING_TIPS: [&str; 12] = [
const ROTATING_TIPS: [&str; 13] = [
color_print::cstr! {"You can resume the last conversation from your current directory by launching with <green!>q chat --resume</green!>"},
color_print::cstr! {"Get notified whenever Q CLI finishes responding. Just run <green!>q settings chat.enableNotifications true</green!>"},
color_print::cstr! {"You can use <green!>/editor</green!> to edit your prompt with a vim-like experience"},
Expand All @@ -217,6 +218,7 @@ const ROTATING_TIPS: [&str; 12] = [
color_print::cstr! {"If you want to file an issue to the Q CLI team, just tell me, or run <green!>q issue</green!>"},
color_print::cstr! {"You can enable custom tools with <green!>MCP servers</green!>. Learn more with /help"},
color_print::cstr! {"You can specify wait time (in ms) for mcp server loading with <green!>q settings mcp.initTimeout {timeout in int}</green!>. Servers that takes longer than the specified time will continue to load in the background. Use /tools to see pending servers."},
color_print::cstr! {"You can see the server load status as well as any warnings or errors associated with <green!>/mcp</green!>"},
];

const GREETING_BREAK_POINT: usize = 80;
Expand Down Expand Up @@ -246,6 +248,7 @@ const HELP_TEXT: &str = color_print::cstr! {"
<em>untrust</em> <black!>Revert a tool or tools to per-request confirmation</black!>
<em>trustall</em> <black!>Trust all tools (equivalent to deprecated /acceptall)</black!>
<em>reset</em> <black!>Reset all tools to default permission levels</black!>
<em>/mcp</em> <black!>See mcp server loaded</black!>
<em>/profile</em> <black!>Manage profiles</black!>
<em>help</em> <black!>Show profile help</black!>
<em>list</em> <black!>List profiles</black!>
Expand Down Expand Up @@ -2948,6 +2951,53 @@ impl ChatContext {
skip_printing_tools: true,
}
},
Command::Mcp => {
let terminal_width = self.terminal_width();
let loaded_servers = self.conversation_state.tool_manager.mcp_load_record.lock().await;
let still_loading = self
.conversation_state
.tool_manager
.pending_clients()
.await
.into_iter()
.map(|name| format!(" - {name}\n"))
.collect::<Vec<_>>()
.join("");
for (server_name, msg) in loaded_servers.iter() {
let msg = msg
.iter()
.map(|record| match record {
LoadingRecord::Err(content)
| LoadingRecord::Warn(content)
| LoadingRecord::Success(content) => content.clone(),
})
.collect::<Vec<_>>()
.join("\n--- tools refreshed ---\n");
queue!(
self.output,
style::Print(server_name),
style::Print("\n"),
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
style::Print(msg),
style::Print("\n")
)?;
}
if !still_loading.is_empty() {
queue!(
self.output,
style::Print("Still loading:\n"),
style::Print(format!("{}\n", "▔".repeat(terminal_width))),
style::Print(still_loading),
style::Print("\n")
)?;
}
self.output.flush()?;
ChatState::PromptUser {
tool_uses: None,
pending_tool_index: None,
skip_printing_tools: true,
}
},
})
}

Expand Down
21 changes: 12 additions & 9 deletions crates/chat-cli/src/cli/chat/server_messenger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,23 +14,23 @@ use crate::mcp_client::{
};

#[allow(dead_code)]
#[derive(Clone, Debug)]
#[derive(Debug)]
pub enum UpdateEventMessage {
ToolsListResult {
server_name: String,
result: ToolsListResult,
result: eyre::Result<ToolsListResult>,
},
PromptsListResult {
server_name: String,
result: PromptsListResult,
result: eyre::Result<PromptsListResult>,
},
ResourcesListResult {
server_name: String,
result: ResourcesListResult,
result: eyre::Result<ResourcesListResult>,
},
ResourceTemplatesListResult {
server_name: String,
result: ResourceTemplatesListResult,
result: eyre::Result<ResourceTemplatesListResult>,
},
InitStart {
server_name: String,
Expand Down Expand Up @@ -67,7 +67,7 @@ pub struct ServerMessenger {

#[async_trait::async_trait]
impl Messenger for ServerMessenger {
async fn send_tools_list_result(&self, result: ToolsListResult) -> Result<(), MessengerError> {
async fn send_tools_list_result(&self, result: eyre::Result<ToolsListResult>) -> Result<(), MessengerError> {
Ok(self
.update_event_sender
.send(UpdateEventMessage::ToolsListResult {
Expand All @@ -78,7 +78,7 @@ impl Messenger for ServerMessenger {
.map_err(|e| MessengerError::Custom(e.to_string()))?)
}

async fn send_prompts_list_result(&self, result: PromptsListResult) -> Result<(), MessengerError> {
async fn send_prompts_list_result(&self, result: eyre::Result<PromptsListResult>) -> Result<(), MessengerError> {
Ok(self
.update_event_sender
.send(UpdateEventMessage::PromptsListResult {
Expand All @@ -89,7 +89,10 @@ impl Messenger for ServerMessenger {
.map_err(|e| MessengerError::Custom(e.to_string()))?)
}

async fn send_resources_list_result(&self, result: ResourcesListResult) -> Result<(), MessengerError> {
async fn send_resources_list_result(
&self,
result: eyre::Result<ResourcesListResult>,
) -> Result<(), MessengerError> {
Ok(self
.update_event_sender
.send(UpdateEventMessage::ResourcesListResult {
Expand All @@ -102,7 +105,7 @@ impl Messenger for ServerMessenger {

async fn send_resource_templates_list_result(
&self,
result: ResourceTemplatesListResult,
result: eyre::Result<ResourceTemplatesListResult>,
) -> Result<(), MessengerError> {
Ok(self
.update_event_sender
Expand Down
Loading
Loading