进程管理服务

PM-MCP是一个模型上下文协议(MCP)服务器,允许Claude和其他LLM管理长期运行的bash进程,适用于开发服务器、构建过程和其他开发会话中的后台任务管理。

  • by patrickjm
  • TypeScript
  • 本地部署
  • 2 星标
  • 更新于
在 GitHub 查看 patrickjm/pm-mcp

使用说明

PM-MCP(过程经理MCP)

一种模型上下文协议(MCP)服务器,允许Claude和其他LLM管理长时间运行的bash进程。非常适合在开发会话期间管理开发服务器、构建流程和其他后台任务。

特性

  • 启动进程:启动具有名称和描述的长时间运行的bash命令
  • 流程管理:一次终止单个进程或所有进程
  • 日志管理:捕获、检索和搜索stdout/stderr日志
  • 过程交互:向正在运行的进程发送输入
  • 故障检测:无法启动的流程立即报告错误
  • CLI工具:用于流程管理的独立命令行界面
  • 持续日志记录:所有进程日志都保存到磁盘上,以便以后检索

安装

npm install -g pm-mcp

用法

作为MCP服务器

配置您的MCP客户端以使用此服务器:

{
  "mcpServers": {
    "pm-mcp": {
      "command": "npx",
      "args": ["pm-mcp"]
    }
  }
}

可用的MCP工具

  1. start_process -启动新流程

    • name (必填):用于识别的流程名称
    • command (必需):要执行的Bash命令
    • description (可选):工艺说明
    • cwd (可选):工作目录
  2. 终止进程 -停止特定进程

    • id (必填):要终止的进程ID
  3. 终止所有流程 -停止所有托管进程

  4. 列表_流程 -列出所有流程

    • id (可选):获取特定流程的信息
  5. get_logs -检索流程日志

    • id (必填):进程ID
    • lines (可选):最近行数
  6. grep_logs -搜索进程日志

    • id (必填):进程ID
    • pattern (必填):正则表达式搜索模式
  7. send_input -向正在运行的进程发送输入

    • id (必填):进程ID
    • input (必填):输入要发送的字符串

CLI工具

# Start a process
npx pm-mcp cli start "dev-server" "npm run dev" --description "Development server"

# List all processes
npx pm-mcp cli list

# Get logs
npx pm-mcp cli logs <process-id>

# Search logs
npx pm-mcp cli grep <process-id> "error"

# Send input to process
npx pm-mcp cli input <process-id> "some input"

# Terminate process
npx pm-mcp cli terminate <process-id>

# Terminate all processes
npx pm-mcp cli terminate-all

Claude使用示例

Claude: I'll start your development servers for you.

User: Start a React dev server on port 3000 and an API server on port 8080

Claude: I'll start both servers for you.

[Uses start_process tool]
- Name: "react-dev"
- Command: "npm run dev"
- Description: "React development server on port 3000"

[Uses start_process tool]  
- Name: "api-server"
- Command: "npm run api:dev"
- Description: "API development server on port 8080"

Both servers are now running. You can check their logs or terminate them anytime.

User: Check if there are any errors in the React server

Claude: [Uses grep_logs tool with pattern "error"]
No errors found in the React server logs.

User: Send "q" to quit the API server

Claude: [Uses send_input tool]
Input "q" sent to the API server process.

日志文件

流程日志存储在 ./pm-mcp-logs/ 格式为的目录 <process-id>.log。每个日志条目包括:

  • 时间戳
  • 流类型(stdout/stderr)
  • 日志内容

发展

# Build the project
npm run build

# Watch mode for development
npm run dev

# Run the MCP server
npm start

# Use the CLI
npx pm-mcp cli --help

建筑

  • 进程管理器:核心类处理流程生命周期、日志记录和管理
  • MCP服务器:通过MCP协议公开流程管理功能
  • CLI工具:用于直接流程管理的独立界面
  • 日志记录:具有时间戳和流类型跟踪的持久性基于文件的日志记录