[FLINK-AGENTS] Fix Java agents failing to connect to MCP servers without prompt support (#538)#539
[FLINK-AGENTS] Fix Java agents failing to connect to MCP servers without prompt support (#538)#539avichaym wants to merge 1 commit intoapache:mainfrom
Conversation
xintongsong
left a comment
There was a problem hiding this comment.
Nice catch, @avichaym, and thanks for the contribution. I left a few comments. PTAL
| // Call listPrompts() only if the server supports prompts (optional per MCP spec). | ||
| // MCP servers like AgentCore Gateway only support tools, not prompts. | ||
| Method supportsPromptsMethod = mcpServer.getClass().getMethod("supportsPrompts"); | ||
| if ((boolean) supportsPromptsMethod.invoke(mcpServer)) { |
There was a problem hiding this comment.
I think it might be better to check supportsPrompts inside listPrompts, so that listPrompts returns an empty list rather than fail when the server doesn't support prompts. AgentPlan doesn't need to be aware of this complexity.
WDYT?
There was a problem hiding this comment.
I think it might be better to check
supportsPromptsinsidelistPrompts, so thatlistPromptsreturns an empty list rather than fail when the server doesn't support prompts.AgentPlandoesn't need to be aware of this complexity.WDYT?
+1
There was a problem hiding this comment.
Done. Moved the supportsPrompts check inside MCPServer.listPrompts() — it returns an empty list when the server has no prompt capability. AgentPlan calls listPrompts() unconditionally and doesn't need
to be aware of prompt support.
| java.lang.reflect.Method method = server.getClass().getMethod("supportsPrompts"); | ||
| assertThat(method).isNotNull(); | ||
| assertThat(method.getReturnType()).isEqualTo(boolean.class); | ||
| } |
There was a problem hiding this comment.
This test case just verifies a method exist and can be called via reflection. It seems a bit unnecessary.
I think what we need to verify is that, when the mcp server does not support prompts, the framework should not fail. This would become easier if we move the supportsPrompt check into listPrompts, as we just need to verify the behavior of MCPServer, without having to involve AgentPlan for the test.
There was a problem hiding this comment.
Replaced with testListPromptsReturnsEmptyWhenNotSupported — calls listPrompts() on a server without prompt support and verifies it returns an empty list without throwing. Tests the actual behavior
rather than checking a method exists via reflection.
e286a0f to
62d30d6
Compare
- Move supportsPrompts check inside MCPServer.listPrompts() so it returns an empty list when the server has no prompt capability - AgentPlan no longer needs to be aware of prompt support — it just calls listPrompts() which handles it internally - Fixes Java agents failing with McpError: Method not found when connecting to MCP servers that only support tools (e.g. AgentCore Gateway)
62d30d6 to
3fafcb4
Compare
Linked issue: #538
What is the purpose of the change
Fix Java agents failing with
McpError: Method not foundwhen connecting to MCP servers that don't support prompts (e.g., AgentCore Gateway). PR #447 fixed the Python path (#412) but the Java path inAgentPlan.extractJavaMCPServerwas not addressed.Brief change log
MCPServer.supportsPrompts()— checksMcpSyncClient.getServerCapabilities().prompts() != nulllistPromptscall inAgentPlan.extractJavaMCPServerwithsupportsPrompts()via reflectionsupportsPromptsmethod exists and is reflection-callableDoes this pull request potentially affect one of the following parts
How was this patch tested?
MCPServerTest.testSupportsPromptsMethodExistscapabilities.prompts=null). Agent plan creation succeeds, tools are discovered, Flink job completes successfully.Documentation
doc-not-needed