Skip to content

Commit 907f340

Browse files
authored
chore: config endpoint may return null for models/mcp servers in the future (#300)
1 parent 01486c8 commit 907f340

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

java-cfenv-boot-tanzu-genai/src/main/java/io/pivotal/cfenv/boot/genai/DefaultGenaiLocator.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,9 @@ public List<McpConnectivity> getMcpServers() {
231231

232232
private List<ModelConnectivity> getAllModelConnectivityDetails() {
233233
ConfigEndpoint e = getEndpointConfig();
234+
if (e.advertisedModels == null) {
235+
return List.of();
236+
}
234237
return e.advertisedModels
235238
.stream()
236239
.map( a ->
@@ -239,14 +242,24 @@ private List<ModelConnectivity> getAllModelConnectivityDetails() {
239242
a.capabilities(),
240243
a.labels(),
241244
apiKey,
242-
apiBase + e.wireFormat().toLowerCase())
245+
merge(apiBase, e.wireFormat().toLowerCase()))
243246
)
244247
.toList();
245248
}
246249

250+
private String merge(String apiBase, String wireFormat) {
251+
if (apiBase.endsWith("/")) {
252+
return apiBase + wireFormat;
253+
}
254+
return apiBase + "/" + wireFormat;
255+
}
256+
247257
private List<McpConnectivity> getAllMcpConnectivityDetails() {
248-
return getEndpointConfig()
249-
.advertisedMcpServers
258+
ConfigEndpoint e = getEndpointConfig();
259+
if (e.advertisedMcpServers == null) {
260+
return List.of();
261+
}
262+
return e.advertisedMcpServers
250263
.stream()
251264
.map(m -> new McpConnectivity(m.url()))
252265
.toList();

0 commit comments

Comments
 (0)