modelcontextprotocol / modelcontextprotocol/java-sdk

Allow disabling `structuredContent` duplication in McpAsyncServer

Abierto
#688 3 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

enhancement P2
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

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. 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

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.