@@ -251,9 +251,19 @@ impl ChatArgs {
251251 let conversation_id = uuid:: Uuid :: new_v4 ( ) . to_string ( ) ;
252252 info ! ( ?conversation_id, "Generated new conversation id" ) ;
253253
254+ // Check MCP status once at the beginning of the session
255+ let mcp_enabled = match os. client . is_mcp_enabled ( ) . await {
256+ Ok ( enabled) => enabled,
257+ Err ( err) => {
258+ tracing:: warn!( ?err, "Failed to check MCP configuration, defaulting to enabled" ) ;
259+ true
260+ } ,
261+ } ;
262+
254263 let agents = {
255264 let skip_migration = self . no_interactive ;
256- let ( mut agents, md) = Agents :: load ( os, self . agent . as_deref ( ) , skip_migration, & mut stderr) . await ;
265+ let ( mut agents, md) =
266+ Agents :: load ( os, self . agent . as_deref ( ) , skip_migration, & mut stderr, mcp_enabled) . await ;
257267 agents. trust_all_tools = self . trust_all_tools ;
258268
259269 os. telemetry
@@ -268,9 +278,11 @@ impl ChatArgs {
268278 . map_err ( |err| error ! ( ?err, "failed to send agent config init telemetry" ) )
269279 . ok ( ) ;
270280
271- if agents
272- . get_active ( )
273- . is_some_and ( |a| !a. mcp_servers . mcp_servers . is_empty ( ) )
281+ // Only show MCP safety message if MCP is enabled and has servers
282+ if mcp_enabled
283+ && agents
284+ . get_active ( )
285+ . is_some_and ( |a| !a. mcp_servers . mcp_servers . is_empty ( ) )
274286 {
275287 if !self . no_interactive && !os. database . settings . get_bool ( Setting :: McpLoadedBefore ) . unwrap_or ( false ) {
276288 execute ! (
@@ -364,6 +376,7 @@ impl ChatArgs {
364376 model_id,
365377 tool_config,
366378 !self . no_interactive ,
379+ mcp_enabled,
367380 )
368381 . await ?
369382 . spawn ( os)
@@ -589,6 +602,7 @@ impl ChatSession {
589602 model_id : Option < String > ,
590603 tool_config : HashMap < String , ToolSpec > ,
591604 interactive : bool ,
605+ mcp_enabled : bool ,
592606 ) -> Result < Self > {
593607 // Reload prior conversation
594608 let mut existing_conversation = false ;
@@ -624,11 +638,23 @@ impl ChatSession {
624638 }
625639 }
626640 cs. agents = agents;
641+ cs. mcp_enabled = mcp_enabled;
627642 cs. update_state ( true ) . await ;
628643 cs. enforce_tool_use_history_invariants ( ) ;
629644 cs
630645 } ,
631- false => ConversationState :: new ( conversation_id, agents, tool_config, tool_manager, model_id, os) . await ,
646+ false => {
647+ ConversationState :: new (
648+ conversation_id,
649+ agents,
650+ tool_config,
651+ tool_manager,
652+ model_id,
653+ os,
654+ mcp_enabled,
655+ )
656+ . await
657+ } ,
632658 } ;
633659
634660 // Spawn a task for listening and broadcasting sigints.
@@ -2967,6 +2993,7 @@ mod tests {
29672993 None ,
29682994 tool_config,
29692995 true ,
2996+ false ,
29702997 )
29712998 . await
29722999 . unwrap ( )
@@ -3108,6 +3135,7 @@ mod tests {
31083135 None ,
31093136 tool_config,
31103137 true ,
3138+ false ,
31113139 )
31123140 . await
31133141 . unwrap ( )
@@ -3204,6 +3232,7 @@ mod tests {
32043232 None ,
32053233 tool_config,
32063234 true ,
3235+ false ,
32073236 )
32083237 . await
32093238 . unwrap ( )
@@ -3278,6 +3307,7 @@ mod tests {
32783307 None ,
32793308 tool_config,
32803309 true ,
3310+ false ,
32813311 )
32823312 . await
32833313 . unwrap ( )
@@ -3328,6 +3358,7 @@ mod tests {
33283358 None ,
33293359 tool_config,
33303360 true ,
3361+ false ,
33313362 )
33323363 . await
33333364 . unwrap ( )
0 commit comments