-
Notifications
You must be signed in to change notification settings - Fork 102
Description
Search before asking
- I searched in the issues and found nothing similar.
Description
Flink Agents Java MCP client crashes when deserializing prompt arguments if the required field is omitted by the MCP server.
According to the MCP specification, PromptArgument.required is optional (required?: boolean). MCP servers may omit it, in which case Jackson deserializes it as null.
In org.apache.flink.agents.integrations.mcp.MCPServer#listPrompts, Flink Agents unconditionally passes arg.required() to new MCPPrompt.PromptArgument(...). Later Boolean unboxing triggers a NullPointerException:
argumentsMap.put(arg.name(), new MCPPrompt.PromptArgument(arg.name(), arg.description(), arg.required()));
Impact: Any Java agent connecting to a standard MCP server that omits required (or is null) will fail to list prompts, crashing agent initialization. Tools-only MCP servers or any server returning optional arguments without required are affected.
Steps to Reproduce
Create a Java agent with @MCPSERVER pointing to an MCP server that returns prompts where required is omitted or null.
Run the agent.
Observe a NullPointerException during MCPServer#listPrompts.
Caused by: java.lang.NullPointerException: Cannot invoke "java.lang.Boolean.booleanValue()" because the return value of "io.modelcontextprotocol.spec.McpSchema$PromptArgument.required()" is null
at org.apache.flink.agents.integrations.mcp.MCPServer.listPrompts(MCPServer.java:354)
at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
How to reproduce
Create a Java agent with @MCPSERVER pointing to an MCP server that returns prompts where required is omitted or null.
Run the agent.
Observe a NullPointerException during MCPServer#listPrompts.
Expected behavior
The agent should treat null required values as false (optional), matching the MCP spec. Agent initialization should succeed, and prompts should be registered correctly.
Version and environment
Flink Agents: 0.2.0
Flink: 2.0.0
Java: 21
OS: macOS (also reproducible on Linux CI)
Are you willing to submit a PR?
- I'm willing to submit a PR!