-
Notifications
You must be signed in to change notification settings - Fork 2.7k
pm2-mcp #6065
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
pm2-mcp #6065
Changes from all commits
468a849
3a90692
29b0f21
7d0c2b9
02181e9
fefa542
a3431f0
341e310
2cf602c
dee69fc
845601f
2b7d9b4
a5a0228
637ff7e
c51a51c
9167ffd
3201d8f
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,24 @@ | ||||||||||||||||||||||||||||||||||
| set dotenv-load | ||||||||||||||||||||||||||||||||||
| set export | ||||||||||||||||||||||||||||||||||
| set shell := ["bash", "-c"] | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Register the stdio MCP server with Codex CLI | ||||||||||||||||||||||||||||||||||
| register-codex-stdio: | ||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||
| codex mcp add pm2-mcp -- pm2-mcp | ||||||||||||||||||||||||||||||||||
| codex mcp list | grep -F "pm2-mcp" || true | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Start the MCP server over HTTP/Streamable transport (adjust host/port/path as needed) | ||||||||||||||||||||||||||||||||||
| run-mcp-http host="127.0.0.1" port="8849" path="/mcp": | ||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||
| pm2-mcp --transport http --host {{host}} --port {{port}} --path {{path}} | ||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||
| # Register the HTTP transport endpoint with Codex CLI (server must already be running) | ||||||||||||||||||||||||||||||||||
| register-codex-http name="pm2-mcp-http" host="127.0.0.1" port="8849" path="/mcp": | ||||||||||||||||||||||||||||||||||
| #!/usr/bin/env bash | ||||||||||||||||||||||||||||||||||
| set -euo pipefail | ||||||||||||||||||||||||||||||||||
| url="http://{{host}}:{{port}}{{path}}" | ||||||||||||||||||||||||||||||||||
| codex mcp add {{name}} --url "$url" | ||||||||||||||||||||||||||||||||||
|
Comment on lines
+19
to
+23
|
||||||||||||||||||||||||||||||||||
| register-codex-http name="pm2-mcp-http" host="127.0.0.1" port="8849" path="/mcp": | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| url="http://{{host}}:{{port}}{{path}}" | |
| codex mcp add {{name}} --url "$url" | |
| # WARNING: Do not expose the MCP server beyond localhost without HTTPS and authentication! | |
| # If you must expose externally, use https:// and provide an API key or mTLS. | |
| register-codex-http name="pm2-mcp-http" host="127.0.0.1" port="8849" path="/mcp" api_key="": | |
| #!/usr/bin/env bash | |
| set -euo pipefail | |
| url="https://{{host}}:{{port}}{{path}}" | |
| if [ -n "{{api_key}}" ]; then | |
| codex mcp add {{name}} --url "$url" --header "Authorization: Bearer {{api_key}}" | |
| else | |
| codex mcp add {{name}} --url "$url" | |
| fi |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -38,7 +38,7 @@ PM2 is constantly assailed by [more than 1800 tests](https://github.com/Unitech/ | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Official website: [https://pm2.keymetrics.io/](https://pm2.keymetrics.io/) | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| Works on Linux (stable) & macOS (stable) & Windows (stable). All Node.js versions are supported starting Node.js 12.X and Bun since v1 | ||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -222,6 +222,21 @@ $ pm2 update | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| *PM2 updates are seamless* | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| ## MCP server | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| PM2 now bundles an [MCP](https://modelcontextprotocol.io/specification/2025-11-25) stdio server that exposes the core process controls (list, describe, start, restart, reload, stop, delete, log flush/rotation, dump, daemon kill) plus process resources. | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| - 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: `pm2-mcp --transport http --port 8849 --host 0.0.0.0 --path /mcp` (env aliases: `PM2_MCP_TRANSPORT`, `PM2_MCP_PORT`, `PM2_MCP_HOST`, `PM2_MCP_PATH`). | ||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||
| - Prefer the Streamable HTTP transport for long-lived usage: `pm2-mcp --transport http --port 8849 --host 0.0.0.0 --path /mcp` (env aliases: `PM2_MCP_TRANSPORT`, `PM2_MCP_PORT`, `PM2_MCP_HOST`, `PM2_MCP_PATH`). | |
| - Prefer the Streamable HTTP transport for long-lived usage: `pm2-mcp --transport http --port 8849 --host 127.0.0.1 --path /mcp` (env aliases: `PM2_MCP_TRANSPORT`, `PM2_MCP_PORT`, `PM2_MCP_HOST`, `PM2_MCP_PATH`). | |
| > ⚠️ **Security Warning:** | |
| > The MCP server exposes powerful PM2 management APIs. **Do not bind to `0.0.0.0` or expose the MCP server to public or untrusted networks without proper security controls.** | |
| > For production or remote access, always: | |
| > - Use HTTPS (e.g., run behind a reverse proxy with TLS termination) | |
| > - Require strong authentication (API key/token or mutual TLS) | |
| > - Bind to `127.0.0.1` by default and only open firewall ports if strictly necessary | |
| > - Document and restrict access via firewall rules | |
| > Exposing the MCP server without these controls can allow attackers to start/stop/delete processes, rotate logs, or kill the PM2 daemon. |
Copilot
AI
Dec 3, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The example command pm2-mcp --transport http --port 8849 --host 0.0.0.0 --path /mcp exposes the MCP control surface over cleartext HTTP on all interfaces without any authentication. This enables remote manipulation of PM2-managed processes by anyone who can reach the port. Prefer HTTPS with TLS, restrict binding to 127.0.0.1 by default, and enforce authentication (API key/token or mTLS).
| - Prefer the Streamable HTTP transport for long-lived usage: `pm2-mcp --transport http --port 8849 --host 0.0.0.0 --path /mcp` (env aliases: `PM2_MCP_TRANSPORT`, `PM2_MCP_PORT`, `PM2_MCP_HOST`, `PM2_MCP_PATH`). | |
| - **Secure usage recommended:** Always bind the MCP server to `127.0.0.1` (localhost) and use HTTPS with authentication. For example:<br> | |
| <code>pm2-mcp --transport https --port 8849 --host 127.0.0.1 --path /mcp --auth-token <YOUR_TOKEN> --tls-cert <PATH_TO_CERT> --tls-key <PATH_TO_KEY></code><br> | |
| <br> | |
| <b>Warning:</b> <i>Do not expose the MCP server on public interfaces (e.g., <code>0.0.0.0</code>) or use cleartext HTTP without authentication. This can allow remote manipulation of PM2-managed processes by anyone who can reach the port.</i><br> | |
| <br> | |
| (env aliases: <code>PM2_MCP_TRANSPORT</code>, <code>PM2_MCP_PORT</code>, <code>PM2_MCP_HOST</code>, <code>PM2_MCP_PATH</code>) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| #!/usr/bin/env node | ||
| require('../lib/mcp/server.js'); |
Large diffs are not rendered by default.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
run-mcp-httprecipe starts the MCP server using cleartexthttpand binds to a user-provided host (default127.0.0.1) with no authentication. If the host is set to0.0.0.0or a public IP, this would expose PM2 controls to remote clients without encryption or auth. Enforce localhost binding by default, support HTTPS/TLS, and require an authentication mechanism (API key/token or mTLS).