返回 CodeWhale
redact-mcp-oauth-logs.mjs
根目录 / crates / engine / extension-host / scripts / redact-mcp-oauth-logs.mjs
1 function replaceExactlyOnce(source, pattern, replacement, label) {
2 const matches = [...source.matchAll(pattern)]
3 if (matches.length !== 1) {
4 throw new Error(`Expected one ${label} in the MCP SDK bundle, found ${matches.length}`)
5 }
6 return source.replace(pattern, replacement)
7 }
8
9 export function redactMcpOAuthLogs(bundle) {
10 let output = replaceExactlyOnce(
11 bundle,
12 /const errorMessage = `\$\{statusCode \? `HTTP \$\{statusCode\}: ` : ""\}Invalid OAuth error response: \$\{error2\}\. Raw body: \$\{body\}`;/g,
13 'const errorMessage = `${statusCode ? `HTTP ${statusCode}: ` : ""}OAuth error response details omitted`;',
14 'raw OAuth response body interpolation',
15 )
16 output = replaceExactlyOnce(
17 output,
18 /console\.warn\(`\[mcp-sdk\] OAuth \$\{JSON\.stringify\(error2\.code\)\} — \$\{action\}\. Cause: \$\{JSON\.stringify\(error2\.message\)\}`\);/g,
19 'console.warn(`[mcp-sdk] OAuth authorization failed — ${action}; details omitted.`);',
20 'OAuth error detail log',
21 )
22 return replaceExactlyOnce(
23 output,
24 /console\.warn\(`\[mcp-sdk\] Could not refresh OAuth tokens; falling back to a new authorization request\. Cause: \$\{JSON\.stringify\(error2 instanceof Error \? error2\.message : String\(error2\)\)\}`\);/g,
25 'console.warn("[mcp-sdk] Could not refresh OAuth tokens; falling back to a new authorization request.");',
26 'refresh-token error detail log',
27 )
28 }
29
29 lines Plain Text