mcp服务器套件
](https://www.npmjs.com/package/mcp-server-kit) ](https://www.npmjs.com/package/mcp-server-kit)
对于人类用户👤
与Claude代码一起使用(推荐):从Claude Code终端开始,获得无缝项目创建的最佳体验。
快速开始
- 在终端中启动Claude Code
- 粘贴此提示:
I want you to scaffold a new MCP server project using the mcp-server-kit CLI. Follow these steps EXACTLY:
1. Install the CLI globally:
npm install -g mcp-server-kit
2. Read the documentation: After installation, run this command to see the full README:
npm view mcp-server-kit readme
Read it carefully to understand all capabilities before proceeding.
3. Use the CLI to scaffold the project:
mcp-server-kit new server --template cloudflare-remote --name
Note: Replace
with your desired name (e.g., my-weather-server, slack-bot, github-integration)
4. After scaffolding completes, show me:
- The generated project structure
- The next steps from the CLI output
IMPORTANT: The mcp-server-kit CLI handles everything automatically - directory creation, file generation, and dependency installation. Do NOT create directories or files manually. Your job is to run the commands and explain what was created.- 克劳德代码将:
- 全局安装mcp服务器工具包 - 阅读包装文档 - 创建项目目录 - 搭建项目脚手架 - 安装依赖项 - 解释接下来的步骤
为什么选择克劳德代码?
- 集成终端 -直接运行命令
- 上下文感知 -了解完整的项目结构
- 自动错误处理 -自动修复问题
也可与其他AI代理配合使用,但Claude Code通过内置终端集成提供了最流畅的体验。
______________________________________________________________________
用于模型上下文协议(MCP)服务器的可扩展脚手架工具和测试工具
使用内置测试基础设施,在几秒钟内创建生产就绪的MCP服务器。通过可扩展的模板系统支持多个部署目标(Cloudflare Workers、Vercel Edge、Node.js)。
特性
- 🚀 快速脚手架 -使用一个命令生成完整的MCP服务器项目
- 🧪 内置测试 -具有声明性YAML测试规范的集成测试工具
- 🔌 可扩展模板 -用于多个MCP框架的插件架构
- 📦 生产就绪 -包括TypeScript、测试、linting和部署配置
- 🤖 代理优化 -专为AI代理构建,具有自动脚手架、示例和验证功能
- 🛠️ 开发工具 -添加工具/提示/资源、验证项目、列出组件,全部来自CLI
- ☁️ Cloudflare绑定 -带有类型安全助手的脚手架KV、D1、R2和工人AI绑定
- 🔐 身份验证支持 -使用特定于提供者的代码(Stytch、Auth0、WorkOS)添加身份验证脚手架
- 📚 丰富的示例 -展示最佳实践的综合示例工具和实用程序
- 🤖 JSON模式 -具有NDJSON进度报告的机器可读输出,用于自动化
对于AI代理🤖
该工具包专门针对AI代理开发进行了优化。 它自动化了代理忘记的机械任务(文件创建、注册、导入),同时保留了创造性解决问题的灵活性。
Claude代码用户:参见 对于人类用户 以获得简化的设置体验。
代理工作流
- 脚手架 -让CLI处理样板
- 实施 -关注工具逻辑(创造性部分)
- 验证 -自动捕捉问题
- 测试 -使用提供的测试工具
# 1. Create project
mcp-server-kit new server --template cloudflare-remote --name my-server
# 2. Add tools, prompts, and resources (auto-scaffolds everything)
cd my-server
mcp-server-kit add tool weather --description "Get weather data"
mcp-server-kit add prompt code-reviewer --description "Review code quality"
mcp-server-kit add resource snippet --description "Code snippet by ID"
mcp-server-kit add resource config --static --description "App configuration"
# 3. (Optional) Add Cloudflare bindings
mcp-server-kit add binding kv --name SESSION_CACHE
mcp-server-kit add binding d1 --name USER_DB --database users
mcp-server-kit add binding r2 --name FILE_STORAGE
mcp-server-kit add binding ai --name AI
# 4. (Optional) Add authentication
mcp-server-kit add-auth stytch # or auth0, workos
# 5. Implement (TODO markers show what to code)
# Edit src/tools/weather.ts, src/prompts/code-reviewer.ts, etc.
# Binding examples appear automatically in generated tools
# 6. Validate (catches missed registrations, tests, etc.)
mcp-server-kit validate
# 7. Test
npm run test:unit
npm run integration:run代理人得到什么:
- 显示所有模式的示例工具
- 可选实用程序助手
- 自动注册(无需手动导入管理)
- 验证捕捉常见错误
- 全面的内联文档
______________________________________________________________________
快速开始
安装
npm install -g mcp-server-kit创建您的第一个MCP服务器
# Scaffold a new Cloudflare Workers MCP server
mcp-server-kit new server \
--name my-mcp-server \
--template cloudflare-remote \
--description "My awesome MCP server"
# Navigate to the project
cd my-mcp-server
# Start development server
npm run dev
# Server runs at http://localhost:8788/sse测试mcp服务器套件本身? 使用 --dev 标记以使用本地mcp服务器工具包路径:
mcp-server-kit new server --name test-project --dev在git存储库根目录下搭建脚手架? 先导航到那里:
cd $(git rev-parse --show-toplevel)
mcp-server-kit new server --name my-server验证它是否有效
# Check health endpoint
curl http://localhost:8788/health
# Run unit tests
npm run test:unit
# Run integration tests
npm run integration:run
# Validate project structure
mcp-server-kit validate脚手架项目包括哪些内容
每个脚手架项目包括:
- ✅ MCP服务器 -使用示例工具完成服务器实现
- ✅ 单元测试 -使用Vitest和测试工具测试基础设施
- ✅ 集成测试 -使用测试工具的声明性YAML测试规范
- ✅ TypeScript -具有适当类型的严格模式配置
- ✅ 代码质量 -用于格式化和起毛的生物特征
- ✅ 部署 -准备部署(Cloudflare、Vercel等)
- ✅ 文档 -README中的“人工智能代理”部分
- ✅ 示例工具 -综合示例文件
- ✅ 实用程序库 -可选助手
- ✅ 开发脚本 -常见任务的npm快捷方式
建筑
mcp-server-kit/
├── src/
│ ├── harness/ # Portable test harness (framework-agnostic)
│ │ ├── types/ # TypeScript interfaces
│ │ ├── assertions/ # Test assertion implementations
│ │ ├── reporters/ # Output formatters
│ │ ├── validation/ # Zod schemas
│ │ └── runner.ts # Test execution engine
│ │
│ └── core/
│ ├── cli/ # CLI commands
│ ├── commands/ # Command implementations
│ └── template-system/ # Extensible template system
│
└── templates/ # Template plugins
├── cloudflare-remote/ # Cloudflare Workers template
├── vercel-edge/ # (Coming soon)
└── node-stdio/ # (Coming soon)关键设计原则
1. 模板驱动的可扩展性
每个MCP框架都是一个自包含的模板插件。添加对新框架的支持只需要创建一个新的模板目录,而不需要更改核心代码。
2. 框架不可知测试线束
测试线束使用依赖注入(IMCPTestClient 接口)以保持跨不同MCP实现的可移植性。
3. 声明性测试
用简单的YAML文件而不是代码编写测试:
name: "Test echo tool"
tool: "echo"
arguments:
message: "Hello, MCP!"
assertions:
- type: "success"
- type: "response_time_ms"
max: 3000
- type: "contains_text"
text: "Hello, MCP!"文档
对于AI代理:
用于MCP开发 (在生成的项目中):
- 测试线束API -详细的测试线束文档
CLI命令
快速参考(参见 CLI指南 详细信息):
# Project creation
mcp-server-kit new server --name --template [--output
] [--json]
# Development commands (for AI agents)
mcp-server-kit add tool --description "" [--json]
mcp-server-kit add prompt --description "" [--json]
mcp-server-kit add resource --description "" [--static] [--json]
mcp-server-kit add binding --name [--database ] [--json]
mcp-server-kit add-auth
[--platform cloudflare] [--json]
mcp-server-kit validate [--strict] [--fix] [--json]
mcp-server-kit list tools [--json]
mcp-server-kit list prompts [--json]
mcp-server-kit list resources [--json]
# Template management
mcp-server-kit template list
mcp-server-kit template info
mcp-server-kit template validate JSON输出
所有命令支持 --json 程序使用标志:
# Get parseable JSON output
mcp-server-kit add tool weather --description "Weather API" --json
# Output: {"success": true, "entityType": "tool", "entityName": "weather", ...}
# Pipe to jq for processing
mcp-server-kit validate --json | jq '.summary'
# Output: {"errors": 0, "warnings": 2, "info": 1}
# Use in scripts
RESULT=$(mcp-server-kit new server --name test --json)
echo $RESULT | jq '.path'
# Output: "/path/to/test"程序化API使用
虽然mcp服务器套件提供了一个用于交互式使用的CLI, 所有核心功能也可作为程序化API使用 用于构建自定义工具、CI/CD集成和高级工作流。
可用的API模块
// Scaffolding API - Create entities programmatically
import { EntityScaffolder } from 'mcp-server-kit/scaffolding';
// Validation API - Validate projects programmatically
import { validateProject } from 'mcp-server-kit/validation';
// Template System API - Scaffold entire projects
import { TemplateProcessor, TemplateRegistry } from 'mcp-server-kit';
// Test Harness API - Run integration tests
import { TestRunner, loadTestSpec } from 'mcp-server-kit/harness';
// Progress Reporter API - Track operation progress
import { ProgressReporter } from 'mcp-server-kit/reporting';
// Error Handling API - Structured error management
import { CLIError, ValidationError, RuntimeError } from 'mcp-server-kit/errors';API脚手架
以编程方式创建工具、提示和资源:
import { EntityScaffolder } from 'mcp-server-kit/scaffolding';
const scaffolder = new EntityScaffolder();
// Create a tool
const result = await scaffolder.scaffold(process.cwd(), {
entityType: 'tool',
name: 'weather-api',
description: 'Get weather data',
generateTests: true,
autoRegister: true,
});
console.log(`Created: ${result.filesCreated.join(', ')}`);
console.log(`Registered: ${result.registered}`);
// No console output from scaffolder - you control output!用例:
- 自定义项目生成器
- 用于代码生成的IDE插件
- CI/CD中的自动化实体脚手架
验证API
以编程方式验证MCP服务器项目:
import { validateProject } from 'mcp-server-kit/validation';
const result = await validateProject(process.cwd(), { strict: true });
if (!result.passed) {
for (const issue of result.issues) {
if (issue.severity === 'error') {
console.error(`❌ ${issue.message}`);
if (issue.file) console.error(` File: ${issue.file}`);
if (issue.suggestion) console.error(` Fix: ${issue.suggestion}`);
}
}
process.exit(1);
}
console.log(`✅ Valid! (${result.summary.errors} errors, ${result.summary.warnings} warnings)`);用例:
- 自定义CI/CD验证
- 预提交挂钩
- 保存时的IDE验证
- 项目运行状况仪表板
模板系统API
以编程方式完成项目:
import { TemplateProcessor, TemplateRegistry } from 'mcp-server-kit';
const registry = new TemplateRegistry();
const processor = new TemplateProcessor(registry);
const result = await processor.scaffold({
template: 'cloudflare-remote',
targetDir: './my-project',
variables: {
PROJECT_NAME: 'my-server',
MCP_SERVER_NAME: 'My MCP Server',
PORT: '8788',
},
noInstall: false,
packageManager: 'npm',
});
if (result.success) {
console.log(`✅ Project created at: ${result.targetDir}`);
}用例:
- 自定义项目模板
- 多项目生成器
- 模板测试自动化
实体发现API
列出并发现项目中的实体:
import { EntityLister } from 'mcp-server-kit/scaffolding';
const lister = new EntityLister({
entityType: 'tool',
entityTypePlural: 'tools',
sourceDir: 'src/tools',
registrationPattern: /register(\w+)Tool/g,
unitTestDir: 'test/unit/tools',
integrationTestDir: 'test/integration/specs',
descriptionPattern: /\/\*\*[\s\S]*?\*\s*([^\n]+)/,
});
const entities = await lister.discoverEntities(process.cwd(), false);
for (const entity of entities) {
console.log(`${entity.name}: registered=${entity.registered}, tested=${entity.hasUnitTest}`);
}用例:
- 自定义状态报告
- IDE实体浏览器
- 文档生成
测试线束API
以编程方式运行集成测试:
import { TestRunner, loadTestSpec } from 'mcp-server-kit/harness';
import { MyMCPClient } from './my-client';
// Create client adapter
const client = new MyMCPClient();
const runner = new TestRunner(client);
// Connect
await runner.connect();
// Load and run tests
const spec = await loadTestSpec('./test.yaml');
const result = await runner.runTest(spec);
console.log(`Test: ${result.name}`);
console.log(`Status: ${result.passed ? 'PASS' : 'FAIL'}`);
console.log(`Duration: ${result.duration}ms`);
// Cleanup
await runner.disconnect();用例:
- 定制测试跑步器
- CI/CD集成
- 性能测试
- 监控和警报
进度报告员API
使用机器可读事件跟踪操作进度:
import { ProgressReporter } from 'mcp-server-kit/reporting';
const reporter = new ProgressReporter({
format: 'json', // or 'text'
output: process.stdout,
});
// Start operation
reporter.start('Creating MCP server', [
'validating-configuration',
'creating-files',
'installing-dependencies',
]);
// Update step status
reporter.stepInProgress('validating-configuration');
reporter.stepCompleted('validating-configuration', 150);
reporter.stepInProgress('creating-files');
reporter.stepCompleted('creating-files', 300);
// Complete operation
reporter.complete(true, {
projectName: 'my-server',
path: '/path/to/my-server',
});输出(NDJSON):
{"type":"start","operation":"Creating MCP server","steps":[...],"timestamp":"..."}
{"type":"step","step":"validating-configuration","status":"in_progress","timestamp":"..."}
{"type":"step","step":"validating-configuration","status":"completed","duration":150,"timestamp":"..."}
{"type":"complete","success":true,"duration":450,"result":{...},"timestamp":"..."}用例:
- CI/CD进度跟踪
- 实时运行监控
- 自定义进度UI
- 自动化工作流程
API错误处理
使用结构化、类型化的错误类处理错误:
import { ValidationError, RuntimeError, CLIError } from 'mcp-server-kit/errors';
// Validation errors (exit code 1)
throw new ValidationError(
'Invalid tool name',
{
field: 'name',
provided: 'MyTool',
expected: 'lowercase-with-hyphens',
},
'Use "my-tool" instead',
);
// Runtime errors (exit code 2)
throw new RuntimeError(
'npm install failed',
{ command: 'npm install', exitCode: 1 },
'Check your package.json for syntax errors',
);
// Catch and handle
try {
await scaffolder.scaffold(options);
} catch (error) {
if (error instanceof CLIError) {
console.error(`Error: ${error.message}`);
if (error.suggestion) console.error(`Suggestion: ${error.suggestion}`);
process.exit(error.exitCode);
}
throw error;
}错误类型:
ValidationError-输入验证失败(退出代码1)RuntimeError-执行失败(退出代码2)FileSystemError-文件/目录错误(退出代码3)CLIError-所有CLI错误的基类
用例:
- 一致的错误处理
- 机器可读错误输出
- CI/CD解析错误
- 用户友好的错误消息
TypeScript类型安全
所有API都是完全类型化的:
import type {
ScaffoldResult,
ValidationResult,
EntityInfo,
TestResult,
ProgressEvent,
ErrorDetails,
} from 'mcp-server-kit/scaffolding';益处:
- VS代码中的智能感知
- 编译时类型检查
- 自文档API
包装出口
{
"imports": {
"mcp-server-kit": "Main exports (template system, utils, services)",
"mcp-server-kit/harness": "Test harness (portable)",
"mcp-server-kit/scaffolding": "Entity scaffolding services",
"mcp-server-kit/validation": "Project validation",
"mcp-server-kit/reporting": "Progress reporting (NDJSON)",
"mcp-server-kit/errors": "Structured error classes",
"mcp-server-kit/commands": "CLI commands (Commander.js)"
}
}发展
从源头构建
git clone https://github.com/mikec-ai/mcp-server-kit.git
cd mcp-server-kit
npm install
npm run build项目结构
src/harness/-便携式测试线束(对核心零依赖)src/core/-CLI和模板系统templates/-模板插件test/-单元和集成测试.claude/skills/-代理商指导和文件
运行测试
# Unit tests (fast)
npm run test:unit
# E2E template tests (slow)
npm run test:e2e
# Type checking
npm run type-check贡献
我们欢迎捐款!我们希望帮助的领域:
- 新模板 -添加对Vercel、Deno等的支持。
- 测试线束功能 -新的断言类型,记者
- 文档 -指南、示例、教程
- 错误修复 -请参阅 问题
许可证
麻省理工学院
资源
______________________________________________________________________
由代理商为代理商打造 🤖
