modelcontextprotocol / modelcontextprotocol/java-sdk

Allow disabling `structuredContent` duplication in McpAsyncServer

Đang mở
#688 3 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

enhancement P2
Ngôn ngữ chính
Java
Star
3.7k
Fork
1.1k
Merge trung bình
1 ngày 15 giờ
Pull request đã merge (30 ngày)
9

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Hướng nghiên cứu

Bắt đầu bằng cách đọc McpAsyncServer.StructuredOutputCallToolHandler và điểm vào apply() của nó, tập trung vào nơi structuredContent được sao chép vào content. Xác định cơ chế cấu hình phù hợp và xác minh rằng người dùng có thể bật hoặc tắt việc nhân bản mà vẫn giữ nguyên hành vi mặc định hiện có.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Đánh giá

Công nghệ
java
Lĩnh vực
backend-api-design
Loại issue
Tính năng
Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức độ hoạt động
Đình trệ
Độ rõ ràng
Khá rõ ràng
Mức phù hợp với người mới
35/100

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.