Skip to content

Commit 814ae3f

Browse files
committed
diasble warining in non-interactive way
1 parent 39cc3b9 commit 814ae3f

File tree

3 files changed

+30
-14
lines changed

3 files changed

+30
-14
lines changed

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

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ pub async fn add_mcp_server(ctx: &Context, output: &mut SharedWriter, args: McpA
6060

6161
if config.mcp_servers.contains_key(&args.name) && !args.force {
6262
bail!(
63-
"MCP server '{}' already exists in {} (scope {}). Use --force to overwrite.",
63+
"\nMCP server '{}' already exists in {} (scope {}). Use --force to overwrite.",
6464
args.name,
6565
config_path.display(),
6666
scope
@@ -74,11 +74,16 @@ pub async fn add_mcp_server(ctx: &Context, output: &mut SharedWriter, args: McpA
7474
"timeout": args.timeout.unwrap_or(default_timeout()),
7575
}))?;
7676

77+
writeln!(
78+
output,
79+
"\nTo learn more about MCP safety, see https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-mcp-security.html\n\n"
80+
)?;
81+
7782
config.mcp_servers.insert(args.name.clone(), tool);
7883
config.save_to_file(ctx, &config_path).await?;
7984
writeln!(
8085
output,
81-
"✓ Added MCP server '{}' to {}",
86+
"✓ Added MCP server '{}' to {}\n",
8287
args.name,
8388
scope_display(&scope, &args.profile)
8489
)?;
@@ -100,15 +105,15 @@ pub async fn remove_mcp_server(ctx: &Context, output: &mut SharedWriter, args: M
100105
config.save_to_file(ctx, &config_path).await?;
101106
writeln!(
102107
output,
103-
"✓ Removed MCP server '{}' from {}",
108+
"\n✓ Removed MCP server '{}' from {}\n",
104109
args.name,
105110
scope_display(&scope, &args.profile)
106111
)?;
107112
},
108113
None => {
109114
writeln!(
110115
output,
111-
"No MCP server named '{}' found in {}",
116+
"\nNo MCP server named '{}' found in {}\n",
112117
args.name,
113118
scope_display(&scope, &args.profile)
114119
)?;
@@ -154,7 +159,7 @@ pub async fn import_mcp_server(ctx: &Context, output: &mut SharedWriter, args: M
154159
for (name, cfg) in src_cfg.mcp_servers {
155160
if dst_cfg.mcp_servers.contains_key(&name) && !args.force {
156161
bail!(
157-
"MCP server '{}' already exists in {} (scope {}). Use --force to overwrite.",
162+
"MCP server '{}' already exists in {} (scope {}). Use --force to overwrite.\n",
158163
name,
159164
config_path.display(),
160165
scope
@@ -164,10 +169,15 @@ pub async fn import_mcp_server(ctx: &Context, output: &mut SharedWriter, args: M
164169
added += 1;
165170
}
166171

172+
writeln!(
173+
output,
174+
"\nTo learn more about MCP safety, see https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-mcp-security.html\n\n"
175+
)?;
176+
167177
dst_cfg.save_to_file(ctx, &config_path).await?;
168178
writeln!(
169179
output,
170-
"✓ Imported {added} MCP server(s) into {}",
180+
"✓ Imported {added} MCP server(s) into {}\n",
171181
scope_display(&scope, &args.profile)
172182
)?;
173183
Ok(())
@@ -199,7 +209,7 @@ pub async fn get_mcp_server_status(ctx: &Context, output: &mut SharedWriter, nam
199209
writeln!(output, "\n")?;
200210

201211
if !found {
202-
bail!("No MCP server named '{name}' found in any scope/profile");
212+
bail!("No MCP server named '{name}' found in any scope/profile\n");
203213
}
204214
Ok(())
205215
}
@@ -297,7 +307,7 @@ async fn ensure_config_file(
297307
ctx.fs().create_dir_all(parent).await?;
298308
}
299309
McpServerConfig::default().save_to_file(ctx, path).await?;
300-
writeln!(out, "📁 Created MCP config in '{}'", path.display())?;
310+
writeln!(out, "\n📁 Created MCP config in '{}'", path.display())?;
301311
}
302312
load_cfg(ctx, path).await
303313
}

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

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -354,12 +354,15 @@ pub async fn chat(
354354

355355
let mcp_server_configs = match McpServerConfig::load_config(&mut output).await {
356356
Ok(config) => {
357-
execute!(
358-
output,
359-
style::Print(
360-
"To learn more about MCP safety, see https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-mcp-security.html\n\n"
361-
)
362-
)?;
357+
if interactive && !database.settings.get_bool(Setting::McpLoadedBefore).unwrap_or(false) {
358+
execute!(
359+
output,
360+
style::Print(
361+
"To learn more about MCP safety, see https://docs.aws.amazon.com/amazonq/latest/qdeveloper-ug/command-line-mcp-security.html\n\n"
362+
)
363+
)?;
364+
}
365+
database.settings.set(Setting::McpLoadedBefore, true).await?;
363366
config
364367
},
365368
Err(e) => {

crates/chat-cli/src/database/settings.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ pub enum Setting {
2929
ApiCodeWhispererService,
3030
ApiQService,
3131
McpInitTimeout,
32+
McpLoadedBefore,
3233
}
3334

3435
impl AsRef<str> for Setting {
@@ -46,6 +47,7 @@ impl AsRef<str> for Setting {
4647
Self::ApiCodeWhispererService => "api.codewhisperer.service",
4748
Self::ApiQService => "api.q.service",
4849
Self::McpInitTimeout => "mcp.initTimeout",
50+
Self::McpLoadedBefore => "mcp.loadedBefore",
4951
}
5052
}
5153
}
@@ -73,6 +75,7 @@ impl TryFrom<&str> for Setting {
7375
"api.codewhisperer.service" => Ok(Self::ApiCodeWhispererService),
7476
"api.q.service" => Ok(Self::ApiQService),
7577
"mcp.initTimeout" => Ok(Self::McpInitTimeout),
78+
"mcp.loadedBefore" => Ok(Self::McpLoadedBefore),
7679
_ => Err(DatabaseError::InvalidSetting(value.to_string())),
7780
}
7881
}

0 commit comments

Comments
 (0)