Skip to content

Commit 1111a2b

Browse files
adwsinghrhernandez35
authored andcommitted
Print out install command output
1 parent 6673274 commit 1111a2b

File tree

1 file changed

+5
-15
lines changed
  • mcp/mcp-cli-api/src/main/java/software/amazon/smithy/java/mcp/cli

1 file changed

+5
-15
lines changed

mcp/mcp-cli-api/src/main/java/software/amazon/smithy/java/mcp/cli/ConfigUtils.java

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,7 @@
77

88
import static software.amazon.smithy.java.io.ByteBufferUtils.getBytes;
99

10-
import java.io.BufferedReader;
1110
import java.io.IOException;
12-
import java.io.InputStreamReader;
1311
import java.nio.charset.StandardCharsets;
1412
import java.nio.file.Files;
1513
import java.nio.file.Path;
@@ -312,7 +310,7 @@ public static McpBundleConfig addMcpBundle(Config config, String id, Bundle bund
312310
.build());
313311
case genericBundle -> {
314312
GenericBundle genericBundle = bundle.getValue();
315-
validate(genericBundle);
313+
validate(genericBundle, id);
316314
install(genericBundle.getInstall());
317315
builder.genericConfig(
318316
GenericToolBundleConfig.builder()
@@ -331,9 +329,9 @@ public static McpBundleConfig addMcpBundle(Config config, String id, Bundle bund
331329
return mcpBundleConfig;
332330
}
333331

334-
private static void validate(GenericBundle genericBundle) {
332+
private static void validate(GenericBundle genericBundle, String id) {
335333
if (!genericBundle.isExecuteDirectly() &&
336-
genericBundle.getRun().getExecutable().equals(genericBundle.getMetadata().getId())) {
334+
genericBundle.getRun().getExecutable().equals(id)) {
337335
throw new IllegalStateException(
338336
"The generic MCP run command has the same value as id which isn't allowed.");
339337
}
@@ -346,10 +344,10 @@ private static void install(List<ExecSpec> execSpecs) {
346344
ProcessBuilder pb = new ProcessBuilder(execSpec.getExecutable());
347345
pb.command().addAll(execSpec.getArgs());
348346
pb.redirectErrorStream(true);
347+
pb.redirectOutput(ProcessBuilder.Redirect.INHERIT);
349348
Process process = null;
350349
try {
351350
process = pb.start();
352-
String output = captureProcessOutput(process);
353351

354352
boolean finished = process.waitFor(5, TimeUnit.MINUTES);
355353

@@ -364,8 +362,7 @@ private static void install(List<ExecSpec> execSpecs) {
364362
throw new RuntimeException(String.format(
365363
"Installation failed with exit code %d. Command: %s. Output: %s",
366364
exitCode,
367-
String.join(" ", pb.command()),
368-
output));
365+
String.join(" ", pb.command())));
369366
}
370367

371368
} catch (InterruptedException e) {
@@ -388,13 +385,6 @@ private static void install(List<ExecSpec> execSpecs) {
388385
}
389386
}
390387

391-
private static String captureProcessOutput(Process process) throws IOException {
392-
try (BufferedReader in =
393-
new BufferedReader(new InputStreamReader(process.getInputStream(), StandardCharsets.UTF_8))) {
394-
return in.lines().collect(Collectors.joining(System.lineSeparator()));
395-
}
396-
}
397-
398388
public static void createWrapperScript(String id) throws IOException {
399389
Path scriptPath = SHIMS_DIR.resolve(id);
400390
String scriptContent = createScriptContent(id);

0 commit comments

Comments
 (0)