MCP增强型管理系统
🚀 与Docker集成的企业级模型上下文协议(MCP)服务器管理
](https://www.docker.com/)  ](https://nodejs.org/) 
📋 概述
MCP增强型管理系统是一个全面的容器化解决方案,用于管理具有企业级功能的模型上下文协议服务器,包括:
- 5个PowerShell模块 用于完整的MCP生命周期管理
- 170+测试 跨合同、单位和绩效类别
- Docker集成 使用多语言示例服务器
- 实时监控 通过健康检查和绩效指标
- 高级配置管理 使用模式验证
- 搜索功能 支持正则表达式和数据分析
🏗️ 建筑
mcp-enhanced-system/
├── 📦 Docker Container (PowerShell 7.4 + Ubuntu 22.04)
├── 🔧 5 Core PowerShell Modules
│ ├── McpManager - Instance lifecycle management
│ ├── McpConfiguration - Settings and profile management
│ ├── McpDiagnostics - System health and troubleshooting
│ ├── McpMonitoring - Real-time performance tracking
│ └── McpData - Search, analytics, and preferences
├── 🧪 Example Servers (Node.js + Python)
├── 📊 Comprehensive Test Suite (170+ tests)
└── 📋 Enterprise Deployment Scripts🚀 快速开始
先决条件
- 码头工人 (使用Docker Compose)
- PowerShell 7.4+ (用于地方发展)
- Node.js 18+ 和 Python 3.10+ (例如服务器)
安装和启动
1.使用Docker(推荐)
# Clone or extract the project
cd mcp-enhanced-system
# Build and start the system
docker-compose up -d
# Or run directly
docker run -it --name mcp-enhanced \
-p 3000-3010:3000-3010 \
-p 8080:8080 \
mcp-enhanced:latest2.使用Docker Build
# Build the image
docker build -t mcp-enhanced:latest .
# Run interactively
docker run -it mcp-enhanced:latest
# Run with port mapping for example servers
docker run -p 3000-3010:3000-3010 -p 8080:8080 mcp-enhanced:latest3.使用预构建脚本
# Automated deployment and testing
./deploy-and-test.sh
# Just deployment
./deploy-and-test.sh --deploy-only
# With monitoring
./deploy-and-test.sh --monitor🎯 核心命令
容器管理
# Start the enhanced MCP console
docker run -it mcp-enhanced:latest
# Run system tests
docker run --rm mcp-enhanced:latest ./test-mcp.sh
# Run performance validation
docker run --rm mcp-enhanced:latest pwsh -File "./tests/Performance/Validate-McpPerformance.ps1"
# Access container shell
docker exec -it mcp-enhanced pwshPowerShell模块使用情况
# Initialize a new MCP session
$session = Initialize-McpSession -UserId "admin" -TimeoutMinutes 60
# Connect to an MCP instance
$instanceConfig = @{
Name = "My MCP Server"
BaseUrl = "http://localhost:3000"
ContainerName = "mcp-server-container"
}
$instance = Manage-McpInstance -Action "Connect" -InstanceConfig $instanceConfig
# List all connected instances
$instances = Manage-McpInstance -Action "List"
# Start real-time monitoring
Start-McpMonitoring -InstanceId $instance.InstanceId -IntervalSeconds 30
# Run diagnostics
$diagnostics = Start-McpDiagnostics -InstanceId $instance.InstanceId -TestType "All"
# Search MCP data
$results = Search-McpData -Query "error" -DataType "Logs" -TimeRange "Last24Hours"
# Create configuration profile
$configData = @{
GlobalSettings = @{
DefaultTimeout = 30
MaxRetries = 3
HealthCheckInterval = 60
}
}
$profile = Manage-McpConfiguration -Action "Create" -Name "Production Config" -ConfigurationData $configData🔧 配置
环境变量
| 变量 | 默认值 | 描述 |
|---|---|---|
MCP_DATA_DIR | /app/mcp/data | 数据目录路径 |
MCP_LOG_LEVEL | Info | 日志记录级别(调试、信息、警告、错误) |
MCP_AUTO_START | false | 容器启动时自动启动实例 |
DOCKER_HOST | unix:///var/run/docker.sock | Docker守护进程连接 |
卷装载
# Persistent data storage
docker run -v mcp-data:/app/mcp/data mcp-enhanced:latest
# Development mode (source code editing)
docker run -v "$(pwd):/app/mcp" mcp-enhanced:latest
# Docker socket access (for container management)
docker run -v /var/run/docker.sock:/var/run/docker.sock mcp-enhanced:latest🧪 示例服务器
Node.js Express服务器
# Start the Node.js example server
cd examples/node-server
npm install && npm start
# Available endpoints:
# GET /health - Health check
# GET /metrics - Performance metrics
# POST /config - Configuration updates
# GET /mcp/status - MCP protocol statusPython Flask服务器
# Start the Python example server
cd examples/python-server
pip install -r requirements.txt && python app.py
# Available endpoints:
# GET /health - System health with psutil metrics
# GET /metrics - Detailed performance data
# POST /mcp/execute - Execute MCP commands
# GET /mcp/tools - Available MCP tools📊 测试与验证
运行所有测试
# Inside container
pwsh -File "./tests/Run-AllTests.ps1" -TestType "All"
# From host
docker run --rm mcp-enhanced:latest pwsh -File "./tests/Run-AllTests.ps1"测试类别
# Contract tests (must fail before implementation)
Invoke-Pester "./tests/powershell/contract/" -Verbose
# Unit tests (component-level validation)
Invoke-Pester "./tests/Unit/" -Verbose
# Performance tests (load and response time)
./tests/Performance/Validate-McpPerformance.ps1 -LoadLevel "Heavy"测试结果
- ✅ 170+测试 所有类别
- ✅ 合同测试 确保正确的API合同
- ✅ 单元测试 验证各个组件
- ✅ 性能测试 验证可扩展性要求
- ✅ 集成测试 确认端到端工作流
🔍 监测和诊断
实时监控
# Start comprehensive monitoring
Start-McpMonitoring -TestSuite "All" -ShowProgress -IntervalSeconds 30
# Monitor specific instance
Start-McpMonitoring -InstanceId "abc123" -MetricTypes @("CPU", "Memory", "Response")
# Health checks
Manage-McpInstance -Action "Health" -InstanceId "abc123"诊断工具
# Full system diagnostics
Start-McpDiagnostics -TestType "All" -ShowProgress
# Network connectivity tests
Start-McpDiagnostics -TestType "Network" -TargetUrl "http://localhost:3000"
# Container status checks
Start-McpDiagnostics -TestType "Container" -ContainerName "mcp-server"🔐 安全与最佳实践
集装箱安全
- 非root用户 尽可能执行
- 最小基础图像 (Ubuntu 22.04 LTS)
- 安全扫描 集成到构建过程中
- 秘密管理 通过环境变量
网络安全
- 端口隔离 具有可配置的范围
- TLS/SSL支持 用于生产部署
- 认证 通过可配置的配置文件
- 访问日志记录 审计合规性
🚨 故障排除
常见问题
容器无法启动
# Check Docker daemon
docker info
# Verify image integrity
docker images | grep mcp-enhanced
# Check logs
docker logs mcp-enhanced模块加载错误
# Verify module paths
Get-Module -ListAvailable
# Force reload modules
Get-Module Mcp* | Remove-Module -Force
Import-Module ./scripts/powershell/modules/McpManager/McpManager.psd1端口冲突
# Check port usage
netstat -tulpn | grep :3000
# Use different ports
docker run -p 3100-3110:3000-3010 mcp-enhanced:latest性能问题
# Check system resources
Start-McpDiagnostics -TestType "Performance"
# Validate configuration
Manage-McpConfiguration -Action "Validate" -ProfileId "current"
# Monitor resource usage
Start-McpMonitoring -MetricTypes @("CPU", "Memory", "Disk", "Network")📚 高级用法
自定义配置文件
# Create production profile
$prodConfig = @{
GlobalSettings = @{
DefaultTimeout = 60
MaxRetries = 5
HealthCheckInterval = 30
LogLevel = "Warning"
}
InstanceSettings = @{
AutoRestart = $true
MaxMemoryMB = 2048
ScaleThreshold = 80
}
UserPreferences = @{
Theme = "Dark"
AutoSave = $true
ShowProgress = $false
}
}
$profile = Manage-McpConfiguration -Action "Create" -Name "Production" -ConfigurationData $prodConfig
Manage-McpConfiguration -Action "Apply" -ProfileId $profile.ProfileId批量操作
# Connect multiple instances
$configs = @(
@{ Name="Server1"; BaseUrl="http://localhost:3001"; ContainerName="mcp1" },
@{ Name="Server2"; BaseUrl="http://localhost:3002"; ContainerName="mcp2" },
@{ Name="Server3"; BaseUrl="http://localhost:3003"; ContainerName="mcp3" }
)
foreach ($config in $configs) {
Manage-McpInstance -Action "Connect" -InstanceConfig $config
}
# Batch health checks
$instances = Manage-McpInstance -Action "List"
$instances | ForEach-Object {
Manage-McpInstance -Action "Health" -InstanceId $_.InstanceId
}与CI/CD集成
# Example GitHub Actions workflow
name: MCP System Test
on: [push, pull_request]
jobs:
test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Build Docker Image
run: docker build -t mcp-enhanced:test .
- name: Run Tests
run: docker run --rm mcp-enhanced:test ./test-mcp.sh
- name: Performance Validation
run: docker run --rm mcp-enhanced:test pwsh -File "./tests/Performance/Validate-McpPerformance.ps1"🤝 贡献
该系统遵循企业开发实践:
- 模块化设计 -每个模块都有单一的职责
- 测试驱动开发 -所有功能都必须经过测试
- 文档 -全面的内联和外部文档
- PowerShell标准 -遵循公认的动词-名词惯例
- Docker最佳实践 -多阶段构建,最少层次
📄 许可证
企业模型上下文协议管理系统-内部使用
🆘 支持
有关技术支持和问题:
- 检查诊断:运行
Start-McpDiagnostics -TestType "All" - 审核日志:检查
/app/mcp/data/logs/目录 - 性能问题:使用
Start-McpMonitoring用于实时度量 - 配置:验证
Manage-McpConfiguration -Action "Validate"
______________________________________________________________________
🎉 您的MCP增强型管理系统已准备好进行企业部署!
从开始 docker run -it mcp-enhanced:latest 探索强大的管理能力。
