使用说明
创建mcp
脚手架新 模型上下文协议(MCP) 服务器具有干净、分层的体系结构,可连接到任何外部API。
用法
来自GitHub(不需要npm发布):
# interactive
npx github:kunal-singh/mcp-generator
# with name
npx github:kunal-singh/mcp-generator github
pnpx github:kunal-singh/mcp-generator github
这将生成一个现成的项目 ./<name>-mcp/.
生成什么
<name>-mcp/
src/
main.ts # Entry point
bootstrap.ts # Infrastructure wiring
config/ # Environment & schema validation (Zod)
core/ # MCP SDK wiring: server, builder, transport, errors
lib/ # Shared utilities: logger, TTL cache, response formatter
registry/ # Generic tool / resource / prompt registries
types/ # Shared TypeScript interfaces
domain/
api/
client.interface.ts # I<Name>Client interface — define your API surface
client.ts # <Name>Client extends HttpClientBase
cached-client.ts # Cached<Name>Client — TTL-cached wrapper
http-client.base.ts # Generic Bearer-auth HTTP base class
tools/
definitions/ # Tool input schemas (MCP ToolDefinition)
handlers/ # Tool handler functions
resources/
definitions/ # Resource definitions (URI + mimeType)
handlers/ # Resource handler functions
prompts/
definitions/ # Prompt definitions (name + arguments)
handlers/ # Prompt handler functions
manifest.ts # Wires everything into a ServerManifest
模板变量
| 占位符 | 示例输入 github |
|---|---|
{{name}} |
github |
{{Name}} |
Github |
{{NAME}} |
GITHUB |
脚手架搭设后
cd <name>-mcp
pnpm install
pnpm build
- 集
TOKENenv-var到您的API令牌 - 实施
src/domain/api/client.ts使用实际的API基础URL和方法 - 用实际实现替换示例工具/资源/提示存根
- 在中注册所有内容
src/domain/manifest.ts - 跑
pnpm inspect与MCP检查员一起进行测试
建筑
生成的项目强制MCP基础设施和域逻辑之间进行清晰的分离:
core/--纯MCP SDK布线;对您的API一无所知registry/--用于工具、资源和提示的通用、类型安全注册表domain/-所有特定于API的代码都存在于此;核心从不从域导入
唯一同时涉及两者的文件是 bootstrap.ts,将它们连接在一起。
发展
pnpm install
pnpm run setup # Install git hooks (run once after cloning)
pnpm build # Build CLI
pnpm dev # Watch mode
pnpm typecheck # TypeScript check
pnpm lint # ESLint
许可证
麻省理工学院
