modelcontextprotocol / modelcontextprotocol/java-sdk

Allow disabling `structuredContent` duplication in McpAsyncServer

オープン
#688 コメント 3 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

enhancement P2
主要言語
Java
スター
3.7k
フォーク
1.1k
平均マージ
1日 15時間
マージ済み PR(30日)
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.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

まず McpAsyncServer.StructuredOutputCallToolHandler とその apply() エントリーポイントを読み、structuredContent が content にコピーされる箇所に注目してください。適切な設定メカニズムを特定し、既存のデフォルト動作を維持したまま、ユーザーが重複を有効化または無効化できることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
java
領域
backend-api-design
issue の種類
機能追加
難易度
4/5
見積もり時間
3〜5日
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
35/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。