pm2 icon indicating copy to clipboard operation
pm2 copied to clipboard

feat: PM2 Native MCP Server — WORKING EXAMPLE

Open elasticdotventures opened this issue 3 months ago • 7 comments

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

elasticdotventures avatar Aug 24 '25 13:08 elasticdotventures

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 avatar Sep 25 '25 20:09 andri

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.

elasticdotventures avatar Sep 26 '25 08:09 elasticdotventures

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.

elasticdotventures avatar Sep 26 '25 23:09 elasticdotventures

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.

elasticdotventures avatar Sep 26 '25 23:09 elasticdotventures

@Unitech my fork has mcp support http://github.com/PromptExecution/pm2-mcp - do you want a PR?

elasticdotventures avatar Dec 02 '25 02:12 elasticdotventures

Sure feel free to make this PR :)

Unitech avatar Dec 02 '25 07:12 Unitech

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. ;-)

elasticdotventures avatar Dec 03 '25 11:12 elasticdotventures