MCP ACS过程服务器
一种模型上下文协议(MCP)服务器,为AI代理提供进程管理和监控功能,具有由可执行的分配列表和资源限制强制执行的严格安全边界。
🔗 仓库
此包现在保存在自己的存储库中: ****
此存储库是 AI功能套件 在GitHub上。
目录
特性
- 进程启动:生成具有指定参数和环境变量的进程
- 资源监控:实时跟踪CPU、内存、线程数和I/O使用情况
- 输出捕获:分别捕获和检索stdout和stderr流
- 过程终止:优雅(SIGTERM)和强制(SIGKILL)终止,超时升级
- 服务管理:具有自动重启和健康检查功能的长期运行服务
- 流程组:管理相关流程并创建管道
- 超时管理:指定持续时间后自动终止进程
- I/O管理:发送stdin输入并检索缓冲输出
- 安全:具有可执行分配列表、参数验证和资源限制的多层安全性
- 审计日志:完整的安全和合规操作跟踪
安全
此服务器通过6层验证实现了深度防御安全:
- 可执行许可列表:只能启动预先批准的可执行文件
- 参数验证:针对注入攻击验证了命令参数
- 环境消毒:已删除危险环境变量
- 资源限制:CPU、内存和时间限制可防止资源耗尽
- 特权预防:没有权限升级或setuid可执行文件
- 审计日志:完整的操作跟踪
看 安全.md 详细的安全实施。
安装
Docker(推荐)
docker pull digitaldefiance/mcp-process:latest看 医生.md 了解详细的Docker使用说明。
NPM
npm install @ai-capabilities-suite/mcp-process纱线
yarn add @ai-capabilities-suite/mcp-process全球安装
npm install -g @ai-capabilities-suite/mcp-process快速开始
Docker快速入门
# Pull the image
docker pull digitaldefiance/mcp-process:latest
# Create config directory
mkdir -p config
# Create configuration
cat > config/mcp-process-config.json setTimeout(resolve, 1000));
// Get output
const output = await mcpClient.callTool("process_get_output", {
pid: result.pid,
});
console.log("Output:", output.stdout);示例2:监控资源使用情况
// Start a process
const result = await mcpClient.callTool("process_start", {
executable: "python3",
args: ["my_script.py"],
resourceLimits: {
maxCpuPercent: 50,
maxMemoryMB: 512,
},
});
// Monitor resources
const stats = await mcpClient.callTool("process_get_stats", {
pid: result.pid,
includeHistory: true,
});
console.log("CPU:", stats.cpuPercent + "%");
console.log("Memory:", stats.memoryMB + "MB");示例3:与Stdin的交互过程
// Start an interactive process
const result = await mcpClient.callTool("process_start", {
executable: "python3",
args: ["-i"],
captureOutput: true,
});
// Send input
await mcpClient.callTool("process_send_stdin", {
pid: result.pid,
data: 'print("Hello from AI agent")\n',
});
// Wait and get output
await new Promise((resolve) => setTimeout(resolve, 500));
const output = await mcpClient.callTool("process_get_output", {
pid: result.pid,
});
console.log("Output:", output.stdout);示例4:长期运行服务
// Start a service with auto-restart
const service = await mcpClient.callTool("process_start_service", {
name: "my-api-server",
executable: "node",
args: ["server.js"],
restartPolicy: {
enabled: true,
maxRetries: 3,
backoffMs: 5000,
},
healthCheck: {
command: "curl http://localhost:3000/health",
interval: 30000,
timeout: 5000,
},
});
console.log("Service started:", service.serviceId);示例5:流程组管道
// Create a process group
const group = await mcpClient.callTool("process_create_group", {
name: "data-pipeline",
pipeline: true,
});
// Start first process
const proc1 = await mcpClient.callTool("process_start", {
executable: "cat",
args: ["data.txt"],
captureOutput: true,
});
// Add to group
await mcpClient.callTool("process_add_to_group", {
groupId: group.groupId,
pid: proc1.pid,
});
// Start second process (will receive output from first)
const proc2 = await mcpClient.callTool("process_start", {
executable: "grep",
args: ["pattern"],
captureOutput: true,
});
await mcpClient.callTool("process_add_to_group", {
groupId: group.groupId,
pid: proc2.pid,
});故障排除
问题:“可执行文件不在allowlist中”
原因: 您尝试启动的可执行文件不在 allowedExecutables 配置。
解决方案: 将可执行文件添加到配置文件中:
{
"allowedExecutables": ["node", "python3", "/path/to/your/executable"]
}您可以使用:
- 绝对路径:
/usr/bin/node - 基础名称 :
node - 球状图案:
/usr/bin/*
问题:“Shell解释器被阻止”
原因: 您正试图启动一个shell(bash、sh、cmd.exe等),并且 blockShellInterpreters 已启用。
解决方案: 要么:
- 集
blockShellInterpreters: false在您的配置中(不推荐) - 直接启动实际的可执行文件,而不是通过shell
问题:“找不到进程”
原因: 进程已终止或PID无效。
解决方案: 使用检查进程是否仍在运行 process_list 或 process_get_status.
问题:“超出CPU限制”或“超出内存限制”
原因: 进程超出了配置的资源限制。
解决方案: 在配置或启动流程时增加资源限制:
{
"defaultResourceLimits": {
"maxCpuPercent": 90,
"maxMemoryMB": 2048
}
}问题:“已达到最大并发进程数”
原因: 您已到达 maxConcurrentProcesses 限制。
解决方案:
- 终止一些正在运行的进程
- 增加
maxConcurrentProcesses在您的配置中 - 等待进程完成
问题:“进程stdin不可用”
原因: 进程stdin已关闭或进程不支持stdin输入。
解决方案: 确保进程仍在运行,并且是在启用stdin的情况下启动的。
问题:找不到配置文件
原因: 服务器找不到您的配置文件。
解决方案:
- 使用
--config标志:mcp-process --config /path/to/config.json - 设置环境变量:
export MCP_PROCESS_CONFIG_PATH=/path/to/config.json - 将配置放置在
./mcp-process-config.json
调试
通过设置审核日志级别启用调试日志记录:
{
"enableAuditLog": true,
"auditLogLevel": "debug"
}查看审核日志,了解有关流程操作和安全违规的详细信息。
发展
先决条件
- Node.js>=18.0.0
- npm>=8.0.0
设置
# Clone the repository
git clone https://github.com/digital-defiance/ai-capabilities-suite.git
cd ai-capabilities-suite/packages/mcp-process
# Install dependencies
npm install
# Build
npm run build测试
# Run all tests (unit, integration, and e2e)
npm test
# Run tests with coverage
npm run test:coverage
# Run tests in watch mode
npm run test:watch
# Run specific test file
npm test -- SecurityManager.spec.ts
# Run only e2e tests
npm run test:e2e
# Run minimal e2e smoke tests (quick validation)
npm run test:e2e:minimal端到端(E2E)测试
MCP ACS Process Server包括全面的e2e测试,通过将服务器生成为子进程并使用JSON-RPC协议通过stdio进行通信来验证完整的系统行为。这些测试确保服务器在实际使用场景中正常工作。
E2E测试结构:
server.e2e.spec.ts-全面的e2e测试,涵盖所有MCP工具和协议功能server.minimal.e2e.spec.ts-用于基本功能验证的快速烟雾测试(\
许可证
MIT许可证-请参阅 许可证 文件以获取详细信息。
支持
- GitHub问题:
- 电子邮件:
相关项目
- MCP文件系统 -AI代理的文件系统操作
- MCP记录 -会话录制和回放
- MCP ACS调试器 -MCP协议调试工具
致谢
内置:
- @模型上下文协议/sdk -MCP协议实现
- 使用率 -过程资源监控
- 哪个 -可执行路径解析
- 小匹配 -球形图案匹配
