modelcontextprotocol / modelcontextprotocol/java-sdk
Allow disabling `structuredContent` duplication in McpAsyncServer
Nadie ha tomado este issue todavía.
- Lenguaje dominante
- Java
- Estrellas
- 3.7k
- Forks
- 1.1k
- Merge medio
- 1 d 15 h
- PR fusionados (30 d)
- 9
Descripción
Expected Behavior
Make io.modelcontextprotocol.server.McpAsyncServer.StructuredOutputCallToolHandler configurable to allow users to decide whether they want to duplicate the structuredContent in the content property.
This configuration could be introduced via a bean or another appropriate mechanism.
A possible solution implementation might look like this:
@Override
public Mono<CallToolResult> apply(McpAsyncServerExchange exchange, McpSchema.CallToolRequest request) {
return this.delegateCallToolResult.apply(exchange, request).map(result -> {
// Skipping some code for brevity
if (Utils.isEmpty(result.content()) && keepCompatibility()) { // <-- HERE keepCompatibility() METHOD IS NEW
// For backwards compatibility, a tool that returns structured
// content SHOULD also return functionally equivalent unstructured
// content. (For example, serialized JSON can be returned in a
// TextContent block.)
// https://modelcontextprotocol.io/specification/2025-06-18/server/tools#structured-content
return CallToolResult.builder()
.content(List.of(new McpSchema.TextContent(validation.jsonStructuredOutput())))
.isError(result.isError())
.structuredContent(result.structuredContent())
.build();
}
return result;
});
}
private boolean keepCompatibility() {
// Provide a way for users to specify whether to keep compatibility or not
}
Current Behavior
Currently, StructuredOutputCallToolHandler always duplicates structuredContent into the content property. This behavior is not mandated by the MCP specification.
Context
MCP tool users may be dissatisfied receiving duplicate content because:
- It causes unnecessary network traffic.
- It reduces performance.
- Most importantly, it consumes unnecessary space in the LLM context window on the client side.
There is no current way to prevent StructuredOutputCallToolHandler#apply() from copying structuredContent into content because the StructuredOutputCallToolHandler class is private and cannot be extended or customized externally.
Guía de contribución
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Línea de trabajo
Comienza leyendo McpAsyncServer.StructuredOutputCallToolHandler y su punto de entrada apply(), centrándote en dónde se copia structuredContent en content. Determina el mecanismo de configuración adecuado y verifica que los usuarios puedan habilitar o deshabilitar la duplicación, preservando el comportamiento predeterminado existente.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- java
- Área
- backend-api-design
- Tipo de issue
- Nueva funcionalidad
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 35/100