feat: PM2 Native MCP Server — WORKING EXAMPLE
PM2 should optionally include a native MCP server to expose process introspection, logs, and control via HTTP/SSE.
Enablement:
pm2 start ecosystem.config.js --mcp
# or
pm2 set mcp.enabled true
pm2 set mcp.port 7777
Endpoints / Features:
/processes (GET) — list all processes, status, CPU/mem, uptime
/process/:id (GET) — detailed info on a process
/logs/:id (GET) — stream or search logs for a process (SSE or tail)
/restart/:id (POST) — restart a process
/stop/:id (POST) — stop a process
/scale/:id (POST) — scale cluster instances up/down
/metrics (GET) — CPU/mem, restart counts, uptime summary
/health (GET) — overall PM2 daemon health
Design Notes:
- MCP server disabled by default
- Authentication optional (token or local-only by default)
- Can serve multiple MCP clients concurrently
- Minimal footprint — reuses PM2 internal process table and log streams
Use Cases:
LLM / AI tool orchestration (query, restart, scale) Dev workflows: auto-tail logs, search history Ops dashboards / monitoring integration Programmatic PM2 control without shell commands
Summary:
- Native, optional MCP server
- Exposes logs, metrics, status, and control
- Lightweight, secure, opt-in
PM2 is not working great in Cursor right now, the logs function hangs most of the time and stalls the coding agent. Would this address that?
PM2 is not working great in Cursor right now, the logs function hangs most of the time and stalls the coding agent. Would this address that?
Yes - that's the idea.
I see that @Unitech gave a 🚀 which I'll assume is a tick of approvel/willingness to merge IF I was willing to contribute a PR.
The main challenge isn't building the mcp server -- is that pm2 is currently built in Node 16. Node.js 16 reached its official End-of-Life (EOL) on September 11, 2023, meaning it no longer receives security updates or maintenance from the Node.js project. All of the well maintained MCP SDK's are Typescript, and probably won't play well with NodeJS < 20.
I think moving a project from NodeJS 16 => 20 .. certainly requires it's own issue/discussion. I'm going to open a separate issue on that and reference this.
Quick update on the MCP workstream: I just opened #6041 to raise the minimum Node.js runtime to 22.x so we are on a currently supported LTS while we wire in MCP. That PR also syncs the packaging scripts and README messaging, so we do not have to do quite as much yak shaving when we slot in the SDK. As soon as #6041 lands, I will stack the MCP server implementation on top of it (using the official @modelcontextprotocol/sdk) and loop back here with the follow-up PR link.
@Unitech my fork has mcp support http://github.com/PromptExecution/pm2-mcp - do you want a PR?
Sure feel free to make this PR :)
PM2 is not working great in Cursor right now, the logs function hangs most of the time and stalls the coding agent. Would this address that?
@andri do you know what environment variable cursor uses in it's sandbox? i can probably detect that and output the logs differently (via mcp instead of stdout). feel free to put in an issue on promptexecution/pm2-mcp (or in this repo once this is merged) .. 🤔 ... or ask cursor to fix itself. 🤣 the code is pretty idiomatic. ;-)