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 摘要。