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

Method execute

crates/chat-cli/src/cli/chat/cli/tools.rs:46–189  ·  view source on GitHub ↗
(self, session: &mut ChatSession)

Source from the content-addressed store, hash-verified

44
45impl ToolsArgs {
46 pub async fn execute(self, session: &mut ChatSession) -> Result<ChatState, ChatError> {
47 if let Some(subcommand) = self.subcommand {
48 return subcommand.execute(session).await;
49 }
50
51 // No subcommand - print the current tools and their permissions.
52 // Determine how to format the output nicely.
53 let terminal_width = session.terminal_width();
54 let longest = session
55 .conversation
56 .tool_manager
57 .tn_map
58 .values()
59 .map(|info| info.host_tool_name.len())
60 .max()
61 .unwrap_or(0)
62 .max(
63 session
64 .conversation
65 .tools
66 .get(&ToolOrigin::Native)
67 .and_then(|tools| {
68 tools
69 .iter()
70 .map(|tool| {
71 let FigTool::ToolSpecification(t) = tool;
72 t.name.len()
73 })
74 .max()
75 })
76 .unwrap_or(0),
77 );
78
79 queue!(
80 session.stderr,
81 style::Print("\n"),
82 style::SetAttribute(Attribute::Bold),
83 style::Print({
84 // Adding 2 because of "- " preceding every tool name
85 let width = (longest + 2).saturating_sub("Tool".len()) + 4;
86 format!("Tool{:>width$}Permission", "", width = width)
87 }),
88 StyledText::reset_attributes(),
89 style::Print("\n"),
90 style::Print("▔".repeat(terminal_width)),
91 )?;
92
93 let mut origin_tools: Vec<_> = session.conversation.tools.iter().collect();
94
95 // Built in tools always appear first.
96 origin_tools.sort_by(|(origin_a, _), (origin_b, _)| match (origin_a, origin_b) {
97 (ToolOrigin::Native, _) => std::cmp::Ordering::Less,
98 (_, ToolOrigin::Native) => std::cmp::Ordering::Greater,
99 (ToolOrigin::McpServer(name_a), ToolOrigin::McpServer(name_b)) => name_a.cmp(name_b),
100 });
101
102 for (origin, tools) in origin_tools.iter() {
103 // Note that Tool is model facing and thus would have names recognized by model.

Callers

nothing calls this directly

Calls 15

CustomClass · 0.85
terminal_widthMethod · 0.80
mapMethod · 0.80
pending_clientsMethod · 0.80
trust_toolsMethod · 0.80
untrust_toolsMethod · 0.80
get_activeMethod · 0.80
get_active_mutMethod · 0.80
valuesMethod · 0.45
lenMethod · 0.45
getMethod · 0.45
as_strMethod · 0.45

Tested by

no test coverage detected