Tool result _meta is lost when the server automatically adds text content for structured output
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 2/5
- Thời gian dự kiến
- 1-3 giờ
- Mức phù hợp với người mới
- 72/100
Hướng nghiên cứu
Bắt đầu từ McpAsyncServer và McpStatelessAsyncServer, tại các nhánh Utils.isEmpty(result.content()) nơi phương án dự phòng văn bản dựng lại CallToolResult. Bước tái hiện là một bài kiểm thử JUnit 5 trong module mcp-test, package io.modelcontextprotocol.server, gọi handleRequest trên handler stateless. Hoàn thành khi bài kiểm thử đó pass, _meta được giữ lại sau khi dựng lại ở cả hai server, và các kiểm thử tích hợp SSE, Streamable HTTP và stateless hiện có vẫn pass.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug description
When a tool has an outputSchema and returns valid structuredContent with empty content, the SDK adds a text fallback but drops _meta when rebuilding the result.
Both McpAsyncServer and McpStatelessAsyncServer have this issue. Results with non-empty content keep their metadata.
Environment
- Java SDK:
2.2.0-SNAPSHOT, main atc531bb80 - Java: JDK 17.0.12
- Reproduced with the existing servlet integration tests
Steps to reproduce
-
Register a tool with an output schema:
{"type": "object"} -
Return structured content and metadata from the handler, without adding
text content:return CallToolResult.builder() .structuredContent(Map.of("value", 42)) .meta(Map.of("example.com/trace-id", "trace-123")) .build(); -
Call the tool from an MCP client and inspect the result.
Expected behavior
The generated text, structured content, and metadata are all present:
{
"content": [
{"type": "text", "text": "{\"value\":42}"}
],
"isError": false,
"structuredContent": {"value": 42},
"_meta": {"example.com/trace-id": "trace-123"}
}
Actual behavior
The generated text and structuredContent are present, but _meta is
missing. The Java client receives result.meta() == null.
Minimal Complete Reproducible example
Failing JUnit 5 test using Mockito, in the mcp-test module,
package io.modelcontextprotocol.server:
@Test
void structuredOutputTextFallbackPreservesMetadata() {
var transport = mock(McpStatelessServerTransport.class);
Map<String, Object> metadata = Map.of("example.com/trace-id", "trace-123");
var tool = McpSchema.Tool.builder("example", Map.of("type", "object"))
.outputSchema(Map.of("type", "object"))
.build();
McpServer.sync(transport)
.serverInfo("test-server", "1.0.0")
.toolCall(tool, (context, request) -> McpSchema.CallToolResult.builder()
.structuredContent(Map.of("value", 42))
.meta(metadata)
.build())
.build();
var handlerCaptor = ArgumentCaptor.forClass(McpStatelessServerHandler.class);
verify(transport).setMcpHandler(handlerCaptor.capture());
var response = handlerCaptor.getValue()
.handleRequest(McpTransportContext.EMPTY,
new McpSchema.JSONRPCRequest(McpSchema.METHOD_TOOLS_CALL, "1",
McpSchema.CallToolRequest.builder("example").build()))
.block(Duration.ofSeconds(5));
// Fails before the fix: actual metadata is null.
assertThat(((McpSchema.CallToolResult) response.result()).meta()).isEqualTo(metadata);
}
Proposed fix
In the Utils.isEmpty(result.content()) branches of both
McpAsyncServer and McpStatelessAsyncServer, preserve the metadata
when rebuilding the result:
return CallToolResult.builder()
.content(List.of(
McpSchema.TextContent.builder(validation.jsonStructuredOutput()).build()
))
.isError(result.isError())
.structuredContent(result.structuredContent())
.meta(result.meta())
.build();
Tested locally with the existing SSE, Streamable HTTP, and stateless HTTP integration tests.
I’d like to submit a fix with regression tests, Please let me
know if this approach looks good and whether I can take this on.
- Ngôn ngữ chính
- Java
- Star
- 3.8k
- Fork
- 1.1k
- Merge trung bình
- 1 ngày 3 giờ
- Pull request đã merge (30 ngày)
- 38
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của modelcontextprotocol/java-sdk
-
Modern `HttpServletMcpTransport` does not check `Mcp-Name` when `params.name` or `params.uri` is not a JSON stringCó thể đã có người làm @starryeye đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
modelcontextprotocol/java-sdk#1352 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Unknown tool error always says "Unknown tool: invalid_tool_name" instead of the name that was calledĐang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 85/100
modelcontextprotocol/java-sdk#1346 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100
modelcontextprotocol/java-sdk#1345 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Client request handlers that complete empty send no JSON-RPC responseCó thể đã có người làm @1fanwang đã nhận 83 ngày trước. Đang mởarea/client bug P2
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
modelcontextprotocol/java-sdk#1124 · 6 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
ServerCapabilities.logging is added unconditionally, overriding the caller's explicit capabilitiesCó thể đã có người làm @1yuxiangJ đã nhận 98 ngày trước. Đang mởbug P2 ready for work
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
modelcontextprotocol/java-sdk#1086 · 2 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của modelcontextprotocol/java-sdk
Issue tương tự
-
crash
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100
-
account bug course exam iris lecture
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 64/100