This is an automated email from the ASF dual-hosted git repository.
xtsong pushed a commit to branch release-0.2
in repository https://gitbox.apache.org/repos/asf/flink-agents.git
The following commit(s) were added to refs/heads/release-0.2 by this push:
new c0425a5e [hotfix][mcp] Skip listPrompts for MCP servers without prompt
support (#539)
c0425a5e is described below
commit c0425a5edcd4f5e7ee9fdaa2bf5db4e139bb673c
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 | 20 ++++++++++++++++++++
.../flink/agents/integrations/mcp/MCPServerTest.java | 11 +++++++++++
2 files changed, 31 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 64e71a32..c927bbd4 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
@@ -41,6 +41,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;
@@ -257,6 +258,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.
*
@@ -340,6 +356,10 @@ public class MCPServer extends Resource {
* @return List of MCPPrompt instances
*/
public List<MCPPrompt> listPrompts() {
+ if (!supportsPrompts()) {
+ return Collections.emptyList();
+ }
+
McpSyncClient mcpClient = getClient();
McpSchema.ListPromptsResult promptsResult = mcpClient.listPrompts();
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 5fe52bcc..37f0a491 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;
@@ -243,4 +244,14 @@ class MCPServerTest {
server.close();
server.close(); // Calling twice should be safe
}
+
+ @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();
+ }
}