This is an automated email from the ASF dual-hosted git repository.
xtsong pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/flink-agents.git
The following commit(s) were added to refs/heads/main by this push:
new eed00ce6 [hotfix][mcp] Skip listPrompts for MCP servers without prompt
support (#539)
eed00ce6 is described below
commit eed00ce6d4f6cd245ad5a98f32818a2068daec77
Author: Avichay Marciano <[email protected]>
AuthorDate: Wed Mar 4 09:11:50 2026 +0200
[hotfix][mcp] Skip listPrompts for MCP servers without prompt support (#539)
---
.../flink/agents/integrations/mcp/MCPServer.java | 19 +++++++++++++++++++
.../flink/agents/integrations/mcp/MCPServerTest.java | 11 +++++++++++
2 files changed, 30 insertions(+)
diff --git
a/integrations/mcp/src/main/java/org/apache/flink/agents/integrations/mcp/MCPServer.java
b/integrations/mcp/src/main/java/org/apache/flink/agents/integrations/mcp/MCPServer.java
index faa03411..ea3eb01e 100644
---
a/integrations/mcp/src/main/java/org/apache/flink/agents/integrations/mcp/MCPServer.java
+++
b/integrations/mcp/src/main/java/org/apache/flink/agents/integrations/mcp/MCPServer.java
@@ -42,6 +42,7 @@ import java.net.URI;
import java.net.http.HttpRequest;
import java.time.Duration;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@@ -360,6 +361,21 @@ public class MCPServer extends Resource {
}
}
+ /**
+ * Check if the MCP server supports prompts based on its declared
capabilities.
+ *
+ * @return true if the server declared prompt capabilities during
initialization
+ */
+ public boolean supportsPrompts() {
+ try {
+ McpSyncClient mcpClient = getClient();
+ McpSchema.ServerCapabilities caps =
mcpClient.getServerCapabilities();
+ return caps != null && caps.prompts() != null;
+ } catch (Exception e) {
+ return false;
+ }
+ }
+
/**
* List available tools from the MCP server.
*
@@ -456,6 +472,9 @@ public class MCPServer extends Resource {
* @return List of MCPPrompt instances
*/
public List<MCPPrompt> listPrompts() {
+ if (!supportsPrompts()) {
+ return Collections.emptyList();
+ }
return getRetryExecutor()
.execute(
() -> {
diff --git
a/integrations/mcp/src/test/java/org/apache/flink/agents/integrations/mcp/MCPServerTest.java
b/integrations/mcp/src/test/java/org/apache/flink/agents/integrations/mcp/MCPServerTest.java
index 85300386..6ae3a23e 100644
---
a/integrations/mcp/src/test/java/org/apache/flink/agents/integrations/mcp/MCPServerTest.java
+++
b/integrations/mcp/src/test/java/org/apache/flink/agents/integrations/mcp/MCPServerTest.java
@@ -30,6 +30,7 @@ import org.junit.jupiter.api.condition.JRE;
import java.time.Duration;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import static
com.fasterxml.jackson.databind.DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES;
@@ -270,4 +271,14 @@ class MCPServerTest {
assertThat(server.getInitialBackoffMs()).isEqualTo(200);
assertThat(server.getMaxBackoffMs()).isEqualTo(5000);
}
+
+ @Test
+ @DisabledOnJre(JRE.JAVA_11)
+ @DisplayName("listPrompts returns empty list when server does not support
prompts")
+ void testListPromptsReturnsEmptyWhenNotSupported() {
+ MCPServer server = MCPServer.builder(DEFAULT_ENDPOINT).build();
+
+ List<MCPPrompt> prompts = server.listPrompts();
+ assertThat(prompts).isEmpty();
+ }
}