7
7
8
8
import static picocli .CommandLine .Command ;
9
9
10
+ import java .util .Map ;
11
+ import org .jline .terminal .Terminal ;
12
+ import org .jline .terminal .TerminalBuilder ;
10
13
import picocli .CommandLine ;
11
14
import picocli .CommandLine .Option ;
12
15
import picocli .CommandLine .Spec ;
13
16
import software .amazon .smithy .java .mcp .cli .ExecutionContext ;
14
17
import software .amazon .smithy .java .mcp .cli .SmithyMcpCommand ;
15
18
import software .amazon .smithy .java .mcp .cli .model .Config ;
16
19
import software .amazon .smithy .java .mcp .cli .model .GenericToolBundleConfig ;
20
+ import software .amazon .smithy .java .mcp .cli .model .McpBundleConfig ;
17
21
import software .amazon .smithy .java .mcp .cli .model .SmithyModeledBundleConfig ;
18
22
import software .amazon .smithy .mcp .bundle .api .Registry ;
19
23
@@ -38,25 +42,7 @@ protected void execute(ExecutionContext context) {
38
42
.string ("@|bold,underline Registry MCP Servers:|@" ));
39
43
System .out .println ();
40
44
41
- // Display registry bundles
42
- for (Registry .RegistryEntry entry : registry .listMcpBundles ()) {
43
- var bundle = entry .getBundleMetadata ();
44
- var installedBundle = installedBundles .get (bundle .getId ());
45
- //If there is a local bundle with the same name, prefer that.
46
- boolean isInstalled = installedBundle != null ;
47
- boolean hasLocalOverride = isInstalled && switch (installedBundle .getValue ()) {
48
- case SmithyModeledBundleConfig config -> config .isLocal ();
49
- case GenericToolBundleConfig config -> config .isLocal ();
50
- default -> false ;
51
- };
52
- String tag = null ;
53
- if (hasLocalOverride ) {
54
- tag = "locally-overriden" ;
55
- } else if (isInstalled ) {
56
- tag = "installed" ;
57
- }
58
- printBundleInfo (commandLine , bundle .getId (), bundle .getName (), bundle .getDescription (), tag );
59
- }
45
+ displayRegistryBundlesPaginated (registry , installedBundles , commandLine );
60
46
61
47
var localBundles = context .config ()
62
48
.getToolBundles ()
@@ -97,6 +83,46 @@ protected String registryToUse(Config config) {
97
83
return registryName ;
98
84
}
99
85
86
+ private void displayRegistryBundlesPaginated (
87
+ Registry registry ,
88
+ Map <String , McpBundleConfig > installedBundles ,
89
+ CommandLine commandLine
90
+ ) {
91
+ var registryIterator = registry .listMcpBundles ().iterator ();
92
+ int displayedCount = 0 ;
93
+ final int pageSize = 10 ;
94
+
95
+ while (registryIterator .hasNext ()) {
96
+ if (displayedCount > 0 && displayedCount % pageSize == 0 ) {
97
+ System .out .println ("Press down arrow for more..." );
98
+ if (!waitForDownArrow ()) {
99
+ break ;
100
+ }
101
+ }
102
+
103
+ var entry = registryIterator .next ();
104
+ var bundle = entry .getBundleMetadata ();
105
+ var installedBundle = installedBundles .get (bundle .getId ());
106
+
107
+ boolean isInstalled = installedBundle != null ;
108
+ boolean hasLocalOverride = isInstalled && switch (installedBundle .getValue ()) {
109
+ case SmithyModeledBundleConfig config -> config .isLocal ();
110
+ case GenericToolBundleConfig config -> config .isLocal ();
111
+ default -> false ;
112
+ };
113
+
114
+ String tag = null ;
115
+ if (hasLocalOverride ) {
116
+ tag = "locally-overriden" ;
117
+ } else if (isInstalled ) {
118
+ tag = "installed" ;
119
+ }
120
+
121
+ printBundleInfo (commandLine , bundle .getId (), bundle .getName (), bundle .getDescription (), tag );
122
+ displayedCount ++;
123
+ }
124
+ }
125
+
100
126
private void printBundleInfo (
101
127
CommandLine commandLine ,
102
128
String bundleId ,
@@ -116,4 +142,24 @@ private void printBundleInfo(
116
142
System .out .println (description );
117
143
System .out .println ();
118
144
}
145
+
146
+ private boolean waitForDownArrow () {
147
+ try (Terminal terminal = TerminalBuilder .builder ()
148
+ .system (true )
149
+ .build ()) {
150
+ terminal .enterRawMode ();
151
+ int ch = terminal .reader ().read ();
152
+
153
+ if (ch == 27 ) {
154
+ int bracket = terminal .reader ().read ();
155
+ if (bracket == 91 ) {
156
+ int arrow = terminal .reader ().read ();
157
+ return arrow == 66 ;
158
+ }
159
+ }
160
+ return false ;
161
+ } catch (Exception e ) {
162
+ return false ;
163
+ }
164
+ }
119
165
}
0 commit comments