Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,23 @@ private JsonRpcResponse handleInitialize(JsonRpcRequest req) {
}

private JsonRpcResponse handlePromptsList(JsonRpcRequest req) {
var allPrompts = new ArrayList<>(prompts.values().stream().map(Prompt::promptInfo).toList());

// Add prompts from proxy servers
for (McpServerProxy proxy : proxies.values()) {
try {
var response = proxy.rpc(req).join();
if (response.getError() == null) {
var proxyPrompts = response.getResult().asShape(ListPromptsResult.builder()).getPrompts();
allPrompts.addAll(proxyPrompts);
}
} catch (Exception e) {
LOG.error("Failed to fetch prompts from proxy: " + proxy.name(), e);
}
Comment on lines +233 to +235
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should not silently swallow. Don't do anything, if there is an exception let it bubble up.

}

var result = ListPromptsResult.builder()
.prompts(prompts.values().stream().map(Prompt::promptInfo).toList())
.prompts(allPrompts)
.build();
return createSuccessResponse(req.getId(), result);
}
Expand All @@ -232,12 +247,24 @@ private JsonRpcResponse handlePromptsGet(JsonRpcRequest req) {

var prompt = prompts.get(normalize(promptName));

if (prompt == null) {
throw new RuntimeException("Prompt not found: " + promptName);
if (prompt != null) {
var result = promptProcessor.buildPromptResult(prompt, promptArguments);
return createSuccessResponse(req.getId(), result);
}

var result = promptProcessor.buildPromptResult(prompt, promptArguments);
return createSuccessResponse(req.getId(), result);
// Try proxy servers
for (McpServerProxy proxy : proxies.values()) {
try {
var response = proxy.rpc(req).join();
if (response.getError() == null) {
return createSuccessResponse(req.getId(), response.getResult());
}
} catch (Exception e) {
LOG.error("Failed to get prompt from proxy: " + proxy.name(), e);
}
}

throw new RuntimeException("Prompt not found: " + promptName);
Comment on lines +256 to +267
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why try again from the Proxy? This goes against the MCP spec too, if a prompt wasn't broadcasted as a part of list/prompts then it should not be returned.

}

private JsonRpcResponse handleToolsList(JsonRpcRequest req, ProtocolVersion protocolVersion) {
Expand Down