Skip to content

Commit c3d6b9f

Browse files
committed
add notification when /mcp & /tools
1 parent fa6b442 commit c3d6b9f

File tree

5 files changed

+67
-35
lines changed

5 files changed

+67
-35
lines changed

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

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -336,22 +336,19 @@ impl ApiClient {
336336
}
337337

338338
pub async fn is_mcp_enabled(&self) -> Result<bool, ApiClientError> {
339-
let request = self
340-
.client
341-
.get_profile()
342-
.set_profile_arn(self.profile.as_ref().map(|p| p.arn.clone()));
343-
344-
let response = request.send().await?;
345-
// yifan todo delete print
346-
eprintln!("response {:?}", response);
347-
tracing::debug!("response is {:?}", response);
348-
let mcp_enabled = response
349-
.profile()
350-
.opt_in_features()
351-
.and_then(|features| features.mcp_configuration())
352-
.is_none_or(|config| matches!(config.toggle(), OptInFeatureToggle::On));
353-
Ok(mcp_enabled)
354-
// Ok(true)
339+
// let request = self
340+
// .client
341+
// .get_profile()
342+
// .set_profile_arn(self.profile.as_ref().map(|p| p.arn.clone()));
343+
344+
// let response = request.send().await?;
345+
// let mcp_enabled = response
346+
// .profile()
347+
// .opt_in_features()
348+
// .and_then(|features| features.mcp_configuration())
349+
// .is_none_or(|config| matches!(config.toggle(), OptInFeatureToggle::On));
350+
// Ok(mcp_enabled)
351+
Ok(false)
355352
}
356353

357354
pub async fn create_subscription_token(&self) -> Result<CreateSubscriptionTokenOutput, ApiClientError> {

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -470,24 +470,14 @@ impl Agents {
470470
},
471471
};
472472

473-
// Yifan delete log
474-
let _ = queue!(
475-
output,
476-
style::SetForegroundColor(Color::Red),
477-
style::Print("MCP status: "),
478-
style::ResetColor,
479-
style::Print(mcp_enabled),
480-
style::Print("\n")
481-
);
482-
483473
if !mcp_enabled {
484474
let _ = execute!(
485475
output,
486476
style::SetForegroundColor(Color::Yellow),
477+
style::Print("\n"),
487478
style::Print("⚠️ WARNING: "),
488479
style::SetForegroundColor(Color::Reset),
489-
style::Print("MCP functionality has been disabled by your administrator.\n"),
490-
style::Print("MCP servers will not be loaded for this session.\n\n")
480+
style::Print("MCP functionality has been disabled by your administrator.\n\n"),
491481
);
492482
}
493483

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

Lines changed: 29 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
use std::io::Write;
22

33
use clap::Args;
4-
use crossterm::{
5-
queue,
6-
style,
4+
use crossterm::queue;
5+
use crossterm::style::{
6+
self,
7+
Color,
78
};
89

910
use crate::cli::chat::tool_manager::LoadingRecord;
@@ -12,13 +13,37 @@ use crate::cli::chat::{
1213
ChatSession,
1314
ChatState,
1415
};
16+
use crate::os::Os;
1517

1618
#[deny(missing_docs)]
1719
#[derive(Debug, PartialEq, Args)]
1820
pub struct McpArgs;
1921

2022
impl McpArgs {
21-
pub async fn execute(self, session: &mut ChatSession) -> Result<ChatState, ChatError> {
23+
pub async fn execute(self, os: &Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
24+
let mcp_enabled = match os.client.is_mcp_enabled().await {
25+
Ok(enabled) => enabled,
26+
Err(err) => {
27+
tracing::warn!(?err, "Failed to check MCP configuration, defaulting to enabled");
28+
true
29+
},
30+
};
31+
32+
if !mcp_enabled {
33+
queue!(
34+
session.stderr,
35+
style::SetForegroundColor(Color::Yellow),
36+
style::Print("\n"),
37+
style::Print("⚠️ WARNING: "),
38+
style::SetForegroundColor(Color::Reset),
39+
style::Print("MCP functionality has been disabled by your administrator.\n\n"),
40+
)?;
41+
session.stderr.flush()?;
42+
return Ok(ChatState::PromptUser {
43+
skip_printing_tools: true,
44+
});
45+
}
46+
2247
let terminal_width = session.terminal_width();
2348
let still_loading = session
2449
.conversation

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ impl SlashCommand {
120120
Self::Knowledge(subcommand) => subcommand.execute(os, session).await,
121121
Self::PromptEditor(args) => args.execute(session).await,
122122
Self::Compact(args) => args.execute(os, session).await,
123-
Self::Tools(args) => args.execute(session).await,
123+
Self::Tools(args) => args.execute(os, session).await,
124124
Self::Issue(args) => {
125125
if let Err(err) = args.execute(os).await {
126126
return Err(ChatError::Custom(err.to_string().into()));
@@ -133,7 +133,7 @@ impl SlashCommand {
133133
Self::Prompts(args) => args.execute(session).await,
134134
Self::Hooks(args) => args.execute(session).await,
135135
Self::Usage(args) => args.execute(os, session).await,
136-
Self::Mcp(args) => args.execute(session).await,
136+
Self::Mcp(args) => args.execute(os, session).await,
137137
Self::Model(args) => args.execute(os, session).await,
138138
Self::Subscribe(args) => args.execute(os, session).await,
139139
Self::Persist(subcommand) => subcommand.execute(os, session).await,

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

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ use crate::cli::chat::{
3333
ChatState,
3434
TRUST_ALL_TEXT,
3535
};
36+
use crate::os::Os;
3637
use crate::util::consts::MCP_SERVER_TOOL_DELIMITER;
3738

3839
#[deny(missing_docs)]
@@ -43,7 +44,7 @@ pub struct ToolsArgs {
4344
}
4445

4546
impl ToolsArgs {
46-
pub async fn execute(self, session: &mut ChatSession) -> Result<ChatState, ChatError> {
47+
pub async fn execute(self, os: &Os, session: &mut ChatSession) -> Result<ChatState, ChatError> {
4748
if let Some(subcommand) = self.subcommand {
4849
return subcommand.execute(session).await;
4950
}
@@ -170,6 +171,25 @@ impl ToolsArgs {
170171
)?;
171172
}
172173

174+
let mcp_enabled = match os.client.is_mcp_enabled().await {
175+
Ok(enabled) => enabled,
176+
Err(err) => {
177+
tracing::warn!(?err, "Failed to check MCP configuration, defaulting to enabled");
178+
true
179+
},
180+
};
181+
182+
if !mcp_enabled {
183+
queue!(
184+
session.stderr,
185+
style::SetForegroundColor(Color::Yellow),
186+
style::Print("\n"),
187+
style::Print("⚠️ WARNING: "),
188+
style::SetForegroundColor(Color::Reset),
189+
style::Print("MCP functionality has been disabled by your administrator.\n\n"),
190+
)?;
191+
}
192+
173193
Ok(ChatState::default())
174194
}
175195

0 commit comments

Comments
 (0)