Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

[v2] Typescript: optional content when structuredContent is present

クローズ
#2,755 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

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

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
62/100
issue の種類
バグ
明瞭さ
おおむね明確
活発さ
活発
技術スタック
typescript
領域
api, backend

調査の方向性

server.registerTool のエントリポイントとツール結果の TypeScript 型から始め、structuredContent がどのように content にシリアライズされるかを追跡します。提供されている ping の再現コードを使って、structuredContent のみを含む結果が型チェックを通過することと、要求どおりにシリアライズ動作を制御できることを確認します。

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

説明

v2
What happened?

If I create a tool with a structuredContent but no content, I get a typescript error saying that the content field is mandatory. But this is stupid for two reasons:

  1. For now at least, it seems like the SDK will anyway add a content automatically if not present… So let me save time (and redundancy) by avoiding to explicitly add it myself.

  2. Worst, according to the spec:

    For backwards compatibility, a tool that returns structured content SHOULD also return the serialized JSON in a TextContent block.

    The verb SHOULD is used, and not MUST, which means that we don't strictly need to follow this rule if we don't want to be backward compatible.

What did you expect?

I'd expect typescript to allow tools to return no content but only a structuredContent. Moreover, we should add an option to say if the SDK should add itself a serialization of the structuredContent into content as this is done for now: I believe that it is a good thing to enable it by default as it is done now, but for efficiency reasons it would be great to disable content and only keep structuredContent (at least in v2) since this is allowed by the specification.

Code to reproduce
server.registerTool(
    'ping',
    {
      description: 'Returns a string pong with a timestamp',
      outputSchema: z.string()
    },
    async () => {
      const str = `Pong at ${new Date()}`
      return {
        // content: [{ type: 'text', text: str }], // Error without this line
        structuredContent: str
      };
    }
  );
SDK version

2.0.0

Area

Server

主要言語
TypeScript
スター
13.5k
フォーク
2.3k
平均マージ
1日 15時間
マージ済み PR(30日)
51

環境構築

はじめの一歩

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

modelcontextprotocol/typescript-sdk のほかの issue

modelcontextprotocol/typescript-sdk の issue をすべて見る

似ている issue

TypeScript の issue をもっと見る

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

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