modelcontextprotocol / modelcontextprotocol/java-sdk
Allow disabling `structuredContent` duplication in McpAsyncServer
还没有人认领这个 Issue。
- 主要语言
- Java
- 星标
- 3.7k
- 派生
- 1.1k
- 平均合并
- 1 天 15 小时
- 30 天内合并 PR
- 9
描述
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.
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
调研方向
首先阅读 McpAsyncServer.StructuredOutputCallToolHandler 及其 apply() 入口点,重点关注 structuredContent 被复制到 content 的位置。确定适当的配置机制,并验证用户可以启用或禁用重复,同时保留现有的默认行为。
由索引模型根据 Issue 内容生成。
评估
- 技术栈
- java
- 领域
- backend-api-design
- Issue 类型
- 功能
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 活跃度
- 停滞
- 描述清晰度
- 基本清楚
- 新手友好度
- 35/100