Vino1016 opened a new issue, #578:
URL: https://github.com/apache/flink-agents/issues/578

   ### Search before asking
   
   - [x] I searched in the 
[issues](https://github.com/apache/flink-agents/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.
   
   <img width="647" height="204" alt="Image" 
src="https://github.com/user-attachments/assets/0e732225-9020-49fd-9e6b-d62fce680e0d";
 />
   
   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?
   
   - [x] I'm willing to submit a PR!


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to