Skip to content

PromptExecution/pm2-mcp

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation


https://raw.githubusercontent.com/Unitech/pm2/master/pres/pm2-logo-2.png

P(rocess) M(anager) 2
Runtime Edition

Downloads per Month Downloads per Year npm version


PM2 is a production process manager for Node.js/Bun applications with a built-in load balancer. It allows you to keep applications alive forever, to reload them without downtime and to facilitate common system admin tasks.

Starting an application in production mode is as easy as:

$ pm2 start app.js

PM2 is constantly assailed by more than 1800 tests.

Official website: https://pm2.keymetrics.io/

Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 22.0.0 and Bun since v1

Installing PM2

With NPM

$ npm install pm2 -g

With Bun

$ bun install pm2 -g

Please note that you might need to symlink node to bun if you only want to use bun via sudo ln -s /home/$USER/.bun/bin/bun /usr/bin/node


You can install Node.js easily with NVM or FNM or install Bun with curl -fsSL https://bun.sh/install | bash

Start an application

You can start any application (Node.js, Bun, and also Python, Ruby, binaries in $PATH...) like that:

$ pm2 start app.js

Your app is now daemonized, monitored and kept alive forever.

Managing Applications

Once applications are started you can manage them easily:

Process listing

To list all running applications:

$ pm2 list

Managing apps is straightforward:

$ pm2 stop     <app_name|namespace|id|'all'|json_conf>
$ pm2 restart  <app_name|namespace|id|'all'|json_conf>
$ pm2 delete   <app_name|namespace|id|'all'|json_conf>

To have more details on a specific application:

$ pm2 describe <id|app_name>

To monitor logs, custom metrics, application information:

$ pm2 monit

More about Process Management

Cluster Mode: Node.js Load Balancing & Zero Downtime Reload

The Cluster mode is a special mode when starting a Node.js application, it starts multiple processes and load-balance HTTP/TCP/UDP queries between them. This increase overall performance (by a factor of x10 on 16 cores machines) and reliability (faster socket re-balancing in case of unhandled errors).

Framework supported

Starting a Node.js application in cluster mode that will leverage all CPUs available:

$ pm2 start api.js -i <processes>

<processes> can be 'max', -1 (all cpu minus 1) or a specified number of instances to start.

Zero Downtime Reload

Hot Reload allows to update an application without any downtime:

$ pm2 reload all

More informations about how PM2 make clustering easy

Container Support

With the drop-in replacement command for node, called pm2-runtime, run your Node.js application in a hardened production environment. Using it is seamless:

RUN npm install pm2 -g
CMD [ "pm2-runtime", "npm", "--", "start" ]

Read More about the dedicated integration

Host monitoring speedbar

PM2 allows to monitor your host/server vitals with a monitoring speedbar.

To enable host monitoring:

$ pm2 set pm2:sysmonit true
$ pm2 update

Framework supported

Terminal Based Monitoring

Monit

Monitor all processes launched straight from the command line:

$ pm2 monit

Log Management

To consult logs just type the command:

$ pm2 logs

Standard, Raw, JSON and formated output are available.

Examples:

$ pm2 logs APP-NAME       # Display APP-NAME logs
$ pm2 logs --json         # JSON output
$ pm2 logs --format       # Formated output

$ pm2 flush               # Flush all logs
$ pm2 reloadLogs          # Reload all logs

To enable log rotation install the following module

$ pm2 install pm2-logrotate

More about log management

Startup Scripts Generation

PM2 can generate and configure a Startup Script to keep PM2 and your processes alive at every server restart.

Init Systems Supported: systemd, upstart, launchd, rc.d

# Generate Startup Script
$ pm2 startup

# Freeze your process list across server restart
$ pm2 save

# Remove Startup Script
$ pm2 unstartup

More about Startup Scripts Generation

Updating PM2

# Install latest PM2 version
$ npm install pm2@latest -g
# Save process list, exit old PM2 & restore all processes
$ pm2 update

PM2 updates are seamless

MCP server

PM2 now bundles an MCP stdio server that exposes the core process controls (list, describe, start, restart, reload, stop, delete, log flush/rotation, dump, daemon kill) plus process resources.

Quick Setup

Claude Code (stdio)

# Add pm2-mcp to Claude Code
claude mcp add pm2-mcp -- pm2-mcp

# Verify it's connected
claude mcp list

# Get details
claude mcp get pm2-mcp

Codex (stdio)

# Add pm2-mcp to Codex
codex mcp add pm2-mcp -- pm2-mcp

# Verify registration
codex mcp list

HTTP Transport (for long-lived usage)

# Start HTTP server
pm2-mcp --transport http --port 8849 --host 127.0.0.1 --path /mcp

# Or with PM2 to keep it alive
pm2-mcp --pm2 --pm2-name mcp-server --transport http --port 8849

# Register with Claude Code (HTTP)
claude mcp add pm2-mcp --transport http -- http://127.0.0.1:8849/mcp

