Skip to content

[FLINK-AGENTS] Fix Java agents failing to connect to MCP servers without prompt support (#538)#539

Open
avichaym wants to merge 1 commit intoapache:mainfrom
avichaym:fix/mcp-optional-prompts
Open

[FLINK-AGENTS] Fix Java agents failing to connect to MCP servers without prompt support (#538)#539
avichaym wants to merge 1 commit intoapache:mainfrom
avichaym:fix/mcp-optional-prompts

Conversation

@avichaym
Copy link

Linked issue: #538

What is the purpose of the change

Fix Java agents failing with McpError: Method not found when connecting to MCP servers that don't support prompts (e.g., AgentCore Gateway). PR #447 fixed the Python path (#412) but the Java path in AgentPlan.extractJavaMCPServer was not addressed.

Brief change log

  • Add MCPServer.supportsPrompts() — checks McpSyncClient.getServerCapabilities().prompts() != null
  • Guard listPrompts call in AgentPlan.extractJavaMCPServer with supportsPrompts() via reflection
  • Add unit test verifying supportsPrompts method exists and is reflection-callable

Does this pull request potentially affect one of the following parts

  • Runtime / Operators: no
  • Plan: yes (AgentPlan.extractJavaMCPServer)
  • Integrations / MCP: yes (MCPServer.supportsPrompts)

How was this patch tested?

  • Unit test: MCPServerTest.testSupportsPromptsMethodExists
  • End-to-end: Tested with Amazon Bedrock AgentCore Gateway (tools-only MCP server, capabilities.prompts=null). Agent plan creation succeeds, tools are discovered, Flink job completes successfully.

Documentation

  • doc-not-needed

@github-actions github-actions bot added priority/major Default priority of the PR or issue. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. doc-not-needed Your PR changes do not impact docs labels Feb 14, 2026
Copy link
Contributor

@xintongsong xintongsong left a comment

Choose a reason for hiding this comment

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

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)) {
Copy link
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Collaborator

Choose a reason for hiding this comment

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

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?

+1

Copy link
Author

Choose a reason for hiding this comment

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

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);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Author

Choose a reason for hiding this comment

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

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.

@xintongsong xintongsong added the fixVersion/0.2.1 The feature or bug should be implemented/fixed in the 0.2.1 version. label Feb 24, 2026
@avichaym avichaym force-pushed the fix/mcp-optional-prompts branch from e286a0f to 62d30d6 Compare March 2, 2026 12:40
- 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)
@avichaym avichaym force-pushed the fix/mcp-optional-prompts branch from 62d30d6 to 3fafcb4 Compare March 2, 2026 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-not-needed Your PR changes do not impact docs fixVersion/0.2.1 The feature or bug should be implemented/fixed in the 0.2.1 version. fixVersion/0.3.0 The feature or bug should be implemented/fixed in the 0.3.0 version. priority/major Default priority of the PR or issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants