MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / load_agents_from_entries

Function load_agents_from_entries

crates/chat-cli/src/cli/agent/mod.rs:884–929  ·  view source on GitHub ↗
(
    mut files: ReadDir,
    os: &Os,
    global_mcp_config: &mut Option<McpServerConfig>,
    mcp_enabled: bool,
    is_from_global_dir: bool,
    output: &mut impl Write,
)

Source from the content-addressed store, hash-verified

882}
883
884async fn load_agents_from_entries(
885 mut files: ReadDir,
886 os: &Os,
887 global_mcp_config: &mut Option<McpServerConfig>,
888 mcp_enabled: bool,
889 is_from_global_dir: bool,
890 output: &mut impl Write,
891) -> Vec<Result<Agent, AgentConfigError>> {
892 let mut res = Vec::<Result<Agent, AgentConfigError>>::new();
893
894 while let Ok(Some(file)) = files.next_entry().await {
895 let file_path = &file.path();
896 if file_path
897 .extension()
898 .and_then(OsStr::to_str)
899 .is_some_and(|s| s == "json")
900 {
901 let agent_res = Agent::load(os, file_path, global_mcp_config, mcp_enabled, output).await;
902 if let Ok(agent) = &agent_res {
903 if res.iter().any(|res| match res {
904 Ok(a) => a.name == agent.name,
905 Err(_) => false,
906 }) {
907 let _ = queue!(
908 output,
909 StyledText::warning_fg(),
910 style::Print("WARNING: "),
911 StyledText::reset(),
912 style::Print("Duplicate agent with name "),
913 StyledText::success_fg(),
914 style::Print(&agent.name),
915 StyledText::reset(),
916 style::Print(" was found in the "),
917 style::Print(if is_from_global_dir { "global" } else { "workspace" }),
918 style::Print(" directory.\n"),
919 StyledText::reset(),
920 );
921 continue;
922 }
923 }
924 res.push(agent_res);
925 }
926 }
927
928 res
929}
930
931/// Loads legacy mcp config by combining workspace and global config.
932/// In case of a server naming conflict, the workspace config is prioritized.

Callers 2

loadMethod · 0.85

Calls 1

pathMethod · 0.45