v2 拆成 @modelcontextprotocol/server 和 @modelcontextprotocol/client,旧包名 @modelcontextprotocol/sdk 属于 v1.x 分支;使用 Express、Fastify、Hono 集成时需额外安装对应框架和中间件包;schema 需自备 Zod v4 等兼容 Standard Schema 的库
typescript-sdk
modelcontextprotocol活跃维护Model Context Protocol 官方 TypeScript SDK,用来快速搭建 MCP 服务端和客户端,让大模型应用以统一协议接入外部工具与数据源。
The official TypeScript SDK for Model Context Protocol servers and clients
npm install @modelcontextprotocol/server
npm install @modelcontextprotocol/clientREADME 未说明,仅要求 Node.js、Bun 或 Deno 运行时
MCP 官方 TypeScript SDK,用统一协议把工具和上下文接给 LLM
Model Context Protocol 官方 TypeScript SDK,用来快速搭建 MCP 服务端和客户端,让大模型应用以统一协议接入外部工具与数据源。
核心能力
- 提供 server 与 client 两套库,实现 MCP 规范
- 支持 stdio 与 Streamable HTTP 两种传输方式
- 内置 OAuth 与认证辅助工具
- 工具和提示词 schema 兼容 Zod v4、Valibot、ArkType
- 提供 Express、Fastify、Hono、Node HTTP 中间件适配包
容易踩的坑
- v2.4.02.4.0最新正式版2026-10-23 · 2026-10-23 18:32 UTC
Package Version @modelcontextprotocol/client2.4.0 @modelcontextprotocol/server2.4.0 @modelcontextprotocol/core2.4.0 @modelcontextprotocol/server-legacy2.4.0 @modelcontextprotocol/codemod2.4.0 @modelcontextprotocol/node2.1.2 @modelcontextprotocol/express,hono,fastifyunchanged Upgrade notes
x-mcp-headeron anumberparameter is rejected, as the 2026-07-28 spec requires: the client does not list such a tool, and the server answers a call to it with-32020. Usez.int()or remove the annotation. (#2762, #2960)outputSchemafromz.object(...).meta({ id }). On a 2025-11-25 connection the result is no longer wrapped in{ result }: readstructuredContent, notstructuredContent.result. (#3081)- The bundled Ajv validator uses fast-uri 3.1.8. It rejects a
$idor$refwith an invalid URI scheme, such asmy_tool:output. (#3083)
New
- Skills over MCP (SEP-2640). A server publishes a folder of skills with
loadSkills(folder)andskills.attach(server); a client lists, reads and verifies them withSkillsClient. It works on 2025-11-25 and 2026-07-28.attachis experimental and may change in a minor release. (#3047, #3080) - Opt-in
scopeon token refresh. ImplementscopeForRefresh(tokens)on yourOAuthClientProviderfor an authorization server that rejects a refresh withoutscope(Microsoft Entra ID,AADSTS90009). The default request does not change. (#3085) ServerEventtakes optionalparams, so a gateway can forward change notifications with their_meta. (#3057)- The v1 to v2 upgrade guide is also an installable agent skill. (#2968)
Fixes
update({ title })on a resource or resource template shows up in list responses. (#3005)- A
Serverconnected to a per-request transport at a modern revision binds that revision instead of answering-32022. (#3057) createMcpHandlersendsAllow: POSTon every405. (#3002)@modelcontextprotocol/nodeaccepts@hono/node-server1.x or 2.x; a new install resolves 2.x. (#3084)
- @modelcontextprotocol/[email protected]2026-10-23 · 2026-10-23 18:19 UTC
查看更新说明
Patch Changes
- Updated dependencies [
46d9c99]:- @modelcontextprotocol/[email protected]
- Updated dependencies [
- @modelcontextprotocol/[email protected]2026-10-23 · 2026-10-23 18:19 UTC
查看更新说明
Minor Changes
-
#3057
c05225aThanks @steipete! -ServerEventtakes optionalparams, which thesubscriptions/listenrouter delivers with its own subscription ID, so a gateway can forward change notifications with their_metaand extension params. -
#3047
46d9c99Thanks @KKonstantinov, @tobi-oye, @mattzcarey! - Add the Skills extension (SEP-2640), reachable through newext/skillssubpaths; package root exports are unchanged.@modelcontextprotocol/server/ext/skills:SkillsExtension(attach(server)servesskills/list,skills/get,resources/directory/readand askill://{+path}resource template),SkillsExtension.load(files)returning aSkillCatalogwithentriesandreload(), theSkillFilesstorage adapter withmemorySkillFiles,SkillSourcefor generated catalogs,skillEntry, andSkillCatalogError. Invalid skills are skipped with a warning (onWarning), or fail understrict. A file whose bytes are valid UTF-8 is served astext, whatever its MIME type; any other file as a base64blob.@modelcontextprotocol/server/ext/skills/node:loadSkills(folder)andnodeSkillFiles(folder).@modelcontextprotocol/client/ext/skills:SkillsClientwithlist()(throws on an invalid entry;skipInvalid: truekeeps the valid ones and returns the rest ininvalid),get(),read(skill, path?)(size, digest andSKILL.mdfrontmatter verified,SkillVerificationErroron a mismatch; a copy from the response cache that fails a check is fetched once more withcacheMode: 'refresh'first) andreadDirectory().@modelcontextprotocol/core/ext/skills: schemas, types and constants, includingSKILL_LIMITS. The result schemas follow the stable spec, sottlMsandcacheScopeare required.
SkillsExtension.attachis@experimental: how an extension is wired to a server may change in a minor release. The rest of the Skills API is stable.Works on 2025-11-25 and 2026-07-28. On 2026-07-28 only, the server sends the caching fields (
ttlMs,cacheScope), andSkillsClientrequires them and returns them fromlist(),get()andreadDirectory().
Patch Changes
-
#3083
ef38c67Thanks @claude! - The bundled Ajv validator is now built with fast-uri 3.1.8 (was 3.1.0). fast-uri 3.1.6 and later reject a$idor$refwhose text before the first colon is not a valid URI scheme (my_tool:output), or whose URN namespace is not valid (urn:my_tool:output): a schema that uses one no longer compiles, and a tool that carries it fails with an invalid-schema error. An underscore without a colon (my_tool_output) and a$refinto#/$defs/...or#/definitions/...are not affected. -
#2960
43c45f4Thanks @claude! - A server whose tool putsx-mcp-headeron anumber-typed parameter keeps checking that tool'sMcp-Param-*headers ontools/call, as 2.3.0 does: a header that is missing for a value in the body, or that disagrees with the body, is answered400with JSON-RPC error-32020. Clients on a 2026-07-28 connection other than stdio no longer list such a tool
-
- @modelcontextprotocol/[email protected]2026-10-23 · 2026-10-23 18:19 UTC
查看更新说明
Patch Changes
-
#3084
10c26b0Thanks @claude! - The@hono/node-serverdependency range widens from^1.19.9to^1.19.9 || ^2.1.3, so a new install resolves to 2.x and an install that cannot get 2.x keeps 1.x. -
Updated dependencies [
ef38c67,c05225a,43c45f4,5820f79,c05225a,b381559,46d9c99,895007f,b022522]:- @modelcontextprotocol/[email protected]
-
- 1.32.22026-10-23 · 2026-10-23 18:06 UTC
查看更新说明
What's Changed
- fix: add explicit | undefined to Transport optional properties (v1.x backport of #1766) by @kishormorol in https://github.com/modelcontextprotocol/typescript-sdk/pull/2814
- [v1.x] fix: allow registering after connect() when the capability was declared by @claude[bot] in https://github.com/modelcontextprotocol/typescript-sdk/pull/2958
- chore: bump version to 1.32.2 by @claude[bot] in https://github.com/modelcontextprotocol/typescript-sdk/pull/3089
New Contributors
- @kishormorol made their first contribution in https://github.com/modelcontextprotocol/typescript-sdk/pull/2814
Full Changelog: https://github.com/modelcontextprotocol/typescript-sdk/compare/1.32.1...1.32.2
用户点评
登录用户的真实使用记录,可按版本和硬件筛选还没有人点评。第一个说出真实体验的人最有价值。
MCP TypeScript SDK
[!IMPORTANT] This is the
mainbranch: v2 of the SDK (@modelcontextprotocol/server,@modelcontextprotocol/client), the stable release line, implementing the 2026-07-28 MCP spec. Start with the v2 documentation; coming from v1, see the migration guide.v1.x (
@modelcontextprotocol/sdk) lives on thev1.xbranch and continues to receive bug fixes and security updates for at least six months after the v2 release (2026-07-27). Its documentation is at ts.sdk.modelcontextprotocol.io.Found a problem in v2? Open an issue.
[!NOTE] Contributors without write access can have one open pull request at a time. Draft pull requests don't count toward the limit. For a feature or a larger change, please open an issue first; see CONTRIBUTING.md.
Overview
The Model Context Protocol (MCP) allows applications to provide context for LLMs in a standardized way, separating the concerns of providing context from the actual LLM interaction.
This repository contains the TypeScript SDK implementation of the MCP specification. It runs on Node.js, Bun, and Deno, and ships:
- MCP server libraries (tools/resources/prompts, Streamable HTTP, stdio, auth helpers)
- MCP client libraries (transports, high-level helpers, OAuth helpers)
- Optional middleware packages for specific runtimes/frameworks (Express, Fastify, Hono, Node.js HTTP)
- Runnable examples (under
examples/)
Packages
This monorepo publishes split packages:
@modelcontextprotocol/server: build MCP servers@modelcontextprotocol/client: build MCP clients
Tool and prompt schemas use Standard Schema — bring Zod v4, Valibot, ArkType, or any compatible library.
Middleware packages (optional)
The SDK also publishes small "middleware" packages under packages/middleware/ that help you wire MCP into a specific runtime or web framework.
They are intentionally thin adapters: they should not introduce new MCP functionality or business logic. See packages/middleware/README.md for details.
@modelcontextprotocol/node: Node.js Streamable HTTP transport wrapper forIncomingMessage/ServerResponse@modelcontextprotocol/express: Express helpers (app defaults + Host header validation)@modelcontextprotocol/fastify: Fastify helpers (app defaults + Host header validation)@modelcontextprotocol/hono: Hono helpers (app defaults + JSON body parsing hook + Host header validation)
Installation
Server
npm install @modelcontextprotocol/server
# or
bun add @modelcontextprotocol/server
# or
deno add npm:@modelcontextprotocol/server
Client
npm install @modelcontextprotocol/client
# or
bun add @modelcontextprotocol/client
# or
deno add npm:@modelcontextprotocol/client
Optional middleware packages
The SDK also publishes optional “middleware” packages that help you wire MCP into a specific runtime or web framework (for example Express, Fastify, Hono, or Node.js http).
These packages are intentionally thin adapters and should not introduce additional MCP features or business logic. See packages/middleware/README.md for details.
# Node.js HTTP (IncomingMessage/ServerResponse) Streamable HTTP transport:
npm install @modelcontextprotocol/node
# Express integration:
npm install @modelcontextprotocol/express express
# Fastify integration:
npm install @modelcontextprotocol/fastify fastify
# Hono integration:
npm install @modelcontextprotocol/hono hono
Getting Started
Here is what an MCP server looks like. This minimal example exposes a single greet tool over stdio:
import { McpServer } from '@modelcontextprotocol/server';
import { StdioServerTransport } from '@modelcontextprotocol/server/stdio';
import * as z from 'zod/v4';
const server = new McpServer({ name: 'greeting-server', version: '1.0.0' });
server.registerTool(
'greet',
{
description: 'Greet someone by name',
inputSchema: z.object({ name: z.string() })
},
async ({ name }) => ({
content: [{ type: 'text', text: `Hello, ${name}!` }]
})
);
async function main() {
const transport = new StdioServerTransport();
await server.connect(transport);
}
main();
Ready to build something real? Follow the step-by-step tutorials:
- Build your first server — a stdio weather-alert server, from
npm initto a tool call - Build your first client — connect to that server, list its tools, and call them
For runnable, end-to-end examples beyond the tutorials, see:
examples/README.md— runnable, self-verifying client/server example pairs (one story per directory)
Documentation
- Build a server — your first MCP server, step by step
- Build a client — your first MCP client, step by step
- Documentation site — the full guides: tools, resources, prompts, serving over HTTP and stdio, clients, OAuth, and migration
- Troubleshooting — common errors and their fixes
- API reference
- MCP documentation
- MCP specification
Building docs locally
To work on the documentation site locally:
pnpm docs:api # Generate the API reference markdown (output: docs/api/)
pnpm docs:dev # Start the VitePress dev server for the V2 site
pnpm docs:build # Build the V2 site (output: docs/.vitepress/dist/)
pnpm docs:multi # Build the combined V1 + V2 site (output: tmp/docs-combined/)
The docs:multi script builds the V2 site from the current checkout, checks out the v1.x branch via a git worktree to build the V1 site, and produces a combined site with V1 docs at the root and V2 docs under /v2/.
v1 (legacy) documentation and fixes
If you are using the v1 generation of the SDK, the v1 API documentation is available at https://ts.sdk.modelcontextprotocol.io/. The v1 source code and any v1-specific fixes live on the long-lived
v1.x branch. V2 API docs are at /v2/.
Contributing
Issues and pull requests are welcome on GitHub at https://github.com/modelcontextprotocol/typescript-sdk.
License
This project is licensed under the Apache License 2.0 for new contributions, with existing code under MIT. See the LICENSE file for details.