pm2-mcp
An MCP server that gives agents structured read and limited write access to PM2 services.
README
pm2-mcp
An MCP server that gives agents structured read and limited write access to PM2 services. Built with FastMCP, transport is streamable-http bound to localhost.
I built this because every other approach to PM2 inspection from an agent involves either raw shell access (homelab-ops run_command) or scraping human-readable pm2 status output. This server speaks directly to pm2 jlist, returns typed fields, and validates service names before issuing any write operations.
flowchart LR
subgraph shell["Shell access"]
direction LR
s1["agent"] -->|"run_command\npm2 jlist"| s2["unparsed\nJSON string"]
end
subgraph mcp["pm2-mcp"]
direction LR
m1["agent"] -->|"list_services"| m2["typed fields\nstatus · uptime_ms\ncpu_pct · memory_mb"]
end
Tools
Read
| Tool | Description |
|---|---|
list_services |
List all PM2 services. Optional status_filter: "online", "stopped", or "errored". |
get_service |
Full detail for one service by name — script path, cwd, args, log file paths, created_at, plus all summary fields. |
get_logs |
Tail recent log output. lines defaults to 50 (max 500); include_errors defaults to true. |
get_status |
Server metadata and PM2 health summary — configured host/port, PM2 version, service counts by status. |
Write
| Tool | Description |
|---|---|
restart_service |
Restart a service. Validates the name first — returns {ok: false} if not found. |
stop_service |
Stop a service. Does not remove it from the PM2 process list. |
start_service |
Resume a stopped service already registered in PM2. Does not register new processes. |
reload_service |
Gracefully reload a service (zero-downtime). Preferred over restart_service for production services. |
save |
Persist the current PM2 process list to disk. Call after write operations to survive reboots. |
flush_logs |
Clear log files for a service. |
Response shape — list_services
[
{
"name": "my-service",
"pm_id": 12,
"status": "online",
"pid": 18432,
"uptime_ms": 3720000,
"restarts": 0,
"cpu_pct": 0.2,
"memory_mb": 48.5,
"exec_mode": "fork_mode"
}
]
get_service extends this with script, cwd, args, log_file, error_file, and created_at.
Setup
Requirements
- Python 3.11+
- PM2 installed and in PATH for the user running the server
fastmcp>=3.2.4(seerequirements.txt)
pip install -r requirements.txt
Run as a PM2 process (recommended)
Using ecosystem.config.js (recommended — add to your existing config):
{
name: 'pm2-mcp',
script: 'server.py',
interpreter: 'python3',
env: {
PYTHONUNBUFFERED: '1',
MCP_HOST: '127.0.0.1',
MCP_PORT: '8486',
}
}
pm2 start ecosystem.config.js --only pm2-mcp
pm2 save
Or inline with env vars:
MCP_HOST=127.0.0.1 MCP_PORT=8486 pm2 start server.py --interpreter python3 --name pm2-mcp
pm2 save
The server manages itself like any other PM2 service — it will appear in its own list_services output.
Run directly
python server.py
Environment Variables
| Variable | Default | Description |
|---|---|---|
MCP_HOST |
127.0.0.1 |
Bind address for the MCP server |
MCP_PORT |
8486 |
Port for the MCP server |
Copy .env.example to .env and fill in the values you need. Blank values use the defaults shown above.
Wiring to Claude Code
Add to ~/.claude/settings.json under mcpServers:
{
"mcpServers": {
"pm2": {
"type": "streamable-http",
"url": "http://127.0.0.1:8486/mcp"
}
}
}
Security
The server binds to 127.0.0.1 by default. Any client that can reach port 8486 can restart or stop services — there is no authentication. This is intentional for local agent use: keep it localhost-only and don't proxy it externally.
The write tools (restart_service, stop_service, start_service, reload_service, flush_logs) validate service names against the live PM2 process list before acting. An unrecognized name returns {ok: false, error: "service '...' not found"} without touching PM2.
Testing
pip install -r requirements.txt -r requirements-dev.txt
pytest -v
All tests mock _run_pm2 — no PM2 installation required.
License
MIT
推荐服务器
Baidu Map
百度地图核心API现已全面兼容MCP协议,是国内首家兼容MCP协议的地图服务商。
Playwright MCP Server
一个模型上下文协议服务器,它使大型语言模型能够通过结构化的可访问性快照与网页进行交互,而无需视觉模型或屏幕截图。
Magic Component Platform (MCP)
一个由人工智能驱动的工具,可以从自然语言描述生成现代化的用户界面组件,并与流行的集成开发环境(IDE)集成,从而简化用户界面开发流程。
Audiense Insights MCP Server
通过模型上下文协议启用与 Audiense Insights 账户的交互,从而促进营销洞察和受众数据的提取和分析,包括人口统计信息、行为和影响者互动。
VeyraX
一个单一的 MCP 工具,连接你所有喜爱的工具:Gmail、日历以及其他 40 多个工具。
graphlit-mcp-server
模型上下文协议 (MCP) 服务器实现了 MCP 客户端与 Graphlit 服务之间的集成。 除了网络爬取之外,还可以将任何内容(从 Slack 到 Gmail 再到播客订阅源)导入到 Graphlit 项目中,然后从 MCP 客户端检索相关内容。
Kagi MCP Server
一个 MCP 服务器,集成了 Kagi 搜索功能和 Claude AI,使 Claude 能够在回答需要最新信息的问题时执行实时网络搜索。
e2b-mcp-server
使用 MCP 通过 e2b 运行代码。
Neon MCP Server
用于与 Neon 管理 API 和数据库交互的 MCP 服务器
Exa MCP Server
模型上下文协议(MCP)服务器允许像 Claude 这样的 AI 助手使用 Exa AI 搜索 API 进行网络搜索。这种设置允许 AI 模型以安全和受控的方式获取实时的网络信息。