Migration note: `ResourceTemplate` from @modelcontextprotocol/server is the high-level class, not the spec type

未關閉 適合新手
#3,270 1 則留言 0 個 reaction 已指派 0 人 在 GitHub 檢視

維護者通常 1 天內回覆

還沒有人認領這個 Issue。

評估

難度
1/5
預估耗時
1 小時以內
新手友好度
72/100
Issue 類型
文件
描述清晰度
描述清楚
活躍度
活躍
技術堆疊
typescript
領域
documentation

研究方向

從遷移指南及其中關於資源範本的章節開始;issue 沒有指出檔案,因此請在儲存庫中找到該指南。說明協定型別現在名為 ResourceTemplateType,並將它與高階 ResourceTemplate 類別區分開。遷移指南清楚指出遷移後的程式碼應使用哪個名稱時,即為完成。

由索引模型根據 Issue 內容生成。

描述

v2

Package: @modelcontextprotocol/server 2.4.0
Compared with: @modelcontextprotocol/sdk 1.32.1 (types.js)

Summary

In 1.x, ResourceTemplate imported from @modelcontextprotocol/sdk/types.js was the protocol type ({ uriTemplate: string, name, … }), and the high-level class lived in server/mcp.js. In 2.x the root of @modelcontextprotocol/server exports both the protocol types and the high-level API, and ResourceTemplate there is the class (uriTemplate: UriTemplate); the protocol type is ResourceTemplateType. Code migrated by swapping @modelcontextprotocol/sdk/types.js for @modelcontextprotocol/server (or a library that re-exports the server's types) compiles against the class instead of the protocol type and fails in unrelated places.

Reproduction

import type { ResourceTemplate } from '@modelcontextprotocol/server';

export const listed: ResourceTemplate = { uriTemplate: 'file:///{path}', name: 'files' };

Expected

With 1.x's types.js this was the protocol type and compiled.

Actual

error TS2322: Type 'string' is not assignable to type 'UriTemplate'.

Suggestion

Mention the rename in the migration guide (ResourceTemplate → ResourceTemplateType for the protocol type), or export the protocol type under a name that doesn't collide with the class.

主要語言
TypeScript
星號
13.8k
分支
2.5k
平均合併
6 天 23 小時
30 天內合併 PR
2

環境準備

  • 沒有 Dockerfile 或 Docker Compose 檔案
  • 沒有 Pull Request 範本
  • 閱讀貢獻指南

從這裡開始

  1. 先讀完整個 Issue,再讀專案的貢獻指南。
  2. 在 Issue 下留言說明你要接手 —— 這能避免兩個人做同樣的事。
  3. Fork 儲存庫,在一個分支上完成修改。
  4. 送出 Pull Request,並在描述裡引用這個 Issue 編號。

modelcontextprotocol/typescript-sdk 的其他 Issue

查看 modelcontextprotocol/typescript-sdk 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 寄到你的電子郵件信箱

精選適合新手參與的 GitHub issue 摘要。