Un-deprecate/add no-arg builders
Ninguém assumiu esta issue ainda.
Avaliação
- Dificuldade
- 5/5
- Tempo estimado
- Mais de uma semana
- Facilidade para iniciantes
- 42/100
- Tipo de issue
- Funcionalidade
- Clareza
- Razoavelmente clara
- Status de atividade
- Pouca atividade
- Stack de tecnologia
- java
- Domínio
- api, backend-api-design
Direção de pesquisa
Comece pelos pontos de entrada do builder de McpSchema nomeados aqui, incluindo CreateMessageRequest, SamplingMessage, TextContent, ProgressNotification e ModelPreferences. Compare as APIs com argumentos obrigatórios e sem argumentos e, em seguida, verifique se os valores do schema podem ser fornecidos incrementalmente, incluindo tokens de progresso gerenciados pelo framework; está concluído quando a abordagem do builder for consistente entre os tipos solicitados.
Escrita pelo modelo de indexação a partir do texto da issue.
Descrição
#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));
- Linguagem predominante
- Java
- Estrelas
- 3.7k
- Forks
- 1.1k
- Merge médio
- 1d 15h
- PRs com merge (30d)
- 9
Guia de contribuição
Primeiros passos
- Leia a issue inteira e depois o guia de contribuição do projeto.
- Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
- Faça um fork do repositório e trabalhe em uma branch.
- Abra um pull request que referencie o número da issue.
Mais de modelcontextprotocol/java-sdk
-
area/transport bug P2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 88/100
modelcontextprotocol/java-sdk#1136 ·
-
area/client bug P2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 84/100
modelcontextprotocol/java-sdk#1124 · 1 comentário ·
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilities Abertabug P2 ready for work
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 68/100
modelcontextprotocol/java-sdk#1086 · 1 comentário ·
-
enhancement good first issue P3
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 82/100
modelcontextprotocol/java-sdk#1067 ·
-
bug P2 ready for work
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 74/100
modelcontextprotocol/java-sdk#898 · 1 comentário ·
Todas as issues de modelcontextprotocol/java-sdk
Issues semelhantes
-
Bug Java Platform: Java
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
getsentry/sentry-java#6138 · 1 comentário ·
-
bug needs triage p2
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
GoogleCloudPlatform/DataflowTemplates#4273 · 1 comentário ·
-
[Studio][Bug] Bulk-deleting a full page of alert rules steps the page back while more rules remain Aberta
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
apache/rocketmq-dashboard#4654 · 1 comentário ·
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 78/100
-
Dificuldade 2/5 1-3 horas Facilidade para iniciantes 76/100