帮助开发者用 Node/TypeScript 快速构建符合规范的 MCP 服务器与工具能力
复制安装指令,让 AI 自动完成配置 · 推荐新手
请帮我安装 askskill 上的 "mcp-server-patterns" 技能: 1. 下载 https://raw.githubusercontent.com/affaan-m/ECC/main/skills/mcp-server-patterns/SKILL.md 2. 保存为 ~/.claude/skills/mcp-server-patterns/SKILL.md 3. 装好后重载技能,告诉我可以用了
请用 Node.js 和 TypeScript SDK 生成一个最小可运行的 MCP 服务器示例,包含一个 tools 接口、一个 resource、一个 prompt,并使用 Zod 做参数校验。请给出项目结构、关键代码和启动命令。
一套可运行的 MCP 服务器脚手架示例,含目录结构、TypeScript 代码与运行说明。
我想为 MCP 服务器添加两个工具:网页摘要和关键词提取。请用 TypeScript SDK 设计 tools 的输入输出 schema,使用 Zod 校验参数,并说明错误处理和返回格式的最佳实践。
两个工具的 schema 与实现建议,包括 Zod 校验、错误处理方式和标准化返回结构。
请比较 MCP 服务器使用 stdio 与 Streamable HTTP 两种传输方式的差异,分别说明适用场景、部署方式、优缺点,并给出 Node/TypeScript SDK 的配置示例。
一份清晰的传输方案对比与配置示例,帮助选择合适的 MCP 服务接入方式。
The Model Context Protocol (MCP) lets AI assistants call tools, read resources, and use prompts from your server. Use this skill when building or maintaining MCP servers. The SDK API evolves; check Context7 (query-docs for "MCP") or the official MCP documentation for current method names and signatures.
For the broader routing decision of when a capability should be a rule, a skill, MCP, or a plain CLI/API workflow, see docs/capability-surface-selection.md.
Use when: implementing a new MCP server, adding tools or resources, choosing stdio vs HTTP, upgrading the SDK, or debugging MCP registration and transport issues.
registerTool() or tool() depending on SDK version.registerResource() or resource(). Handlers typically receive a uri argument.registerPrompt() or equivalent.The Node/TypeScript SDK may expose tool() / resource() or registerTool() / registerResource(); the official SDK has changed over time. Always verify against the current MCP docs or Context7.
For local clients, create a stdio transport and pass it to your server’s connect method. The exact API varies by SDK version (e.g. constructor vs factory). See the official MCP documentation or query Context7 for "MCP stdio server" for the current pattern.
Keep server logic (tools + resources) independent of transport so you can plug in stdio or HTTP in the entrypoint.
For Cursor, cloud, or other remote clients, use Streamable HTTP (single MCP HTTP endpoint per current spec). Support legacy HTTP/SSE only when backward compatibility is required.
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" });
Register tools and resources using the API your SDK version provides: some versions use server.tool(name, description, schema, handler) (positional args), others use server.tool({ name, description, inputSchema }, handler) or registerTool(). Same for resources — include a uri in the handler when the API provides it. Check the official MCP docs or Context7 for the current @modelcontextprotocol/sdk signatures to avoid copy-paste errors.
Use Zod (or the SDK’s preferred schema format) for input validation.
@modelcontextprotocol/sdk (npm). Use Context7 with library name "MCP" for current registration and transport patterns.modelcontextprotocol/go-sdk).帮助用户在回答前选择简短、标准或详细版本,控制回复深度与 token 用量。
帮助开发者搭建支持鉴权与资源调用的远程 MCP 服务