Un-deprecate/add no-arg builders
維護者通常 3 天內回覆
還沒有人認領這個 Issue。
評估
- 難度
- 5/5
- 預估耗時
- 一週以上
- 新手友好度
- 42/100
- Issue 類型
- 功能
- 描述清晰度
- 基本清楚
- 活躍度
- 冷清
- 技術堆疊
- java
研究方向
從這裡列出的 McpSchema builder 入口開始,包括 CreateMessageRequest、SamplingMessage、TextContent、ProgressNotification 和 ModelPreferences。比較需要引數和不需要引數的 API,然後檢查是否可以逐步提供 schema 值,包括由 framework 管理的進度 token;當 builder 方案在所要求的型別之間保持一致時,即表示完成。
由索引模型根據 Issue 內容生成。
描述
#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 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.
The problem is that it makes it undermines one of the main advantages of the builder pattern, which is to make construction clearer.
Here was my attempt to write a CreateMessageRequest with only required properties:
var request = McpSchema.CreateMessageRequest.builder(
List.of(McpSchema.SamplingMessage.builder(
McpSchema.Role.USER,
McpSchema.TextContent.builder("Test Sampling Message").build()).build()
),
50
)
.build();
Maybe there's a better way to format/indent this, but I tried several variations and I thought this was the best one.
Compare that with the same thing constructed with named properties
var request = McpSchema.CreateMessageRequest.builder()
.messages(List.of(
McpSchema.SamplingMessage.builder()
.role(McpSchema.Role.USER)
.content(McpSchema.TextContent.builder("Test Sampling Message").build())
.build()
))
.maxTokens(50)
.build();
It'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(
Beyond readability
I'm writing a framework and builders enforcing all required params at once makes them inflexible for some possible API designs.
For example, my framework automatically manages progress tokens. I considered a design such as
void sendProgress(Consumer<McpSchema.ProgressNotification.Builder> consumer);
// an example caller. mcp creates the builder and applies the token
mcp.sendProgress(p -> p.progress(5).total(10));
However, 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.
So the builder has to be worked around, for example to this
void sendProgress(double progress, Consumer<McpSchema.ProgressNotification.Builder> consumer);
// an example caller
mcp.sendProgress(5, p -> p.total(10));
- 主要語言
- Java
- 星號
- 3.7k
- 分支
- 1.1k
- 平均合併
- 2 天 5 小時
- 30 天內合併 PR
- 4
環境準備
- 沒有 Dockerfile 或 Docker Compose 檔案
- 沒有 Pull Request 範本
- 閱讀貢獻指南
從這裡開始
- 先讀完整個 Issue,再讀專案的貢獻指南。
- 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
- Fork 儲存庫,在一個分支上完成修改。
- 送出 Pull Request,並在描述裡引用這個 Issue 編號。
modelcontextprotocol/java-sdk 的其他 Issue
-
HttpServletStreamableServerTransportProvider: GET stream sends no status or headers until the first event可能已有人在做 @karthiksenv 於 1 天前認領。 未關閉
難度 2/5 1-3 小時 新手友好度 86/100
modelcontextprotocol/java-sdk#1155 ·
維護者通常 3 天內回覆
-
Client request handlers that complete empty send no JSON-RPC response可能已有人在做 @1fanwang 於 30 天前認領。 未關閉area/client bug P2
難度 2/5 1-3 小時 新手友好度 84/100
modelcontextprotocol/java-sdk#1124 · 5 則留言 ·
維護者通常 3 天內回覆
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities可能已有人在做 @1yuxiangJ 於 45 天前認領。 未關閉bug P2 ready for work
難度 2/5 1-3 小時 新手友好度 68/100
modelcontextprotocol/java-sdk#1086 · 1 則留言 ·
維護者通常 3 天內回覆
-
Reject listRoots if not supported by client, without sending any request可能已有人在做 @nikita-kibitkin 於 69 天前認領。 未關閉enhancement good first issue P3
難度 2/5 1-3 小時 新手友好度 82/100
modelcontextprotocol/java-sdk#1067 · 1 則留言 ·
維護者通常 3 天內回覆
-
StdioClientTransport missing explicit UTF-8 charset in InputStreamReader (same issue as #295, but on client side)可能已有人在做 @suryateja-g13 於 140 天前認領。 未關閉bug P2 ready for work
難度 2/5 1-3 小時 新手友好度 74/100
modelcontextprotocol/java-sdk#898 · 1 則留言 ·
維護者通常 3 天內回覆
查看 modelcontextprotocol/java-sdk 的全部 Issue
相似的 Issue
-
bug good first issue help wanted priority medium size S
難度 2/5 1-3 小時 新手友好度 84/100
martin-francois/symphony-trello#776 · 1 則留言 ·
維護者通常 1 天內回覆
-
Console.printHex未關閉good first issue kernel
難度 2/5 1-3 小時 新手友好度 88/100
JackFurton/who-would-build-a-kernel-in-java#33 · 2 則留言 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 78/100
objectionary/eo#9182 ·
維護者通常 1 天內回覆
-
難度 2/5 1-3 小時 新手友好度 88/100
objectionary/hone-maven-plugin#1293 ·
維護者通常 1 天內回覆
-
1.severity: security
難度 2/5 1-3 小時 新手友好度 62/100
NixOS/nixpkgs#569828 · 1 個 reaction ·
維護者通常 1 天內回覆