docs/zh-CN/skills/mcp-server-patterns/SKILL.md
使用Node/TypeScript SDK构建MCP服务器——工具、资源、提示、Zod验证、stdio与可流式HTTP对比。使用Context7或官方MCP文档获取最新API信息。
npx skillsauth add affaan-m/everything-claude-code mcp-server-patternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
模型上下文协议(MCP)允许 AI 助手调用工具、读取资源和使用来自服务器的提示。在构建或维护 MCP 服务器时使用此技能。SDK API 会演进;请查阅 Context7(查询文档 "MCP")或官方 MCP 文档以获取当前的方法名称和签名。
在以下情况时使用:实现新的 MCP 服务器、添加工具或资源、选择 stdio 与 HTTP、升级 SDK,或调试 MCP 注册和传输问题。
registerTool() 或 tool() 注册。registerResource() 或 resource() 注册。处理程序通常接收一个 uri 参数。registerPrompt() 或等效方法注册。Node/TypeScript SDK 可能暴露 tool() / resource() 或 registerTool() / registerResource();官方 SDK 已随时间变化。请始终根据当前 MCP 文档 或 Context7 进行验证。
对于本地客户端,创建一个 stdio 传输并将其传递给服务器的连接方法。确切的 API 因 SDK 版本而异(例如构造函数与工厂函数)。请参阅官方 MCP 文档或查询 Context7 中的 "MCP stdio server" 以获取当前模式。
保持服务器逻辑(工具 + 资源)独立于传输,以便您可以在入口点中插入 stdio 或 HTTP。
对于 Cursor、云端或其他远程客户端,使用可流式 HTTP(根据当前规范,每个 MCP HTTP 端点)。仅在需要向后兼容性时支持传统 HTTP/SSE。
npm install @modelcontextprotocol/sdk zod
import { McpServer } from "@modelcontextprotocol/sdk/server/mcp.js";
import { z } from "zod";
const server = new McpServer({ name: "my-server", version: "1.0.0" });
使用您的 SDK 版本提供的 API 注册工具和资源:某些版本使用 server.tool(name, description, schema, handler)(位置参数),其他版本使用 server.tool({ name, description, inputSchema }, handler) 或 registerTool()。资源同理——当 API 提供时,在处理程序中包含一个 uri。请查阅官方 MCP 文档或 Context7 以获取当前的 @modelcontextprotocol/sdk 签名,避免复制粘贴错误。
使用 Zod(或 SDK 首选的模式格式)进行输入验证。
@modelcontextprotocol/sdk (npm)。使用库名 "MCP" 的 Context7 以获取当前的注册和传输模式。modelcontextprotocol/go-sdk)。data-ai
Run team-based orchestration for agent squads using work items, ownership, agent Kanban, merge gates, and control pane handoffs.
data-ai
Design task-local harnesses, eval gates, and reusable skill extraction for Claude dynamic workflow mode and other adaptive agent harnesses.
development
React component testing with React Testing Library, Vitest/Jest, MSW for network mocking, accessibility assertions with axe, and the decision boundary between component tests and Playwright/Cypress end-to-end runs. Use when writing or fixing tests for React components, hooks, or pages.
tools
React and Next.js performance optimization patterns adapted from Vercel Engineering's React Best Practices (https://github.com/vercel-labs/agent-skills). Organizes 70+ rules across 8 priority categories — waterfalls, bundle size, server-side, client fetching, re-render, rendering, JS micro-perf, advanced. Use when writing, reviewing, or refactoring React/Next.js code for performance.