Title: Un-deprecate/add no-arg builders · Issue #1065 · modelcontextprotocol/java-sdk · GitHub
Open Graph Title: Un-deprecate/add no-arg builders · Issue #1065 · modelcontextprotocol/java-sdk
X Title: Un-deprecate/add no-arg builders · Issue #1065 · modelcontextprotocol/java-sdk
Description: #928 deprecated no-arg builders for schema types, e.g. McpSchema.Resource I'd like you to consider reversing that decision, and also to add no-arg versions for types without them (e.g. ProgressNotification). I understand the motivation t...
Open Graph Description: #928 deprecated no-arg builders for schema types, e.g. McpSchema.Resource I'd like you to consider reversing that decision, and also to add no-arg versions for types without them (e.g. ProgressNoti...
X Description: #928 deprecated no-arg builders for schema types, e.g. McpSchema.Resource I'd like you to consider reversing that decision, and also to add no-arg versions for types without them (e.g. Progress...
Opengraph URL: https://github.com/modelcontextprotocol/java-sdk/issues/1065
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Un-deprecate/add no-arg builders","articleBody":"#928 deprecated no-arg builders for schema types, e.g. McpSchema.Resource\n\nI'd like you to consider reversing that decision, and also to add no-arg versions for types without them (e.g. ProgressNotification).\n\nI understand the motivation that builders not be left in an invalid state. It's worth noting that it might achieve that aim currently (I didn't audit all the classes), but if the schema ever has any fields which are mutually exclusive or conditionally required, then using constructors will only offer partial protection.\n\nThe problem is that it makes it undermines one of the main advantages of the builder pattern, which is to make construction clearer.\n\nHere was my attempt to write a CreateMessageRequest with only required properties:\n\n```java\nvar request = McpSchema.CreateMessageRequest.builder(\n List.of(McpSchema.SamplingMessage.builder(\n McpSchema.Role.USER,\n McpSchema.TextContent.builder(\"Test Sampling Message\").build()).build()\n ),\n 50\n )\n .build();\n```\n\nMaybe there's a better way to format/indent this, but I tried several variations and I thought this was the best one. \n\nCompare that with the same thing constructed with named properties\n\n```java\nvar request = McpSchema.CreateMessageRequest.builder()\n .messages(List.of(\n McpSchema.SamplingMessage.builder()\n .role(McpSchema.Role.USER)\n .content(McpSchema.TextContent.builder(\"Test Sampling Message\").build())\n .build()\n ))\n .maxTokens(50)\n .build();\n```\n\nIt's also worth noting that some builders have APIs like `ModelPreferences#addHint`. If that pattern were applied consistently, it could be simplified a little more by replacing `messages(List.of(` with `addMessage(`\n\n## Beyond readability\n\nI'm writing a framework and builders enforcing all required params at once makes them inflexible for some possible API designs. \n\nFor example, my framework automatically manages progress tokens. I considered a design such as\n\n```java\nvoid sendProgress(Consumer\u003cMcpSchema.ProgressNotification.Builder\u003e consumer);\n\n// an example caller. mcp creates the builder and applies the token\nmcp.sendProgress(p -\u003e p.progress(5).total(10));\n```\n\nHowever, it's not possible for the framework to implement this with the current builder methods. The user of the framework knows the progress value, the framework itself knows the progress token, but the builder expects both at once.\n\nSo the builder has to be worked around, for example to this\n\n```java\nvoid sendProgress(double progress, Consumer\u003cMcpSchema.ProgressNotification.Builder\u003e consumer);\n// an example caller\nmcp.sendProgress(5, p -\u003e p.total(10));\n```","author":{"url":"https://github.com/michaelboyles","@type":"Person","name":"michaelboyles"},"datePublished":"2026-07-18T02:11:26.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":0},"url":"https://github.com/1065/java-sdk/issues/1065"}
| 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:0a34feea-1961-2f09-5909-887b21076b7d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 82A6:35CFD7:43B7DC:5A896D:6A5ED4F6 |
| html-safe-nonce | d746606f42412b4dd6e34fb6e31e67e001cee4add21d2a20f0cc72245089d106 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MkE2OjM1Q0ZENzo0M0I3REM6NUE4OTZEOjZBNUVENEY2IiwidmlzaXRvcl9pZCI6IjkxMDA5OTgyNzk5NTg1NDk3NTAiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 4ffa22bc9b659c537d108fdb7f04e2162d4d4720cb942a52c8f8665dbb4fbf9e |
| hovercard-subject-tag | issue:4916216273 |
| 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/1065/issue_layout |
| twitter:image | https://opengraph.githubassets.com/c8ef24a24fb660445eeba967d371b74cbf6f8462370a669a0d9ff207b3c45495/modelcontextprotocol/java-sdk/issues/1065 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/c8ef24a24fb660445eeba967d371b74cbf6f8462370a669a0d9ff207b3c45495/modelcontextprotocol/java-sdk/issues/1065 |
| og:image:alt | #928 deprecated no-arg builders for schema types, e.g. McpSchema.Resource I'd like you to consider reversing that decision, and also to add no-arg versions for types without them (e.g. ProgressNoti... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | michaelboyles |
| hostname | github.com |
| expected-hostname | github.com |
| None | 82d0004a35927bdb00c652a57f456c55aa0eda4ade1bc7956d7510fdea6e454b |
| 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 | d2d913dd727d2d7ac189fb4d05b10bc34ecd03ee |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width