[v2] Typescript: optional content when structuredContent is present
メンテナーはふだん 1 日以内に返信
まだ誰も着手していません。
評価
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 初心者へのやさしさ
- 62/100
- issue の種類
- バグ
- 明瞭さ
- おおむね明確
- 活発さ
- 活発
- 技術スタック
- typescript
調査の方向性
server.registerTool のエントリポイントとツール結果の TypeScript 型から始め、structuredContent がどのように content にシリアライズされるかを追跡します。提供されている ping の再現コードを使って、structuredContent のみを含む結果が型チェックを通過することと、要求どおりにシリアライズ動作を制御できることを確認します。
索引モデルが issue の本文から書いたものです。
説明
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:
-
For now at least, it seems like the SDK will anyway add a
contentautomatically if not present… So let me save time (and redundancy) by avoiding to explicitly add it myself. -
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
SHOULDis used, and notMUST, 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
環境構築
- Dockerfile・Docker Compose ファイルなし
- プルリクエストのテンプレートなし
- コントリビューションガイドを読む
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
modelcontextprotocol/typescript-sdk のほかの issue
-
Stateless 405 response omits the Allow header対応中かも @Hugo-DDT が今日担当しました。 オープンv2
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
modelcontextprotocol/typescript-sdk#2970 · コメント 2 件 ·
メンテナーはふだん 1 日以内に返信
-
[v2] @modelcontextprotocol/server inlines fast-uri 3.1.0, which has 9 published advisories対応中かも @Andiii208 が 2 日前に担当しました。 オープンv2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/typescript-sdk#2966 · コメント 3 件 ·
メンテナーはふだん 1 日以内に返信
-
v1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
modelcontextprotocol/typescript-sdk#2946 · コメント 4 件 ·
メンテナーはふだん 1 日以内に返信
-
[v2] URI template reserved expansions encode existing %HH sequences again対応中かも @takagibit18 が 9 日前に担当しました。 オープンv1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelcontextprotocol/typescript-sdk#2920 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
-
[v2] URI template strict expansions leave !'()* unencoded対応中かも @takagibit18 が 9 日前に担当しました。 オープンv1 v2
難易度 2/5 1〜3時間 初心者へのやさしさ 84/100
modelcontextprotocol/typescript-sdk#2919 · コメント 1 件 ·
メンテナーはふだん 1 日以内に返信
modelcontextprotocol/typescript-sdk の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
メンテナーはふだん 1 日以内に返信
-
難易度 1/5 1時間未満 初心者へのやさしさ 82/100
homarr-labs/dashboard-icons#2939 ·
メンテナーはふだん 1 日以内に返信
-
Agent/category reasoning variants are still checked against the stale model cache in chat.paramsオープンopencode
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
code-yeongyu/oh-my-openagent#10003 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
メンテナーはふだん 1 日以内に返信
-
Actions on Toastsオープン
難易度 2/5 1〜3時間 初心者へのやさしさ 65/100
nextcloud-libraries/nextcloud-dialogs#2669 ·
メンテナーはふだん 1 日以内に返信