Token导航 LogoToken导航TokenDH.com
开发external-servicegithub未标认证来源可访问许可证需确认审计提醒

build-mcp-server-sdk-v2构建 MCP server SDK V2

Agent Skill

build-mcp-server-sdk-v2 用于处理 GitHub 仓库、Issue、Pull Request 和代码协作信息,适合在 Codex、Claude、Cursor、Gemini CLI 中需要围绕仓库状态、代码变更或协作事项进行整理时使用。可结合来源仓库、安装命令和原始 README 继续核验具体用法。安装前建议确认权限范围、维护状态,以及是否会触发联网、命令执行或文件读写。

总安装

256

周安装

11

GitHub Stars

5

下载量

90
CodexClaudeCursorGemini CLI

安装说明

本站只整理中文说明和来源信息,不托管安装包,也不代用户安装。

GitHub

来源数

2

许可证

unknown

最后核验

2026-05-01

来源状态

来源可访问

安装方式

通过对话安装

复制提示词发给支持本地命令或 Skills 的 AI 助手,先确认命令和权限,再让它执行。

请帮我安装这个 Agent Skill:build-mcp-server-sdk-v2(构建 MCP server SDK V2)
来源仓库:https://github.com/yigitkonur/skills-by-yigitkonur
仓库路径:skills/build-mcp-server-sdk-v2
安装命令:
npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-mcp-server-sdk-v2
安装前请先检查当前环境是否支持对应 CLI,并向我确认将要执行的命令、安装目录、联网范围和文件读写权限;确认后再执行。

命令行安装

复制命令到本机终端执行。该命令会通过 npx skills 从第三方来源获取 Skill;本站只展示命令,不托管安装包,也不自动执行。

skills.shnpx skills
npx skills add https://github.com/yigitkonur/skills-by-yigitkonur --skill build-mcp-server-sdk-v2

简介

采用 v2 拆分包 SDK 构建 ESM-only Node.js 20+ MCP 服务器。

  • 依赖 @modelcontextprotocol/server/client/core 三件套。
  • 社区采用率尚低,适合早期技术探索项目使用。
  • 可通过 package.json 结构判断当前应选用 v1 或 v2 方案。
  • build-mcp-server-sdk-v2 属于开发类 Skill,可作为该场景下的辅助能力补充。

SKILL.md

Build MCP Server (SDK v2)

Build and maintain MCP servers using the v2 split-package SDK: @modelcontextprotocol/server, @modelcontextprotocol/client, @modelcontextprotocol/core. Node.js 20+, ESM-only, Zod v4. Released Q1 2026, community adoption still early.

When to use a different skill instead:

  • @modelcontextprotocol/sdk (single package) in package.json → use build-mcp-server-sdk-v1
  • Handlers use (args, extra) with extra.sendNotification / extra.authInfo → that's v1, use build-mcp-server-sdk-v1
  • Uses the mcp-use wrapper library → use build-mcp-use-server

How to detect v2: Look for split package imports (@modelcontextprotocol/server, @modelcontextprotocol/client), handlers using (args, ctx) with ctx.mcpReq.log() / ctx.mcpReq.signal, and "type": "module" in package.json.

Core rules:

  • Always use McpServer from @modelcontextprotocol/server — the Server class is deprecated
  • Always use registerTool / registerResource / registerPrompt — positional overloads removed
  • Always use Zod v4 full schemas (z.object({...})) — raw shapes not accepted in v2
  • Always use NodeStreamableHTTPServerTransport from @modelcontextprotocol/node for HTTP
  • Server-side OAuth is removed — use better-auth or a dedicated auth library
  • SSE server transport is removed — use Streamable HTTP
  • ESM-only — no CommonJS support
  • Node.js 20+ required

Workflow

1 — Detect what exists

Run tree -L 3 and check package.json. Look for:

  • @modelcontextprotocol/server in dependencies → existing v2 server
  • @modelcontextprotocol/sdk (single package) → v1, redirect to build-mcp-server-sdk-v1
  • mcp-use → wrong skill, redirect to build-mcp-use-server
  • Handler patterns: ctx.mcpReq → v2; extra.sendNotification → v1

2A — Maintain or fix an existing v2 server

Read the implementation. Check for:

  • Correct context usage: ctx.mcpReq.signal, ctx.http?.authInfo, ctx.mcpReq.notify()
  • Proper schema usage: full z.object() not raw shapes
  • Framework adapter usage: createMcpExpressApp() from @modelcontextprotocol/express
  • outputSchema validation: tools with outputSchema must return structuredContent

