modelcontextprotocol / modelcontextprotocol/java-sdk
Allow disabling `structuredContent` duplication in McpAsyncServer
Personne n'a encore pris cette issue.
- Langage dominant
- Java
- Étoiles
- 3.7k
- Forks
- 1.1k
- Merge moyen
- 1 j 15 h
- PR mergées (30 j)
- 9
Description
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.
Guide de contribution
Ouvrir le guide de contribution
Par où commencer
- Lisez l'issue en entier, puis le guide de contribution du projet.
- Signalez en commentaire que vous la prenez — cela évite que deux personnes fassent le même travail.
- Forkez le dépôt et travaillez sur une branche.
- Ouvrez une pull request qui référence le numéro de l'issue.
Piste de recherche
Commencez par lire McpAsyncServer.StructuredOutputCallToolHandler et son point d’entrée apply(), en vous concentrant sur l’endroit où structuredContent est copié dans content. Déterminez le mécanisme de configuration approprié et vérifiez que les utilisateurs peuvent activer ou désactiver la duplication tout en préservant le comportement par défaut existant.
Rédigé par le modèle d'indexation à partir du texte de l'issue.
Évaluation
- Stack technique
- java
- Domaine
- backend-api-design
- Type d'issue
- Fonctionnalité
- Difficulté
- 4/5
- Temps estimé
- 3-5 jours
- Activité
- À l'abandon
- Clarté
- Plutôt claire
- Accessibilité débutants
- 35/100