-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat: add Model Context Protocol (MCP) server #6066
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
Open
elasticdotventures
wants to merge
6
commits into
Unitech:master
Choose a base branch
from
PromptExecution:feature/mcp-server
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+1,219
β8
Open
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9dea47b
feat: add Model Context Protocol (MCP) server
elasticdotventures e842e3c
Update lib/mcp/server.js
elasticdotventures f5c335b
Update lib/mcp/server.js
elasticdotventures aea6485
Update lib/mcp/server.js
elasticdotventures a8dd92a
Update package.json
elasticdotventures ad9597f
Update Justfile
elasticdotventures File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,62 @@ | ||
| set dotenv-load | ||
| set export | ||
| set shell := ["bash", "-c"] | ||
|
|
||
| # Register the stdio MCP server with Claude Code | ||
| register-claude-stdio: | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| claude mcp add pm2-mcp -- pm2-mcp | ||
| claude mcp list | grep -F "pm2-mcp" || true | ||
|
|
||
| # 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}} | ||
|
|
||
| # Start the MCP server under PM2 management with HTTP transport | ||
| run-mcp-http-pm2 name="pm2-mcp-server" port="8849": | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| pm2-mcp --pm2 --pm2-name {{name}} --transport http --port {{port}} | ||
| pm2 list | grep -F "{{name}}" || true | ||
|
|
||
| # Register the HTTP transport endpoint with Claude Code (server must already be running) | ||
| register-claude-http name="pm2-mcp" host="127.0.0.1" port="8849" path="/mcp": | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| url="http://{{host}}:{{port}}{{path}}" | ||
| claude mcp add {{name}} --transport http -- "$url" | ||
| claude mcp list | grep -F "{{name}}" || true | ||
|
|
||
| # 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" | ||
| codex mcp list | grep -F "{{name}}" || true | ||
|
|
||
| # Run pm2-mcp with debug logging to see sandbox detection | ||
| debug-mcp: | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| PM2_MCP_DEBUG=true DEBUG=pm2-mcp* pm2-mcp | ||
|
|
||
| # Test sandbox detection | ||
| test-sandbox: | ||
| #!/usr/bin/env bash | ||
| set -euo pipefail | ||
| echo "Testing normal environment:" | ||
| node -e "const {detectSandbox} = require('./lib/mcp/server.js'); console.log(detectSandbox ? 'Available' : 'Not exported');" || echo "Normal detection test" | ||
| echo "" | ||
| echo "Testing with CLAUDE_CODE_SANDBOX=true:" | ||
| CLAUDE_CODE_SANDBOX=true PM2_MCP_DEBUG=true timeout 2 pm2-mcp 2>&1 | grep -i sandbox || echo "Check logs for sandbox detection" | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,105 @@ | ||
| #!/usr/bin/env node | ||
| 'use strict'; | ||
|
|
||
| const path = require('path'); | ||
| const { spawn } = require('child_process'); | ||
| const { startMcpServer } = require('../lib/mcp/server.js'); | ||
|
|
||
| function parseArgs(argv) { | ||
| const opts = { | ||
| serverOptions: {}, | ||
| passthroughArgs: [], | ||
| runWithPm2: false, | ||
| pm2Name: 'pm2-mcp' | ||
| }; | ||
|
|
||
| for (let i = 0; i < argv.length; i++) { | ||
| const arg = argv[i]; | ||
|
|
||
| if (arg === '--transport' && argv[i + 1]) { | ||
| opts.serverOptions.transportType = argv[++i]; | ||
| opts.passthroughArgs.push('--transport', opts.serverOptions.transportType); | ||
| continue; | ||
| } | ||
| if (arg.startsWith('--transport=')) { | ||
| const [, value] = arg.split('='); | ||
| opts.serverOptions.transportType = value; | ||
| opts.passthroughArgs.push(arg); | ||
| continue; | ||
| } | ||
|
|
||
| if (arg === '--port' && argv[i + 1]) { | ||
| opts.serverOptions.port = Number(argv[++i]); | ||
| opts.passthroughArgs.push('--port', String(opts.serverOptions.port)); | ||
| continue; | ||
| } | ||
| if (arg.startsWith('--port=')) { | ||
| const [, value] = arg.split('='); | ||
| opts.serverOptions.port = Number(value); | ||
| opts.passthroughArgs.push(arg); | ||
| continue; | ||
| } | ||
|
|
||
| if (arg === '--host' && argv[i + 1]) { | ||
| opts.serverOptions.host = argv[++i]; | ||
| opts.passthroughArgs.push('--host', opts.serverOptions.host); | ||
| continue; | ||
| } | ||
| if (arg.startsWith('--host=')) { | ||
| const [, value] = arg.split('='); | ||
| opts.serverOptions.host = value; | ||
| opts.passthroughArgs.push(arg); | ||
| continue; | ||
| } | ||
|
|
||
| if (arg === '--path' && argv[i + 1]) { | ||
| opts.serverOptions.path = argv[++i]; | ||
| opts.passthroughArgs.push('--path', opts.serverOptions.path); | ||
| continue; | ||
| } | ||
| if (arg.startsWith('--path=')) { | ||
| const [, value] = arg.split('='); | ||
| opts.serverOptions.path = value; | ||
| opts.passthroughArgs.push(arg); | ||
| continue; | ||
| } | ||
|
|
||
| if (arg === '--pm2' || arg === '--pm2-manage') { | ||
| opts.runWithPm2 = true; | ||
| continue; | ||
| } | ||
|
|
||
| if (arg === '--pm2-name' && argv[i + 1]) { | ||
| opts.pm2Name = argv[++i]; | ||
| continue; | ||
| } | ||
| if (arg.startsWith('--pm2-name=')) { | ||
| const [, value] = arg.split('='); | ||
| opts.pm2Name = value; | ||
| continue; | ||
| } | ||
|
|
||
| opts.passthroughArgs.push(arg); | ||
| } | ||
|
|
||
| return opts; | ||
| } | ||
|
|
||
| async function main() { | ||
| const { serverOptions, passthroughArgs, runWithPm2, pm2Name } = parseArgs(process.argv.slice(2)); | ||
|
|
||
| if (runWithPm2) { | ||
| const pm2Bin = path.join(__dirname, 'pm2'); | ||
| const args = ['start', __filename, '--name', pm2Name, '--', ...passthroughArgs]; | ||
| const child = spawn(pm2Bin, args, { stdio: 'inherit' }); | ||
| child.on('exit', code => process.exit(code ?? 0)); | ||
| return; | ||
| } | ||
|
|
||
| await startMcpServer(serverOptions); | ||
| } | ||
|
|
||
| main().catch(err => { | ||
| console.error('[pm2-mcp] failed to start', err); | ||
| process.exit(1); | ||
| }); |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.