mcp-optimizer 0.0.4-alpha.1 → 0.0.6-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/dist/mcpServer.js CHANGED
@@ -246,10 +246,15 @@ async function startMcpServer() {
246
246
  // launched as a stdio child by an MCP host and use the stdio transport.
247
247
  const shouldUseStdio = (process.stdin && !process.stdin.isTTY) && (process.stdout && !process.stdout.isTTY);
248
248
  if (shouldUseStdio) {
249
+ // Redirect console output to stderr to avoid corrupting the JSON stdio protocol
250
+ const _orig = { log: console.log, info: console.info, warn: console.warn };
251
+ console.log = (...args) => { process.stderr.write(args.map(String).join(' ') + '\n'); };
252
+ console.info = console.log;
253
+ console.warn = console.log;
249
254
  try {
250
255
  stdioTransport = new stdio_js_1.StdioServerTransport(process.stdin, process.stdout);
251
256
  await mcp.connect(stdioTransport);
252
- console.info('Stdio: connected to parent process over stdio');
257
+ console.error('Stdio: connected to parent process over stdio');
253
258
  // When running over stdio we do not start the HTTP server; stay alive
254
259
  // and let the parent coordinate messages. Return a promise that
255
260
  // resolves when the transport closes.
@@ -261,6 +266,10 @@ async function startMcpServer() {
261
266
  catch (err) {
262
267
  console.error('Stdio: failed to start transport, falling back to HTTP:', err);
263
268
  stdioTransport = null;
269
+ // restore console in case we fall back to HTTP server mode
270
+ console.log = _orig.log;
271
+ console.info = _orig.info;
272
+ console.warn = _orig.warn;
264
273
  }
265
274
  }
266
275
  const pendingPosts = [];
@@ -30,7 +30,9 @@ async function runLighthouseAudit(url, opts) {
30
30
  // Run via npx to ensure local package is used
31
31
  const cmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
32
32
  const reportJson = await new Promise((resolve, reject) => {
33
- execFile(cmd, args, { maxBuffer: 10 * 1024 * 1024 }, (err, stdout, stderr) => {
33
+ // Use a shell on Windows to ensure .cmd/.bat wrappers are executed
34
+ // correctly (avoids spawn EINVAL in some environments).
35
+ execFile(cmd, args, { maxBuffer: 10 * 1024 * 1024, shell: true, env: process.env }, (err, stdout, stderr) => {
34
36
  if (err) {
35
37
  const message = stderr || (err && err.message) || String(err);
36
38
  return reject(new Error(message));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mcp-optimizer",
3
- "version": "0.0.4-alpha.1",
3
+ "version": "0.0.6-alpha.1",
4
4
  "description": "An MCP server that runs Lighthouse audits and enables LLMs to automatically optimize your code.",
5
5
  "main": "dist/index.js",
6
6
  "bin": {
package/src/mcpServer.ts CHANGED
@@ -231,10 +231,15 @@ export async function startMcpServer(): Promise<void> {
231
231
  // launched as a stdio child by an MCP host and use the stdio transport.
232
232
  const shouldUseStdio = (process.stdin && !process.stdin.isTTY) && (process.stdout && !process.stdout.isTTY);
233
233
  if (shouldUseStdio) {
234
+ // Redirect console output to stderr to avoid corrupting the JSON stdio protocol
235
+ const _orig = { log: console.log, info: console.info, warn: console.warn };
236
+ console.log = (...args: any[]) => { process.stderr.write(args.map(String).join(' ') + '\n'); };
237
+ console.info = console.log;
238
+ console.warn = console.log;
234
239
  try {
235
240
  stdioTransport = new StdioServerTransport(process.stdin, process.stdout);
236
241
  await mcp.connect(stdioTransport as unknown as Transport);
237
- console.info('Stdio: connected to parent process over stdio');
242
+ console.error('Stdio: connected to parent process over stdio');
238
243
  // When running over stdio we do not start the HTTP server; stay alive
239
244
  // and let the parent coordinate messages. Return a promise that
240
245
  // resolves when the transport closes.
@@ -245,6 +250,10 @@ export async function startMcpServer(): Promise<void> {
245
250
  } catch (err) {
246
251
  console.error('Stdio: failed to start transport, falling back to HTTP:', err);
247
252
  stdioTransport = null;
253
+ // restore console in case we fall back to HTTP server mode
254
+ console.log = _orig.log;
255
+ console.info = _orig.info;
256
+ console.warn = _orig.warn;
248
257
  }
249
258
  }
250
259
  const pendingPosts: Array<{ body: string; url: string | undefined; headers: any }> = [];
@@ -31,7 +31,9 @@ export async function runLighthouseAudit(
31
31
  const cmd = process.platform === 'win32' ? 'npx.cmd' : 'npx';
32
32
 
33
33
  const reportJson: string = await new Promise((resolve, reject) => {
34
- execFile(cmd, args, { maxBuffer: 10 * 1024 * 1024 }, (err: any, stdout: string, stderr: string) => {
34
+ // Use a shell on Windows to ensure .cmd/.bat wrappers are executed
35
+ // correctly (avoids spawn EINVAL in some environments).
36
+ execFile(cmd, args, { maxBuffer: 10 * 1024 * 1024, shell: true, env: process.env }, (err: any, stdout: string, stderr: string) => {
35
37
  if (err) {
36
38
  const message = stderr || (err && err.message) || String(err);
37
39
  return reject(new Error(message));