@@ -362,13 +362,15 @@ impl Agent {
362362 agent. mcp_servers = McpServerConfig :: default ( ) ;
363363 agent. use_legacy_mcp_json = false ;
364364
365- // Filter out MCP tools from the tools list
366- agent. tools . retain ( |tool| !tool. starts_with ( "@" ) ) ;
367-
368- // Filter out MCP tools from allowed_tools
369- agent. allowed_tools . retain ( |tool| !tool. starts_with ( "@" ) ) ;
370-
371- // Still thaw the agent but with empty MCP config
365+ // Remove MCP tools
366+ agent. tools . retain ( |tool| !is_mcp_ref ( tool) ) ;
367+ agent. allowed_tools . retain ( |tool| !is_mcp_ref ( tool) ) ;
368+ agent. tool_aliases . retain ( |orig, _alias| !is_mcp_ref ( & orig. to_string ( ) ) ) ;
369+ agent
370+ . tools_settings
371+ . retain ( |target, _| !is_mcp_ref ( & target. to_string ( ) ) ) ;
372+
373+ // Thaw the agent with empty MCP config to finalize normalization.
372374 agent. thaw ( agent_path. as_ref ( ) , None ) ?;
373375 }
374376 Ok ( agent)
@@ -378,8 +380,10 @@ impl Agent {
378380 pub fn clear_mcp_configs ( & mut self ) {
379381 self . mcp_servers = McpServerConfig :: default ( ) ;
380382 self . use_legacy_mcp_json = false ;
381- self . tools . retain ( |tool| !tool. starts_with ( "@" ) ) ;
382- self . allowed_tools . retain ( |tool| !tool. starts_with ( "@" ) ) ;
383+ self . tools . retain ( |tool| !is_mcp_ref ( tool) ) ;
384+ self . allowed_tools . retain ( |tool| !is_mcp_ref ( tool) ) ;
385+ self . tool_aliases . retain ( |orig, _alias| !is_mcp_ref ( & orig. to_string ( ) ) ) ;
386+ self . tools_settings . retain ( |target, _| !is_mcp_ref ( & target. to_string ( ) ) ) ;
383387 }
384388}
385389
@@ -934,6 +938,11 @@ fn default_schema() -> String {
934938 "https://raw.githubusercontent.com/aws/amazon-q-developer-cli/refs/heads/main/schemas/agent-v1.json" . into ( )
935939}
936940
941+ fn is_mcp_ref ( s : & str ) -> bool {
942+ // Any tool reference starting with '@' is considered MCP (e.g., "@git", "@git/git_status").
943+ s. starts_with ( '@' )
944+ }
945+
937946#[ cfg( test) ]
938947fn validate_agent_name ( name : & str ) -> eyre:: Result < ( ) > {
939948 // Check if name is empty
0 commit comments