Title: fix: guard against null Prompt.arguments() in completion handlers by sainathreddyb · Pull Request #933 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: fix: guard against null Prompt.arguments() in completion handlers by sainathreddyb · Pull Request #933 · modelcontextprotocol/java-sdk
X Title: fix: guard against null Prompt.arguments() in completion handlers by sainathreddyb · Pull Request #933 · modelcontextprotocol/java-sdk
Description: Fixes #932 The 2.0 forward-compat refactor (#972) changed Prompt constructors to stop coercing null arguments to an empty list, but the completion validation code in McpAsyncServer and McpStatelessAsyncServer still called .arguments().stream() without a null guard, causing a NullPointerException when a Prompt with null arguments receives a completion/complete request. Additionally, MIGRATION-2.0.md references Prompt.withDefaults() as the migration path, but this factory method was never implemented. This commit: Adds a null check before .arguments().stream() in both McpAsyncServer and McpStatelessAsyncServer Adds Prompt.withDefaults(name, description, arguments) factory that coerces null to an empty list, matching the 1.x behaviour Motivation and Context After #972 merged, any MCP server that registers a Prompt with null arguments and a completion handler will crash with a NullPointerException when a completion/complete request arrives. This is the SDK's own internal code failing to handle the null-semantics change it introduced — not a user error. How Has This Been Tested? Reproduced the bug with a standalone stdio MCP server that registers a prompt with null arguments and sends a completion/complete request — confirmed the NPE Applied the fix and verified the server returns an empty completion result instead of crashing All existing tests pass (./mvnw clean test) Breaking Changes None. This is a bugfix that makes the SDK more tolerant. Types of changes Bug fix (non-breaking change which fixes an issue) New feature (non-breaking change which adds functionality) Breaking change (fix or feature that would cause existing functionality to change) Documentation update Checklist I have read the [MCP Documentation](https://modelcontextprotocol.io) My code follows the repository's style guidelines New and existing tests pass locally I have added appropriate error handling I have added or updated documentation as needed Additional context The Prompt.withDefaults() factory was documented in MIGRATION-2.0.md as the recommended migration path but never implemented. This PR adds it so the migration guide is accurate.
Open Graph Description: Fixes #932 The 2.0 forward-compat refactor (#972) changed Prompt constructors to stop coercing null arguments to an empty list, but the completion validation code in McpAsyncServer and McpStateless...
X Description: Fixes #932 The 2.0 forward-compat refactor (#972) changed Prompt constructors to stop coercing null arguments to an empty list, but the completion validation code in McpAsyncServer and McpStateless...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/pull/933
X: @github
Domain: github.com
| route-pattern | /:user_id/:repository/pull/:id/files(.:format) |
| route-controller | pull_requests |
| route-action | files |
| fetch-nonce | v2:31692fb7-72f8-3936-89ca-a3af9ba75679 |
| current-catalog-service-hash | ae870bc5e265a340912cde392f23dad3671a0a881730ffdadd82f2f57d81641b |
| request-id | C0A4:13C9B5:A2CA47:D90ED6:6A5B5D6D |
| html-safe-nonce | eb04b4a837a6a2405f2426a33ea86db3a4d68eabd1e692d2b4162852b3b4d1ec |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJDMEE0OjEzQzlCNTpBMkNBNDc6RDkwRUQ2OjZBNUI1RDZEIiwidmlzaXRvcl9pZCI6IjQ0NTUxNTczNzE2MjgxMTczNTciLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 46529e4027e034fa9643ec1a137348128ca16cd6d13f06383c32cd61161681d0 |
| hovercard-subject-tag | pull_request:3576131362 |
| github-keyboard-shortcuts | repository,pull-request-list,pull-request-conversation,pull-request-files-changed,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/modelcontextprotocol/java-sdk/pull/933/files |
| twitter:image | https://avatars.githubusercontent.com/u/39425617?s=400&v=4 |
| twitter:card | summary_large_image |
| og:image | https://avatars.githubusercontent.com/u/39425617?s=400&v=4 |
| og:image:alt | Fixes #932 The 2.0 forward-compat refactor (#972) changed Prompt constructors to stop coercing null arguments to an empty list, but the completion validation code in McpAsyncServer and McpStateless... |
| og:site_name | GitHub |
| og:type | object |
| hostname | github.com |
| expected-hostname | github.com |
| None | 5290d7e14309ad1e76106a9c4237bd1041517e83ea182c8ab756752cb0c6940b |
| turbo-cache-control | no-preview |
| diff-view | unified |
| 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 full-width |
| disable-turbo | true |
| 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