2B — Scope a new v2 server

Ask or infer:

  1. What does the server wrap? (API, database, filesystem, CLI)
  2. Transport? stdio for local, Streamable HTTP for remote
  3. Framework? Express or Hono (both have dedicated adapters)
  4. Auth? Client-side only in v2 (server-side OAuth removed)

3 — Choose the implementation branch

ScenarioAction
New stdio serverreferences/guides/quick-start.md
New HTTP server (Express)references/guides/transports.md + references/guides/framework-adapters.md
New HTTP server (Hono)references/guides/transports.md + references/guides/framework-adapters.md
Add toolsreferences/guides/tools-and-schemas.md
Add resources or promptsreferences/guides/resources-and-prompts.md
Build an MCP clientreferences/guides/client-api.md
Deploy to productionreferences/patterns/deployment.md

4 — Preflight setup

  • Node.js 20+ installed
  • npm install @modelcontextprotocol/server zod (Zod v4)
  • If HTTP: npm install @modelcontextprotocol/node (Node.js transport)
  • If Express: npm install @modelcontextprotocol/express express
  • If Hono: npm install @modelcontextprotocol/hono hono
  • "type": "module" in package.json
  • TypeScript 5+ with "module": "Node16", "moduleResolution": "Node16"

5 — Build or extend

  1. Create McpServer with name, version, optional description/icons
  2. Define Zod v4 schemas: z.object({field: z.string()}) (not raw shapes)
  3. Register tools with server.registerTool() — input schema, annotations, handler with (args, ctx) pattern
  4. Register resources with server.registerResource() if exposing data
  5. Register prompts with server.registerPrompt() if providing templates
  6. Create transport and connect: await server.connect(transport)
  7. Handle graceful shutdown

6 — Validate

  • stdio: npx @anthropic-ai/mcp-inspector npx tsx src/index.ts
  • HTTP: Start server, test with curl or Inspector
  • Schemas: Verify Zod validation catches bad input
  • Context: Confirm ctx.mcpReq is used (not extra)

Quick start — minimal v2 stdio server

import { McpServer, StdioServerTransport } from "@modelcontextprotocol/server";
import * as z from "zod/v4";

const server = new McpServer(
  { name: "my-server", version: "1.0.0" },
  { instructions: "A helpful server" }
);

server.registerTool("greet", {
  title: "Greet User",
  description: "Greet a user by name",
  inputSchema: z.object({
    name: z.string().describe("The user's name"),
  }),
  annotations: { readOnlyHint: true, destructiveHint: false },
}, async ({ name }, ctx) => {
  await ctx.mcpReq.log("info", `Greeting ${name}`);
  return {
    content: [{ type: "text" as const, text: `Hello, ${name}!` }],
  };
});

const transport = new StdioServerTransport();
await server.connect(transport);

Core API summary

McpServer

import { McpServer, StdioServerTransport } from "@modelcontextprotocol/server";

new McpServer(
  { name: string, version: string, description?: string, icons?: Icon[] },
  { capabilities?: ServerCapabilities, instructions?: string }
)

server.connect(transport: Transport): Promise<void>
server.close(): Promise<void>
server.registerTool(name, config, handler): RegisteredTool
server.registerResource(name, uri | template, config, handler): RegisteredResource
server.registerPrompt(name, config, handler): RegisteredPrompt
server.sendToolListChanged(): void
server.sendResourceListChanged(): void
server.sendPromptListChanged(): void
server.sendLoggingMessage(params): Promise<void>
server.isConnected(): boolean
server.experimental.tasks  // ExperimentalMcpServerTasks

registerTool config

{
  title?: string,
  description?: string,
  inputSchema?: AnySchema,           // z.object({...}) — full Zod v4 schema
  outputSchema?: AnySchema,          // enables structuredContent validation
  annotations?: ToolAnnotations,
  _meta?: Record<string, unknown>,
}

ServerContext (handler second argument)

// Tool handler: (args, ctx) => CallToolResult
// No-args tool: (ctx) => CallToolResult

