Minimal stdio MCP server that reproduces a NullPointerException in the MCP Java SDK's completion handler.
When a Prompt is registered with null arguments and a completion/complete request arrives for that prompt, the server crashes with a NullPointerException because McpAsyncServer.completionCompleteRequestHandler calls prompt.arguments().stream() without a null guard.
Location: McpAsyncServer.java, in the completionCompleteRequestHandler lambda — the line that does:
promptSpec.prompt().arguments().stream()
.filter(arg -> arg.name().equals(argumentName))
.findFirst()When prompt.arguments() returns null, calling .stream() on it throws NullPointerException.
cd bug-repro-server
mvn packageRequires the MCP Java SDK 2.0.0-SNAPSHOT installed in your local Maven repo (~/.m2).
Run the server:
java -jar target/bug-repro-server-1.0-SNAPSHOT.jarThen send these three JSON-RPC messages to stdin (one per line):
1. Initialize:
{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{"roots":{"listChanged":true}},"clientInfo":{"name":"test","version":"1.0"}}}2. Initialized notification:
{"jsonrpc":"2.0","method":"notifications/initialized"}3. Completion request (triggers the bug):
{"jsonrpc":"2.0","id":2,"method":"completion/complete","params":{"ref":{"type":"ref/prompt","name":"summarize"},"argument":{"name":"query","value":"sum"}}}echo '{"jsonrpc":"2.0","id":1,"method":"initialize","params":{"protocolVersion":"2025-06-18","capabilities":{"roots":{"listChanged":true}},"clientInfo":{"name":"test","version":"1.0"}}}
{"jsonrpc":"2.0","method":"notifications/initialized"}
{"jsonrpc":"2.0","id":2,"method":"completion/complete","params":{"ref":{"type":"ref/prompt","name":"summarize"},"argument":{"name":"query","value":"sum"}}}' | java -jar target/bug-repro-server-1.0-SNAPSHOT.jarA proper error response or empty completion result.
The server returns an internal error with the NPE:
{
"jsonrpc": "2.0",
"id": 2,
"error": {
"code": -32603,
"message": "Cannot invoke \"java.util.List.stream()\" because the return value of \"io.modelcontextprotocol.spec.McpSchema$Prompt.arguments()\" is null",
"data": "NullPointerException: Cannot invoke \"java.util.List.stream()\" because the return value of \"io.modelcontextprotocol.spec.McpSchema$Prompt.arguments()\" is null"
}
}The SDK should add a null guard before streaming prompt arguments. Something like:
List<PromptArgument> args = promptSpec.prompt().arguments();
if (args == null || args.stream().noneMatch(arg -> arg.name().equals(argumentName))) {
logger.warn("Argument not found: {} in prompt: {}", argumentName, promptRef.name());
return EMPTY_COMPLETION_RESULT;
}