Title: NullPointerException in completion handler when Prompt has null arguments · Issue #932 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: NullPointerException in completion handler when Prompt has null arguments · Issue #932 · modelcontextprotocol/java-sdk
X Title: NullPointerException in completion handler when Prompt has null arguments · Issue #932 · modelcontextprotocol/java-sdk
Description: Bug description The completion validation code in McpAsyncServer and McpStatelessAsyncServer throws a NullPointerException when a Prompt is registered with null arguments and a completion/complete request is received for that prompt. Thi...
Open Graph Description: Bug description The completion validation code in McpAsyncServer and McpStatelessAsyncServer throws a NullPointerException when a Prompt is registered with null arguments and a completion/complete ...
X Description: Bug description The completion validation code in McpAsyncServer and McpStatelessAsyncServer throws a NullPointerException when a Prompt is registered with null arguments and a completion/complete ...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/issues/932
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"NullPointerException in completion handler when Prompt has null arguments","articleBody":"Bug description\n\nThe completion validation code in `McpAsyncServer` and `McpStatelessAsyncServer` throws a `NullPointerException` when a `Prompt` is registered with `null` arguments and a `completion/complete` request is received for that prompt.\n\nThis was introduced in commit `4c85963` (#972, the 2.0 forward-compat refactor), which changed `Prompt` constructors to stop coercing `null` arguments to an empty list — but did not update the SDK's own completion handler code that calls `.arguments().stream()` without a null guard.\n\nAdditionally, `MIGRATION-2.0.md` references a `Prompt.withDefaults()` factory method as the migration path, but this method was never implemented.\n\n### Environment\n\n- MCP Java SDK: `main` branch, commit `4c85963`\n- Java: 17+\n- Transport: stdio (also affects servlet-based transports)\n\n### Steps to reproduce\n\n1. Create a server with a prompt that has null arguments:\n```java\nPrompt prompt = new Prompt(\"summarize\", \"Summarize a document\", (List\u003cPromptArgument\u003e) null);\n```\n2. Register a completion handler for that prompt\n3. Send a `completion/complete` request:\n```json\n{\"jsonrpc\":\"2.0\",\"id\":2,\"method\":\"completion/complete\",\"params\":{\"ref\":{\"type\":\"ref/prompt\",\"name\":\"summarize\"},\"argument\":{\"name\":\"query\",\"value\":\"sum\"}}}\n```\n\n### Expected behavior\n\nAn empty completion result or a proper error response.\n\n### Actual behavior\n\n```json\n{\"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\"}}\n```\n\n### Minimal Complete Reproducible example\nhttps://github.com/sainathreddyb/mcp-test-servers/tree/main/bug-repro-server\n\n### Root cause\n\n`McpAsyncServer.java` ~line 1002 and `McpStatelessAsyncServer.java` ~line 747:\n```java\nif (!promptSpec.prompt()\n .arguments() // returns null since 2.0\n .stream() // NPE\n ...\n```\n\n### Fix\n- Add null guard before `.stream()` in both server classes\n- Implement the `Prompt.withDefaults()` factory referenced in `MIGRATION-2.0.md`\n---","author":{"url":"https://github.com/sainathreddyb","@type":"Person","name":"sainathreddyb"},"datePublished":"2026-04-23T23:22:17.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/932/java-sdk/issues/932"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:4b21a663-d371-572a-ec14-95e9a4b604db |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D164:12E7FC:1353DF6:19933E7:6A5BD6F9 |
| html-safe-nonce | 3129671f85746043977bd4de41a96782963c1631a90fc6496712a98c7d084715 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMTY0OjEyRTdGQzoxMzUzREY2OjE5OTMzRTc6NkE1QkQ2RjkiLCJ2aXNpdG9yX2lkIjoiNzU5NTI5OTIzNDA4Mzc1NTc2OSIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | aa21f4a690caa1d374bb7d32986de35e718763d89f415fdfdad829d68fffd671 |
| hovercard-subject-tag | issue:4319437686 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/modelcontextprotocol/java-sdk/932/issue_layout |
| twitter:image | https://opengraph.githubassets.com/cfefc9168c4fac771d051f6e42ee80a87e9fd8d6cbf4beac5bf9deab60005bd2/modelcontextprotocol/java-sdk/issues/932 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/cfefc9168c4fac771d051f6e42ee80a87e9fd8d6cbf4beac5bf9deab60005bd2/modelcontextprotocol/java-sdk/issues/932 |
| og:image:alt | Bug description The completion validation code in McpAsyncServer and McpStatelessAsyncServer throws a NullPointerException when a Prompt is registered with null arguments and a completion/complete ... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sainathreddyb |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| go-import | github.com/modelcontextprotocol/java-sdk git https://github.com/modelcontextprotocol/java-sdk.git |
| octolytics-dimension-user_id | 182288589 |
| octolytics-dimension-user_login | modelcontextprotocol |
| octolytics-dimension-repository_id | 919609219 |
| octolytics-dimension-repository_nwo | modelcontextprotocol/java-sdk |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 919609219 |
| octolytics-dimension-repository_network_root_nwo | modelcontextprotocol/java-sdk |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 9c975978430e9ad293956f2bbdaf153b1bd84a99 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width