lighthouse-mcp 0.1.10 → 0.1.12
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/build/index.js +57 -1
- package/package.json +1 -1
package/build/index.js
CHANGED
|
@@ -4,6 +4,40 @@ import { StdioServerTransport } from '@modelcontextprotocol/sdk/server/stdio.js'
|
|
|
4
4
|
import { CallToolRequestSchema, ErrorCode, ListToolsRequestSchema, McpError, } from '@modelcontextprotocol/sdk/types.js';
|
|
5
5
|
import lighthouse from 'lighthouse';
|
|
6
6
|
import * as chromeLauncher from 'chrome-launcher';
|
|
7
|
+
import os from 'os';
|
|
8
|
+
import fs from 'fs';
|
|
9
|
+
import path from 'path';
|
|
10
|
+
// Workaround for modelcontextprotocol/typescript-sdk#1380
|
|
11
|
+
// In some Zod runtimes, the method literal is stored under `_def.values[0]`
|
|
12
|
+
// instead of `_def.value` / `.value`, causing "Schema method literal must be a string"
|
|
13
|
+
// during Server initialization. This patches setRequestHandler to handle both cases.
|
|
14
|
+
const originalSetRequestHandler = Server.prototype.setRequestHandler;
|
|
15
|
+
Server.prototype.setRequestHandler = function patchedSetRequestHandler(requestSchema, handler) {
|
|
16
|
+
try {
|
|
17
|
+
return originalSetRequestHandler.call(this, requestSchema, handler);
|
|
18
|
+
}
|
|
19
|
+
catch (err) {
|
|
20
|
+
if (err?.message !== 'Schema method literal must be a string')
|
|
21
|
+
throw err;
|
|
22
|
+
// Attempt to fix the schema by copying values[0] to value
|
|
23
|
+
try {
|
|
24
|
+
const shape = requestSchema?.shape ?? requestSchema?._def?.shape?.();
|
|
25
|
+
const methodSchema = shape?.method;
|
|
26
|
+
const def = methodSchema?._def;
|
|
27
|
+
const maybeValue = Array.isArray(def?.values) ? def.values[0] : undefined;
|
|
28
|
+
if (typeof maybeValue === 'string') {
|
|
29
|
+
if (def && def.value === undefined)
|
|
30
|
+
def.value = maybeValue;
|
|
31
|
+
if (methodSchema && methodSchema.value === undefined)
|
|
32
|
+
methodSchema.value = maybeValue;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
// If patching fails, rethrow the original error
|
|
37
|
+
}
|
|
38
|
+
return originalSetRequestHandler.call(this, requestSchema, handler);
|
|
39
|
+
}
|
|
40
|
+
};
|
|
7
41
|
const isValidAuditArgs = (args) => {
|
|
8
42
|
return (typeof args === 'object' &&
|
|
9
43
|
args !== null &&
|
|
@@ -111,7 +145,29 @@ class LighthouseServer {
|
|
|
111
145
|
throw new McpError(ErrorCode.InvalidParams, 'Invalid audit arguments');
|
|
112
146
|
}
|
|
113
147
|
try {
|
|
114
|
-
|
|
148
|
+
// Ensure temp directory exists and is writable (fixes #19 - Windows EPERM)
|
|
149
|
+
// On Windows, os.tmpdir() reads TEMP -> TMP -> USERPROFILE, so we verify
|
|
150
|
+
// the resolved path is usable before launching Chrome.
|
|
151
|
+
const tmpDir = os.tmpdir();
|
|
152
|
+
try {
|
|
153
|
+
fs.accessSync(tmpDir, fs.constants.W_OK);
|
|
154
|
+
}
|
|
155
|
+
catch {
|
|
156
|
+
// If the default temp dir isn't writable, create a fallback in the user's home
|
|
157
|
+
const fallbackTmp = path.join(os.homedir(), '.lighthouse-tmp');
|
|
158
|
+
if (!fs.existsSync(fallbackTmp)) {
|
|
159
|
+
fs.mkdirSync(fallbackTmp, { recursive: true });
|
|
160
|
+
}
|
|
161
|
+
process.env.TEMP = fallbackTmp;
|
|
162
|
+
process.env.TMP = fallbackTmp;
|
|
163
|
+
process.env.TMPDIR = fallbackTmp;
|
|
164
|
+
}
|
|
165
|
+
// Explicitly pass process.env so MCP-configured env vars (TEMP, TMP, TMPDIR)
|
|
166
|
+
// propagate to the Chrome child process on all platforms.
|
|
167
|
+
const chrome = await chromeLauncher.launch({
|
|
168
|
+
chromeFlags: ['--headless', '--no-sandbox'],
|
|
169
|
+
envVars: process.env,
|
|
170
|
+
});
|
|
115
171
|
const options = {
|
|
116
172
|
logLevel: 'info',
|
|
117
173
|
output: 'json',
|