@haakco/mcp模式同步器
自动模式同步工具,用于使MCP服务器与最新最佳实践保持一致
让您的MCP服务器了解最新的模式、最佳实践和共享配置。自动检测过时的模式,管理冲突,并同步多个项目之间的更改。
](https://www.npmjs.com/package/@haakco/mcp-pattern-synchronizer)  
🚀 主要特点
- 🔄 自动同步 -在所有MCP服务器上保持模式最新
- 🎯 选择性更新 -选择要同步的模式和要跳过的模式
- 🛡️ 冲突解决 -智能冲突检测和解决策略
- 📦 多个来源 -从Git、NPM、本地目录或模式注册表同步
- 🔍 变化检测 -跟踪本地修改并适当处理
- 💾 备份支持 -应用更改前的自动备份
- 🚦 多种模式 -仅检查、更新、强制或交互式同步
- 📊 详细报告 -包含建议的全面同步报告
安装
npm install -g @haakco/mcp-pattern-synchronizer或者用作项目依赖项:
npm install --save-dev @haakco/mcp-pattern-synchronizer用法
基本同步
# Sync patterns from default source
mcp-sync sync
# Sync from specific Git repository
mcp-sync sync --source git --url https://github.com/org/patterns.git
# Sync from NPM package
mcp-sync sync --source npm --url @org/mcp-patterns
# Sync from local directory
mcp-sync sync --source local --url ../shared-patterns同步模式
# Check mode - only report what would change
mcp-sync sync --mode check
# Update mode - update outdated patterns (default)
mcp-sync sync --mode update
# Force mode - overwrite all patterns
mcp-sync sync --mode force
# Interactive mode - choose updates one by one
mcp-sync sync --mode interactive选择性同步
# Sync specific patterns only
mcp-sync sync --patterns error-handling tool-registry
# Exclude certain patterns
mcp-sync sync --exclude docker-support legacy-patterns
# Dry run to preview changes
mcp-sync sync --dry-run高级选项
# Auto-commit changes
mcp-sync sync --auto-commit --branch feat/update-patterns
# Create backups before updating
mcp-sync sync --backup
# Verbose output
mcp-sync sync --verbose命令
sync [project-path]
同步项目中的模式。
选项:
-s, --source-模式源类型(git | npm | local | registry)-u, --url-源URL或路径-m, --mode-同步模式(更新|检查|强制|交互)- `-p, --patterns
` -要同步的特定模式
- `-e, --exclude
` -要排除的模式
--auto-commit-自动提交更改- `--branch
` -Git自动提交分支
--dry-run-预览更改而不应用--backup-更新前创建备份-v, --verbose-详细输出
check [project-path]
在不更新的情况下检查模式状态。
list [project-path]
列出已安装的模式及其状态。
validate [project-path]
验证模式完整性并检测本地修改。
search
在注册表中搜索模式。
配置
创建 .mcp-sync.json 在您的项目中:
{
"source": {
"type": "git",
"url": "https://github.com/org/mcp-patterns.git",
"branch": "main"
},
"patterns": ["error-handling", "tool-registry", "multi-instance"],
"excludePatterns": ["legacy-*"],
"autoCommit": true,
"syncMode": "update"
}图案来源
Git仓库
{
"type": "git",
"url": "https://github.com/org/patterns.git",
"branch": "main"
}NPM包
{
"type": "npm",
"package": "@org/mcp-patterns",
"version": "^1.0.0"
}本地目录
{
"type": "local",
"path": "../shared-patterns"
}模式注册表
{
"type": "registry",
"url": "https://registry.mcp-patterns.dev/v1/patterns"
}冲突解决
同步器提供了多种处理冲突的策略:
自动策略
- 我们的 -保留本地版本
- 他们的 -使用远程版本
- 合并 -尝试自动合并
手动分辨率
当冲突无法自动解决时,该工具会创建冲突标记:
>>>>>> remote (pattern: error-handling)模式清单
同步器在以下位置维护清单文件 .mcp-patterns/manifest.json:
{
"patterns": {
"error-handling": {
"id": "error-handling",
"version": "1.2.0",
"checksum": "sha256:...",
"installed": "2025-01-09T10:00:00Z",
"modified": false,
"source": {
"type": "git",
"url": "https://github.com/org/patterns.git"
}
}
},
"lastSync": "2025-01-09T10:00:00Z",
"version": "1.0.0"
}程序化使用
import { PatternSynchronizer, SyncConfig } from '@haakco/mcp-pattern-synchronizer';
const synchronizer = new PatternSynchronizer();
const config: SyncConfig = {
projectPath: './my-mcp-server',
patternSource: {
type: 'git',
url: 'https://github.com/org/patterns.git'
},
syncMode: 'update',
patterns: ['error-handling', 'tool-registry'],
autoCommit: true,
dryRun: false
};
const result = await synchronizer.sync(config, {
verbose: true,
backup: true
});
console.log(`Updated ${result.summary.updated} patterns`);
console.log(`Conflicts: ${result.summary.conflicts}`);事件
同步器在操作过程中发出事件:
synchronizer.on('sync:start', (config) => {
console.log('Starting synchronization...');
});
synchronizer.on('pattern:updating', (patternId) => {
console.log(`Updating pattern: ${patternId}`);
});
synchronizer.on('sync:complete', ({ result, duration }) => {
console.log(`Sync completed in ${duration}ms`);
});
synchronizer.on('sync:error', (error) => {
console.error('Sync failed:', error);
});最佳实践
- 定期同步 -将同步作为CI/CD管道的一部分运行
- 先使用检查模式 -在更新之前,始终检查会发生什么变化
- 备份重要项目 -使用
--backup用于生产项目 - 审查冲突 -不要盲目强制更新,审查冲突
- 同步后测试 -同步模式后运行测试套件
🚀 发展
# Install dependencies
npm install
# Run tests
npm test
# Build the library
npm run build
# Test CLI locally
npm run dev -- sync . --mode check
# Lint and format
npm run lint
npm run format📄 许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
🔗 相关项目
- @haakco/mcp模式生成器 -为MCP服务器生成模式
- @haakco/mcp配置验证器 -验证MCP服务器配置
- @haakco/mcp迁移工具 -迁移现有项目
______________________________________________________________________
使用TypeScript构建,旨在跨MCP服务器生态系统进行无缝模式管理。