# Register with Codex (HTTP)
codex mcp add pm2-mcp --transport http -- http://127.0.0.1:8849/mcp

Environment Variables

Variable Default Description
PM2_HOME ~/.pm2 PM2 home directory for sockets/logs
PM2_MCP_HOME - Override PM2_HOME specifically for MCP server
PM2_MCP_TRANSPORT stdio Transport type: stdio, http, sse, streamable
PM2_MCP_PORT 8849 Port for HTTP/SSE transport
PM2_MCP_HOST 127.0.0.1 Host for HTTP/SSE transport
PM2_MCP_PATH /mcp Path for HTTP/SSE transport
PM2_MCP_NO_DAEMON true Use PM2 no-daemon mode (recommended for sandboxed clients)
PM2_SILENT true Silence PM2 CLI output for clean stdio
PM2_PROGRAMMATIC true Run PM2 in programmatic mode
PM2_MCP_DEBUG false Enable debug logging (sandbox detection, transport info)
PM2_MCP_ALLOWED_HOSTS - Comma-separated list of allowed hosts for HTTP transport
PM2_MCP_ALLOWED_ORIGINS - Comma-separated list of allowed origins for HTTP transport
PM2_MCP_DNS_PROTECTION true Enable DNS rebinding protection
DEBUG - Node.js debug namespace: pm2-mcp* for all logs, pm2-mcp:req for requests
CLAUDE_CODE_SANDBOX - Set to true to indicate Claude Code sandbox environment

Sandbox Detection

The MCP server automatically detects sandboxed environments and adapts:

  • Home Directory Check: Tests if ~/.pm2 is writable
  • Environment Detection: Checks for CLAUDE_CODE_SANDBOX=true
  • Permission Detection: Detects UID mismatches (setuid)
  • Fallback Locations: Automatically tries /tmp/pm2-mcp and ./.pm2-mcp in sandboxed environments
  • Client Notifications: Sends MCP logging notifications to clients when sandbox is detected

When running in a sandboxed environment, the server will:

  1. Automatically use a writable location for PM2_HOME
  2. Send a warning notification to the MCP client with:
    • Sandbox detection reasons
    • Current PM2_HOME location
    • Recommendations for optimal configuration
  3. Log sandbox status (when PM2_MCP_DEBUG=true)

Enable PM2_MCP_DEBUG=true to see sandbox detection details:

DEBUG=pm2-mcp* PM2_MCP_DEBUG=true pm2-mcp

MCP Protocol Support: The server uses the MCP notifications/message logging protocol to inform clients about sandbox status and limitations. Compatible MCP clients (like Claude Code) will display these notifications automatically.

Features

  • Run it with pm2-mcp (or npm run mcp) and point your MCP client at that stdio command.
  • Prefer the Streamable HTTP transport for long-lived usage.
  • By default the server starts in PM2 no-daemon mode for compatibility with sandboxed MCP clients. Set PM2_MCP_NO_DAEMON=false to connect to an existing PM2 daemon instead.
  • PM2 CLI noise is silenced automatically to keep stdio clean for the MCP handshake; set PM2_SILENT=false only if you need PM2 console output.
  • Run the server under PM2 itself with pm2-mcp --pm2 --pm2-name mcp-server --transport http --port 8849 to keep it alive across restarts.
  • Logging: set DEBUG=pm2-mcp* to see lifecycle/activity logs (transport selection, PM2 connects, tool calls).

Available Tools

  • pm2_list_processes - List all PM2 processes with basic metrics
  • pm2_describe_process - Get detailed process information
  • pm2_start_process - Start a new process or ecosystem file
  • pm2_restart_process - Restart a process by id/name
  • pm2_reload_process - Zero-downtime reload (cluster mode)
  • pm2_stop_process - Stop a process by id/name
  • pm2_delete_process - Delete a process from PM2
  • pm2_flush_logs - Flush log files for a process
  • pm2_reload_logs - Rotate and reopen log files
  • pm2_dump - Save process list to disk
  • pm2_tail_logs - Read last N lines from process logs
  • pm2_kill_daemon - Stop PM2 daemon and all processes

Available Resources

  • pm2://processes - Current PM2 process list as JSON
  • pm2://process/{id} - Detailed process information as JSON

PM2+ Monitoring

If you manage your apps with PM2, PM2+ makes it easy to monitor and manage apps across servers.

https://app.pm2.io/

Feel free to try it:

Discover the monitoring dashboard for PM2

Thanks in advance and we hope that you like PM2!

CHANGELOG

CHANGELOG

Contributors

Contributors

License

PM2 is made available under the terms of the GNU Affero General Public License 3.0 (AGPL 3.0). For other licenses contact us.

About

Node.js Production Process Manager with a built-in Load Balancer.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 81.9%
  • Shell 17.3%
  • Smarty 0.6%
  • Just 0.2%
  • Dockerfile 0.0%
  • Python 0.0%