Skip to content

Commit 9230558

Browse files
committed
Handle null bundle returned from the registry and improve messages
1 parent d73315e commit 9230558

File tree

4 files changed

+36
-20
lines changed

4 files changed

+36
-20
lines changed

aws/aws-mcp-cli-commands/src/main/java/software/amazon/smithy/java/aws/mcp/cli/AwsMcpRegistry.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public List<RegistryEntry> listMcpBundles() {
5656
}
5757

5858
@Override
59-
public Bundle getMcpBundle(String name) {
60-
var bundle = AwsServiceBundler.builder().serviceName(name).build().bundle();
59+
public Bundle getMcpBundle(String id) {
60+
var bundle = AwsServiceBundler.builder().serviceName(id).build().bundle();
6161
return Bundle.builder()
6262
.smithyBundle(SmithyMcpBundle.builder().bundle(bundle).build())
6363
.build();

mcp/mcp-bundle-api/src/main/java/software/amazon/smithy/mcp/bundle/api/Registry.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,6 @@ public BundleMetadata getBundleMetadata() {
4141

4242
List<RegistryEntry> listMcpBundles();
4343

44-
Bundle getMcpBundle(String name);
44+
Bundle getMcpBundle(String id);
4545

4646
}

mcp/mcp-cli/src/main/java/software/amazon/smithy/java/mcp/cli/commands/InstallBundle.java

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
import static picocli.CommandLine.Command;
99

1010
import java.io.IOException;
11+
import java.util.HashMap;
12+
import java.util.Map;
1113
import java.util.Set;
1214
import picocli.CommandLine.ArgGroup;
1315
import picocli.CommandLine.Option;
@@ -17,16 +19,17 @@
1719
import software.amazon.smithy.java.mcp.cli.ExecutionContext;
1820
import software.amazon.smithy.java.mcp.cli.SmithyMcpCommand;
1921
import software.amazon.smithy.java.mcp.cli.model.Config;
22+
import software.amazon.smithy.mcp.bundle.api.model.Bundle;
2023

21-
@Command(name = "install", description = "Downloads and adds a bundle from the MCP registry.")
24+
@Command(name = "install", description = "Downloads and installs a MCP server from the MCP registry.")
2225
public class InstallBundle extends SmithyMcpCommand {
2326

2427
@Option(names = {"-r", "--registry"},
25-
description = "Name of the registry to list the bundles from. If not provided it will use the default registry.")
28+
description = "Name of the registry to list the mcp server from. If not provided it will use the default registry.")
2629
String registryName;
2730

28-
@Parameters(description = "Names of the MCP bundles to install.")
29-
Set<String> names;
31+
@Parameters(description = "Id(s) of the MCP server(s) to install.")
32+
Set<String> ids;
3033

3134
@ArgGroup
3235
ClientsInput clientsInput;
@@ -35,11 +38,24 @@ public class InstallBundle extends SmithyMcpCommand {
3538
protected void execute(ExecutionContext context) throws IOException {
3639
var registry = context.registry();
3740
var config = context.config();
38-
for (var name : names) {
39-
var bundle = registry.getMcpBundle(name);
40-
ConfigUtils.addMcpBundle(config, name, bundle);
41-
ConfigUtils.createWrapperAndUpdateClientConfigs(name, bundle, config, clientsInput);
42-
System.out.println("Successfully installed " + name);
41+
42+
// First, collect all server and validate they exist
43+
Map<String, Bundle> bundles = new HashMap<>();
44+
for (var id : ids) {
45+
var bundle = registry.getMcpBundle(id);
46+
if (bundle == null) {
47+
throw new IllegalArgumentException("MCP with id '" + id + "' not found.");
48+
}
49+
bundles.put(id, bundle);
50+
}
51+
52+
// Now install all server
53+
for (var entry : bundles.entrySet()) {
54+
var id = entry.getKey();
55+
var bundle = entry.getValue();
56+
ConfigUtils.addMcpBundle(config, id, bundle);
57+
ConfigUtils.createWrapperAndUpdateClientConfigs(id, bundle, config, clientsInput);
58+
System.out.println("Successfully installed " + id);
4359
}
4460
}
4561

mcp/mcp-cli/src/main/java/software/amazon/smithy/java/mcp/cli/commands/UninstallBundle.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,11 @@
1313
import software.amazon.smithy.java.mcp.cli.ExecutionContext;
1414
import software.amazon.smithy.java.mcp.cli.SmithyMcpCommand;
1515

16-
@Command(name = "uninstall", description = "Uninstall a MCP bundle.")
16+
@Command(name = "uninstall", description = "Uninstall a MCP server.")
1717
public class UninstallBundle extends SmithyMcpCommand {
1818

19-
@Parameters(description = "Name of the MCP bundle to uninstall.")
20-
String name;
19+
@Parameters(description = "Id of the MCP server to uninstall.")
20+
String id;
2121

2222
@Option(names = {"--clients"},
2323
description = "Names of client configs to update. If not specified all client configs registered would be updated.")
@@ -26,13 +26,13 @@ public class UninstallBundle extends SmithyMcpCommand {
2626
@Override
2727
protected void execute(ExecutionContext context) throws Exception {
2828
var config = context.config();
29-
if (!config.getToolBundles().containsKey(name)) {
30-
System.out.println("No such MCP bundle exists. Nothing to do.");
29+
if (!config.getToolBundles().containsKey(id)) {
30+
System.out.println("No such MCP server is installed. Nothing to do.");
3131
return;
3232
}
33-
ConfigUtils.removeMcpBundle(config, name);
34-
System.out.println("Uninstalled MCP bundle: " + name);
35-
ConfigUtils.removeFromClientConfigs(config, name, clients);
33+
ConfigUtils.removeMcpBundle(config, id);
34+
System.out.println("Uninstalled MCP bundle: " + id);
35+
ConfigUtils.removeFromClientConfigs(config, id, clients);
3636
System.out.println("Updated client configs");
3737
}
3838
}

0 commit comments

Comments
 (0)