mcp-optimizer 0.0.1-alpha.1 → 0.0.3-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/mcp-optimizer.js +29 -1
- package/dist/mcpServer.js +33 -1
- package/package.json +1 -1
- package/src/mcpServer.ts +31 -1
package/bin/mcp-optimizer.js
CHANGED
|
@@ -1,9 +1,37 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
|
|
3
3
|
// Lightweight CLI wrapper for the MCP Optimizer package.
|
|
4
|
-
//
|
|
4
|
+
// Accept `--port <n>` or `--port=<n>` (or `--audit-port`) to configure the server
|
|
5
|
+
// port when launching via `npx` (e.g. `npx -y mcp-optimizer -- --port 6000`).
|
|
5
6
|
|
|
6
7
|
try {
|
|
8
|
+
const args = process.argv.slice(2);
|
|
9
|
+
for (let i = 0; i < args.length; i++) {
|
|
10
|
+
const a = args[i];
|
|
11
|
+
// Accept environment-style args like PORT=6000
|
|
12
|
+
if (a.includes('=') && !a.startsWith('--')) {
|
|
13
|
+
const [k, v] = a.split('=', 2);
|
|
14
|
+
if (k && v !== undefined) {
|
|
15
|
+
process.env[k] = v;
|
|
16
|
+
continue;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
if (a.startsWith('--port=')) {
|
|
20
|
+
process.env.PORT = a.split('=')[1];
|
|
21
|
+
}
|
|
22
|
+
else if (a === '--port' && args[i + 1]) {
|
|
23
|
+
process.env.PORT = args[i + 1];
|
|
24
|
+
i++;
|
|
25
|
+
}
|
|
26
|
+
else if (a.startsWith('--audit-port=')) {
|
|
27
|
+
process.env.AUDIT_PORT = a.split('=')[1];
|
|
28
|
+
}
|
|
29
|
+
else if (a === '--audit-port' && args[i + 1]) {
|
|
30
|
+
process.env.AUDIT_PORT = args[i + 1];
|
|
31
|
+
i++;
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
7
35
|
// Require built output. When installed via npm the package root
|
|
8
36
|
// will contain `dist/index.js` after `npm pack` / `npm publish`.
|
|
9
37
|
require('../dist/index.js');
|
package/dist/mcpServer.js
CHANGED
|
@@ -205,7 +205,39 @@ exports.LighthouseMcpServer = LighthouseMcpServer;
|
|
|
205
205
|
exports.default = LighthouseMcpServer;
|
|
206
206
|
async function startMcpServer() {
|
|
207
207
|
// Run HTTP/SSE server
|
|
208
|
-
|
|
208
|
+
// Prefer explicit environment variables, but also allow parsing CLI args
|
|
209
|
+
// (e.g. when launched directly without the lightweight `bin` wrapper).
|
|
210
|
+
let portEnv = process.env.PORT || process.env.AUDIT_PORT;
|
|
211
|
+
if (!portEnv) {
|
|
212
|
+
const args = process.argv.slice(2);
|
|
213
|
+
for (let i = 0; i < args.length; i++) {
|
|
214
|
+
const a = args[i];
|
|
215
|
+
if (a.includes('=') && !a.startsWith('--')) {
|
|
216
|
+
const [k, v] = a.split('=', 2);
|
|
217
|
+
if ((k === 'PORT' || k === 'AUDIT_PORT') && v !== undefined) {
|
|
218
|
+
portEnv = v;
|
|
219
|
+
break;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
if (a.startsWith('--port=')) {
|
|
223
|
+
portEnv = a.split('=')[1];
|
|
224
|
+
break;
|
|
225
|
+
}
|
|
226
|
+
else if (a === '--port' && args[i + 1]) {
|
|
227
|
+
portEnv = args[i + 1];
|
|
228
|
+
break;
|
|
229
|
+
}
|
|
230
|
+
else if (a.startsWith('--audit-port=')) {
|
|
231
|
+
portEnv = a.split('=')[1];
|
|
232
|
+
break;
|
|
233
|
+
}
|
|
234
|
+
else if (a === '--audit-port' && args[i + 1]) {
|
|
235
|
+
portEnv = args[i + 1];
|
|
236
|
+
break;
|
|
237
|
+
}
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
const port = Number(portEnv || 5000);
|
|
209
241
|
const mcp = new LighthouseMcpServer();
|
|
210
242
|
let sseTransport = null;
|
|
211
243
|
const pendingPosts = [];
|
package/package.json
CHANGED
package/src/mcpServer.ts
CHANGED
|
@@ -192,7 +192,37 @@ export default LighthouseMcpServer;
|
|
|
192
192
|
|
|
193
193
|
export async function startMcpServer(): Promise<void> {
|
|
194
194
|
// Run HTTP/SSE server
|
|
195
|
-
|
|
195
|
+
// Prefer explicit environment variables, but also allow parsing CLI args
|
|
196
|
+
// (e.g. when launched directly without the lightweight `bin` wrapper).
|
|
197
|
+
let portEnv = process.env.PORT || process.env.AUDIT_PORT;
|
|
198
|
+
if (!portEnv) {
|
|
199
|
+
const args = process.argv.slice(2);
|
|
200
|
+
for (let i = 0; i < args.length; i++) {
|
|
201
|
+
const a = args[i];
|
|
202
|
+
if (a.includes('=') && !a.startsWith('--')) {
|
|
203
|
+
const [k, v] = a.split('=', 2);
|
|
204
|
+
if ((k === 'PORT' || k === 'AUDIT_PORT') && v !== undefined) {
|
|
205
|
+
portEnv = v;
|
|
206
|
+
break;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
if (a.startsWith('--port=')) {
|
|
210
|
+
portEnv = a.split('=')[1];
|
|
211
|
+
break;
|
|
212
|
+
} else if (a === '--port' && args[i + 1]) {
|
|
213
|
+
portEnv = args[i + 1];
|
|
214
|
+
break;
|
|
215
|
+
} else if (a.startsWith('--audit-port=')) {
|
|
216
|
+
portEnv = a.split('=')[1];
|
|
217
|
+
break;
|
|
218
|
+
} else if (a === '--audit-port' && args[i + 1]) {
|
|
219
|
+
portEnv = args[i + 1];
|
|
220
|
+
break;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
const port = Number(portEnv || 5000);
|
|
196
226
|
const mcp = new LighthouseMcpServer();
|
|
197
227
|
let sseTransport: SSEServerTransport | null = null;
|
|
198
228
|
const pendingPosts: Array<{ body: string; url: string | undefined; headers: any }> = [];
|