ctx.sessionId?: string
ctx.mcpReq.id: RequestId
ctx.mcpReq.method: string
ctx.mcpReq.signal: AbortSignal
ctx.mcpReq._meta?: RequestMeta
ctx.mcpReq.send(request, schema, options?): Promise<Result>
ctx.mcpReq.notify(notification): Promise<void>
ctx.mcpReq.log(level, data, logger?): Promise<void>
ctx.mcpReq.elicitInput(params): Promise<ElicitResult>
ctx.mcpReq.requestSampling(params): Promise<CreateMessageResult>
ctx.http?.authInfo?: AuthInfo
ctx.http?.req?: RequestInfo
ctx.http?.closeSSE?(): void
ctx.http?.closeStandaloneSSE?(): void
ctx.task?.id?: string
ctx.task?.store?: RequestTaskStore

Error handling

import { ProtocolError, ProtocolErrorCode } from "@modelcontextprotocol/core";

// Hard protocol errors:
throw new ProtocolError(ProtocolErrorCode.InvalidParams, "Bad input");

// Soft tool errors (LLM can self-correct):
return { content: [{ type: "text", text: "Error: not found" }], isError: true };

Decision rules

  • Always use z.object({...}) — raw shapes ({name: z.string()}) are not accepted in v2
  • Prefer isError: true for recoverable tool errors — LLMs self-correct from these
  • Prefer ctx.mcpReq.log() over console.error() — sends structured logs to the client
  • Prefer ctx.mcpReq.elicitInput() over ctx.mcpReq.send() for user input — cleaner API
  • Use createMcpExpressApp() or createMcpHonoApp() instead of raw Express/Hono setup
  • Set annotations on every tool

Guardrails

  • Never use raw Zod shapes — v2 requires full z.object() schemas
  • Never use extra.sendNotification / extra.authInfo — those are v1 patterns; use ctx.mcpReq
  • Never import from @modelcontextprotocol/sdk — that's v1; import from /server, /client, /core
  • Never use SSEServerTransport — removed in v2
  • Never implement server-side OAuth with the SDK — removed; use external auth library
  • Never use CommonJS — v2 is ESM-only
  • Never use Node.js < 20

Reference routing

Start here

ReferenceWhen to read
references/guides/quick-start.mdScaffolding a new v2 server from scratch
references/guides/tools-and-schemas.mdRegistering tools with Zod v4, ServerContext, annotations
references/guides/transports.mdstdio, Streamable HTTP, web-standard transport

Server capabilities

ReferenceWhen to read
references/guides/resources-and-prompts.mdResources (static/template URI) and prompts
references/guides/client-api.mdBuilding MCP clients, auth providers, middleware
references/guides/framework-adapters.mdExpress and Hono adapters, DNS rebinding protection
references/guides/context-and-lifecycle.mdServerContext fields, sampling, elicitation, sessions, shutdown

Build and ship

ReferenceWhen to read
references/examples/server-recipes.mdComplete v2 server examples
references/patterns/deployment.mdDocker, serverless, Cloudflare Workers
references/patterns/anti-patterns.mdCommon mistakes — including v1 patterns to avoid

Community adoption note

v2 shipped Q1 2026. Most production MCP servers still run v1.x. You may encounter:

  • Fewer community examples and Stack Overflow answers
  • Some MCP clients not yet supporting v2-specific features
  • Third-party tools still targeting v1 patterns

The SDK itself is stable and actively maintained on the main branch.

适合场景

01

用户想查找某类 Agent Skill 时

02

需要根据任务场景推荐可安装能力包时

03

需要对比不同来源的安装命令和来源信息时

能力概览

能力 1

按任务关键词查找相关 Skills

能力 2

展示可复制的安装命令

能力 3

保留来源站点、仓库和原始说明,方便继续核验

能力 4

展示第三方安全扫描或审计结果

安装后应在对应宿主中按原始 README 的触发条件使用;具体调用方式请以来源页面和 README 为准。

平台分布

Codex

36.31%
按下载量换算33

Claude

33.17%
按下载量换算30

Cursor

17.8%
按下载量换算16

Gemini CLI

10.34%
按下载量换算9

安全审计

Gen Agent Trust Hub

通过

Socket

通过

Snyk

可疑

权限和风险

external-service

该 Skill 可能调用第三方服务、云服务或外部模型 API,使用前需要确认账号、额度、数据发送范围和服务条款。

安装前确认

本站仅展示第三方公开信息,不托管安装包,不提供自动安装或运行环境。安装前应自行审查源码、依赖和命令行为。来源安全扫描存在 warning/failed 结果,不能写成本站确认安全。当前只有一个来源,正式发布前建议补源仓库或其他目录站核验。

来源信息

继续浏览同类 Skills